Skip to content

Commit 554e74c

Browse files
authored
Merge pull request #114 from haskell-jp/grammar
英文の改善
2 parents cb5bcd4 + e23a18b commit 554e74c

File tree

11 files changed

+45
-47
lines changed

11 files changed

+45
-47
lines changed

src/Education/MakeMistakesToLearnHaskell/Exercise/Core.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ isInWords wd = any (Text.isInfixOf wd)
125125

126126
detailsForgetToWriteDo :: Text -> Details
127127
detailsForgetToWriteDo funcNames =
128-
"HINT: You seem to forget to write `do`. `do` must be put before listing " <> funcNames <> "."
128+
"HINT: You seem to have forgotten to write `do`. `do` must be put before listing " <> funcNames <> "."
129129

130130
detailsDoConsistentWidth :: Details
131131
detailsDoConsistentWidth = "HINT: instructions in a `do` must be in a consistent width."

src/Education/MakeMistakesToLearnHaskell/Exercise/Ex01.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ diag1 :: Diagnosis
1717
diag1 code msg
1818
| "parse error on input" `Text.isInfixOf` msg
1919
&& "'" `Text.isInfixOf` code =
20-
"HINT: In Haskell, you must surround string literals with double-quote '\"'. Such as \"Hello, world\"."
20+
"HINT: In Haskell, you must surround string literals with double-quotes '\"', like \"Hello, world\"."
2121
| ("parse error" `Text.isInfixOf` msg || "Parse error" `Text.isInfixOf` msg)
2222
&& "top-level declaration expected." `Text.isInfixOf` msg =
23-
"HINT: This error indicates you haven't defined main function."
23+
"HINT: This error indicates that you haven't defined the main function."
2424
| "Variable not in scope: main :: IO" `Text.isInfixOf` msg =
25-
"HINT: This error indicates you haven't defined main function."
25+
"HINT: This error indicates that you haven't defined the main function."
2626
| "Variable not in scope:" `Text.isInfixOf` msg =
2727
"HINT: you might have misspelled 'putStrLn'."
2828
| otherwise = ""

src/Education/MakeMistakesToLearnHaskell/Exercise/Ex02.hs

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ diag2 code msg
1717
| "parse error" `Text.isInfixOf` msg || "Parse error" `Text.isInfixOf` msg =
1818
if "top-level declaration expected." `Text.isInfixOf` msg
1919
then
20-
"HINT: This error indicates you haven't defined main function."
20+
"HINT: This error indicates that you haven't defined the main function."
2121
else
2222
-- TODO: Use regex or ghc tokenizer
2323
case compare (Text.count "(" code) (Text.count ")" code) of
24-
GT -> "HINT: you might have forgot to write close parenthesis"
25-
LT -> "HINT: you might have forgot to write open parenthesis"
24+
GT -> "HINT: you might have forgotten to write a close parenthesis"
25+
LT -> "HINT: you might have forgotten to write an open parenthesis"
2626
EQ -> ""
2727
| "No instance for (Fractional (IO ()))" `Text.isInfixOf` msg || "No instance for (Num (IO ()))" `Text.isInfixOf` msg =
28-
"HINT: you might have forgot to write parentheses"
28+
"HINT: you might have forgotten to write parentheses"
2929
| "No instance for (Show (a0 -> a0))" `Text.isInfixOf` msg =
30-
"HINT: you might have forgot to write some numbers between operators ('*', '/' etc.)."
30+
"HINT: you might have forgotten to write some numbers between operators ('*', '/' etc.)."
3131
| "No instance for (Num (t0 -> a0))" `Text.isInfixOf` msg =
32-
"HINT: you might have forgot to write multiplication operator '*'"
32+
"HINT: you might have forgotten to write the multiplication operator '*'"
3333
| "No instance for (Fractional (t0 -> a0))" `Text.isInfixOf` msg =
34-
"HINT: you might have forgot to write division operator '/'"
34+
"HINT: you might have forgotten to write the division operator '/'"
3535
| "Variable not in scope: main :: IO" `Text.isInfixOf` msg =
36-
"HINT: This error indicates you haven't defined main function."
36+
"HINT: This error indicates that you haven't defined the main function."
3737
| otherwise = ""

