Skip to content
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

Remove nonEmptyOrFail function from recent tests #1237

Merged
merged 4 commits into from
Apr 26, 2021
Merged
Changes from 1 commit
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
56 changes: 27 additions & 29 deletions persistent/test/main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,36 @@ main = hspec $ do
`shouldBe`
( [NEL.toList helloWorldTokens, NEL.toList foobarbazTokens], mempty )
it "works4" $ do
let foobarbarz = ["foo", "Bar", "baz"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were also causing some type ambiguity errors, where with OverloadedLists we want to use this value here both as a [Text] and NonEmpty Text, so I have opted to re-writing the test with literals rather than trying to re-use the values. I've tried to include some more realworld looking values too while changing things here.

fbbTokens = Token <$> nonEmptyOrFail foobarbarz
splitExtras
[ Line 0 (pure (Token "Hello"))
, Line 2 fbbTokens
, Line 2 fbbTokens
[ Line 0 [Token "Product"]
, Line 2 (Token <$> ["name", "Text"])
, Line 2 (Token <$> ["added", "UTCTime", "default=CURRENT_TIMESTAMP"])
]
`shouldBe`
( []
, Map.fromList
[ ("Hello", [foobarbarz, foobarbarz])
]
[ ("Product",
[ ["name", "Text"]
, ["added", "UTCTime", "default=CURRENT_TIMESTAMP"]
]
) ]
)
it "works5" $ do
let foobarbarz = ["foo", "Bar", "baz"]
fbbTokens = Token <$> nonEmptyOrFail foobarbarz
splitExtras
[ Line 0 (pure (Token "Hello"))
, Line 2 fbbTokens
, Line 4 fbbTokens
[ Line 0 [Token "Product"]
, Line 2 (Token <$> ["name", "Text"])
, Line 4 [Token "ExtraBlock"]
, Line 4 (Token <$> ["added", "UTCTime", "default=CURRENT_TIMESTAMP"])
]
`shouldBe`
( []
, Map.fromList
[ ("Hello", [foobarbarz, foobarbarz])
]
[ ("Product",
[ ["name", "Text"]
, ["ExtraBlock"]
, ["added", "UTCTime", "default=CURRENT_TIMESTAMP"]
]
)]
)
describe "takeColsEx" $ do
let subject = takeColsEx upperCaseSettings
Expand Down Expand Up @@ -140,7 +144,7 @@ main = hspec $ do
it "handles normal words" $
parseLine " foo bar baz" `shouldBe`
Just
( Line 1 $ nonEmptyOrFail
( Line 1
[ Token "foo"
, Token "bar"
, Token "baz"
Expand All @@ -150,7 +154,7 @@ main = hspec $ do
it "handles quotes" $
parseLine " \"foo bar\" \"baz\"" `shouldBe`
Just
( Line 2 $ nonEmptyOrFail
( Line 2
[ Token "foo bar"
, Token "baz"
]
Expand All @@ -159,7 +163,7 @@ main = hspec $ do
it "handles quotes mid-token" $
parseLine " x=\"foo bar\" \"baz\"" `shouldBe`
Just
( Line 2 $ nonEmptyOrFail
( Line 2
[ Token "x=foo bar"
, Token "baz"
]
Expand All @@ -168,7 +172,7 @@ main = hspec $ do
it "handles escaped quote mid-token" $
parseLine " x=\\\"foo bar\" \"baz\"" `shouldBe`
Just
( Line 2 $ nonEmptyOrFail
( Line 2
[ Token "x=\\\"foo"
, Token "bar\""
, Token "baz"
Expand All @@ -178,7 +182,7 @@ main = hspec $ do
it "handles unnested parantheses" $
parseLine " (foo bar) (baz)" `shouldBe`
Just
( Line 2 $ nonEmptyOrFail
( Line 2
[ Token "foo bar"
, Token "baz"
]
Expand All @@ -187,7 +191,7 @@ main = hspec $ do
it "handles unnested parantheses mid-token" $
parseLine " x=(foo bar) (baz)" `shouldBe`
Just
( Line 2 $ nonEmptyOrFail
( Line 2
[ Token "x=foo bar"
, Token "baz"
]
Expand All @@ -196,7 +200,7 @@ main = hspec $ do
it "handles nested parantheses" $
parseLine " (foo (bar)) (baz)" `shouldBe`
Just
( Line 2 $ nonEmptyOrFail
( Line 2
[ Token "foo (bar)"
, Token "baz"
]
Expand All @@ -205,7 +209,7 @@ main = hspec $ do
it "escaping" $
parseLine " (foo \\(bar) y=\"baz\\\"\"" `shouldBe`
Just
( Line 2 $ nonEmptyOrFail
( Line 2
[ Token "foo (bar"
, Token "y=baz\""
]
Expand All @@ -214,7 +218,7 @@ main = hspec $ do
it "mid-token quote in later token" $
parseLine "foo bar baz=(bin\")" `shouldBe`
Just
( Line 0 $ nonEmptyOrFail
( Line 0
[ Token "foo"
, Token "bar"
, Token "baz=bin\""
Expand Down Expand Up @@ -881,12 +885,6 @@ takePrefix :: Value -> Value
takePrefix (String a) = String (T.take 1 a)
takePrefix a = a

nonEmptyOrFail :: [a] -> NonEmpty a
nonEmptyOrFail = maybe failure id . NEL.nonEmpty
where
failure =
error "nonEmptyOrFail expected a non empty list"

arbitraryWhiteSpaceChar :: Gen Char
arbitraryWhiteSpaceChar =
oneof $ pure <$> [' ', '\t', '\n', '\r']