From f7ccebbf9319e39d05d2724dadb7f6c95131cb9e Mon Sep 17 00:00:00 2001 From: Arpad Ryszka Date: Sun, 29 Jul 2018 13:07:33 +0200 Subject: [PATCH] fix eskip tests, test mml multiple operators on the same level --- eskip_test.go | 32 +++++++++++++++++--------------- examples/mml.treerack | 12 ++++++------ mml_test.go | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/eskip_test.go b/eskip_test.go index 8d35b2d..68e1136 100644 --- a/eskip_test.go +++ b/eskip_test.go @@ -529,22 +529,24 @@ func checkTerm(t *testing.T, gotName, expectedName string, gotArgs, expectedArgs return } - // legacy bug support - for i := len(expectedArgs) - 1; i >= 0; i-- { - if _, ok := expectedArgs[i].(int); ok { - expectedArgs = append(expectedArgs[:i], expectedArgs[i+1:]...) - continue - } - - if v, ok := expectedArgs[i].(float64); ok && v < 0 { - gotArgs = append(gotArgs[:i], gotArgs[i+1:]...) - expectedArgs = append(expectedArgs[:i], expectedArgs[i+1:]...) - } + if len(gotArgs) != len(expectedArgs) { + t.Error("invalid term args length in:", gotName, len(gotArgs), len(expectedArgs)) + return } - if len(gotArgs) != len(expectedArgs) { - t.Error("invalid term args length", len(gotArgs), len(expectedArgs)) - return + // legacy bug support, dropping numeric arguments: + for i, a := range gotArgs { + ea := expectedArgs[i] + switch a.(type) { + case int, float64: + switch ea.(type) { + case int, float64: + gotArgs = append(gotArgs[:i], gotArgs[i+1:]...) + expectedArgs = append(expectedArgs[:i], expectedArgs[i+1:]...) + default: + t.Error("invalid argument type at:", i) + } + } } for i, a := range gotArgs { @@ -723,7 +725,7 @@ func TestEskip(t *testing.T) { const count = 1 << 9 r := generateEskip(count) - e := eskip.Print(true, r...) + e := eskip.Print(eskip.PrettyPrintInfo{Pretty: true}, r...) b := bytes.NewBufferString(e) s, err := openSyntaxFile("examples/eskip.treerack") diff --git a/examples/mml.treerack b/examples/mml.treerack index 60acbeb..6016a94 100644 --- a/examples/mml.treerack +++ b/examples/mml.treerack @@ -434,12 +434,12 @@ operand3:alias = operand2 | binary2; operand4:alias = operand3 | binary3; operand5:alias = operand4 | binary4; -binary0 = operand0 binary-op0 operand0; -binary1 = operand1 binary-op1 operand1; -binary2 = operand2 binary-op2 operand2; -binary3 = operand3 binary-op3 operand3; -binary4 = operand4 binary-op4 operand4; -binary5 = operand5 binary-op5 operand5; +binary0 = operand0 (binary-op0 operand0)+; +binary1 = operand1 (binary-op1 operand1)+; +binary2 = operand2 (binary-op2 operand2)+; +binary3 = operand3 (binary-op3 operand3)+; +binary4 = operand4 (binary-op4 operand4)+; +binary5 = operand5 (binary-op5 operand5)+; binary-expression:alias = binary0 | binary1 | binary2 | binary3 | binary4 | binary5; diff --git a/mml_test.go b/mml_test.go index 14b6807..60b7476 100644 --- a/mml_test.go +++ b/mml_test.go @@ -2308,6 +2308,24 @@ func TestMML(t *testing.T) { }}, }}, ignorePosition: true, + }, { + title: "binary 1, 1, 1", + text: "a + b + c", + nodes: []*Node{{ + Name: "binary1", + Nodes: []*Node{{ + Name: "symbol", + }, { + Name: "add", + }, { + Name: "symbol", + }, { + Name: "add", + }, { + Name: "symbol", + }}, + }}, + ignorePosition: true, }, { title: "binary 3, 4, 5", text: "a * b + c * d == e * f && g || h -> f()",