diff options
author | EuAndreh <eu@euandre.org> | 2024-12-11 16:48:12 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-12-11 16:48:12 -0300 |
commit | 27b4729bd1a57740ea68e774d58d9cb3f45c5589 (patch) | |
tree | 152ff5686ade087e29e102cbbd39c0405cb63c02 /tests/unit/tester | |
parent | Consolidate packages spread across multiple files into single one (diff) | |
download | cotia-27b4729bd1a57740ea68e774d58d9cb3f45c5589.tar.gz cotia-27b4729bd1a57740ea68e774d58d9cb3f45c5589.tar.xz |
Do the same single file consolidation on tests
Diffstat (limited to 'tests/unit/tester')
-rw-r--r-- | tests/unit/tester/tester_test.go | 169 |
1 files changed, 0 insertions, 169 deletions
diff --git a/tests/unit/tester/tester_test.go b/tests/unit/tester/tester_test.go deleted file mode 100644 index 3c6b1db..0000000 --- a/tests/unit/tester/tester_test.go +++ /dev/null @@ -1,169 +0,0 @@ -package tester - -import ( - "fmt" - "strings" - "testing" - - "urubu/grammar" - "urubu/spec/grammar/parser" - tspec "urubu/spec/test" -) - -func TestTester_Run(t *testing.T) { - grammarSrc1 := ` -#name test; - -s - : foo bar baz - | foo error baz #recover - ; - -ws #skip - : "[\u{0009}\u{0020}]+"; -foo - : 'foo'; -bar - : 'bar'; -baz - : 'baz'; -` - - grammarSrc2 := ` -#name test; - -s - : foos - ; -foos - : foos foo #ast foos... foo - | foo - ; - -ws #skip - : "[\u{0009}\u{0020}]+"; -foo - : 'foo'; -` - - tests := []struct { - grammarSrc string - testSrc string - error bool - }{ - { - grammarSrc: grammarSrc1, - testSrc: ` -Test ---- -foo bar baz ---- -(s - (foo 'foo') (bar 'bar') (baz 'baz')) -`, - }, - { - grammarSrc: grammarSrc1, - testSrc: ` -Test ---- -foo ? baz ---- -(s - (foo 'foo') (error) (baz 'baz')) -`, - }, - { - grammarSrc: grammarSrc1, - testSrc: ` -Test ---- -foo bar baz ---- -(s) -`, - error: true, - }, - { - grammarSrc: grammarSrc1, - testSrc: ` -Test ---- -foo bar baz ---- -(s - (foo) (bar)) -`, - error: true, - }, - { - grammarSrc: grammarSrc1, - testSrc: ` -Test ---- -foo bar baz ---- -(s - (foo) (bar) (xxx)) -`, - error: true, - }, - { - grammarSrc: grammarSrc2, - testSrc: ` -Test ---- -foo foo foo ---- -(s - (foos - (foo 'foo') (foo 'foo') (foo 'foo'))) -`, - }, - } - for i, tt := range tests { - t.Run(fmt.Sprintf("#%v", i), func(t *testing.T) { - ast, err := parser.Parse(strings.NewReader(tt.grammarSrc)) - if err != nil { - t.Fatal(err) - } - b := grammar.GrammarBuilder{ - AST: ast, - } - cg, _, err := b.Build() - if err != nil { - t.Fatal(err) - } - c, err := tspec.ParseTestCase(strings.NewReader(tt.testSrc)) - if err != nil { - t.Fatal(err) - } - tester := &Tester{ - Grammar: cg, - Cases: []*TestCaseWithMetadata{ - { - TestCase: c, - }, - }, - } - rs := tester.Run() - if tt.error { - errOccurred := false - for _, r := range rs { - if r.Error != nil { - errOccurred = true - } - } - if !errOccurred { - t.Fatal("this test must fail, but it passed") - } - } else { - for _, r := range rs { - if r.Error != nil { - t.Fatalf("unexpected error occurred: %v", r.Error) - } - } - } - }) - } -} |