diff options
Diffstat (limited to 'testsuite/tests/ghc-api')
81 files changed, 1051 insertions, 0 deletions
diff --git a/testsuite/tests/ghc-api/exactprint/.gitignore b/testsuite/tests/ghc-api/exactprint/.gitignore new file mode 100644 index 0000000000..c643ad1efe --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/.gitignore @@ -0,0 +1,4 @@ +*.hi +*.o +*.run.* +*.normalised diff --git a/testsuite/tests/ghc-api/exactprint/AddDecl1.expected.hs b/testsuite/tests/ghc-api/exactprint/AddDecl1.expected.hs new file mode 100644 index 0000000000..88ef0fdd7d --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddDecl1.expected.hs @@ -0,0 +1,13 @@ +module AddDecl where + +nn = n2 + +-- Adding a declaration to an existing file + +-- | Do foo +foo a b = a + b + +-- | Do bar +bar x y = {- baz -} foo (x+y) x + +-- end of file diff --git a/testsuite/tests/ghc-api/exactprint/AddDecl1.hs b/testsuite/tests/ghc-api/exactprint/AddDecl1.hs new file mode 100644 index 0000000000..45c0cb3864 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddDecl1.hs @@ -0,0 +1,11 @@ +module AddDecl where + +-- Adding a declaration to an existing file + +-- | Do foo +foo a b = a + b + +-- | Do bar +bar x y = {- baz -} foo (x+y) x + +-- end of file diff --git a/testsuite/tests/ghc-api/exactprint/AddDecl2.expected.hs b/testsuite/tests/ghc-api/exactprint/AddDecl2.expected.hs new file mode 100644 index 0000000000..2bbbcf5b37 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddDecl2.expected.hs @@ -0,0 +1,13 @@ +module AddDecl where + +-- Adding a declaration to an existing file + +-- | Do foo +foo a b = a + b + +-- | Do bar +bar x y = {- baz -} foo (x+y) x + +nn = n2 + +-- end of file diff --git a/testsuite/tests/ghc-api/exactprint/AddDecl2.hs b/testsuite/tests/ghc-api/exactprint/AddDecl2.hs new file mode 100644 index 0000000000..45c0cb3864 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddDecl2.hs @@ -0,0 +1,11 @@ +module AddDecl where + +-- Adding a declaration to an existing file + +-- | Do foo +foo a b = a + b + +-- | Do bar +bar x y = {- baz -} foo (x+y) x + +-- end of file diff --git a/testsuite/tests/ghc-api/exactprint/AddDecl3.expected.hs b/testsuite/tests/ghc-api/exactprint/AddDecl3.expected.hs new file mode 100644 index 0000000000..dd3044fcc5 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddDecl3.expected.hs @@ -0,0 +1,13 @@ +module AddDecl where + +-- Adding a declaration to an existing file + +-- | Do foo +foo a b = a + b + +nn = n2 + +-- | Do bar +bar x y = {- baz -} foo (x+y) x + +-- end of file diff --git a/testsuite/tests/ghc-api/exactprint/AddDecl3.hs b/testsuite/tests/ghc-api/exactprint/AddDecl3.hs new file mode 100644 index 0000000000..45c0cb3864 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddDecl3.hs @@ -0,0 +1,11 @@ +module AddDecl where + +-- Adding a declaration to an existing file + +-- | Do foo +foo a b = a + b + +-- | Do bar +bar x y = {- baz -} foo (x+y) x + +-- end of file diff --git a/testsuite/tests/ghc-api/exactprint/AddHiding1.expected.hs b/testsuite/tests/ghc-api/exactprint/AddHiding1.expected.hs new file mode 100644 index 0000000000..f3c8f17c8b --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddHiding1.expected.hs @@ -0,0 +1,8 @@ +module AddHiding1 where + +import Data.Maybe hiding (n1,n2) + +import Data.Maybe hiding (n1,n2) + +f = 1 + diff --git a/testsuite/tests/ghc-api/exactprint/AddHiding1.hs b/testsuite/tests/ghc-api/exactprint/AddHiding1.hs new file mode 100644 index 0000000000..abcd47879a --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddHiding1.hs @@ -0,0 +1,8 @@ +module AddHiding1 where + +import Data.Maybe + +import Data.Maybe hiding (n1,n2) + +f = 1 + diff --git a/testsuite/tests/ghc-api/exactprint/AddHiding2.expected.hs b/testsuite/tests/ghc-api/exactprint/AddHiding2.expected.hs new file mode 100644 index 0000000000..d62005227b --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddHiding2.expected.hs @@ -0,0 +1,5 @@ +module AddHiding2 where + +import Data.Maybe hiding (f1,f2,n1,n2) + +f = 1 diff --git a/testsuite/tests/ghc-api/exactprint/AddHiding2.hs b/testsuite/tests/ghc-api/exactprint/AddHiding2.hs new file mode 100644 index 0000000000..f5f551a9cb --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddHiding2.hs @@ -0,0 +1,5 @@ +module AddHiding2 where + +import Data.Maybe hiding (f1,f2) + +f = 1 diff --git a/testsuite/tests/ghc-api/exactprint/AddLocalDecl1.expected.hs b/testsuite/tests/ghc-api/exactprint/AddLocalDecl1.expected.hs new file mode 100644 index 0000000000..023e2ea05d --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddLocalDecl1.expected.hs @@ -0,0 +1,15 @@ +module AddLocalDecl1 where + +-- |This is a function +foo = x -- comment1 + where + nn = 2 +-- trailing 1 + +-- |Another fun +x = a -- comment2 + where + a = 3 +-- trailing 2 + +y = 3 diff --git a/testsuite/tests/ghc-api/exactprint/AddLocalDecl1.hs b/testsuite/tests/ghc-api/exactprint/AddLocalDecl1.hs new file mode 100644 index 0000000000..3bb4953c51 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddLocalDecl1.hs @@ -0,0 +1,13 @@ +module AddLocalDecl1 where + +-- |This is a function +foo = x -- comment1 +-- trailing 1 + +-- |Another fun +x = a -- comment2 + where + a = 3 +-- trailing 2 + +y = 3 diff --git a/testsuite/tests/ghc-api/exactprint/AddLocalDecl2.expected.hs b/testsuite/tests/ghc-api/exactprint/AddLocalDecl2.expected.hs new file mode 100644 index 0000000000..ff25b79157 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddLocalDecl2.expected.hs @@ -0,0 +1,11 @@ +module AddLocalDecl2 where + +-- |This is a function +foo = x -- comment 0 + where nn = 2 + p = 2 -- comment 1 + +-- |Another fun +bar = a -- comment 2 + where nn = 2 + p = 2 -- comment 3 diff --git a/testsuite/tests/ghc-api/exactprint/AddLocalDecl2.hs b/testsuite/tests/ghc-api/exactprint/AddLocalDecl2.hs new file mode 100644 index 0000000000..7609f657ed --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddLocalDecl2.hs @@ -0,0 +1,10 @@ +module AddLocalDecl2 where + +-- |This is a function +foo = x -- comment 0 + where p = 2 -- comment 1 + +-- |Another fun +bar = a -- comment 2 + where nn = 2 + p = 2 -- comment 3 diff --git a/testsuite/tests/ghc-api/exactprint/AddLocalDecl3.expected.hs b/testsuite/tests/ghc-api/exactprint/AddLocalDecl3.expected.hs new file mode 100644 index 0000000000..deaf1e7cb8 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddLocalDecl3.expected.hs @@ -0,0 +1,13 @@ +module AddLocalDecl3 where + +-- |This is a function +foo = x -- comment 0 + where p = 2 -- comment 1 + nn = 2 + -- comment f + +-- |Another fun +bar = a -- comment 2 + where p = 2 -- comment 3 + nn = 2 + -- comment b diff --git a/testsuite/tests/ghc-api/exactprint/AddLocalDecl3.hs b/testsuite/tests/ghc-api/exactprint/AddLocalDecl3.hs new file mode 100644 index 0000000000..eb14013031 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddLocalDecl3.hs @@ -0,0 +1,12 @@ +module AddLocalDecl3 where + +-- |This is a function +foo = x -- comment 0 + where p = 2 -- comment 1 + -- comment f + +-- |Another fun +bar = a -- comment 2 + where p = 2 -- comment 3 + nn = 2 + -- comment b diff --git a/testsuite/tests/ghc-api/exactprint/AddLocalDecl4.expected.hs b/testsuite/tests/ghc-api/exactprint/AddLocalDecl4.expected.hs new file mode 100644 index 0000000000..b3c1445d0d --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddLocalDecl4.expected.hs @@ -0,0 +1,6 @@ +module AddLocalDecl4 where + +toplevel x = c * x + where + nn :: Int + nn = 2 diff --git a/testsuite/tests/ghc-api/exactprint/AddLocalDecl4.hs b/testsuite/tests/ghc-api/exactprint/AddLocalDecl4.hs new file mode 100644 index 0000000000..2ec2c0bf73 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddLocalDecl4.hs @@ -0,0 +1,3 @@ +module AddLocalDecl4 where + +toplevel x = c * x diff --git a/testsuite/tests/ghc-api/exactprint/AddLocalDecl5.expected.hs b/testsuite/tests/ghc-api/exactprint/AddLocalDecl5.expected.hs new file mode 100644 index 0000000000..5e66dc5a6b --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddLocalDecl5.expected.hs @@ -0,0 +1,9 @@ +module AddLocalDecl5 where + +toplevel :: Integer -> Integer +toplevel x = c * x + where + -- c,d :: Integer + c = 7 + +d = 9 diff --git a/testsuite/tests/ghc-api/exactprint/AddLocalDecl5.hs b/testsuite/tests/ghc-api/exactprint/AddLocalDecl5.hs new file mode 100644 index 0000000000..9f07e1071b --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddLocalDecl5.hs @@ -0,0 +1,8 @@ +module AddLocalDecl5 where + +toplevel :: Integer -> Integer +toplevel x = c * x + +-- c,d :: Integer +c = 7 +d = 9 diff --git a/testsuite/tests/ghc-api/exactprint/AddLocalDecl6.expected.hs b/testsuite/tests/ghc-api/exactprint/AddLocalDecl6.expected.hs new file mode 100644 index 0000000000..9cedb7d63f --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddLocalDecl6.expected.hs @@ -0,0 +1,12 @@ +module AddLocalDecl6 where + +foo [] = 1 -- comment 0 + where + x = 3 +foo xs = 2 -- comment 1 + +bar [] = 1 -- comment 2 + where + x = 3 +bar xs = 2 -- comment 3 + diff --git a/testsuite/tests/ghc-api/exactprint/AddLocalDecl6.hs b/testsuite/tests/ghc-api/exactprint/AddLocalDecl6.hs new file mode 100644 index 0000000000..d0bdffca41 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/AddLocalDecl6.hs @@ -0,0 +1,10 @@ +module AddLocalDecl6 where + +foo [] = 1 -- comment 0 +foo xs = 2 -- comment 1 + +bar [] = 1 -- comment 2 + where + x = 3 +bar xs = 2 -- comment 3 + diff --git a/testsuite/tests/ghc-api/exactprint/EmptyWheres.hs b/testsuite/tests/ghc-api/exactprint/EmptyWheres.hs new file mode 100644 index 0000000000..edc0570012 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/EmptyWheres.hs @@ -0,0 +1,9 @@ +module EmptyWheres where + +x = 2 where +y = 3 + +instance Foo1 Int where + +ff = ff where g = g where +type T = Int diff --git a/testsuite/tests/ghc-api/exactprint/LayoutIn1.expected.hs b/testsuite/tests/ghc-api/exactprint/LayoutIn1.expected.hs new file mode 100644 index 0000000000..2b23b21853 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutIn1.expected.hs @@ -0,0 +1,9 @@ +module LayoutIn1 where + +--Layout rule applies after 'where','let','do' and 'of' + +--In this Example: rename 'sq' to 'square'. + +sumSquares x y= square x + square y where sq x= x^pow + --There is a comment. + pow=2 diff --git a/testsuite/tests/ghc-api/exactprint/LayoutIn1.hs b/testsuite/tests/ghc-api/exactprint/LayoutIn1.hs new file mode 100644 index 0000000000..3ea1f8402c --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutIn1.hs @@ -0,0 +1,9 @@ +module LayoutIn1 where + +--Layout rule applies after 'where','let','do' and 'of' + +--In this Example: rename 'sq' to 'square'. + +sumSquares x y= sq x + sq y where sq x= x^pow + --There is a comment. + pow=2 diff --git a/testsuite/tests/ghc-api/exactprint/LayoutIn3.expected.hs b/testsuite/tests/ghc-api/exactprint/LayoutIn3.expected.hs new file mode 100644 index 0000000000..900d6daf63 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutIn3.expected.hs @@ -0,0 +1,13 @@ +module LayoutIn3 where + +--Layout rule applies after 'where','let','do' and 'of' + +--In this Example: rename 'x' after 'let' to 'anotherX'. + +foo x = let anotherX = 12 in (let y = 3 + z = 2 in anotherX * y * z * w) where y = 2 + --there is a comment. + w = x + where + x = let y = 5 in y + 3 + diff --git a/testsuite/tests/ghc-api/exactprint/LayoutIn3.hs b/testsuite/tests/ghc-api/exactprint/LayoutIn3.hs new file mode 100644 index 0000000000..c8c110d65c --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutIn3.hs @@ -0,0 +1,13 @@ +module LayoutIn3 where + +--Layout rule applies after 'where','let','do' and 'of' + +--In this Example: rename 'x' after 'let' to 'anotherX'. + +foo x = let x = 12 in (let y = 3 + z = 2 in x * y * z * w) where y = 2 + --there is a comment. + w = x + where + x = let y = 5 in y + 3 + diff --git a/testsuite/tests/ghc-api/exactprint/LayoutIn3a.expected.hs b/testsuite/tests/ghc-api/exactprint/LayoutIn3a.expected.hs new file mode 100644 index 0000000000..c0a552c0d0 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutIn3a.expected.hs @@ -0,0 +1,13 @@ +module LayoutIn3a where + +--Layout rule applies after 'where','let','do' and 'of' + +--In this Example: rename 'x' after 'let' to 'anotherX'. + +foo x = let anotherX = 12 in ( + anotherX ) where y = 2 + --there is a comment. + w = x + where + x = let y = 5 in y + 3 + diff --git a/testsuite/tests/ghc-api/exactprint/LayoutIn3a.hs b/testsuite/tests/ghc-api/exactprint/LayoutIn3a.hs new file mode 100644 index 0000000000..58b36b07f8 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutIn3a.hs @@ -0,0 +1,13 @@ +module LayoutIn3a where + +--Layout rule applies after 'where','let','do' and 'of' + +--In this Example: rename 'x' after 'let' to 'anotherX'. + +foo x = let x = 12 in ( + x ) where y = 2 + --there is a comment. + w = x + where + x = let y = 5 in y + 3 + diff --git a/testsuite/tests/ghc-api/exactprint/LayoutIn3b.expected.hs b/testsuite/tests/ghc-api/exactprint/LayoutIn3b.expected.hs new file mode 100644 index 0000000000..057d9d346a --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutIn3b.expected.hs @@ -0,0 +1,12 @@ +module LayoutIn3b where + +--Layout rule applies after 'where','let','do' and 'of' + +--In this Example: rename 'x' after 'let' to 'anotherX'. + +foo x = let anotherX = 12 in ( anotherX ) where y = 2 + --there is a comment. + w = x + where + x = let y = 5 in y + 3 + diff --git a/testsuite/tests/ghc-api/exactprint/LayoutIn3b.hs b/testsuite/tests/ghc-api/exactprint/LayoutIn3b.hs new file mode 100644 index 0000000000..32bc294ae4 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutIn3b.hs @@ -0,0 +1,12 @@ +module LayoutIn3b where + +--Layout rule applies after 'where','let','do' and 'of' + +--In this Example: rename 'x' after 'let' to 'anotherX'. + +foo x = let x = 12 in ( x ) where y = 2 + --there is a comment. + w = x + where + x = let y = 5 in y + 3 + diff --git a/testsuite/tests/ghc-api/exactprint/LayoutIn4.expected.hs b/testsuite/tests/ghc-api/exactprint/LayoutIn4.expected.hs new file mode 100644 index 0000000000..531478da48 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutIn4.expected.hs @@ -0,0 +1,13 @@ +module LayoutIn4 where + +--Layout rule applies after 'where','let','do' and 'of' + +--In this Example: rename 'ioFun' to 'io' + +main = io "hello" where io s= do let k = reverse s +--There is a comment + s <- getLine + let q = (k ++ s) + putStr q + putStr "foo" + diff --git a/testsuite/tests/ghc-api/exactprint/LayoutIn4.hs b/testsuite/tests/ghc-api/exactprint/LayoutIn4.hs new file mode 100644 index 0000000000..d99d05649d --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutIn4.hs @@ -0,0 +1,13 @@ +module LayoutIn4 where + +--Layout rule applies after 'where','let','do' and 'of' + +--In this Example: rename 'ioFun' to 'io' + +main = ioFun "hello" where ioFun s= do let k = reverse s + --There is a comment + s <- getLine + let q = (k ++ s) + putStr q + putStr "foo" + diff --git a/testsuite/tests/ghc-api/exactprint/LayoutLet2.expected.hs b/testsuite/tests/ghc-api/exactprint/LayoutLet2.expected.hs new file mode 100644 index 0000000000..8da499ce3a --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutLet2.expected.hs @@ -0,0 +1,8 @@ +module LayoutLet2 where + +-- Simple let expression, rename xxx to something longer or shorter +-- and the let/in layout should adjust accordingly +-- In this case the tokens for xxx + a + b should also shift out + +foo xxxlonger = let a = 1 + b = 2 in xxxlonger + a + b diff --git a/testsuite/tests/ghc-api/exactprint/LayoutLet2.hs b/testsuite/tests/ghc-api/exactprint/LayoutLet2.hs new file mode 100644 index 0000000000..378aa587a8 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutLet2.hs @@ -0,0 +1,8 @@ +module LayoutLet2 where + +-- Simple let expression, rename xxx to something longer or shorter +-- and the let/in layout should adjust accordingly +-- In this case the tokens for xxx + a + b should also shift out + +foo xxx = let a = 1 + b = 2 in xxx + a + b diff --git a/testsuite/tests/ghc-api/exactprint/LayoutLet3.expected.hs b/testsuite/tests/ghc-api/exactprint/LayoutLet3.expected.hs new file mode 100644 index 0000000000..797cf5f483 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutLet3.expected.hs @@ -0,0 +1,10 @@ +module LayoutLet3 where + +-- Simple let expression, rename xxx to something longer or shorter +-- and the let/in layout should adjust accordingly +-- In this case the tokens for xxx + a + b should also shift out + +foo xxxlonger = let a = 1 + b = 2 + in xxxlonger + a + b + diff --git a/testsuite/tests/ghc-api/exactprint/LayoutLet3.hs b/testsuite/tests/ghc-api/exactprint/LayoutLet3.hs new file mode 100644 index 0000000000..5ba80aff6a --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutLet3.hs @@ -0,0 +1,10 @@ +module LayoutLet3 where + +-- Simple let expression, rename xxx to something longer or shorter +-- and the let/in layout should adjust accordingly +-- In this case the tokens for xxx + a + b should also shift out + +foo xxx = let a = 1 + b = 2 + in xxx + a + b + diff --git a/testsuite/tests/ghc-api/exactprint/LayoutLet4.expected.hs b/testsuite/tests/ghc-api/exactprint/LayoutLet4.expected.hs new file mode 100644 index 0000000000..b3c52f424e --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutLet4.expected.hs @@ -0,0 +1,12 @@ +module LayoutLet4 where + +-- Simple let expression, rename xxx to something longer or shorter +-- and the let/in layout should adjust accordingly +-- In this case the tokens for xxx + a + b should also shift out + +foo xxxlonger = let a = 1 + b = 2 + in xxxlonger + a + b + +bar = 3 + diff --git a/testsuite/tests/ghc-api/exactprint/LayoutLet4.hs b/testsuite/tests/ghc-api/exactprint/LayoutLet4.hs new file mode 100644 index 0000000000..28fe599432 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LayoutLet4.hs @@ -0,0 +1,12 @@ +module LayoutLet4 where + +-- Simple let expression, rename xxx to something longer or shorter +-- and the let/in layout should adjust accordingly +-- In this case the tokens for xxx + a + b should also shift out + +foo xxx = let a = 1 + b = 2 + in xxx + a + b + +bar = 3 + diff --git a/testsuite/tests/ghc-api/exactprint/LetIn1.expected.hs b/testsuite/tests/ghc-api/exactprint/LetIn1.expected.hs new file mode 100644 index 0000000000..d233115ee6 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LetIn1.expected.hs @@ -0,0 +1,18 @@ +module LetIn1 where + +--A definition can be demoted to the local 'where' binding of a friend declaration, +--if it is only used by this friend declaration. + +--Demoting a definition narrows down the scope of the definition. +--In this example, demote the local 'pow' to 'sq' +--This example also aims to test the demoting a local declaration in 'let'. + +sumSquares x y = let sq 0=0 + sq z=z^pow + in sq x + sq y + + +anotherFun 0 y = sq y + where sq x = x^2 + + diff --git a/testsuite/tests/ghc-api/exactprint/LetIn1.hs b/testsuite/tests/ghc-api/exactprint/LetIn1.hs new file mode 100644 index 0000000000..f1109b8f03 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LetIn1.hs @@ -0,0 +1,19 @@ +module LetIn1 where + +--A definition can be demoted to the local 'where' binding of a friend declaration, +--if it is only used by this friend declaration. + +--Demoting a definition narrows down the scope of the definition. +--In this example, demote the local 'pow' to 'sq' +--This example also aims to test the demoting a local declaration in 'let'. + +sumSquares x y = let sq 0=0 + sq z=z^pow + pow=2 + in sq x + sq y + + +anotherFun 0 y = sq y + where sq x = x^2 + + diff --git a/testsuite/tests/ghc-api/exactprint/LocToName.expected.hs b/testsuite/tests/ghc-api/exactprint/LocToName.expected.hs new file mode 100644 index 0000000000..0b1484873a --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LocToName.expected.hs @@ -0,0 +1,25 @@ +module LocToName where + +{- + + + + + + + + +-} + + + + + + + +LocToName.newPoint (x:xs) = x ^2 + LocToName.newPoint xs + -- where sq x = x ^pow + -- pow = 2 + +LocToName.newPoint [] = 0 + diff --git a/testsuite/tests/ghc-api/exactprint/LocToName.hs b/testsuite/tests/ghc-api/exactprint/LocToName.hs new file mode 100644 index 0000000000..89a0acea12 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LocToName.hs @@ -0,0 +1,25 @@ +module LocToName where + +{- + + + + + + + + +-} + + + + + + + +sumSquares (x:xs) = x ^2 + sumSquares xs + -- where sq x = x ^pow + -- pow = 2 + +sumSquares [] = 0 + diff --git a/testsuite/tests/ghc-api/exactprint/LocalDecls.expected.hs b/testsuite/tests/ghc-api/exactprint/LocalDecls.expected.hs new file mode 100644 index 0000000000..7c41178ba0 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LocalDecls.expected.hs @@ -0,0 +1,11 @@ +module LocalDecls where + +foo a = bar a + where + nn :: Int + nn = 2 + + bar :: Int -> Int + bar x = x + 2 + + baz = 4 diff --git a/testsuite/tests/ghc-api/exactprint/LocalDecls.hs b/testsuite/tests/ghc-api/exactprint/LocalDecls.hs new file mode 100644 index 0000000000..ebb774ac63 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LocalDecls.hs @@ -0,0 +1,8 @@ +module LocalDecls where + +foo a = bar a + where + bar :: Int -> Int + bar x = x + 2 + + baz = 4 diff --git a/testsuite/tests/ghc-api/exactprint/LocalDecls2.expected.hs b/testsuite/tests/ghc-api/exactprint/LocalDecls2.expected.hs new file mode 100644 index 0000000000..d2353e94c5 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LocalDecls2.expected.hs @@ -0,0 +1,8 @@ +module LocalDecls2 where + +foo a = bar a + where + nn :: Int + nn = 2 + + diff --git a/testsuite/tests/ghc-api/exactprint/LocalDecls2.hs b/testsuite/tests/ghc-api/exactprint/LocalDecls2.hs new file mode 100644 index 0000000000..92a8649649 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/LocalDecls2.hs @@ -0,0 +1,3 @@ +module LocalDecls2 where + +foo a = bar a diff --git a/testsuite/tests/ghc-api/exactprint/Makefile b/testsuite/tests/ghc-api/exactprint/Makefile new file mode 100644 index 0000000000..8d3b71ac9b --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/Makefile @@ -0,0 +1,160 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk + +LIBDIR := "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" + +clean: + rm -f *.o *.hi + +.PHONY: RenameCase1 +RenameCase1: + $(CHECK_EXACT) $(LIBDIR) RenameCase1.hs changeRenameCase1 + +.PHONY: LayoutLet2 +LayoutLet2: + $(CHECK_EXACT) $(LIBDIR) LayoutLet2.hs changeLayoutLet2 + +.PHONY: LayoutLet3 +LayoutLet3: + $(CHECK_EXACT) $(LIBDIR) LayoutLet3.hs changeLayoutLet3 + +.PHONY: LayoutLet4 +LayoutLet4: + $(CHECK_EXACT) $(LIBDIR) LayoutLet4.hs changeLayoutLet3 + +.PHONY: Rename1 +Rename1: + $(CHECK_EXACT) $(LIBDIR) Rename1.hs changeRename1 + +.PHONY: Rename2 +Rename2: + $(CHECK_EXACT) $(LIBDIR) Rename2.hs changeRename2 + +.PHONY: LayoutIn1 +LayoutIn1: + $(CHECK_EXACT) $(LIBDIR) LayoutIn1.hs changeLayoutIn1 + +.PHONY: LayoutIn3 +LayoutIn3: + $(CHECK_EXACT) $(LIBDIR) LayoutIn3.hs changeLayoutIn3 + +.PHONY: LayoutIn3a +LayoutIn3a: + $(CHECK_EXACT) $(LIBDIR) LayoutIn3a.hs changeLayoutIn3 + +.PHONY: LayoutIn3b +LayoutIn3b: + $(CHECK_EXACT) $(LIBDIR) LayoutIn3b.hs changeLayoutIn3 + +.PHONY: LayoutIn4 +LayoutIn4: + $(CHECK_EXACT) $(LIBDIR) LayoutIn4.hs changeLayoutIn4 + +.PHONY: LocToName +LocToName: + $(CHECK_EXACT) $(LIBDIR) LocToName.hs changeLocToName + +.PHONY: LetIn1 +LetIn1: + $(CHECK_EXACT) $(LIBDIR) LetIn1.hs changeLetIn1 + +.PHONY: WhereIn4 +WhereIn4: + $(CHECK_EXACT) $(LIBDIR) WhereIn4.hs changeWhereIn4 + +.PHONY: AddDecl1 +AddDecl1: + $(CHECK_EXACT) $(LIBDIR) AddDecl1.hs changeAddDecl1 + +.PHONY: AddDecl2 +AddDecl2: + $(CHECK_EXACT) $(LIBDIR) AddDecl2.hs changeAddDecl2 + +.PHONY: AddDecl3 +AddDecl3: + $(CHECK_EXACT) $(LIBDIR) AddDecl3.hs changeAddDecl3 + +.PHONY: LocalDecls +LocalDecls: + $(CHECK_EXACT) $(LIBDIR) LocalDecls.hs changeLocalDecls + +.PHONY: LocalDecls2 +LocalDecls2: + $(CHECK_EXACT) $(LIBDIR) LocalDecls2.hs changeLocalDecls2 + +.PHONY: WhereIn3a +WhereIn3a: + $(CHECK_EXACT) $(LIBDIR) WhereIn3a.hs changeWhereIn3a + +.PHONY: WhereIn3b +WhereIn3b: + $(CHECK_EXACT) $(LIBDIR) WhereIn3b.hs changeWhereIn3b + +.PHONY: AddLocalDecl1 +AddLocalDecl1: + $(CHECK_EXACT) $(LIBDIR) AddLocalDecl1.hs ADDLOCALDECL1 + +.PHONY: AddLocalDecl2 +AddLocalDecl2: + $(CHECK_EXACT) $(LIBDIR) AddLocalDecl2.hs ADDLOCALDECL2 + +.PHONY: AddLocalDecl3 +AddLocalDecl3: + $(CHECK_EXACT) $(LIBDIR) AddLocalDecl3.hs ADDLOCALDECL3 + +.PHONY: AddLocalDecl4 +AddLocalDecl4: + $(CHECK_EXACT) $(LIBDIR) AddLocalDecl4.hs ADDLOCALDECL4 + +.PHONY: AddLocalDecl5 +AddLocalDecl5: + $(CHECK_EXACT) $(LIBDIR) AddLocalDecl5.hs ADDLOCALDECL5 + +.PHONY: AddLocalDecl6 +AddLocalDecl6: + $(CHECK_EXACT) $(LIBDIR) AddLocalDecl6.hs ADDLOCALDECL6 + +.PHONY: RmDecl1 +RmDecl1: + $(CHECK_EXACT) $(LIBDIR) RmDecl1.hs rmDecl1 + +.PHONY: RmDecl2 +RmDecl2: + $(CHECK_EXACT) $(LIBDIR) RmDecl2.hs rmDecl2 + +.PHONY: RmDecl3 +RmDecl3: + $(CHECK_EXACT) $(LIBDIR) RmDecl3.hs rmDecl3 + +.PHONY: RmDecl4 +RmDecl4: + $(CHECK_EXACT) $(LIBDIR) RmDecl4.hs rmDecl4 + +.PHONY: RmDecl5 +RmDecl5: + $(CHECK_EXACT) $(LIBDIR) RmDecl5.hs rmDecl5 + +.PHONY: RmDecl6 +RmDecl6: + $(CHECK_EXACT) $(LIBDIR) RmDecl6.hs rmDecl6 + +.PHONY: RmDecl7 +RmDecl7: + $(CHECK_EXACT) $(LIBDIR) RmDecl7.hs rmDecl7 + +.PHONY: RmTypeSig1 +RmTypeSig1: + $(CHECK_EXACT) $(LIBDIR) RmTypeSig1.hs rmTypeSig1 + +.PHONY: RmTypeSig2 +RmTypeSig2: + $(CHECK_EXACT) $(LIBDIR) RmTypeSig2.hs rmTypeSig2 + +.PHONY: AddHiding1 +AddHiding1: + $(CHECK_EXACT) $(LIBDIR) AddHiding1.hs addHiding1 + +.PHONY: AddHiding2 +AddHiding2: + $(CHECK_EXACT) $(LIBDIR) AddHiding2.hs addHiding2 diff --git a/testsuite/tests/ghc-api/exactprint/Rename1.expected.hs b/testsuite/tests/ghc-api/exactprint/Rename1.expected.hs new file mode 100644 index 0000000000..353a7420e2 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/Rename1.expected.hs @@ -0,0 +1,6 @@ +module Rename1 where + +bar2 x y = + do c <- getChar + return c + diff --git a/testsuite/tests/ghc-api/exactprint/Rename1.hs b/testsuite/tests/ghc-api/exactprint/Rename1.hs new file mode 100644 index 0000000000..1ad343afd3 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/Rename1.hs @@ -0,0 +1,6 @@ +module Rename1 where + +foo x y = + do c <- getChar + return c + diff --git a/testsuite/tests/ghc-api/exactprint/Rename2.expected.hs b/testsuite/tests/ghc-api/exactprint/Rename2.expected.hs new file mode 100644 index 0000000000..6be3ff6e0a --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/Rename2.expected.hs @@ -0,0 +1,4 @@ + +joe x = case (odd x) of + True -> "Odd" + False -> "Even" diff --git a/testsuite/tests/ghc-api/exactprint/Rename2.hs b/testsuite/tests/ghc-api/exactprint/Rename2.hs new file mode 100644 index 0000000000..29fea060c2 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/Rename2.hs @@ -0,0 +1,4 @@ + +foo' x = case (odd x) of + True -> "Odd" + False -> "Even" diff --git a/testsuite/tests/ghc-api/exactprint/RenameCase1.expected.hs b/testsuite/tests/ghc-api/exactprint/RenameCase1.expected.hs new file mode 100644 index 0000000000..dad6765012 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RenameCase1.expected.hs @@ -0,0 +1,5 @@ +module RenameCase1 where + +foo x = case (bazLonger x) of + 1 -> "a" + _ -> "b" diff --git a/testsuite/tests/ghc-api/exactprint/RenameCase1.hs b/testsuite/tests/ghc-api/exactprint/RenameCase1.hs new file mode 100644 index 0000000000..22d549367a --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RenameCase1.hs @@ -0,0 +1,5 @@ +module RenameCase1 where + +foo x = case (baz x) of + 1 -> "a" + _ -> "b" diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl1.expected.hs b/testsuite/tests/ghc-api/exactprint/RmDecl1.expected.hs new file mode 100644 index 0000000000..6bb503aede --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl1.expected.hs @@ -0,0 +1,9 @@ +module RmDecl1 where + +sumSquares x = x * p + where p=2 {-There is a comment-} + +{- foo bar -} +anotherFun 0 y = sq y + where sq x = x^2 + diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl1.hs b/testsuite/tests/ghc-api/exactprint/RmDecl1.hs new file mode 100644 index 0000000000..15cd9f1e04 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl1.hs @@ -0,0 +1,13 @@ +module RmDecl1 where + +sumSquares x = x * p + where p=2 {-There is a comment-} + +sq :: Int -> Int -> Int +sq pow 0 = 0 +sq pow z = z^pow --there is a comment + +{- foo bar -} +anotherFun 0 y = sq y + where sq x = x^2 + diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl2.expected.hs b/testsuite/tests/ghc-api/exactprint/RmDecl2.expected.hs new file mode 100644 index 0000000000..d77b760dca --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl2.expected.hs @@ -0,0 +1,9 @@ +module RmDecl2 where + +sumSquares x y = let sq 0=0 + sq z=z^pow + in sq x + sq y + +anotherFun 0 y = sq y + where sq x = x^2 + diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl2.hs b/testsuite/tests/ghc-api/exactprint/RmDecl2.hs new file mode 100644 index 0000000000..2f0dbd3ace --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl2.hs @@ -0,0 +1,10 @@ +module RmDecl2 where + +sumSquares x y = let sq 0=0 + sq z=z^pow + pow=2 + in sq x + sq y + +anotherFun 0 y = sq y + where sq x = x^2 + diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl3.expected.hs b/testsuite/tests/ghc-api/exactprint/RmDecl3.expected.hs new file mode 100644 index 0000000000..ca14f33ad5 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl3.expected.hs @@ -0,0 +1,9 @@ +module RmDecl3 where + +-- Remove last declaration from a where clause, where should disappear too +ff y = y + zz + +zz = 1 + +foo = 3 +-- EOF diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl3.hs b/testsuite/tests/ghc-api/exactprint/RmDecl3.hs new file mode 100644 index 0000000000..280bccf259 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl3.hs @@ -0,0 +1,9 @@ +module RmDecl3 where + +-- Remove last declaration from a where clause, where should disappear too +ff y = y + zz + where + zz = 1 + +foo = 3 +-- EOF diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl4.expected.hs b/testsuite/tests/ghc-api/exactprint/RmDecl4.expected.hs new file mode 100644 index 0000000000..e7c71dbd08 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl4.expected.hs @@ -0,0 +1,10 @@ +module RmDecl4 where + +-- Remove first declaration from a where clause, last should still be indented +ff y = y + zz + xx + where + xx = 2 + +zz = 1 + +-- EOF diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl4.hs b/testsuite/tests/ghc-api/exactprint/RmDecl4.hs new file mode 100644 index 0000000000..532b738763 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl4.hs @@ -0,0 +1,9 @@ +module RmDecl4 where + +-- Remove first declaration from a where clause, last should still be indented +ff y = y + zz + xx + where + zz = 1 + xx = 2 + +-- EOF diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl5.expected.hs b/testsuite/tests/ghc-api/exactprint/RmDecl5.expected.hs new file mode 100644 index 0000000000..67ac8ddfab --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl5.expected.hs @@ -0,0 +1,5 @@ +module RmDecl5 where + +sumSquares x y = let pow=2 + in sq x + sq y + diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl5.hs b/testsuite/tests/ghc-api/exactprint/RmDecl5.hs new file mode 100644 index 0000000000..40f86199ce --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl5.hs @@ -0,0 +1,7 @@ +module RmDecl5 where + +sumSquares x y = let sq 0=0 + sq z=z^pow + pow=2 + in sq x + sq y + diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl6.expected.hs b/testsuite/tests/ghc-api/exactprint/RmDecl6.expected.hs new file mode 100644 index 0000000000..a2bd7d0443 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl6.expected.hs @@ -0,0 +1,9 @@ +module RmDecl6 where + +foo a = baz + where + x = 1 + + y :: Int -> Int -> Int + y a b = undefined + diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl6.hs b/testsuite/tests/ghc-api/exactprint/RmDecl6.hs new file mode 100644 index 0000000000..cab5093ce8 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl6.hs @@ -0,0 +1,12 @@ +module RmDecl6 where + +foo a = baz + where + baz :: Int + baz = x + a + + x = 1 + + y :: Int -> Int -> Int + y a b = undefined + diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl7.expected.hs b/testsuite/tests/ghc-api/exactprint/RmDecl7.expected.hs new file mode 100644 index 0000000000..9d7b8b9a69 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl7.expected.hs @@ -0,0 +1,7 @@ +module RmDecl7 where + +toplevel :: Integer -> Integer +toplevel x = c * x + +d = 9 + diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl7.hs b/testsuite/tests/ghc-api/exactprint/RmDecl7.hs new file mode 100644 index 0000000000..62cefe2154 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmDecl7.hs @@ -0,0 +1,9 @@ +module RmDecl7 where + +toplevel :: Integer -> Integer +toplevel x = c * x + +-- c,d :: Integer +c = 7 +d = 9 + diff --git a/testsuite/tests/ghc-api/exactprint/RmTypeSig1.expected.hs b/testsuite/tests/ghc-api/exactprint/RmTypeSig1.expected.hs new file mode 100644 index 0000000000..46f7b13399 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmTypeSig1.expected.hs @@ -0,0 +1,8 @@ +module RmTypeSig1 where + +anotherFun :: Int -> Int +sq 0 = 0 +sq z = z^2 + +anotherFun x = x^2 + diff --git a/testsuite/tests/ghc-api/exactprint/RmTypeSig1.hs b/testsuite/tests/ghc-api/exactprint/RmTypeSig1.hs new file mode 100644 index 0000000000..498892d791 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmTypeSig1.hs @@ -0,0 +1,8 @@ +module RmTypeSig1 where + +sq,anotherFun :: Int -> Int +sq 0 = 0 +sq z = z^2 + +anotherFun x = x^2 + diff --git a/testsuite/tests/ghc-api/exactprint/RmTypeSig2.expected.hs b/testsuite/tests/ghc-api/exactprint/RmTypeSig2.expected.hs new file mode 100644 index 0000000000..c30e201bd0 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmTypeSig2.expected.hs @@ -0,0 +1,7 @@ +module RmTypeSig2 where + +-- Pattern bind +tup@(h,t) = (1,ff) + where + ff = 15 + diff --git a/testsuite/tests/ghc-api/exactprint/RmTypeSig2.hs b/testsuite/tests/ghc-api/exactprint/RmTypeSig2.hs new file mode 100644 index 0000000000..e8771f99dd --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/RmTypeSig2.hs @@ -0,0 +1,8 @@ +module RmTypeSig2 where + +-- Pattern bind +tup@(h,t) = (1,ff) + where + ff :: Int + ff = 15 + diff --git a/testsuite/tests/ghc-api/exactprint/WhereIn3a.expected.hs b/testsuite/tests/ghc-api/exactprint/WhereIn3a.expected.hs new file mode 100644 index 0000000000..acc94d3621 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/WhereIn3a.expected.hs @@ -0,0 +1,20 @@ +module WhereIn3a where + +--A definition can be demoted to the local 'where' binding of a friend declaration, +--if it is only used by this friend declaration. + +--Demoting a definition narrows down the scope of the definition. +--In this example, demote the top level 'sq' to 'sumSquares' +--In this case (there are multi matches), the parameters are not folded after demoting. + +sumSquares x y = sq p x + sq p y + where p=2 {-There is a comment-} + +sq :: Int -> Int -> Int +sq pow 0 = 0 -- prior comment +sq pow z = z^pow --there is a comment + +-- A leading comment +anotherFun 0 y = sq y + where sq x = x^2 + diff --git a/testsuite/tests/ghc-api/exactprint/WhereIn3a.hs b/testsuite/tests/ghc-api/exactprint/WhereIn3a.hs new file mode 100644 index 0000000000..acc94d3621 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/WhereIn3a.hs @@ -0,0 +1,20 @@ +module WhereIn3a where + +--A definition can be demoted to the local 'where' binding of a friend declaration, +--if it is only used by this friend declaration. + +--Demoting a definition narrows down the scope of the definition. +--In this example, demote the top level 'sq' to 'sumSquares' +--In this case (there are multi matches), the parameters are not folded after demoting. + +sumSquares x y = sq p x + sq p y + where p=2 {-There is a comment-} + +sq :: Int -> Int -> Int +sq pow 0 = 0 -- prior comment +sq pow z = z^pow --there is a comment + +-- A leading comment +anotherFun 0 y = sq y + where sq x = x^2 + diff --git a/testsuite/tests/ghc-api/exactprint/WhereIn3b.expected.hs b/testsuite/tests/ghc-api/exactprint/WhereIn3b.expected.hs new file mode 100644 index 0000000000..80ddc04825 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/WhereIn3b.expected.hs @@ -0,0 +1,27 @@ +module WhereIn3a where + +--A definition can be demoted to the local 'where' binding of a friend declaration, +--if it is only used by this friend declaration. + +--Demoting a definition narrows down the scope of the definition. +--In this example, demote the top level 'sq' to 'sumSquares' +--In this case (there are multi matches), the parameters are not folded after demoting. + +-- A leading comment +anotherFun 0 y = sq y + where sq x = x^2 + +sq pow 0 = 0 -- prior comment +sq pow z = z^pow --there is a comment + +sumSquares x y = sq p x + sq p y + where p=2 {-There is a comment-} + +sq :: Int -> Int -> Int +sq pow 0 = 0 -- prior comment +sq pow z = z^pow --there is a comment + +-- A leading comment +anotherFun 0 y = sq y + where sq x = x^2 + diff --git a/testsuite/tests/ghc-api/exactprint/WhereIn3b.hs b/testsuite/tests/ghc-api/exactprint/WhereIn3b.hs new file mode 100644 index 0000000000..acc94d3621 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/WhereIn3b.hs @@ -0,0 +1,20 @@ +module WhereIn3a where + +--A definition can be demoted to the local 'where' binding of a friend declaration, +--if it is only used by this friend declaration. + +--Demoting a definition narrows down the scope of the definition. +--In this example, demote the top level 'sq' to 'sumSquares' +--In this case (there are multi matches), the parameters are not folded after demoting. + +sumSquares x y = sq p x + sq p y + where p=2 {-There is a comment-} + +sq :: Int -> Int -> Int +sq pow 0 = 0 -- prior comment +sq pow z = z^pow --there is a comment + +-- A leading comment +anotherFun 0 y = sq y + where sq x = x^2 + diff --git a/testsuite/tests/ghc-api/exactprint/WhereIn4.expected.hs b/testsuite/tests/ghc-api/exactprint/WhereIn4.expected.hs new file mode 100644 index 0000000000..4357bfdac7 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/WhereIn4.expected.hs @@ -0,0 +1,19 @@ +module WhereIn4 where + +--A definition can be demoted to the local 'where' binding of a friend declaration, +--if it is only used by this friend declaration. + +--Demoting a definition narrows down the scope of the definition. +--In this example, demote the top level 'sq' to 'sumSquares' +--In this case (there is single matches), if possible, +--the parameters will be folded after demoting and type sigature will be removed. + +sumSquares x y = sq p x + sq p y + where p_2=2 {-There is a comment-} + +sq::Int->Int->Int +sq pow z = z^pow --there is a comment + +anotherFun 0 y = sq y + where sq x = x^2 + diff --git a/testsuite/tests/ghc-api/exactprint/WhereIn4.hs b/testsuite/tests/ghc-api/exactprint/WhereIn4.hs new file mode 100644 index 0000000000..8b941fff4a --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/WhereIn4.hs @@ -0,0 +1,19 @@ +module WhereIn4 where + +--A definition can be demoted to the local 'where' binding of a friend declaration, +--if it is only used by this friend declaration. + +--Demoting a definition narrows down the scope of the definition. +--In this example, demote the top level 'sq' to 'sumSquares' +--In this case (there is single matches), if possible, +--the parameters will be folded after demoting and type sigature will be removed. + +sumSquares x y = sq p x + sq p y + where p=2 {-There is a comment-} + +sq::Int->Int->Int +sq pow z = z^pow --there is a comment + +anotherFun 0 y = sq y + where sq x = x^2 + diff --git a/testsuite/tests/ghc-api/exactprint/Windows.hs b/testsuite/tests/ghc-api/exactprint/Windows.hs new file mode 100644 index 0000000000..ad8ae692b6 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/Windows.hs @@ -0,0 +1,10 @@ +module Windows where + +{- + This file has windows-style line endings, to check that trailing + \r's get stripped in comments. +-} +baz = 2 + +-- Another comment +foo = 1 diff --git a/testsuite/tests/ghc-api/exactprint/all.T b/testsuite/tests/ghc-api/exactprint/all.T new file mode 100644 index 0000000000..385b74a243 --- /dev/null +++ b/testsuite/tests/ghc-api/exactprint/all.T @@ -0,0 +1,38 @@ +test('RenameCase1', ignore_stderr, makefile_test, ['RenameCase1']) +test('LayoutLet2', ignore_stderr, makefile_test, ['LayoutLet2']) +test('LayoutLet3', ignore_stderr, makefile_test, ['LayoutLet3']) +test('LayoutLet4', ignore_stderr, makefile_test, ['LayoutLet4']) +test('Rename1', ignore_stderr, makefile_test, ['Rename1']) +test('Rename2', ignore_stderr, makefile_test, ['Rename2']) +test('LayoutIn1', ignore_stderr, makefile_test, ['LayoutIn1']) +test('LayoutIn3', ignore_stderr, makefile_test, ['LayoutIn3']) +test('LayoutIn3a', ignore_stderr, makefile_test, ['LayoutIn3a']) +test('LayoutIn3b', ignore_stderr, makefile_test, ['LayoutIn3b']) +test('LayoutIn4', ignore_stderr, makefile_test, ['LayoutIn4']) +test('LocToName', ignore_stderr, makefile_test, ['LocToName']) +test('LetIn1', ignore_stderr, makefile_test, ['LetIn1']) +test('WhereIn4', ignore_stderr, makefile_test, ['WhereIn4']) +test('AddDecl1', ignore_stderr, makefile_test, ['AddDecl1']) +test('AddDecl2', ignore_stderr, makefile_test, ['AddDecl2']) +test('AddDecl3', ignore_stderr, makefile_test, ['AddDecl3']) +test('LocalDecls', ignore_stderr, makefile_test, ['LocalDecls']) +test('LocalDecls2', ignore_stderr, makefile_test, ['LocalDecls2']) +test('WhereIn3a', ignore_stderr, makefile_test, ['WhereIn3a']) +test('WhereIn3b', ignore_stderr, makefile_test, ['WhereIn3b']) +test('AddLocalDecl1', ignore_stderr, makefile_test, ['AddLocalDecl1']) +test('AddLocalDecl2', ignore_stderr, makefile_test, ['AddLocalDecl2']) +test('AddLocalDecl3', ignore_stderr, makefile_test, ['AddLocalDecl3']) +test('AddLocalDecl4', ignore_stderr, makefile_test, ['AddLocalDecl4']) +test('AddLocalDecl5', ignore_stderr, makefile_test, ['AddLocalDecl5']) +test('AddLocalDecl6', ignore_stderr, makefile_test, ['AddLocalDecl6']) +test('RmDecl1', ignore_stderr, makefile_test, ['RmDecl1']) +test('RmDecl2', ignore_stderr, makefile_test, ['RmDecl2']) +test('RmDecl3', ignore_stderr, makefile_test, ['RmDecl3']) +test('RmDecl4', ignore_stderr, makefile_test, ['RmDecl4']) +test('RmDecl5', ignore_stderr, makefile_test, ['RmDecl5']) +test('RmDecl6', ignore_stderr, makefile_test, ['RmDecl6']) +test('RmDecl7', ignore_stderr, makefile_test, ['RmDecl7']) +test('RmTypeSig1', ignore_stderr, makefile_test, ['RmTypeSig1']) +test('RmTypeSig2', ignore_stderr, makefile_test, ['RmTypeSig2']) +test('AddHiding1', ignore_stderr, makefile_test, ['AddHiding1']) +test('AddHiding2', ignore_stderr, makefile_test, ['AddHiding2']) |