From 88aac156228f94e17b81d8bcfb961ddcde878489 Mon Sep 17 00:00:00 2001 From: Simon Jakobi Date: Fri, 20 Jul 2018 15:06:06 +0200 Subject: Additional tests for the identifier parser (#816) * Add tests for the identifier parser * docs: Clarify how to delimit identifiers (cherry picked from commit 0861affeca4d72938f05a2eceddfae2c19199071) --- .../test/Documentation/Haddock/ParserSpec.hs | 48 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'haddock-library/test/Documentation/Haddock/ParserSpec.hs') diff --git a/haddock-library/test/Documentation/Haddock/ParserSpec.hs b/haddock-library/test/Documentation/Haddock/ParserSpec.hs index 86ed3b35..0449c917 100644 --- a/haddock-library/test/Documentation/Haddock/ParserSpec.hs +++ b/haddock-library/test/Documentation/Haddock/ParserSpec.hs @@ -86,6 +86,18 @@ spec = do it "parses identifiers enclosed within backticks" $ do "`foo`" `shouldParseTo` DocIdentifier "foo" + it "parses identifiers preceded by a backtick and followed by a single quote" $ do + "`foo'" `shouldParseTo` DocIdentifier "foo" + + it "parses identifiers preceded by a single quote and followed by a backtick" $ do + "'foo`" `shouldParseTo` DocIdentifier "foo" + + it "can parse a constructor identifier" $ do + "'Foo'" `shouldParseTo` DocIdentifier "Foo" + + it "can parse a qualified identifier" $ do + "'Foo.bar'" `shouldParseTo` DocIdentifier "Foo.bar" + it "parses a word with an one of the delimiters in it as DocString" $ do "don't" `shouldParseTo` "don't" @@ -99,9 +111,43 @@ spec = do it "doesn't parse empty identifiers" $ do "``" `shouldParseTo` "``" - it "can parse infix identifiers" $ do + it "can parse an identifier in infix notation enclosed within backticks" $ do "``infix``" `shouldParseTo` "`" <> DocIdentifier "infix" <> "`" + it "can parse identifiers containing a single quote" $ do + "'don't'" `shouldParseTo` DocIdentifier "don't" + + it "can parse identifiers ending with a single quote" $ do + "'foo''" `shouldParseTo` DocIdentifier "foo'" + + it "can parse an identifier containing a digit" $ do + "'f0'" `shouldParseTo` DocIdentifier "f0" + + it "can parse an identifier containing unicode characters" $ do + "'λ'" `shouldParseTo` DocIdentifier "λ" + + it "can parse a single quote followed by an identifier" $ do + "''foo'" `shouldParseTo` "'" <> DocIdentifier "foo" + + it "can parse an identifier that starts with an underscore" $ do + "'_x'" `shouldParseTo` DocIdentifier "_x" + + context "when parsing operators" $ do + it "can parse an operator enclosed within single quotes" $ do + "'.='" `shouldParseTo` DocIdentifier ".=" + + it "can parse a qualified operator" $ do + "'F..'" `shouldParseTo` DocIdentifier "F.." + + it "can parse a constructor operator" $ do + "':='" `shouldParseTo` DocIdentifier ":=" + + it "can parse a qualified constructor operator" $ do + "'F.:='" `shouldParseTo` DocIdentifier "F.:=" + + it "can parse a unicode operator" $ do + "'∧'" `shouldParseTo` DocIdentifier "∧" + context "when parsing URLs" $ do it "parses a URL" $ do "" `shouldParseTo` hyperlink "http://example.com/" Nothing -- cgit v1.2.3