Skip to content

Commit

Permalink
Merge pull request #89 from codecrafters-io/andy/patch
Browse files Browse the repository at this point in the history
CC-1568: Add test case of `echo 'hello''world'` for Quoting [Shell]
  • Loading branch information
andy1li authored Jan 3, 2025
2 parents 40ed31c + 522dee8 commit b288ef2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions internal/stage_q1.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func testQ1(stageHarness *test_case_harness.TestCaseHarness) error {
inputs := []string{
fmt.Sprintf(`echo '%s %s'`, L[0], L[1]),
fmt.Sprintf(`echo %s %s`, L[1], L[4]),
fmt.Sprintf(`echo '%s %s'`, L[2], L[3]),
fmt.Sprintf(`echo '%s %s' '%s''%s'`, L[2], L[3], L[4], L[0]),
fmt.Sprintf(`cat '%s' '%s' '%s'`, filePaths[0], filePaths[1], filePaths[2]),
}
expectedOutputs := []string{
fmt.Sprintf("%s %s", L[0], L[1]),
fmt.Sprintf("%s %s", L[1], L[4]),
fmt.Sprintf("%s %s", L[2], L[3]),
fmt.Sprintf("%s %s %s%s", L[2], L[3], L[4], L[0]),
fileContents[0] + fileContents[1] + strings.TrimRight(fileContents[2], "\n"),
}
testCaseContents := newTestCaseContents(inputs, expectedOutputs)
Expand Down
4 changes: 2 additions & 2 deletions internal/stage_q2.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func testQ2(stageHarness *test_case_harness.TestCaseHarness) error {
L := random.RandomElementsFromArray(LARGE_WORDS, 5)
inputs := []string{
fmt.Sprintf(`echo "%s %s"`, L[0], L[1]),
fmt.Sprintf(`echo "%s %s" "%s"`, L[1], L[2], L[3]),
fmt.Sprintf(`echo "%s %s" "%s""%s"`, L[1], L[2], L[3], L[0]),
fmt.Sprintf(`echo "%s" "%s's" "%s"`, L[3], L[4], L[1]),
fmt.Sprintf(`cat "%s" "%s" "%s"`, filePaths[0], filePaths[1], filePaths[2]),
}
expectedOutputs := []string{
fmt.Sprintf("%s %s", L[0], L[1]),
fmt.Sprintf("%s %s %s", L[1], L[2], L[3]),
fmt.Sprintf("%s %s %s%s", L[1], L[2], L[3], L[0]),
fmt.Sprintf(`%s %s's %s`, L[3], L[4], L[1]),
fileContents[0] + fileContents[1] + strings.TrimRight(fileContents[2], "\n"),
}
Expand Down
8 changes: 4 additions & 4 deletions internal/test_helpers/fixtures/quoting/pass
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Debug = true
[your-program] $ echo world script
[your-program] world script
[stage-6] ✓ Received expected response
[your-program] $ echo 'shell example'
[your-program] shell example
[your-program] $ echo 'shell example' 'script''test'
[your-program] shell example scripttest
[stage-6] ✓ Received expected response
[stage-6] Writing file "/tmp/foo/f 30" with content "grape banana."
[stage-6] Writing file "/tmp/foo/f 67" with content "strawberry apple."
Expand All @@ -25,8 +25,8 @@ Debug = true
[your-program] $ echo "world shell"
[your-program] world shell
[stage-5] ✓ Received expected response
[your-program] $ echo "shell script" "hello"
[your-program] shell script hello
[your-program] $ echo "shell script" "hello""world"
[your-program] shell script helloworld
[stage-5] ✓ Received expected response
[your-program] $ echo "hello" "test's" "shell"
[your-program] hello test's shell
Expand Down

0 comments on commit b288ef2

Please sign in to comment.