Skip to content

Commit 4743bcf

Browse files
authored
Merge pull request #34 from codecrafters-io/andy/tweak
Update test cases for #zm7 alternation
2 parents ee1157a + f0b0d3a commit 4743bcf

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

internal/stage_alternation.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ func testAlternation(stageHarness *test_case_harness.TestCaseHarness) error {
1212
ExpectedExitCode: 0,
1313
},
1414
{
15-
Pattern: "a (cat|dog) and (cat|dog)s",
16-
Input: "a dog and cats",
15+
Pattern: "a (cat|dog)",
16+
Input: "a cow",
17+
ExpectedExitCode: 1,
18+
},
19+
{
20+
Pattern: "^I see (\\d (cat|dog|cow)s?(, | and )?)+$",
21+
Input: "I see 1 cat, 2 dogs and 3 cows",
1722
ExpectedExitCode: 0,
1823
},
1924
{
20-
Pattern: "a (cat|dog)",
21-
Input: "a cow",
25+
Pattern: "^I see (\\d (cat|dog|cow)(, | and )?)+$",
26+
Input: "I see 1 cat, 2 dogs and 3 cows",
2227
ExpectedExitCode: 1,
2328
},
2429
}

internal/test_helpers/fixtures/alternation/success

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
[stage-12] $ echo -n "a cat" | ./your_grep.sh -E "a (cat|dog)"
33
[your_program] a cat
44
[stage-12] ✓ Received exit code 0.
5-
[stage-12] $ echo -n "a dog and cats" | ./your_grep.sh -E "a (cat|dog) and (cat|dog)s"
6-
[your_program] a dog and cats
7-
[stage-12] ✓ Received exit code 0.
85
[stage-12] $ echo -n "a cow" | ./your_grep.sh -E "a (cat|dog)"
96
[stage-12] ✓ Received exit code 1.
7+
[stage-12] $ echo -n "I see 1 cat, 2 dogs and 3 cows" | ./your_grep.sh -E "^I see (\d (cat|dog|cow)s?(, | and )?)+$"
8+
[your_program] I see 1 cat, 2 dogs and 3 cows
9+
[stage-12] ✓ Received exit code 0.
10+
[stage-12] $ echo -n "I see 1 cat, 2 dogs and 3 cows" | ./your_grep.sh -E "^I see (\d (cat|dog|cow)(, | and )?)+$"
11+
[stage-12] ✓ Received exit code 1.
1012
[stage-12] Test passed.
1113

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

internal/test_helpers/fixtures/backreferences_multiple/success

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,13 @@
8484
[stage-12] $ echo -n "a cat" | ./your_grep.sh -E "a (cat|dog)"
8585
[your_program] a cat
8686
[stage-12] ✓ Received exit code 0.
87-
[stage-12] $ echo -n "a dog and cats" | ./your_grep.sh -E "a (cat|dog) and (cat|dog)s"
88-
[your_program] a dog and cats
89-
[stage-12] ✓ Received exit code 0.
9087
[stage-12] $ echo -n "a cow" | ./your_grep.sh -E "a (cat|dog)"
9188
[stage-12] ✓ Received exit code 1.
89+
[stage-12] $ echo -n "I see 1 cat, 2 dogs and 3 cows" | ./your_grep.sh -E "^I see (\d (cat|dog|cow)s?(, | and )?)+$"
90+
[your_program] I see 1 cat, 2 dogs and 3 cows
91+
[stage-12] ✓ Received exit code 0.
92+
[stage-12] $ echo -n "I see 1 cat, 2 dogs and 3 cows" | ./your_grep.sh -E "^I see (\d (cat|dog|cow)(, | and )?)+$"
93+
[stage-12] ✓ Received exit code 1.
9294
[stage-12] Test passed.
9395

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

internal/test_helpers/fixtures/backreferences_nested/success

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,13 @@
125125
[stage-12] $ echo -n "a cat" | ./your_grep.sh -E "a (cat|dog)"
126126
[your_program] a cat
127127
[stage-12] ✓ Received exit code 0.
128-
[stage-12] $ echo -n "a dog and cats" | ./your_grep.sh -E "a (cat|dog) and (cat|dog)s"
129-
[your_program] a dog and cats
130-
[stage-12] ✓ Received exit code 0.
131128
[stage-12] $ echo -n "a cow" | ./your_grep.sh -E "a (cat|dog)"
132129
[stage-12] ✓ Received exit code 1.
130+
[stage-12] $ echo -n "I see 1 cat, 2 dogs and 3 cows" | ./your_grep.sh -E "^I see (\d (cat|dog|cow)s?(, | and )?)+$"
131+
[your_program] I see 1 cat, 2 dogs and 3 cows
132+
[stage-12] ✓ Received exit code 0.
133+
[stage-12] $ echo -n "I see 1 cat, 2 dogs and 3 cows" | ./your_grep.sh -E "^I see (\d (cat|dog|cow)(, | and )?)+$"
134+
[stage-12] ✓ Received exit code 1.
133135
[stage-12] Test passed.
134136

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

internal/test_helpers/fixtures/backreferences_single/success

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@
4343
[stage-12] $ echo -n "a cat" | ./your_grep.sh -E "a (cat|dog)"
4444
[your_program] a cat
4545
[stage-12] ✓ Received exit code 0.
46-
[stage-12] $ echo -n "a dog and cats" | ./your_grep.sh -E "a (cat|dog) and (cat|dog)s"
47-
[your_program] a dog and cats
48-
[stage-12] ✓ Received exit code 0.
4946
[stage-12] $ echo -n "a cow" | ./your_grep.sh -E "a (cat|dog)"
5047
[stage-12] ✓ Received exit code 1.
48+
[stage-12] $ echo -n "I see 1 cat, 2 dogs and 3 cows" | ./your_grep.sh -E "^I see (\d (cat|dog|cow)s?(, | and )?)+$"
49+
[your_program] I see 1 cat, 2 dogs and 3 cows
50+
[stage-12] ✓ Received exit code 0.
51+
[stage-12] $ echo -n "I see 1 cat, 2 dogs and 3 cows" | ./your_grep.sh -E "^I see (\d (cat|dog|cow)(, | and )?)+$"
52+
[stage-12] ✓ Received exit code 1.
5153
[stage-12] Test passed.
5254

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

0 commit comments

Comments
 (0)