| 1 | //Copyright 2012 Vastech SA (PTY) LTD |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package examplescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/ |
| 16 | |
| 17 | import ( |
| 18 | "testingscip-go gomod github.com/golang/go/src go1.24 testing/" |
| 19 | |
| 20 | "github.com/goccmack/gocc/example/bools/astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools/ast`/" |
| 21 | "github.com/goccmack/gocc/example/bools/lexerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools/lexer`/" |
| 22 | "github.com/goccmack/gocc/example/bools/parserscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools/parser`/" |
| 23 | ) |
| 24 | |
| 25 | func testEvalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/testEval().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#, exampleStr string, output bool) { |
| 26 | lex := lexerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools/lexer`/.NewLexerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools/lexer`/NewLexer().([]byte(exampleStr)) |
| 27 | p := parserscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools/parser`/.NewParserscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools/parser`/NewParser().() |
| 28 | st, err := p.Parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools/parser`/Parser#Parse().(lex) |
| 29 | if err != nil { |
| 30 | panic(err) |
| 31 | } |
| 32 | if st.(astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools/ast`/.Valscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools/ast`/Val#).Evalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools/ast`/Val#Eval.() != output { |
| 33 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24 testing/common#Fatalf().("Should be %v for %v", output, exampleStr) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func TestOrscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/TestOr().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 38 | testEvalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/testEval().(t, "true | false", true) |
| 39 | } |
| 40 | |
| 41 | func TestAndscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/TestAnd().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 42 | testEvalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/testEval().(t, "true & false", false) |
| 43 | } |
| 44 | |
| 45 | func TestSubStringscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/TestSubString().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 46 | testEvalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/testEval().(t, `"true" in "false"`, false) |
| 47 | testEvalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/testEval().(t, `"true" in "trues"`, true) |
| 48 | } |
| 49 | |
| 50 | func TestLessscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/TestLess().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 51 | testEvalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/testEval().(t, "0 < 5", true) |
| 52 | testEvalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/testEval().(t, "0 > 5", false) |
| 53 | } |
| 54 | |
| 55 | func TestMixedscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/TestMixed().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 56 | testEvalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/testEval().(t, "0 < 5 | false", true) |
| 57 | } |
| 58 | |
| 59 | func TestGroupscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/TestGroup().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 60 | testEvalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/testEval().(t, "( true | false ) & ( true & true )", true) |
| 61 | } |
| 62 | |
| 63 | func TestGroupMixedscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/TestGroupMixed().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 64 | testEvalscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/bools`/testEval().(t, `( true | false ) & 0 > 100000 | "t" in "taddle"`, true) |
| 65 | } |