src/Education/MakeMistakesToLearnHaskell/Exercise/Ex03.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ diag3 code msg
2525
| code `isInconsistentlyIndentedAfter` "do" = detailsDoConsistentWidth
2626
| "parse error on input" `Text.isInfixOf` msg
2727
&& "'" `Text.isInfixOf` code =
28-
"HINT: In Haskell, you must surround string literals with double-quote '\"'. Such as \"Hello, world\"."
28+
"HINT: In Haskell, you must surround string literals with double-quotes '\"', like \"Hello, world\"."
2929
| ("parse error" `Text.isInfixOf` msg || "Parse error" `Text.isInfixOf` msg)
3030
&& "top-level declaration expected." `Text.isInfixOf` msg =
31-
"HINT: This error indicates you haven't defined main function."
31+
"HINT: This error indicates that you haven't defined the main function."
3232
| "Variable not in scope: main :: IO" `Text.isInfixOf` msg =
33-
"HINT: This error indicates you haven't defined main function."
33+
"HINT: This error indicates that you haven't defined the main function."
3434
| "Variable not in scope:" `Text.isInfixOf` msg =
3535
"HINT: you might have misspelled 'putStrLn'."
3636
| "Couldn't match expected type ‘(String -> IO ())" `Text.isInfixOf` msg =

src/Education/MakeMistakesToLearnHaskell/Exercise/Ex04.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ diag4 code msg
3535
"HINT: Don't assign the result of `getContents` with `=`. Use `<-` instead."
3636
| "Couldn't match type ‘IO String’ with ‘[Char]’" `Text.isInfixOf` msg
3737
&& "In the first argument of ‘lines’" `Text.isInfixOf` msg =
38-
"HINT: Unfortunately, you have to assign the result of `getContents` with `<-` operator."
38+
"HINT: You have to assign the result of `getContents` with `<-` operator."
3939
| otherwise =
4040
let mtoks = GHC.tokenizeHaskell (Text.toStrict code)
4141
tokPutStr = (GHC.VariableTok, "putStr")

test/Education/MakeMistakesToLearnHaskell/Exercise1Spec.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ spec = do
2424
itShouldFailForCaseWithMessage
2525
"1"
2626
"single-quote"
27-
["HINT: In Haskell, you must surround string literals with double-quote '\"'. Such as \"Hello, world\"."]
27+
["HINT: In Haskell, you must surround string literals with double-quotes '\"', like \"Hello, world\"."]
2828

2929
itShouldFailForCaseWithMessage
3030
"1"
3131
"no-main"
32-
["HINT: This error indicates you haven't defined main function."]
32+
["HINT: This error indicates that you haven't defined the main function."]
3333

3434
itShouldFailForCaseWithMessage "1" "typo" []

test/Education/MakeMistakesToLearnHaskell/Exercise2Spec.hs

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,47 +32,47 @@ spec = do
3232
itShouldFailForCaseWithMessage
3333
"2"
3434
"no-number-1"
35-
["HINT: you might have forgot to write some numbers between operators ('*', '/' etc.)."]
35+
["HINT: you might have forgotten to write some numbers between operators ('*', '/' etc.)."]
3636

3737
itShouldFailForCaseWithMessage
3838
"2"
3939
"no-number-2"
40-
["HINT: you might have forgot to write some numbers between operators ('*', '/' etc.)."]
40+
["HINT: you might have forgotten to write some numbers between operators ('*', '/' etc.)."]
4141

4242
itShouldFailForCaseWithMessage
4343
"2"
4444
"no-number-3"
45-
["HINT: you might have forgot to write some numbers between operators ('*', '/' etc.)."]
45+
["HINT: you might have forgotten to write some numbers between operators ('*', '/' etc.)."]
4646

4747
itShouldFailForCaseWithMessage
4848
"2"
4949
"no-paren"
50-
["HINT: you might have forgot to write parentheses"]
50+
["HINT: you might have forgotten to write parentheses"]
5151

