goccy wip

This commit is contained in:
Mike Farah 2023-10-10 14:28:53 +11:00
parent f3743204ed
commit e4894528a3
4 changed files with 60 additions and 17 deletions

View File

@ -58,6 +58,13 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap) er
case ast.FloatType:
o.Kind = ScalarNode
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:
o.Kind = ScalarNode
o.Tag = "!!str"

View File

@ -20,7 +20,7 @@ func NewGoccyYAMLDecoder() Decoder {
func (dec *goccyYamlDecoder) Init(reader io.Reader) error {
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
}

View File

@ -109,18 +109,54 @@ var goccyYamlFormatScenarios = []formatScenario{
// input: "# head comment\na: #line comment\n meow\n",
// 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,
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: "trailing comment",
input: "test:",
expected: "test:",
},
// {
// 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) {

View File

@ -7,12 +7,12 @@ import (
)
var yamlFormatScenarios = []formatScenario{
{
description: "basic - null",
skipDoc: true,
input: "null",
expected: "null\n",
},
// {
// description: "basic - null",
// skipDoc: true,
// input: "null",
// expected: "null\n",
// },
// {
// description: "basic - ~",
// skipDoc: true,
@ -86,7 +86,7 @@ var yamlParseScenarios = []expressionScenario{
}
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) {