File: test.lua

package info (click to toggle)
lua-sandbox-extensions 0~git20161128-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,596 kB
  • ctags: 1,458
  • sloc: ansic: 4,402; cpp: 2,102; makefile: 8
file content (28 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.

local string = require "string"
local util = require "heka.util"

local t = {toplevel=0, struct = { item0 = 0, item1 = 1, item2 = {nested = "n1"}}}
local fa = {}
local fb = {}

local function table_to_fields()
    util.table_to_fields(t, fa, nil)
    assert(fa.toplevel == 0, fa.toplevel)
    assert(fa["struct.item0"] == 0, fa["struct.item0"])
    assert(fa["struct.item1"] == 1, fa["struct.item1"])
    assert(fa["struct.item2.nested"] == "n1", fa["struct.item2.nested"])
    util.table_to_fields(t, fb, nil, "_", 2)
    assert(fb.toplevel == 0, fb.toplevel)
    assert(fb["struct_item0"] == 0, fb["struct_item0"])
    assert(fb["struct_item1"] == 1, fb["struct_item1"])
    assert(fb["struct_item2"] == '{"nested":"n1"}', fb["struct_item2"])
end

function process_message ()
    table_to_fields()
    return 0
end