mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-10 08:35:42 +00:00
Add initial test for Lua encoder
Boilerplate mostly copied from toml_test.go
This commit is contained in:
parent
58d14f7ea9
commit
0b54f9caca
51
pkg/yqlib/lua_test.go
Normal file
51
pkg/yqlib/lua_test.go
Normal file
@ -0,0 +1,51 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/mikefarah/yq/v4/test"
|
||||
)
|
||||
|
||||
var luaScenarios = []formatScenario{
|
||||
{
|
||||
skipDoc: true,
|
||||
description: "Basic example",
|
||||
input: "hello: world\n? look: non-string keys\n: True\nnumbers: [123,456]\n",
|
||||
expected: "return {[\"hello\"]=\"world\";[{[\"look\"]=\"non-string keys\";}]=true;[\"numbers\"]={123,456,};};\n",
|
||||
scenarioType: "encode",
|
||||
},
|
||||
}
|
||||
|
||||
func testLuaScenario(t *testing.T, s formatScenario) {
|
||||
switch s.scenarioType {
|
||||
case "encode":
|
||||
test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewYamlDecoder(ConfiguredYamlPreferences), NewLuaEncoder(ConfiguredLuaPreferences)), s.description)
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled scenario type %q", s.scenarioType))
|
||||
}
|
||||
}
|
||||
|
||||
func documentLuaScenario(t *testing.T, w *bufio.Writer, i interface{}) {
|
||||
s := i.(formatScenario)
|
||||
|
||||
if s.skipDoc {
|
||||
return
|
||||
}
|
||||
switch s.scenarioType {
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled scenario type %q", s.scenarioType))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLuaScenarios(t *testing.T) {
|
||||
for _, tt := range luaScenarios {
|
||||
testLuaScenario(t, tt)
|
||||
}
|
||||
genericScenarios := make([]interface{}, len(luaScenarios))
|
||||
for i, s := range luaScenarios {
|
||||
genericScenarios[i] = s
|
||||
}
|
||||
documentScenarios(t, "usage", "lua", genericScenarios, documentLuaScenario)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user