mirror of
https://github.com/mikefarah/yq.git
synced 2025-03-15 16:37:46 +00:00
Fixing tests
This commit is contained in:
parent
c8f35d912d
commit
b9a952ae6e
@ -174,8 +174,7 @@ func (o *CandidateNode) goccyProcessMappingValueNode(mappingEntry *ast.MappingVa
|
|||||||
if mappingEntry.FootComment != nil {
|
if mappingEntry.FootComment != nil {
|
||||||
valueNode.FootComment = mappingEntry.FootComment.String()
|
valueNode.FootComment = mappingEntry.FootComment.String()
|
||||||
}
|
}
|
||||||
|
o.AddKeyValueChild(keyNode, valueNode)
|
||||||
o.Content = append(o.Content, keyNode, valueNode)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -108,22 +108,6 @@ func (o *CandidateNode) decodeIntoChild(childNode *yaml.Node, anchorMap map[stri
|
|||||||
func (o *CandidateNode) UnmarshalYAML(node *yaml.Node, anchorMap map[string]*CandidateNode) error {
|
func (o *CandidateNode) UnmarshalYAML(node *yaml.Node, anchorMap map[string]*CandidateNode) error {
|
||||||
log.Debugf("UnmarshalYAML %v", node.Tag)
|
log.Debugf("UnmarshalYAML %v", node.Tag)
|
||||||
switch node.Kind {
|
switch node.Kind {
|
||||||
// case yaml.DocumentNode:
|
|
||||||
// log.Debugf("UnmarshalYAML - a document")
|
|
||||||
// o.Kind = DocumentNode
|
|
||||||
// o.copyFromYamlNode(node, anchorMap)
|
|
||||||
// if len(node.Content) == 0 {
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// singleChild, err := o.decodeIntoChild(node.Content[0], anchorMap)
|
|
||||||
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// o.Content = []*CandidateNode{singleChild}
|
|
||||||
// log.Debugf("UnmarshalYAML - finished document node")
|
|
||||||
// return nil
|
|
||||||
case yaml.AliasNode:
|
case yaml.AliasNode:
|
||||||
log.Debug("UnmarshalYAML - alias from yaml: %v", o.Tag)
|
log.Debug("UnmarshalYAML - alias from yaml: %v", o.Tag)
|
||||||
o.Kind = AliasNode
|
o.Kind = AliasNode
|
||||||
@ -197,19 +181,6 @@ func (o *CandidateNode) UnmarshalYAML(node *yaml.Node, anchorMap map[string]*Can
|
|||||||
func (o *CandidateNode) MarshalYAML() (*yaml.Node, error) {
|
func (o *CandidateNode) MarshalYAML() (*yaml.Node, error) {
|
||||||
log.Debug("MarshalYAML to yaml: %v", o.Tag)
|
log.Debug("MarshalYAML to yaml: %v", o.Tag)
|
||||||
switch o.Kind {
|
switch o.Kind {
|
||||||
// case DocumentNode:
|
|
||||||
// log.Debug("MarshalYAML its a document")
|
|
||||||
// target := &yaml.Node{Kind: yaml.DocumentNode}
|
|
||||||
// o.copyToYamlNode(target)
|
|
||||||
|
|
||||||
// singleChild, err := o.Content[0].MarshalYAML()
|
|
||||||
|
|
||||||
// log.Debug("MarshalYAML its a document - singChild is %v", singleChild)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// target.Content = []*yaml.Node{singleChild}
|
|
||||||
// return target, nil
|
|
||||||
case AliasNode:
|
case AliasNode:
|
||||||
log.Debug("MarshalYAML - alias to yaml: %v", o.Tag)
|
log.Debug("MarshalYAML - alias to yaml: %v", o.Tag)
|
||||||
target := &yaml.Node{Kind: yaml.AliasNode}
|
target := &yaml.Node{Kind: yaml.AliasNode}
|
||||||
|
@ -76,7 +76,6 @@ func (o *CandidateNode) UnmarshalJSON(data []byte) error {
|
|||||||
if err := dec.Decode(childValue); err != nil {
|
if err := dec.Decode(childValue); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Content = append(o.Content, childKey, childValue)
|
o.Content = append(o.Content, childKey, childValue)
|
||||||
}
|
}
|
||||||
// unexpected error
|
// unexpected error
|
||||||
@ -133,10 +132,6 @@ func (o *CandidateNode) MarshalJSON() ([]byte, error) {
|
|||||||
enc.SetEscapeHTML(false) // do not escape html chars e.g. &, <, >
|
enc.SetEscapeHTML(false) // do not escape html chars e.g. &, <, >
|
||||||
|
|
||||||
switch o.Kind {
|
switch o.Kind {
|
||||||
// case DocumentNode:
|
|
||||||
// log.Debugf("MarshalJSON DocumentNode")
|
|
||||||
// err := enc.Encode(o.Content[0])
|
|
||||||
// return buf.Bytes(), err
|
|
||||||
case AliasNode:
|
case AliasNode:
|
||||||
log.Debugf("MarshalJSON AliasNode")
|
log.Debugf("MarshalJSON AliasNode")
|
||||||
err := enc.Encode(o.Alias)
|
err := enc.Encode(o.Alias)
|
||||||
|
@ -112,11 +112,13 @@ func (dec *luaDecoder) convertToYamlNode(ls *lua.LState, lv lua.LValue) *Candida
|
|||||||
} else {
|
} else {
|
||||||
i = 0
|
i = 0
|
||||||
}
|
}
|
||||||
yaml_map.Content = append(yaml_map.Content, dec.convertToYamlNode(ls, k))
|
newKey := dec.convertToYamlNode(ls, k)
|
||||||
|
|
||||||
yv := dec.convertToYamlNode(ls, v)
|
yv := dec.convertToYamlNode(ls, v)
|
||||||
yaml_map.Content = append(yaml_map.Content, yv)
|
yaml_map.AddKeyValueChild(newKey, yv)
|
||||||
|
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
yaml_sequence.Content = append(yaml_sequence.Content, yv)
|
yaml_sequence.AddChild(yv)
|
||||||
}
|
}
|
||||||
k, v = ls.Next(t, k)
|
k, v = ls.Next(t, k)
|
||||||
}
|
}
|
||||||
|
@ -21,3 +21,113 @@ The not equals `!=` operator returns `false` if the LHS is equal to the RHS.
|
|||||||
- select operator [here](https://mikefarah.gitbook.io/yq/operators/select)
|
- select operator [here](https://mikefarah.gitbook.io/yq/operators/select)
|
||||||
|
|
||||||
|
|
||||||
|
## Match string
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
- cat
|
||||||
|
- goat
|
||||||
|
- dog
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.[] | (. == "*at")' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
true
|
||||||
|
true
|
||||||
|
false
|
||||||
|
```
|
||||||
|
|
||||||
|
## Don't match string
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
- cat
|
||||||
|
- goat
|
||||||
|
- dog
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.[] | (. != "*at")' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
false
|
||||||
|
false
|
||||||
|
true
|
||||||
|
```
|
||||||
|
|
||||||
|
## Match number
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
- 3
|
||||||
|
- 4
|
||||||
|
- 5
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.[] | (. == 4)' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
false
|
||||||
|
true
|
||||||
|
false
|
||||||
|
```
|
||||||
|
|
||||||
|
## Don't match number
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
- 3
|
||||||
|
- 4
|
||||||
|
- 5
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.[] | (. != 4)' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
true
|
||||||
|
false
|
||||||
|
true
|
||||||
|
```
|
||||||
|
|
||||||
|
## Match nulls
|
||||||
|
Running
|
||||||
|
```bash
|
||||||
|
yq --null-input 'null == ~'
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
true
|
||||||
|
```
|
||||||
|
|
||||||
|
## Non existent key doesn't equal a value
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a: frog
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq 'select(.b != "thing")' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
a: frog
|
||||||
|
```
|
||||||
|
|
||||||
|
## Two non existent keys are equal
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a: frog
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq 'select(.b == .c)' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
a: frog
|
||||||
|
```
|
||||||
|
|
||||||
|
@ -126,6 +126,22 @@ var jsonScenarios = []formatScenario{
|
|||||||
expected: "[\"cat\"]\n",
|
expected: "[\"cat\"]\n",
|
||||||
scenarioType: "decode",
|
scenarioType: "decode",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "Parse json: deeper: path",
|
||||||
|
input: `{"cat": {"noises": "meow"}}`,
|
||||||
|
expression: ".cat.noises | path",
|
||||||
|
expected: "[\"cat\",\"noises\"]\n",
|
||||||
|
scenarioType: "decode",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "Parse json: array path",
|
||||||
|
input: `{"cat": {"noises": ["meow"]}}`,
|
||||||
|
expression: ".cat.noises[0] | path",
|
||||||
|
expected: "[\"cat\",\"noises\",0]\n",
|
||||||
|
scenarioType: "decode",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "bad json",
|
description: "bad json",
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
@ -342,8 +358,10 @@ func decodeJSON(t *testing.T, jsonString string) *CandidateNode {
|
|||||||
|
|
||||||
func testJSONScenario(t *testing.T, s formatScenario) {
|
func testJSONScenario(t *testing.T, s formatScenario) {
|
||||||
switch s.scenarioType {
|
switch s.scenarioType {
|
||||||
case "encode", "decode":
|
case "encode":
|
||||||
test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewYamlDecoder(ConfiguredYamlPreferences), NewJSONEncoder(s.indent, false, false)), s.description)
|
test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewYamlDecoder(ConfiguredYamlPreferences), NewJSONEncoder(s.indent, false, false)), s.description)
|
||||||
|
case "decode":
|
||||||
|
test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewJSONDecoder(), NewJSONEncoder(s.indent, false, false)), s.description)
|
||||||
case "decode-ndjson":
|
case "decode-ndjson":
|
||||||
test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewJSONDecoder(), NewYamlEncoder(2, false, ConfiguredYamlPreferences)), s.description)
|
test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewJSONDecoder(), NewYamlEncoder(2, false, ConfiguredYamlPreferences)), s.description)
|
||||||
case "roundtrip-ndjson":
|
case "roundtrip-ndjson":
|
||||||
|
@ -31,6 +31,38 @@ cities:
|
|||||||
- Perth
|
- Perth
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "path",
|
||||||
|
expression: ".cities[2] | path",
|
||||||
|
input: `return {
|
||||||
|
["country"] = "Australia"; -- this place
|
||||||
|
["cities"] = {
|
||||||
|
"Sydney",
|
||||||
|
"Melbourne",
|
||||||
|
"Brisbane",
|
||||||
|
"Perth",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
`,
|
||||||
|
expected: "- cities\n- 2\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "path",
|
||||||
|
expression: ".cities[2] | key",
|
||||||
|
input: `return {
|
||||||
|
["country"] = "Australia"; -- this place
|
||||||
|
["cities"] = {
|
||||||
|
"Sydney",
|
||||||
|
"Melbourne",
|
||||||
|
"Brisbane",
|
||||||
|
"Perth",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
`,
|
||||||
|
expected: "2\n",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Basic output example",
|
description: "Basic output example",
|
||||||
scenarioType: "encode",
|
scenarioType: "encode",
|
||||||
|
@ -170,15 +170,15 @@ var anchorOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (!!map)::{b: &meow purr, a: *meow}\n",
|
"D0, P[], (!!map)::{b: &meow purr, a: *meow}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// description: "Dont explode alias and anchor - check alias parent",
|
description: "Dont explode alias and anchor - check alias parent",
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: `{a: &a [1], b: *a}`,
|
document: `{a: &a [1], b: *a}`,
|
||||||
// expression: `.b[]`,
|
expression: `.b[]`,
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[b], (!!str)::cat\n",
|
"D0, P[a 0], (!!int)::1\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
description: "Explode alias and anchor - check alias parent",
|
description: "Explode alias and anchor - check alias parent",
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
|
@ -12,181 +12,181 @@ var equalsOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[a], (!!bool)::true\n",
|
"D0, P[a], (!!bool)::true\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// expression: `(.k | length) == 0`,
|
expression: `(.k | length) == 0`,
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[k], (!!bool)::true\n",
|
"D0, P[k], (!!bool)::true\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: `a: cat`,
|
document: `a: cat`,
|
||||||
// expression: ".a == .b",
|
expression: ".a == .b",
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[a], (!!bool)::false\n",
|
"D0, P[a], (!!bool)::false\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: `a: cat`,
|
document: `a: cat`,
|
||||||
// expression: ".b == .a",
|
expression: ".b == .a",
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[b], (!!bool)::false\n",
|
"D0, P[b], (!!bool)::false\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: "cat",
|
document: "cat",
|
||||||
// document2: "dog",
|
document2: "dog",
|
||||||
// expression: "select(fi==0) == select(fi==1)",
|
expression: "select(fi==0) == select(fi==1)",
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[], (!!bool)::false\n",
|
"D0, P[], (!!bool)::false\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: "{}",
|
document: "{}",
|
||||||
// expression: "(.a == .b) as $x | .",
|
expression: "(.a == .b) as $x | .",
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[], (!!map)::{}\n",
|
"D0, P[], (!!map)::{}\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: "{}",
|
document: "{}",
|
||||||
// expression: ".a == .b",
|
expression: ".a == .b",
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[a], (!!bool)::true\n",
|
"D0, P[a], (!!bool)::true\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: "{}",
|
document: "{}",
|
||||||
// expression: "(.a != .b) as $x | .",
|
expression: "(.a != .b) as $x | .",
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[], (!!map)::{}\n",
|
"D0, P[], (!!map)::{}\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: "{}",
|
document: "{}",
|
||||||
// expression: ".a != .b",
|
expression: ".a != .b",
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[], (!!bool)::false\n",
|
"D0, P[], (!!bool)::false\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: "{a: {b: 10}}",
|
document: "{a: {b: 10}}",
|
||||||
// expression: "select(.c != null)",
|
expression: "select(.c != null)",
|
||||||
// expected: []string{},
|
expected: []string{},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: "{a: {b: 10}}",
|
document: "{a: {b: 10}}",
|
||||||
// expression: "select(.d == .c)",
|
expression: "select(.d == .c)",
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[], (!!map)::{a: {b: 10}}\n",
|
"D0, P[], (!!map)::{a: {b: 10}}\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: "{a: {b: 10}}",
|
document: "{a: {b: 10}}",
|
||||||
// expression: "select(null == .c)",
|
expression: "select(null == .c)",
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[], (!!map)::{a: {b: 10}}\n",
|
"D0, P[], (!!map)::{a: {b: 10}}\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: "{a: { b: {things: \"\"}, f: [1], g: [] }}",
|
document: "{a: { b: {things: \"\"}, f: [1], g: [] }}",
|
||||||
// expression: ".. | select(. == \"\")",
|
expression: ".. | select(. == \"\")",
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[a b things], (!!str)::\n",
|
"D0, P[a b things], (!!str)::\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// description: "Match string",
|
description: "Match string",
|
||||||
// document: `[cat,goat,dog]`,
|
document: `[cat,goat,dog]`,
|
||||||
// expression: `.[] | (. == "*at")`,
|
expression: `.[] | (. == "*at")`,
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[0], (!!bool)::true\n",
|
"D0, P[0], (!!bool)::true\n",
|
||||||
// "D0, P[1], (!!bool)::true\n",
|
"D0, P[1], (!!bool)::true\n",
|
||||||
// "D0, P[2], (!!bool)::false\n",
|
"D0, P[2], (!!bool)::false\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// description: "Don't match string",
|
description: "Don't match string",
|
||||||
// document: `[cat,goat,dog]`,
|
document: `[cat,goat,dog]`,
|
||||||
// expression: `.[] | (. != "*at")`,
|
expression: `.[] | (. != "*at")`,
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[0], (!!bool)::false\n",
|
"D0, P[0], (!!bool)::false\n",
|
||||||
// "D0, P[1], (!!bool)::false\n",
|
"D0, P[1], (!!bool)::false\n",
|
||||||
// "D0, P[2], (!!bool)::true\n",
|
"D0, P[2], (!!bool)::true\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// description: "Match number",
|
description: "Match number",
|
||||||
// document: `[3, 4, 5]`,
|
document: `[3, 4, 5]`,
|
||||||
// expression: `.[] | (. == 4)`,
|
expression: `.[] | (. == 4)`,
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[0], (!!bool)::false\n",
|
"D0, P[0], (!!bool)::false\n",
|
||||||
// "D0, P[1], (!!bool)::true\n",
|
"D0, P[1], (!!bool)::true\n",
|
||||||
// "D0, P[2], (!!bool)::false\n",
|
"D0, P[2], (!!bool)::false\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// description: "Don't match number",
|
description: "Don't match number",
|
||||||
// document: `[3, 4, 5]`,
|
document: `[3, 4, 5]`,
|
||||||
// expression: `.[] | (. != 4)`,
|
expression: `.[] | (. != 4)`,
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[0], (!!bool)::true\n",
|
"D0, P[0], (!!bool)::true\n",
|
||||||
// "D0, P[1], (!!bool)::false\n",
|
"D0, P[1], (!!bool)::false\n",
|
||||||
// "D0, P[2], (!!bool)::true\n",
|
"D0, P[2], (!!bool)::true\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: `a: { cat: {b: apple, c: whatever}, pat: {b: banana} }`,
|
document: `a: { cat: {b: apple, c: whatever}, pat: {b: banana} }`,
|
||||||
// expression: `.a | (.[].b == "apple")`,
|
expression: `.a | (.[].b == "apple")`,
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[a cat b], (!!bool)::true\n",
|
"D0, P[a cat b], (!!bool)::true\n",
|
||||||
// "D0, P[a pat b], (!!bool)::false\n",
|
"D0, P[a pat b], (!!bool)::false\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// skipDoc: true,
|
skipDoc: true,
|
||||||
// document: ``,
|
document: ``,
|
||||||
// expression: `null == null`,
|
expression: `null == null`,
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[], (!!bool)::true\n",
|
"D0, P[], (!!bool)::true\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// description: "Match nulls",
|
description: "Match nulls",
|
||||||
// document: ``,
|
document: ``,
|
||||||
// expression: `null == ~`,
|
expression: `null == ~`,
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[], (!!bool)::true\n",
|
"D0, P[], (!!bool)::true\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// description: "Non existent key doesn't equal a value",
|
description: "Non existent key doesn't equal a value",
|
||||||
// document: "a: frog",
|
document: "a: frog",
|
||||||
// expression: `select(.b != "thing")`,
|
expression: `select(.b != "thing")`,
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[], (!!map)::a: frog\n",
|
"D0, P[], (!!map)::a: frog\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// description: "Two non existent keys are equal",
|
description: "Two non existent keys are equal",
|
||||||
// document: "a: frog",
|
document: "a: frog",
|
||||||
// expression: `select(.b == .c)`,
|
expression: `select(.b == .c)`,
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[], (!!map)::a: frog\n",
|
"D0, P[], (!!map)::a: frog\n",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEqualOperatorScenarios(t *testing.T) {
|
func TestEqualOperatorScenarios(t *testing.T) {
|
||||||
|
@ -53,7 +53,6 @@ func keysOperator(d *dataTreeNavigator, context Context, expressionNode *Express
|
|||||||
return Context{}, fmt.Errorf("Cannot get keys of %v, keys only works for maps and arrays", candidate.Tag)
|
return Context{}, fmt.Errorf("Cannot get keys of %v, keys only works for maps and arrays", candidate.Tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// result := candidate.CreateReplacement(targetNode)
|
|
||||||
results.PushBack(targetNode)
|
results.PushBack(targetNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ type expressionScenario struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
logging.SetLevel(logging.DEBUG, "")
|
logging.SetLevel(logging.ERROR, "")
|
||||||
Now = func() time.Time {
|
Now = func() time.Time {
|
||||||
return time.Date(2021, time.May, 19, 1, 2, 3, 4, time.UTC)
|
return time.Date(2021, time.May, 19, 1, 2, 3, 4, time.UTC)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user