aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Jakobi <simon.jakobi@gmail.com>2018-07-20 15:06:06 +0200
committerSimon Jakobi <simon.jakobi@gmail.com>2018-07-20 15:09:05 +0200
commit88aac156228f94e17b81d8bcfb961ddcde878489 (patch)
tree54e4f565c6a893c32b8fb6532291142865f12f58
parent051427bce8e0e42610b6a6332e121aebf7bf244b (diff)
Additional tests for the identifier parser (#816)
* Add tests for the identifier parser * docs: Clarify how to delimit identifiers (cherry picked from commit 0861affeca4d72938f05a2eceddfae2c19199071)
-rw-r--r--doc/markup.rst13
-rw-r--r--haddock-library/test/Documentation/Haddock/ParserSpec.hs48
2 files changed, 51 insertions, 10 deletions
diff --git a/doc/markup.rst b/doc/markup.rst
index 1a278da3..a9878837 100644
--- a/doc/markup.rst
+++ b/doc/markup.rst
@@ -859,10 +859,13 @@ Hyperlinked Identifiers
~~~~~~~~~~~~~~~~~~~~~~~
Referring to a Haskell identifier, whether it be a type, class,
-constructor, or function, is done by surrounding it with single quotes: ::
+constructor, or function, is done by surrounding it with a combination
+of single quotes and backticks. For example: ::
-- | This module defines the type 'T'.
+```T``` is also ok. ``'T``` and ```T'`` are accepted but less common.
+
If there is an entity ``T`` in scope in the current module, then the
documentation will hyperlink the reference in the text to the definition
of ``T`` (if the output format supports hyperlinking, of course; in a
@@ -890,14 +893,6 @@ apostrophes themselves: to hyperlink ``foo'`` one would simply type
``'foo''``. To hyperlink identifiers written in infix form, simply put
them in quotes as always: ``'`elem`'``.
-For compatibility with other systems, the following alternative form of
-markup is accepted [3]_: ```T'``.
-
-.. [3]
- We chose not to use this as the primary markup for identifiers
- because strictly speaking the ````` character should not be used as a
- left quote, it is a grave accent.
-
Emphasis, Bold and Monospaced Text
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
"<http://example.com/>" `shouldParseTo` hyperlink "http://example.com/" Nothing