postfix wip!

This commit is contained in:
Mike Farah 2020-09-20 22:47:53 +10:00
parent a8bdc12d83
commit e32bc43c4e
2 changed files with 48 additions and 2 deletions

View File

@ -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:

View File

@ -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)
}