From 3a372ef9e005dea3fea1844b1fd8829a9d41dde6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 3 Aug 2023 19:30:24 +0200 Subject: [PATCH] Additional Lua output tests --- pkg/yqlib/lua_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pkg/yqlib/lua_test.go b/pkg/yqlib/lua_test.go index 899e6657..90dc4a19 100644 --- a/pkg/yqlib/lua_test.go +++ b/pkg/yqlib/lua_test.go @@ -16,6 +16,48 @@ var luaScenarios = []formatScenario{ expected: "return {[\"hello\"]=\"world\";[{[\"look\"]=\"non-string keys\";}]=true;[\"numbers\"]={123,456,};};\n", scenarioType: "encode", }, + { + skipDoc: true, + description: "Sequence", + input: "- a\n- b\n- c\n", + expected: "return {\"a\",\"b\",\"c\",};\n", + scenarioType: "encode", + }, + { + skipDoc: true, + description: "Mapping", + input: "a: b\nc:\n d: e\nf: 0\n", + expected: "return {[\"a\"]=\"b\";[\"c\"]={[\"d\"]=\"e\";};[\"f\"]=0;};\n", + scenarioType: "encode", + }, + { + skipDoc: true, + description: "Scalar str", + input: "str: |\n foo\n bar\n", + expected: "return {[\"str\"]=\"foo\\nbar\\n\";};\n", + scenarioType: "encode", + }, + { + skipDoc: true, + description: "Scalar null", + input: "x: null\n", + expected: "return {[\"x\"]=nil;};\n", + scenarioType: "encode", + }, + { + skipDoc: true, + description: "Scalar int", + input: "- 1\n- 2\n- 0x10\n- -999\n", + expected: "return {1,2,0x10,-999,};\n", + scenarioType: "encode", + }, + { + skipDoc: true, + description: "Scalar float", + input: "- 1.0\n- 3.14\n- 1e100\n- .Inf\n- .NAN\n", + expected: "return {1.0,3.14,1e100,(1/0),(0/0),};\n", + scenarioType: "encode", + }, } func testLuaScenario(t *testing.T, s formatScenario) {