From cb3e8ef32313bd3f7f0b19173134f466af7f300c Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Tue, 17 Oct 2023 14:50:32 +1100 Subject: [PATCH] Goccy wip --- pkg/yqlib/candidate_node_goccy_yaml.go | 4 +- pkg/yqlib/decoder_goccy_yaml.go | 4 +- pkg/yqlib/goccy_yaml_test.go | 276 ++++++++++++------------- pkg/yqlib/yaml_test.go | 2 +- project-words.txt | 3 +- 5 files changed, 147 insertions(+), 142 deletions(-) diff --git a/pkg/yqlib/candidate_node_goccy_yaml.go b/pkg/yqlib/candidate_node_goccy_yaml.go index bed150b5..c29f7419 100644 --- a/pkg/yqlib/candidate_node_goccy_yaml.go +++ b/pkg/yqlib/candidate_node_goccy_yaml.go @@ -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") diff --git a/pkg/yqlib/decoder_goccy_yaml.go b/pkg/yqlib/decoder_goccy_yaml.go index c775a9f3..7494d7cd 100644 --- a/pkg/yqlib/decoder_goccy_yaml.go +++ b/pkg/yqlib/decoder_goccy_yaml.go @@ -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 } diff --git a/pkg/yqlib/goccy_yaml_test.go b/pkg/yqlib/goccy_yaml_test.go index ecdd526c..018a849a 100644 --- a/pkg/yqlib/goccy_yaml_test.go +++ b/pkg/yqlib/goccy_yaml_test.go @@ -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", diff --git a/pkg/yqlib/yaml_test.go b/pkg/yqlib/yaml_test.go index 6b51de58..6305220b 100644 --- a/pkg/yqlib/yaml_test.go +++ b/pkg/yqlib/yaml_test.go @@ -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) { diff --git a/project-words.txt b/project-words.txt index 2371c1fb..a68e7542 100644 --- a/project-words.txt +++ b/project-words.txt @@ -249,4 +249,5 @@ yamld yqlib yuin zabbix -tonumber \ No newline at end of file +tonumber +noyaml \ No newline at end of file