diff --git a/pkg/yqlib/path_postfix.go b/pkg/yqlib/path_postfix.go index 7f40efa..9a036c6 100644 --- a/pkg/yqlib/path_postfix.go +++ b/pkg/yqlib/path_postfix.go @@ -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: diff --git a/pkg/yqlib/path_postfix_test.go b/pkg/yqlib/path_postfix_test.go index b377619..d3c6d72 100644 --- a/pkg/yqlib/path_postfix_test.go +++ b/pkg/yqlib/path_postfix_test.go @@ -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) +}