Skip to content

Update test cases for #zm7 alternation #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions internal/stage_alternation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ func testAlternation(stageHarness *test_case_harness.TestCaseHarness) error {
Input: "a cat",
ExpectedExitCode: 0,
},
{
Pattern: "a (cat|dog) and (cat|dog)s",
Input: "a dog and cats",
ExpectedExitCode: 0,
},
{
Pattern: "a (cat|dog)",
Input: "a cow",
ExpectedExitCode: 1,
},
{
Pattern: "^((Buffalo|buffalo)[ ]?)+$",
Input: "Buffalo buffalo buffalo Buffalo buffalo",
Copy link
Member

@rohitpaulk rohitpaulk Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still seems super arcane @andy1li - I saw the link you shared and now remember it, but what we're looking for is something that a user is going to be happy to debug and figure out. If it seems like something that isn't "obvious" or something that they might not use in the real-world this is going to be frustrating for them.

I'll give you one example to get started (don't have to use this one, just to illustrate and I'm also not sure if all features used here are covered in previous stages):

I see 1 cat, 2 dogs and 3 cows
^I see (\d (cat|dog|apple)s?(, | and )?)+

Copy link
Member Author

@andy1li andy1li Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

Yep, all features are covered. (We just cannot use sentence-ending punctuations like . or ?, because we didn't introduce escaping.)

ExpectedExitCode: 0,
},
{
Pattern: "^([Ww]ill(, | |'s )?)+$",
Input: "Will, will Will will Will Will's will",
ExpectedExitCode: 0,
},
}

return RunTestCases(testCases, stageHarness)
Expand Down
9 changes: 6 additions & 3 deletions internal/test_helpers/fixtures/alternation/success
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
[stage-12] $ echo -n "a cat" | ./your_grep.sh -E "a (cat|dog)"
[your_program] a cat
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo -n "a dog and cats" | ./your_grep.sh -E "a (cat|dog) and (cat|dog)s"
[your_program] a dog and cats
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo -n "a cow" | ./your_grep.sh -E "a (cat|dog)"
[stage-12] ✓ Received exit code 1.
[stage-12] $ echo -n "Buffalo buffalo buffalo Buffalo buffalo" | ./your_grep.sh -E "^((Buffalo|buffalo)[ ]?)+$"
[your_program] Buffalo buffalo buffalo Buffalo buffalo
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo -n "Will, will Will will Will Will's will" | ./your_grep.sh -E "^([Ww]ill(, | |'s )?)+$"
[your_program] Will, will Will will Will Will's will
[stage-12] ✓ Received exit code 0.
[stage-12] Test passed.

[stage-11] Running tests for Stage #11: zb3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@
[stage-12] $ echo -n "a cat" | ./your_grep.sh -E "a (cat|dog)"
[your_program] a cat
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo -n "a dog and cats" | ./your_grep.sh -E "a (cat|dog) and (cat|dog)s"
[your_program] a dog and cats
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo -n "a cow" | ./your_grep.sh -E "a (cat|dog)"
[stage-12] ✓ Received exit code 1.
[stage-12] $ echo -n "Buffalo buffalo buffalo Buffalo buffalo" | ./your_grep.sh -E "^((Buffalo|buffalo)[ ]?)+$"
[your_program] Buffalo buffalo buffalo Buffalo buffalo
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo -n "Will, will Will will Will Will's will" | ./your_grep.sh -E "^([Ww]ill(, | |'s )?)+$"
[your_program] Will, will Will will Will Will's will
[stage-12] ✓ Received exit code 0.
[stage-12] Test passed.

[stage-11] Running tests for Stage #11: zb3
Expand Down
9 changes: 6 additions & 3 deletions internal/test_helpers/fixtures/backreferences_nested/success
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,14 @@
[stage-12] $ echo -n "a cat" | ./your_grep.sh -E "a (cat|dog)"
[your_program] a cat
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo -n "a dog and cats" | ./your_grep.sh -E "a (cat|dog) and (cat|dog)s"
[your_program] a dog and cats
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo -n "a cow" | ./your_grep.sh -E "a (cat|dog)"
[stage-12] ✓ Received exit code 1.
[stage-12] $ echo -n "Buffalo buffalo buffalo Buffalo buffalo" | ./your_grep.sh -E "^((Buffalo|buffalo)[ ]?)+$"
[your_program] Buffalo buffalo buffalo Buffalo buffalo
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo -n "Will, will Will will Will Will's will" | ./your_grep.sh -E "^([Ww]ill(, | |'s )?)+$"
[your_program] Will, will Will will Will Will's will
[stage-12] ✓ Received exit code 0.
[stage-12] Test passed.

[stage-11] Running tests for Stage #11: zb3
Expand Down
9 changes: 6 additions & 3 deletions internal/test_helpers/fixtures/backreferences_single/success
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@
[stage-12] $ echo -n "a cat" | ./your_grep.sh -E "a (cat|dog)"
[your_program] a cat
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo -n "a dog and cats" | ./your_grep.sh -E "a (cat|dog) and (cat|dog)s"
[your_program] a dog and cats
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo -n "a cow" | ./your_grep.sh -E "a (cat|dog)"
[stage-12] ✓ Received exit code 1.
[stage-12] $ echo -n "Buffalo buffalo buffalo Buffalo buffalo" | ./your_grep.sh -E "^((Buffalo|buffalo)[ ]?)+$"
[your_program] Buffalo buffalo buffalo Buffalo buffalo
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo -n "Will, will Will will Will Will's will" | ./your_grep.sh -E "^([Ww]ill(, | |'s )?)+$"
[your_program] Will, will Will will Will Will's will
[stage-12] ✓ Received exit code 0.
[stage-12] Test passed.

[stage-11] Running tests for Stage #11: zb3
Expand Down