diff --git a/internal/stage_p10.go b/internal/stage_p10.go index 4d70c96..eb1d451 100644 --- a/internal/stage_p10.go +++ b/internal/stage_p10.go @@ -14,14 +14,24 @@ func testParseErrors(stageHarness *test_case_harness.TestCaseHarness) error { logger := stageHarness.Logger + // Unterminated string error1 := fmt.Sprintf("\"%s", random.RandomElementFromArray(STRINGS)) - error2 := fmt.Sprintf("(%d +)", getRandInt()) - error3 := "+" + + // Unbalanced parentheses + error2 := "(foo" + + // Missing operand + error3 := fmt.Sprintf("(%d +)", getRandInt()) + + // Missing operands + error4 := "+" + parseTestCase := testcases.MultiParseTestCase{ TestCases: []testcases.ParseTestCase{ {FileContents: error1, ExpectsError: true}, {FileContents: error2, ExpectsError: true}, {FileContents: error3, ExpectsError: true}, + {FileContents: error4, ExpectsError: true}, }, } return parseTestCase.RunAll(b, logger) diff --git a/internal/stage_p4.go b/internal/stage_p4.go index 344ff21..efa2c7e 100644 --- a/internal/stage_p4.go +++ b/internal/stage_p4.go @@ -1,6 +1,8 @@ package internal import ( + "fmt" + "github.com/codecrafters-io/interpreter-tester/internal/interpreter_executable" testcases "github.com/codecrafters-io/interpreter-tester/internal/test_cases" "github.com/codecrafters-io/tester-utils/test_case_harness" @@ -14,13 +16,13 @@ func testParseParens(stageHarness *test_case_harness.TestCaseHarness) error { parens1 := "(\"foo\")" parens2 := "((true))" parens3 := "(nil)" - parens4 := "(\"foo\"" + parens4 := fmt.Sprintf("(%d.%d)", getRandInt(), getRandInt()) parseTestCase := testcases.MultiParseTestCase{ TestCases: []testcases.ParseTestCase{ {FileContents: parens1, ExpectsError: false}, {FileContents: parens2, ExpectsError: false}, {FileContents: parens3, ExpectsError: false}, - {FileContents: parens4, ExpectsError: true}, + {FileContents: parens4, ExpectsError: false}, }, } return parseTestCase.RunAll(b, logger) diff --git a/internal/test_helpers/fixtures/pass_parsing b/internal/test_helpers/fixtures/pass_parsing index 5595c94..9766e1e 100644 --- a/internal/test_helpers/fixtures/pass_parsing +++ b/internal/test_helpers/fixtures/pass_parsing @@ -11,18 +11,25 @@ Debug = true [stage-10] [test-1] ✓ Received exit code 65. [stage-10] [test-2] Running test case: 2 [stage-10] [test-2] Writing contents to ./test.lox: -[stage-10] [test-2] [test.lox] (49 +) +[stage-10] [test-2] [test.lox] (foo [stage-10] [test-2] $ ./your_program.sh parse test.lox -[your_program] [line 1] Error at ')': Expect expression. +[your_program] [line 1] Error at 'foo': Expect expression. [stage-10] [test-2] ✓ 1 line(s) match on stdout [stage-10] [test-2] ✓ Received exit code 65. [stage-10] [test-3] Running test case: 3 [stage-10] [test-3] Writing contents to ./test.lox: -[stage-10] [test-3] [test.lox] + +[stage-10] [test-3] [test.lox] (49 +) [stage-10] [test-3] $ ./your_program.sh parse test.lox -[your_program] [line 1] Error at '+': Expect expression. +[your_program] [line 1] Error at ')': Expect expression. [stage-10] [test-3] ✓ 1 line(s) match on stdout [stage-10] [test-3] ✓ Received exit code 65. +[stage-10] [test-4] Running test case: 4 +[stage-10] [test-4] Writing contents to ./test.lox: +[stage-10] [test-4] [test.lox] + +[stage-10] [test-4] $ ./your_program.sh parse test.lox +[your_program] [line 1] Error at '+': Expect expression. +[stage-10] [test-4] ✓ 1 line(s) match on stdout +[stage-10] [test-4] ✓ Received exit code 65. [stage-10] Test passed. [stage-9] Running tests for Stage #9: ht8 @@ -204,40 +211,40 @@ Debug = true [stage-4] [test-3] ✓ Received exit code 0. [stage-4] [test-4] Running test case: 4 [stage-4] [test-4] Writing contents to ./test.lox: -[stage-4] [test-4] [test.lox] ("foo" +[stage-4] [test-4] [test.lox] (11.95) [stage-4] [test-4] $ ./your_program.sh parse test.lox -[your_program] [line 1] Error at end: Expect ')' after expression. +[your_program] (group 11.95) [stage-4] [test-4] ✓ 1 line(s) match on stdout -[stage-4] [test-4] ✓ Received exit code 65. +[stage-4] [test-4] ✓ Received exit code 0. [stage-4] Test passed. [stage-3] Running tests for Stage #3: th5 [stage-3] [test-1] Running test case: 1 [stage-3] [test-1] Writing contents to ./test.lox: -[stage-3] [test-1] [test.lox] "baz bar" +[stage-3] [test-1] [test.lox] "quz foo" [stage-3] [test-1] $ ./your_program.sh parse test.lox -[your_program] baz bar +[your_program] quz foo [stage-3] [test-1] ✓ 1 line(s) match on stdout [stage-3] [test-1] ✓ Received exit code 0. [stage-3] [test-2] Running test case: 2 [stage-3] [test-2] Writing contents to ./test.lox: -[stage-3] [test-2] [test.lox] "'bar'" +[stage-3] [test-2] [test.lox] "'foo'" [stage-3] [test-2] $ ./your_program.sh parse test.lox -[your_program] 'bar' +[your_program] 'foo' [stage-3] [test-2] ✓ 1 line(s) match on stdout [stage-3] [test-2] ✓ Received exit code 0. [stage-3] [test-3] Running test case: 3 [stage-3] [test-3] Writing contents to ./test.lox: -[stage-3] [test-3] [test.lox] "// baz" +[stage-3] [test-3] [test.lox] "// quz" [stage-3] [test-3] $ ./your_program.sh parse test.lox -[your_program] // baz +[your_program] // quz [stage-3] [test-3] ✓ 1 line(s) match on stdout [stage-3] [test-3] ✓ Received exit code 0. [stage-3] [test-4] Running test case: 4 [stage-3] [test-4] Writing contents to ./test.lox: -[stage-3] [test-4] [test.lox] "72" +[stage-3] [test-4] [test.lox] "90" [stage-3] [test-4] $ ./your_program.sh parse test.lox -[your_program] 72 +[your_program] 90 [stage-3] [test-4] ✓ 1 line(s) match on stdout [stage-3] [test-4] ✓ Received exit code 0. [stage-3] Test passed. @@ -245,9 +252,9 @@ Debug = true [stage-2] Running tests for Stage #2: ra8 [stage-2] [test-1] Running test case: 1 [stage-2] [test-1] Writing contents to ./test.lox: -[stage-2] [test-1] [test.lox] 83 +[stage-2] [test-1] [test.lox] 91 [stage-2] [test-1] $ ./your_program.sh parse test.lox -[your_program] 83.0 +[your_program] 91.0 [stage-2] [test-1] ✓ 1 line(s) match on stdout [stage-2] [test-1] ✓ Received exit code 0. [stage-2] [test-2] Running test case: 2 @@ -259,9 +266,9 @@ Debug = true [stage-2] [test-2] ✓ Received exit code 0. [stage-2] [test-3] Running test case: 3 [stage-2] [test-3] Writing contents to ./test.lox: -[stage-2] [test-3] [test.lox] 90.91 +[stage-2] [test-3] [test.lox] 12.52 [stage-2] [test-3] $ ./your_program.sh parse test.lox -[your_program] 90.91 +[your_program] 12.52 [stage-2] [test-3] ✓ 1 line(s) match on stdout [stage-2] [test-3] ✓ Received exit code 0. [stage-2] Test passed.