mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-10 00:05:38 +00:00
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
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)
|
|
}
|