2020-11-03 23:48:43 +00:00
|
|
|
package yqlib
|
2020-10-17 11:39:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var valueOperatorScenarios = []expressionScenario{
|
|
|
|
{
|
|
|
|
document: ``,
|
|
|
|
expression: `1`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!int)::1\n",
|
|
|
|
},
|
2020-10-20 04:33:20 +00:00
|
|
|
},
|
|
|
|
{
|
2020-10-17 11:39:01 +00:00
|
|
|
document: ``,
|
|
|
|
expression: `-1`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!int)::-1\n",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
document: ``,
|
|
|
|
expression: `1.2`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!float)::1.2\n",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
document: ``,
|
|
|
|
expression: `-5.2e11`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!float)::-5.2e11\n",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
document: ``,
|
|
|
|
expression: `5e-10`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!float)::5e-10\n",
|
|
|
|
},
|
2020-12-21 23:38:52 +00:00
|
|
|
},
|
|
|
|
{
|
2020-10-17 11:39:01 +00:00
|
|
|
document: ``,
|
|
|
|
expression: `"cat"`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!str)::cat\n",
|
|
|
|
},
|
2020-12-21 23:38:52 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
document: ``,
|
|
|
|
expression: `"frog jumps"`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!str)::frog jumps\n",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-10-17 11:39:01 +00:00
|
|
|
document: ``,
|
|
|
|
expression: `"1.3"`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!str)::\"1.3\"\n",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
document: ``,
|
|
|
|
expression: `"true"`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!str)::\"true\"\n",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
document: ``,
|
|
|
|
expression: `true`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!bool)::true\n",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
document: ``,
|
|
|
|
expression: `false`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!bool)::false\n",
|
|
|
|
},
|
|
|
|
},
|
2020-10-20 04:40:11 +00:00
|
|
|
{
|
|
|
|
document: ``,
|
|
|
|
expression: `Null`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!null)::Null\n",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
document: ``,
|
|
|
|
expression: `~`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!null)::~\n",
|
|
|
|
},
|
|
|
|
},
|
2020-10-17 11:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestValueOperatorScenarios(t *testing.T) {
|
|
|
|
for _, tt := range valueOperatorScenarios {
|
|
|
|
testScenario(t, &tt)
|
|
|
|
}
|
|
|
|
}
|