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 // to solve the multiline > problem
o.Value = astLiteral.Value.Value o.Value = astLiteral.Value.Value
case ast.TagType: 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 o.Tag = node.(*ast.TagNode).Start.Value
case ast.MappingType: case ast.MappingType:
log.Debugf("UnmarshalYAML - a mapping node") log.Debugf("UnmarshalYAML - a mapping node")

View File

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

View File

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

View File

@ -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, 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) { func TestYamlParseScenarios(t *testing.T) {

View File

@ -250,3 +250,4 @@ yqlib
yuin yuin
zabbix zabbix
tonumber tonumber
noyaml