Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
Prev Previous commit
Next Next commit
language-nix/test: report how many tested identifiers need quoting
Currently this is practically > 95% which isn't great. Presumably, the
examples for simple identifiers are very short as well.
  • Loading branch information
sternenseemann committed Sep 12, 2025
commit 1b257dd0bee74c3f5aab5dfad8ca3426e2b30d9b
8 changes: 6 additions & 2 deletions language-nix/test/hspec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ main = hspec $ do

describe "HasParser Identifier" $ do
it "can parse the result of prettyShow" $
property $ \i -> parseM "Identifier" (prettyShow i) == Just (i :: Identifier)
identProperty $ \i -> parseM "Identifier" (prettyShow i) == Just (i :: Identifier)
it "can parse the result of quote" $
stringIdentProperty $ \str -> parseM "Identifier" (quote str) == Just (ident # str)

stringIdentProperty :: (String -> Bool) -> Property
stringIdentProperty p = property $ \s ->
'\0' `notElem` s ==> p s
'\0' `notElem` s ==> classify (needsQuoting s) "need quoting" $ p s

identProperty :: (Identifier -> Bool) -> Property
identProperty p = property $ \i ->
classify (needsQuoting (from ident # i)) "need quoting" $ p i