(t *testing.T, tests expTestsT)
| 25 | } |
| 26 | |
| 27 | func testParserSymbol(t *testing.T, tests expTestsT) { |
| 28 | t.Helper() |
| 29 | |
| 30 | count.Tests(t, len(tests.tests)) |
| 31 | |
| 32 | lang.InitEnv() |
| 33 | defaults.Config(lang.ShellProcess.Config, false) |
| 34 | p := lang.NewTestProcess() |
| 35 | p.Name.Set("(test)") |
| 36 | p.Config.Set("proc", "strict-vars", false, nil) |
| 37 | p.Config.Set("proc", "strict-arrays", false, nil) |
| 38 | |
| 39 | for i, test := range tests.tests { |
| 40 | tree := NewParser(p, []rune(test.input), 0) |
| 41 | err := tree.parseExpression(true, true) |
| 42 | |
| 43 | switch { |
| 44 | case (err != nil) != test.error: |
| 45 | t.Errorf("Error: %v", err) |
| 46 | t.Logf(" Test: %d", i) |
| 47 | t.Logf(" Expression: '%s'", test.input) |
| 48 | t.Logf(" exp symbol: '%s'", tests.symbol.String()) |
| 49 | continue |
| 50 | |
| 51 | case test.error: |
| 52 | continue |
| 53 | |
| 54 | case len(tree.ast) == 0: |
| 55 | t.Error("No ASTs generated:") |
| 56 | t.Logf(" Test: %d", i) |
| 57 | t.Logf(" Expression: '%s'", test.input) |
| 58 | t.Logf(" exp symbol: '%s'", tests.symbol.String()) |
| 59 | continue |
| 60 | |
| 61 | case tree.ast[0].key != tests.symbol: |
| 62 | t.Error("Unexpected symbol:") |
| 63 | |
| 64 | case tree.ast[0].Value() != test.expected: |
| 65 | t.Error("Expected doesn't match actual:") |
| 66 | |
| 67 | case tree.ast[0].pos != test.pos: |
| 68 | t.Errorf("Pos doesn't match expected:") |
| 69 | |
| 70 | default: |
| 71 | // success |
| 72 | continue |
| 73 | } |
| 74 | |
| 75 | t.Logf(" Test: %d", i) |
| 76 | t.Logf(" Expression: '%s'", test.input) |
| 77 | t.Logf(" exp symbol: '%s'", tests.symbol.String()) |
| 78 | t.Logf(" act symbol: '%s'", tree.ast[0].key.String()) |
| 79 | t.Logf(" Expected: '%s'", test.expected) |
| 80 | t.Logf(" Actual: '%s'", tree.ast[0].Value()) |
| 81 | t.Logf(" act bytes: %v", tree.ast[0].value) |
| 82 | t.Logf(" Character pos (exp: %d, act: %d)", test.pos, tree.ast[0].pos) |
| 83 | } |
| 84 | } |
no test coverage detected