mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-06 04:45:39 +00:00
goccy wip
This commit is contained in:
parent
f3743204ed
commit
e4894528a3
@ -58,6 +58,13 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap) er
|
|||||||
case ast.FloatType:
|
case ast.FloatType:
|
||||||
o.Kind = ScalarNode
|
o.Kind = ScalarNode
|
||||||
o.Tag = "!!float"
|
o.Tag = "!!float"
|
||||||
|
case ast.BoolType:
|
||||||
|
o.Kind = ScalarNode
|
||||||
|
o.Tag = "!!bool"
|
||||||
|
case ast.NullType:
|
||||||
|
o.Kind = ScalarNode
|
||||||
|
o.Tag = "!!null"
|
||||||
|
o.Value = node.GetToken().Value
|
||||||
case ast.StringType:
|
case ast.StringType:
|
||||||
o.Kind = ScalarNode
|
o.Kind = ScalarNode
|
||||||
o.Tag = "!!str"
|
o.Tag = "!!str"
|
||||||
|
|||||||
@ -20,7 +20,7 @@ func NewGoccyYAMLDecoder() Decoder {
|
|||||||
|
|
||||||
func (dec *goccyYamlDecoder) Init(reader io.Reader) error {
|
func (dec *goccyYamlDecoder) Init(reader io.Reader) error {
|
||||||
dec.cm = yaml.CommentMap{}
|
dec.cm = yaml.CommentMap{}
|
||||||
dec.decoder = *yaml.NewDecoder(reader, yaml.CommentToMap(dec.cm))
|
dec.decoder = *yaml.NewDecoder(reader, yaml.CommentToMap(dec.cm), yaml.UseOrderedMap())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -109,18 +109,54 @@ var goccyYamlFormatScenarios = []formatScenario{
|
|||||||
// input: "# head comment\na: #line comment\n meow\n",
|
// input: "# head comment\na: #line comment\n meow\n",
|
||||||
// expected: "# head comment\na: meow #line comment\n", // go-yaml does this
|
// expected: "# head comment\na: meow #line comment\n", // go-yaml does this
|
||||||
// },
|
// },
|
||||||
|
// {
|
||||||
|
// description: "basic - foot comment",
|
||||||
|
// skipDoc: true,
|
||||||
|
// input: "a: meow\n# foot comment\n",
|
||||||
|
// expected: "a: meow\n# foot comment\n",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// description: "basic - foot comment",
|
||||||
|
// skipDoc: true,
|
||||||
|
// input: "a: meow\nb: woof\n# foot comment\n",
|
||||||
|
// expected: "a: meow\nb: woof\n# foot comment\n",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// description: "basic - boolean",
|
||||||
|
// skipDoc: true,
|
||||||
|
// input: "true\n",
|
||||||
|
// expected: "true\n",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// description: "basic - null",
|
||||||
|
// skipDoc: true,
|
||||||
|
// input: "a: null\n",
|
||||||
|
// expected: "a: null\n",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// description: "basic - ~",
|
||||||
|
// skipDoc: true,
|
||||||
|
// input: "a: ~\n",
|
||||||
|
// expected: "a: ~\n",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// description: "basic - ~",
|
||||||
|
// skipDoc: true,
|
||||||
|
// input: "null\n",
|
||||||
|
// expected: "null\n",
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
description: "basic - foot comment",
|
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
input: "a: meow\n# foot comment\n",
|
description: "trailing comment",
|
||||||
expected: "a: meow\n# foot comment\n",
|
input: "test:",
|
||||||
},
|
expected: "test:",
|
||||||
{
|
|
||||||
description: "basic - foot comment",
|
|
||||||
skipDoc: true,
|
|
||||||
input: "a: meow\nb: woof\n# foot comment\n",
|
|
||||||
expected: "a: meow\nb: woof\n# foot comment\n",
|
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// skipDoc: true,
|
||||||
|
// description: "trailing comment",
|
||||||
|
// input: "test:\n# this comment will be removed",
|
||||||
|
// expected: "test:\n# this comment will be removed",
|
||||||
|
// },
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGoccyYamlScenario(t *testing.T, s formatScenario) {
|
func testGoccyYamlScenario(t *testing.T, s formatScenario) {
|
||||||
|
|||||||
@ -7,12 +7,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var yamlFormatScenarios = []formatScenario{
|
var yamlFormatScenarios = []formatScenario{
|
||||||
{
|
// {
|
||||||
description: "basic - null",
|
// description: "basic - null",
|
||||||
skipDoc: true,
|
// skipDoc: true,
|
||||||
input: "null",
|
// input: "null",
|
||||||
expected: "null\n",
|
// expected: "null\n",
|
||||||
},
|
// },
|
||||||
// {
|
// {
|
||||||
// description: "basic - ~",
|
// description: "basic - ~",
|
||||||
// skipDoc: true,
|
// skipDoc: true,
|
||||||
@ -86,7 +86,7 @@ var yamlParseScenarios = []expressionScenario{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testYamlScenario(t *testing.T, s formatScenario) {
|
func testYamlScenario(t *testing.T, s formatScenario) {
|
||||||
test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewYamlDecoder(ConfiguredYamlPreferences), NewYamlEncoder(2, false, ConfiguredYamlPreferences)), s.description)
|
test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewGoccyYAMLDecoder(), NewYamlEncoder(2, false, ConfiguredYamlPreferences)), s.description)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestYamlParseScenarios(t *testing.T) {
|
func TestYamlParseScenarios(t *testing.T) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user