MCPcopy
hub / github.com/lmorg/murex / testParserSymbol

Function testParserSymbol

lang/expressions/parse_expression_test.go:27–84  ·  view source on GitHub ↗
(t *testing.T, tests expTestsT)

Source from the content-addressed store, hash-verified

25}
26
27func 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}

Callers 8

TestParseLambdaScalarFunction · 0.85
TestParseBooleanFunction · 0.85
TestParseQuoteParenFunction · 0.85
TestParseQuoteSingleFunction · 0.85
TestParseQuoteDoubleFunction · 0.85
TestParseBarewordFunction · 0.85
TestParseNumberFunction · 0.85

Calls 10

TestsFunction · 0.92
InitEnvFunction · 0.92
ConfigFunction · 0.92
NewTestProcessFunction · 0.92
NewParserFunction · 0.70
SetMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.65
parseExpressionMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected