Skip to content

Commit eb6475f

Browse files
Language.Nix.Identifier: generate more simple identifiers
With this, we can get below 70% generated identifiers that don't need quoting.
1 parent 1b257dd commit eb6475f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

language-nix/src/Language/Nix/Identifier.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ instance NFData Identifier where
5151
rnf (Identifier str) = rnf str
5252

5353
instance Arbitrary Identifier where
54-
arbitrary = Identifier <$> listOf1 (arbitraryUnicodeChar `suchThat` (/= '\0'))
54+
arbitrary = Identifier <$> oneof
55+
[ -- almost always needs quoting, unreasonable
56+
listOf1 (nonNul arbitraryUnicodeChar)
57+
-- almost always needs quoting, reasonable-ish
58+
, listOf1 (nonNul arbitraryPrintableChar)
59+
-- rarely needs quoting
60+
, listOf1 (arbitraryASCIIChar `suchThat` isSimpleChar) ]
61+
where nonNul g = g `suchThat` (/= '\0')
62+
isSimpleChar c = isAlphaNum c || c `elem` "_-'"
5563
shrink (Identifier i) = map Identifier (shrink i)
5664

5765
instance CoArbitrary Identifier

0 commit comments

Comments
 (0)