mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
postfix wip!
This commit is contained in:
parent
a8bdc12d83
commit
e32bc43c4e
@ -39,7 +39,11 @@ func (p *PathElement) toString() string {
|
||||
var result string = `Type: `
|
||||
switch p.PathElementType {
|
||||
case PathKey:
|
||||
result = result + fmt.Sprintf("PathKey - %v\n", p.Value)
|
||||
result = result + fmt.Sprintf("PathKey - %v", p.Value)
|
||||
for _, next := range p.ChildElements[0] {
|
||||
result = result + fmt.Sprintf(".%v", next.Value)
|
||||
}
|
||||
result = result + "\n"
|
||||
case ArrayIndex:
|
||||
result = result + fmt.Sprintf("ArrayIndex - %v\n", p.Value)
|
||||
case Operation:
|
||||
|
@ -27,7 +27,23 @@ func testExpression(expression string) (string, error) {
|
||||
|
||||
func TestPostFixSimple(t *testing.T) {
|
||||
var infix = "a"
|
||||
var expectedOutput = "Type: PathKey - a\n"
|
||||
var expectedOutput = `Type: PathKey - a
|
||||
--------
|
||||
`
|
||||
|
||||
actual, err := testExpression(infix)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
test.AssertResultComplex(t, expectedOutput, actual)
|
||||
}
|
||||
|
||||
func TestPostFixSimplePath(t *testing.T) {
|
||||
var infix = "apples.bananas*.cat"
|
||||
var expectedOutput = `Type: PathKey - apples.bananas*.cat
|
||||
--------
|
||||
`
|
||||
|
||||
actual, err := testExpression(infix)
|
||||
if err != nil {
|
||||
@ -80,3 +96,29 @@ Type: Operation - OR
|
||||
|
||||
test.AssertResultComplex(t, expectedOutput, actual)
|
||||
}
|
||||
|
||||
func TestPostFixOrWithEqualsPath(t *testing.T) {
|
||||
var infix = "apples.monkeys==thing OR bogs.bobos==thongs"
|
||||
var expectedOutput = `Type: PathKey - apples.monkeys
|
||||
--------
|
||||
Type: PathKey - thing
|
||||
--------
|
||||
Type: Operation - EQUALS
|
||||
--------
|
||||
Type: PathKey - bogs.bobos
|
||||
--------
|
||||
Type: PathKey - thongs
|
||||
--------
|
||||
Type: Operation - EQUALS
|
||||
--------
|
||||
Type: Operation - OR
|
||||
--------
|
||||
`
|
||||
|
||||
actual, err := testExpression(infix)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
test.AssertResultComplex(t, expectedOutput, actual)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user