5252
itShouldFailForCaseWithMessage
5353
"2"
5454
"no-close-paren"
55-
["HINT: you might have forgot to write close parenthesis"]
55+
["HINT: you might have forgotten to write a close parenthesis"]
5656

5757
itShouldFailForCaseWithMessage
5858
"2"
5959
"no-main"
60-
["HINT: This error indicates you haven't defined main function."]
60+
["HINT: This error indicates that you haven't defined the main function."]
6161

6262
itShouldFailForCaseWithMessage
6363
"2"
6464
"no-open-paren"
65-
["HINT: you might have forgot to write open parenthesis"]
65+
["HINT: you might have forgotten to write an open parenthesis"]
6666

6767
itShouldFailForCaseWithMessage
6868
"2"
6969
"no-slash"
70-
["HINT: you might have forgot to write division operator '/'"]
70+
["HINT: you might have forgotten to write the division operator '/'"]
7171

7272
itShouldFailForCaseWithMessage
7373
"2"
7474
"no-star"
75-
["HINT: you might have forgot to write multiplication operator '*'"]
75+
["HINT: you might have forgotten to write the multiplication operator '*'"]
7676

7777
itShouldFailForCaseWithMessage "2" "typo" []
7878

test/Education/MakeMistakesToLearnHaskell/Exercise3Spec.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec = do
3232
itShouldFailForCaseWithMessage
3333
"3"
3434
"no-main"
35-
["HINT: This error indicates you haven't defined main function."]
35+
["HINT: This error indicates that you haven't defined the main function."]
3636

3737
itShouldFailForCaseWithMessage
3838
"3"
@@ -47,12 +47,12 @@ spec = do
4747
itShouldFailForCaseWithMessage
4848
"3"
4949
"no-do"
50-
["HINT: You seem to forget to write `do`. `do` must be put before listing `putStrLn`s."]
50+
["HINT: You seem to have forgotten to write `do`. `do` must be put before listing `putStrLn`s."]
5151

5252
itShouldFailForCaseWithMessage
5353
"3"
5454
"single-quote"
55-
["HINT: In Haskell, you must surround string literals with double-quote '\"'. Such as \"Hello, world\"."]
55+
["HINT: In Haskell, you must surround string literals with double-quotes '\"', like \"Hello, world\"."]
5656

5757
itShouldFailForCaseWithMessage "3" "typo" []
5858

test/Education/MakeMistakesToLearnHaskell/Exercise4Spec.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ spec = do
2828
itShouldFailForCaseWithMessage
2929
"4"
3030
"no-do"
31-
["HINT: You seem to forget to write `do`. `do` must be put before listing `putStr`s and `getContents`."]
31+
["HINT: You seem to have forgotten to write `do`. `do` must be put before listing `putStr`s and `getContents`."]
3232

3333
let useLeftThinArrow = "HINT: Don't assign the result of `getContents` with `=`. Use `<-` instead."
3434
-- ^ TODO: Collect common error messages
@@ -61,7 +61,7 @@ spec = do
6161
itShouldFailForCaseWithMessage
6262
"4"
6363
"no-arrow"
64-
["HINT: Unfortunately, you have to assign the result of `getContents` with `<-` operator."]
64+
["HINT: You have to assign the result of `getContents` with `<-` operator."]
6565

6666
itShouldFailForCaseWithMessage
6767
"4"

test/Education/MakeMistakesToLearnHaskell/SpecHelper.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module Education.MakeMistakesToLearnHaskell.SpecHelper where
77
import qualified Education.MakeMistakesToLearnHaskell.Exercise as Exercise
88
import Education.MakeMistakesToLearnHaskell.SpecEnv (setRunHaskellFailureWithOutput, mkDefaultSpecEnv)
99

10-
1110
shouldFail :: Exercise.Result -> IO Exercise.Details
1211
shouldFail (Exercise.Fail d) = return d
1312
shouldFail other = fail $ "Unexpected exercise result: " ++ show other
@@ -29,4 +28,4 @@ itShouldFailForCaseWithMessage ename tcid messages = do
2928
let e = setRunHaskellFailureWithOutput baseEnv err
3029
d <- shouldFail =<< Exercise.verify subject e ("test/assets/" ++ ename ++ "/" ++ tcid ++ ".hs")
3130

