1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00

Removed custom value parsing logic

This commit is contained in:
Mike Farah
2020-01-20 08:42:08 +11:00
parent 8a65822b0b
commit 1a4d8158ba
6 changed files with 16 additions and 40 deletions

View File

@@ -1,8 +1,6 @@
package yqlib
import (
"strconv"
yaml "gopkg.in/yaml.v3"
)
@@ -18,30 +16,8 @@ func NewValueParser() ValueParser {
}
func (v *valueParser) Parse(argument string, customTag string) *yaml.Node {
var err interface{}
var tag = customTag
if tag == "" {
_, err = strconv.ParseBool(argument)
if err == nil {
tag = "!!bool"
}
_, err = strconv.ParseFloat(argument, 64)
if err == nil {
tag = "!!float"
}
_, err = strconv.ParseInt(argument, 10, 64)
if err == nil {
tag = "!!int"
}
if argument == "null" {
tag = "!!null"
}
if argument == "[]" {
return &yaml.Node{Tag: "!!seq", Kind: yaml.SequenceNode}
}
if argument == "[]" {
return &yaml.Node{Tag: "!!seq", Kind: yaml.SequenceNode}
}
log.Debugf("parsed value '%v', tag: '%v'", argument, tag)
return &yaml.Node{Value: argument, Tag: tag, Kind: yaml.ScalarNode}
return &yaml.Node{Value: argument, Tag: customTag, Kind: yaml.ScalarNode}
}

View File

@@ -13,13 +13,9 @@ var parseValueTests = []struct {
expectedTag string
testDescription string
}{
{"true", "", "!!bool", "boolean"},
{"true", "!!str", "!!str", "boolean forced as string"},
{"3.4", "", "!!float", "float"},
{"1212121", "", "!!int", "big number"},
{"1212121.1", "", "!!float", "big float number"},
{"3", "", "!!int", "int"},
{"null", "", "!!null", "null"},
{"3", "!!int", "!!int", "int"},
{"cat", "", "", "default"},
}
func TestValueParserParse(t *testing.T) {