goccy wip

This commit is contained in:
Mike Farah 2023-10-05 20:22:53 +11:00
parent 45802f384c
commit 0fceef741b
2 changed files with 108 additions and 45 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/goccy/go-yaml/ast"
goccyToken "github.com/goccy/go-yaml/token"
)
func (o *CandidateNode) goccyDecodeIntoChild(childNode ast.Node, anchorMap map[string]*CandidateNode) (*CandidateNode, error) {
@ -16,6 +17,7 @@ func (o *CandidateNode) goccyDecodeIntoChild(childNode ast.Node, anchorMap map[s
func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, anchorMap map[string]*CandidateNode) error {
log.Debugf("UnmarshalYAML %v", node)
log.Debugf("UnmarshalYAML %v", node.Type().String())
log.Debugf("UnmarshalYAML Value: %v", node.String())
o.Value = node.String()
switch node.Type() {
@ -28,6 +30,25 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, anchorMap map[string]*
case ast.StringType:
o.Kind = ScalarNode
o.Tag = "!!str"
switch node.GetToken().Type {
case goccyToken.SingleQuoteType:
o.Style = SingleQuotedStyle
case goccyToken.DoubleQuoteType:
o.Style = DoubleQuotedStyle
}
o.Value = node.(*ast.StringNode).Value
log.Debugf("string value %v", node.(*ast.StringNode).Value)
case ast.LiteralType:
o.Kind = ScalarNode
o.Tag = "!!str"
o.Style = LiteralStyle
astLiteral := node.(*ast.LiteralNode)
if astLiteral.Start.Type == goccyToken.FoldedType {
o.Style = FoldedStyle
}
log.Debug("startvalue: %v ", node.(*ast.LiteralNode).Start.Value)
log.Debug("startvalue: %v ", node.(*ast.LiteralNode).Start.Type)
o.Value = astLiteral.Value.Value
case ast.TagType:
o.UnmarshalGoccyYAML(node.(*ast.TagNode).Value, anchorMap)
o.Tag = node.(*ast.TagNode).Start.Value

View File

@ -7,53 +7,95 @@ 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 - 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 - 3",
description: "basic - string block",
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 - 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",
input: "a: >\n meow\n",
expected: "a: >\n meow\n",
},
}