32-
for_ messages $ \message -> d `shouldSatisfy` Text.isInfixOf message
31+
for_ messages $ \message -> (Text.unpack d `shouldContain` Text.unpack message)

test/Education/MakeMistakesToLearnHaskellSpec.hs

+12-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module Education.MakeMistakesToLearnHaskellSpec (main, spec) where
77
import qualified Education.MakeMistakesToLearnHaskell
88
import Education.MakeMistakesToLearnHaskell.Env
99

10-
1110
-- `main` is here so that this module can be run from GHCi on its own. It is
1211
-- not needed for automatic spec discovery.
1312
main :: IO ()
@@ -25,7 +24,7 @@ spec =
2524
it "given an empty answer, show FAIL" $ do
2625
void $ runMmlh ["show", "--terminal", "1"]
2726
runMmlh ["verify", "test/assets/common/empty.hs"]
28-
>>= shouldExitWithHints ["HINT: This error indicates you haven't defined main function."]
27+
>>= shouldExitWithHints ["HINT: This error indicates that you haven't defined the main function."]
2928

3029
it "given non-existing answer of exercise 2.5, show NOT VERIFIED" $ do
3130
void $ runMmlh ["show", "--terminal", "2.5"]
@@ -44,7 +43,7 @@ spec =
4443

4544
it "given a not-compilable answer of exercise 4, show FAIL" $ do
4645
let msgs =
47-
["HINT: You seem to forget to write `do`. `do` must be put before listing `putStr`s and `getContents`."]
46+
["HINT: You seem to have forgotten to write `do`. `do` must be put before listing `putStr`s and `getContents`."]
4847
void $ runMmlh ["show", "--terminal", "4"]
4948
runMmlh ["verify", "test/assets/4/no-do.hs"]
5049
>>= shouldExitWithHints msgs
@@ -58,30 +57,30 @@ runMmlh args = do
5857
$ withEnv env
5958
$ captureProcessResult Education.MakeMistakesToLearnHaskell.main
6059

61-
62-
includes :: ByteString'.ByteString -> ByteString'.ByteString -> Bool
63-
includes = ByteString'.isInfixOf
64-
60+
shouldContainBS :: ByteString'.ByteString -> ByteString'.ByteString -> Expectation
61+
shouldContainBS a b = if ByteString'.isInfixOf b a
62+
then pure ()
63+
else expectationFailure $ unwords [show a, "does not contain", show b]
6564

6665
shouldExitWithHints :: [ByteString'.ByteString] -> ProcessResult -> IO ()
6766
shouldExitWithHints hintMsgs (ProcessResult out err code ex) = do
6867
fmap show ex `shouldBe` Nothing
69-
err `shouldSatisfy` ByteString'.null
70-
mapM_ ((out `shouldSatisfy`) . includes) hintMsgs
68+
err `shouldBe` ByteString'.empty
69+
mapM_ (out `shouldContainBS`) hintMsgs
7170
code `shouldBe` ExitFailure 1
7271

7372

7473
shouldVerifySuccess :: ProcessResult -> IO ()
7574
shouldVerifySuccess (ProcessResult out err code ex) = do
7675
fmap show ex `shouldBe` Nothing
77-
err `shouldSatisfy` ByteString'.null
78-
out `shouldSatisfy` includes "SUCCESS"
76+
err `shouldBe` ByteString'.empty
77+
out `shouldContainBS` "SUCCESS"
7978
code `shouldBe` ExitSuccess
8079

8180

8281
shouldPrintNotVerified :: ProcessResult -> IO ()
8382
shouldPrintNotVerified (ProcessResult out err code ex) = do
8483
fmap show ex `shouldBe` Nothing
85-
err `shouldSatisfy` ByteString'.null
86-
out `shouldSatisfy` includes "NOT VERIFIED"
84+
err `shouldBe` ByteString'.empty
85+
out `shouldContainBS` "NOT VERIFIED"
8786
code `shouldBe` ExitSuccess

0 commit comments

Comments
 (0)