diff options
author | Alec Theriault <alec.theriault@gmail.com> | 2018-01-12 16:45:48 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-01-12 16:45:51 -0500 |
commit | e20046a0c4a552c5037797cf720fb34877bc2d21 (patch) | |
tree | ae4e5a12d4fa6dabbc4d535b458f297dd812e332 /testsuite/tests/haddock | |
parent | b2f10d8981bebe44f1ab39e417818dfa2d50639d (diff) | |
download | haskell-e20046a0c4a552c5037797cf720fb34877bc2d21.tar.gz |
Support constructor Haddocks in more places
This adds support for adding Haddocks on individual non-record fields
of regular (and GADT) constructors. The following now parses just fine
with `-haddock` enabled:
data Foo
= Baz -- ^ doc on the `Baz` constructor
Int -- ^ doc on the `Int` field of `Baz`
String -- ^ doc on the `String` field of `Baz`
| Int -- ^ doc on the `Int` field of the `:*` constructor
:* -- ^ doc on the `:*` constructor
String -- ^ doc on the `String` field of the `:*`
constructor
| Boa -- ^ doc on the `Boa` record constructor
{ y :: () }
The change is backwards compatible: if there is only one doc and it
occurs
on the last field, it is lifted to apply to the whole constructor (as
before).
Reviewers: bgamari, alanz
Subscribers: rwbarton, thomie, mpickering, carter
Differential Revision: https://phabricator.haskell.org/D4292
Diffstat (limited to 'testsuite/tests/haddock')
11 files changed, 110 insertions, 0 deletions
diff --git a/testsuite/tests/haddock/should_compile_flag_haddock/all.T b/testsuite/tests/haddock/should_compile_flag_haddock/all.T index 7db4379b16..90d4a55c3f 100644 --- a/testsuite/tests/haddock/should_compile_flag_haddock/all.T +++ b/testsuite/tests/haddock/should_compile_flag_haddock/all.T @@ -39,6 +39,9 @@ test('haddockA029', normal, compile, ['-haddock -ddump-parsed']) test('haddockA030', normal, compile, ['-haddock -ddump-parsed']) test('haddockA031', normal, compile, ['-haddock -ddump-parsed -XExistentialQuantification']) test('haddockA032', normal, compile, ['-haddock -ddump-parsed']) +test('haddockA035', normal, compile, ['-haddock -ddump-parsed']) +test('haddockA036', normal, compile, ['-haddock -ddump-parsed']) +test('haddockA037', normal, compile, ['-haddock -ddump-parsed']) # The tests below this line are not duplicated in # should_compile_noflag_haddock. diff --git a/testsuite/tests/haddock/should_compile_flag_haddock/haddockA035.hs b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA035.hs new file mode 100644 index 0000000000..25ed2acb83 --- /dev/null +++ b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA035.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE GADTs #-} + +module Hi where + +data Hi where + Hi :: () -- ^ This is a comment on the '()' field of 'Hi' + -> Int + -> String -- ^ This is a comment on the 'String' field of 'Hi' + -> Hi -- ^ This is a comment on the return type of 'Hi' diff --git a/testsuite/tests/haddock/should_compile_flag_haddock/haddockA035.stderr b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA035.stderr new file mode 100644 index 0000000000..d0e5bbc57d --- /dev/null +++ b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA035.stderr @@ -0,0 +1,9 @@ + +==================== Parser ==================== +module Hi where +data Hi + where + Hi :: () This is a comment on the '()' field of 'Hi' + -> Int + -> String This is a comment on the 'String' field of 'Hi' + -> Hi This is a comment on the return type of 'Hi' diff --git a/testsuite/tests/haddock/should_compile_flag_haddock/haddockA036.hs b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA036.hs new file mode 100644 index 0000000000..02dd1f9022 --- /dev/null +++ b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA036.hs @@ -0,0 +1,19 @@ +module ConstructorFields where + +data Foo + = Bar Int String -- ^ doc on `Bar` constructor + + | Baz -- ^ doc on the `Baz` constructor + Int -- ^ doc on the `Int` field of `Baz` + String -- ^ doc on the `String` field of `Baz` + + | Int :+ String -- ^ doc on the `:+` constructor + + | Int -- ^ doc on the `Int` field of the `:*` constructor + :* -- ^ doc on the `:*` constructor + String -- ^ doc on the `String` field of the `:*` constructor + + | Boo { x :: () } -- ^ doc on the `Boo` record constructor + + | Boa -- ^ doc on the `Boa` record constructor + { y :: () } diff --git a/testsuite/tests/haddock/should_compile_flag_haddock/haddockA036.stderr b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA036.stderr new file mode 100644 index 0000000000..0d884ab0e3 --- /dev/null +++ b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA036.stderr @@ -0,0 +1,12 @@ + +==================== Parser ==================== +module ConstructorFields where +data Foo + = doc on `Bar` constructor Bar Int String | + doc on the `Baz` constructor + Baz Int doc on the `Int` field of `Baz` String doc on the `String` field of `Baz` | + doc on the `:+` constructor Int :+ String | + doc on the `:*` constructor + Int doc on the `Int` field of the `:*` constructor :* String doc on the `String` field of the `:*` constructor | + doc on the `Boo` record constructor Boo {x :: ()} | + doc on the `Boa` record constructor Boa {y :: ()} diff --git a/testsuite/tests/haddock/should_compile_flag_haddock/haddockA037.hs b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA037.hs new file mode 100644 index 0000000000..4571e09583 --- /dev/null +++ b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA037.hs @@ -0,0 +1,10 @@ +module UnamedConstructorFields where + +data A = A +data B = B +data C = C + +-- Haddock on 'A' prevents the haddock on 'C' from being applied to 'MkFoo' +data Foo = MkFoo A -- ^ 'A' has a comment + B -- This doesn't + C -- ^ 'C' has a comment diff --git a/testsuite/tests/haddock/should_compile_flag_haddock/haddockA037.stderr b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA037.stderr new file mode 100644 index 0000000000..8e90efa691 --- /dev/null +++ b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA037.stderr @@ -0,0 +1,7 @@ + +==================== Parser ==================== +module UnamedConstructorFields where +data A = A +data B = B +data C = C +data Foo = MkFoo A 'A' has a comment B C 'C' has a comment diff --git a/testsuite/tests/haddock/should_compile_noflag_haddock/all.T b/testsuite/tests/haddock/should_compile_noflag_haddock/all.T index c0d62aed43..edb2bd0e05 100644 --- a/testsuite/tests/haddock/should_compile_noflag_haddock/all.T +++ b/testsuite/tests/haddock/should_compile_noflag_haddock/all.T @@ -39,6 +39,9 @@ test('haddockC029', normal, compile, ['']) test('haddockC030', normal, compile, ['']) test('haddockC031', normal, compile, ['-XExistentialQuantification']) test('haddockC032', normal, compile, ['']) +test('haddockC035', normal, compile, ['']) +test('haddockC036', normal, compile, ['']) +test('haddockC037', normal, compile, ['']) # The tests below this line are not duplicated in # should_compile_flag_haddock. diff --git a/testsuite/tests/haddock/should_compile_noflag_haddock/haddockC035.hs b/testsuite/tests/haddock/should_compile_noflag_haddock/haddockC035.hs new file mode 100644 index 0000000000..25ed2acb83 --- /dev/null +++ b/testsuite/tests/haddock/should_compile_noflag_haddock/haddockC035.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE GADTs #-} + +module Hi where + +data Hi where + Hi :: () -- ^ This is a comment on the '()' field of 'Hi' + -> Int + -> String -- ^ This is a comment on the 'String' field of 'Hi' + -> Hi -- ^ This is a comment on the return type of 'Hi' diff --git a/testsuite/tests/haddock/should_compile_noflag_haddock/haddockC036.hs b/testsuite/tests/haddock/should_compile_noflag_haddock/haddockC036.hs new file mode 100644 index 0000000000..02dd1f9022 --- /dev/null +++ b/testsuite/tests/haddock/should_compile_noflag_haddock/haddockC036.hs @@ -0,0 +1,19 @@ +module ConstructorFields where + +data Foo + = Bar Int String -- ^ doc on `Bar` constructor + + | Baz -- ^ doc on the `Baz` constructor + Int -- ^ doc on the `Int` field of `Baz` + String -- ^ doc on the `String` field of `Baz` + + | Int :+ String -- ^ doc on the `:+` constructor + + | Int -- ^ doc on the `Int` field of the `:*` constructor + :* -- ^ doc on the `:*` constructor + String -- ^ doc on the `String` field of the `:*` constructor + + | Boo { x :: () } -- ^ doc on the `Boo` record constructor + + | Boa -- ^ doc on the `Boa` record constructor + { y :: () } diff --git a/testsuite/tests/haddock/should_compile_noflag_haddock/haddockC037.hs b/testsuite/tests/haddock/should_compile_noflag_haddock/haddockC037.hs new file mode 100644 index 0000000000..4571e09583 --- /dev/null +++ b/testsuite/tests/haddock/should_compile_noflag_haddock/haddockC037.hs @@ -0,0 +1,10 @@ +module UnamedConstructorFields where + +data A = A +data B = B +data C = C + +-- Haddock on 'A' prevents the haddock on 'C' from being applied to 'MkFoo' +data Foo = MkFoo A -- ^ 'A' has a comment + B -- This doesn't + C -- ^ 'C' has a comment |