Goccy wip

This commit is contained in:
Mike Farah 2023-10-17 14:50:32 +11:00
parent e4894528a3
commit cb3e8ef323
5 changed files with 147 additions and 142 deletions

View File

@ -92,7 +92,9 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap) er
// to solve the multiline > problem
o.Value = astLiteral.Value.Value
case ast.TagType:
o.UnmarshalGoccyYAML(node.(*ast.TagNode).Value, cm)
if err := o.UnmarshalGoccyYAML(node.(*ast.TagNode).Value, cm); err != nil {
return err
}
o.Tag = node.(*ast.TagNode).Start.Value
case ast.MappingType:
log.Debugf("UnmarshalYAML - a mapping node")

View File

@ -34,7 +34,9 @@ func (dec *goccyYamlDecoder) Decode() (*CandidateNode, error) {
}
candidateNode := &CandidateNode{}
candidateNode.UnmarshalGoccyYAML(ast, dec.cm)
if err := candidateNode.UnmarshalGoccyYAML(ast, dec.cm); err != nil {
return nil, err
}
return candidateNode, nil
}

View File

@ -7,150 +7,150 @@ import (
)
var goccyYamlFormatScenarios = []formatScenario{
// {
// description: "basic - 3",
// skipDoc: true,
// input: "3",
// expected: "3\n",
// },
// {
// description: "basic - 3.1",
// skipDoc: true,
// input: "3.1",
// expected: "3.1\n",
// },
// {
// description: "basic - 3.1",
// skipDoc: true,
// input: "mike: 3",
// expected: "mike: 3\n",
// },
// {
// description: "basic - 3.1",
// skipDoc: true,
// input: "{mike: 3}",
// expected: "{mike: 3}\n",
// },
// {
// description: "basic - map multiple entries",
// skipDoc: true,
// input: "mike: 3\nfred: 12\n",
// expected: "mike: 3\nfred: 12\n",
// },
// {
// description: "basic - 3.1",
// skipDoc: true,
// input: "{\nmike: 3\n}",
// expected: "{mike: 3}\n",
// },
// {
// description: "basic - 3.1",
// skipDoc: true,
// input: "mike: !!cat 3",
// expected: "mike: !!cat 3\n",
// },
// {
// description: "basic - 3.1",
// skipDoc: true,
// input: "- 3",
// expected: "- 3\n",
// },
// {
// description: "basic - 3.1",
// skipDoc: true,
// input: "[3]",
// expected: "[3]\n",
// },
// {
// description: "basic - plain string",
// skipDoc: true,
// input: `a: meow`,
// expected: "a: meow\n",
// },
// {
// description: "basic - double quoted string",
// skipDoc: true,
// input: `a: "meow"`,
// expected: "a: \"meow\"\n",
// },
// {
// description: "basic - single quoted string",
// skipDoc: true,
// input: `a: 'meow'`,
// expected: "a: 'meow'\n",
// },
// {
// description: "basic - string block",
// skipDoc: true,
// input: "a: |\n meow\n",
// expected: "a: |\n meow\n",
// },
// {
// description: "basic - long string",
// skipDoc: true,
// input: "a: the cute cat wrote a long sentence that wasn't wrapped at all.\n",
// expected: "a: the cute cat wrote a long sentence that wasn't wrapped at all.\n",
// },
// {
// description: "basic - string block",
// skipDoc: true,
// input: "a: |-\n meow\n",
// expected: "a: |-\n meow\n",
// },
// {
// description: "basic - line comment",
// skipDoc: true,
// input: "a: meow # line comment\n",
// expected: "a: meow # line comment\n",
// },
// {
// description: "basic - line comment",
// skipDoc: true,
// 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 - 3",
skipDoc: true,
input: "3",
expected: "3\n",
},
{
description: "basic - 3.1",
skipDoc: true,
input: "3.1",
expected: "3.1\n",
},
{
description: "basic - 3.1",
skipDoc: true,
input: "mike: 3",
expected: "mike: 3\n",
},
{
description: "basic - 3.1",
skipDoc: true,
input: "{mike: 3}",
expected: "{mike: 3}\n",
},
{
description: "basic - map multiple entries",
skipDoc: true,
input: "mike: 3\nfred: 12\n",
expected: "mike: 3\nfred: 12\n",
},
{
description: "basic - 3.1",
skipDoc: true,
input: "{\nmike: 3\n}",
expected: "{mike: 3}\n",
},
{
description: "basic - 3.1",
skipDoc: true,
input: "mike: !!cat 3",
expected: "mike: !!cat 3\n",
},
{
description: "basic - 3.1",
skipDoc: true,
input: "- 3",
expected: "- 3\n",
},
{
description: "basic - 3.1",
skipDoc: true,
input: "[3]",
expected: "[3]\n",
},
{
description: "basic - plain string",
skipDoc: true,
input: `a: meow`,
expected: "a: meow\n",
},
{
description: "basic - double quoted string",
skipDoc: true,
input: `a: "meow"`,
expected: "a: \"meow\"\n",
},
{
description: "basic - single quoted string",
skipDoc: true,
input: `a: 'meow'`,
expected: "a: 'meow'\n",
},
{
description: "basic - string block",
skipDoc: true,
input: "a: |\n meow\n",
expected: "a: |\n meow\n",
},
{
description: "basic - long string",
skipDoc: true,
input: "a: the cute cat wrote a long sentence that wasn't wrapped at all.\n",
expected: "a: the cute cat wrote a long sentence that wasn't wrapped at all.\n",
},
{
description: "basic - string block",
skipDoc: true,
input: "a: |-\n meow\n",
expected: "a: |-\n meow\n",
},
{
description: "basic - line comment",
skipDoc: true,
input: "a: meow # line comment\n",
expected: "a: meow # line comment\n",
},
{
description: "basic - line comment",
skipDoc: true,
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",
// },
{
skipDoc: true,
description: "trailing comment",
input: "test:",
expected: "test:",
},
// {
// skipDoc: true,
// description: "trailing comment",
// input: "test:",
// expected: "test:",
// },
// {
// skipDoc: true,
// description: "trailing comment",

View File

@ -86,7 +86,7 @@ var yamlParseScenarios = []expressionScenario{
}
func testYamlScenario(t *testing.T, s formatScenario) {
test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewGoccyYAMLDecoder(), NewYamlEncoder(2, false, ConfiguredYamlPreferences)), s.description)
test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewYamlDecoder(NewDefaultYamlPreferences()), NewYamlEncoder(2, false, ConfiguredYamlPreferences)), s.description)
}
func TestYamlParseScenarios(t *testing.T) {

View File

@ -249,4 +249,5 @@ yamld
yqlib
yuin
zabbix
tonumber
tonumber
noyaml