summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/driver/T4437.hs1
-rw-r--r--testsuite/tests/parser/should_compile/LexNegVsNegLit.hs17
-rw-r--r--testsuite/tests/parser/should_compile/LexicalNegation.hs15
-rw-r--r--testsuite/tests/parser/should_compile/all.T2
-rw-r--r--testsuite/tests/parser/should_run/LexNegLit.hs26
-rw-r--r--testsuite/tests/parser/should_run/LexNegLit.stdout8
-rw-r--r--testsuite/tests/parser/should_run/all.T1
7 files changed, 70 insertions, 0 deletions
diff --git a/testsuite/tests/driver/T4437.hs b/testsuite/tests/driver/T4437.hs
index 9a11780dc5..a0bcebf889 100644
--- a/testsuite/tests/driver/T4437.hs
+++ b/testsuite/tests/driver/T4437.hs
@@ -42,6 +42,7 @@ expectedGhcOnlyExtensions =
, "AlternativeLayoutRuleTransitional"
, "LinearTypes"
, "QualifiedDo"
+ , "LexicalNegation"
]
expectedCabalOnlyExtensions :: [String]
diff --git a/testsuite/tests/parser/should_compile/LexNegVsNegLit.hs b/testsuite/tests/parser/should_compile/LexNegVsNegLit.hs
new file mode 100644
index 0000000000..665893e95b
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/LexNegVsNegLit.hs
@@ -0,0 +1,17 @@
+{-# LANGUAGE NegativeLiterals, LexicalNegation #-}
+
+module LexNegVsNegLit where
+
+-- NegativeLiterals specifies that we parse x-1 as x (-1), even though it's
+-- considered a shortcoming.
+--
+-- LexicalNegation does not change that.
+--
+b :: Bool
+b = even-1 -- parsed as: even (-1)
+ -- so it is well-typed.
+ --
+ -- with LexicalNegation alone, we'd get (-) even 1,
+ -- but NegativeLiterals takes precedence here.
+
+-- See also: GHC Proposal #344
diff --git a/testsuite/tests/parser/should_compile/LexicalNegation.hs b/testsuite/tests/parser/should_compile/LexicalNegation.hs
new file mode 100644
index 0000000000..e3e3491aed
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/LexicalNegation.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE LexicalNegation #-}
+
+module LexicalNegation where
+
+x :: Int
+x = 42
+
+negx :: Int
+negx = f -x where f = (- 5)
+
+subx :: Int -> Int
+subx = (- x)
+
+assertion1 :: Bool
+assertion1 = (- x) -x == -(2*x)
diff --git a/testsuite/tests/parser/should_compile/all.T b/testsuite/tests/parser/should_compile/all.T
index 8c7f058062..fb2bd6b587 100644
--- a/testsuite/tests/parser/should_compile/all.T
+++ b/testsuite/tests/parser/should_compile/all.T
@@ -152,6 +152,8 @@ test('proposal-229a', normal, compile, [''])
test('proposal-229b', normal, compile, [''])
test('proposal-229d', normal, compile, [''])
test('proposal-229e', normal, compile, [''])
+test('LexicalNegation', normal, compile, [''])
+test('LexNegVsNegLit', normal, compile, [''])
# We omit 'profasm' because it fails with:
# Cannot load -prof objects when GHC is built with -dynamic
diff --git a/testsuite/tests/parser/should_run/LexNegLit.hs b/testsuite/tests/parser/should_run/LexNegLit.hs
new file mode 100644
index 0000000000..7c8b0b0f19
--- /dev/null
+++ b/testsuite/tests/parser/should_run/LexNegLit.hs
@@ -0,0 +1,26 @@
+{-# LANGUAGE LexicalNegation #-}
+
+data FreeNum
+ = FromInteger Integer
+ | FromRational Rational
+ | Negate FreeNum
+ | FreeNum `Subtract` FreeNum
+ deriving (Show)
+
+instance Num FreeNum where
+ fromInteger = FromInteger
+ negate = Negate
+ (-) = Subtract
+
+instance Fractional FreeNum where
+ fromRational = FromRational
+
+main = do
+ print (-123 :: FreeNum)
+ print (-1.5 :: FreeNum)
+ print (let x = 5 in -x :: FreeNum)
+ print (5-1 :: FreeNum) -- unlike NegativeLiterals, we parse it as (5 - 1), not (5 (-1))
+ print (-0 :: FreeNum)
+ print (-0.0 :: FreeNum)
+ print (-0o10 :: FreeNum)
+ print (-0x10 :: FreeNum)
diff --git a/testsuite/tests/parser/should_run/LexNegLit.stdout b/testsuite/tests/parser/should_run/LexNegLit.stdout
new file mode 100644
index 0000000000..b178fc8394
--- /dev/null
+++ b/testsuite/tests/parser/should_run/LexNegLit.stdout
@@ -0,0 +1,8 @@
+FromInteger (-123)
+FromRational ((-3) % 2)
+Negate (FromInteger 5)
+FromInteger 5 `Subtract` FromInteger 1
+Negate (FromInteger 0)
+Negate (FromRational (0 % 1))
+FromInteger (-8)
+FromInteger (-16)
diff --git a/testsuite/tests/parser/should_run/all.T b/testsuite/tests/parser/should_run/all.T
index fa639de734..2fa6fce766 100644
--- a/testsuite/tests/parser/should_run/all.T
+++ b/testsuite/tests/parser/should_run/all.T
@@ -18,3 +18,4 @@ test('CountParserDeps',
[ only_ways(['normal']), extra_run_opts('"' + config.libdir + '"') ],
compile_and_run,
['-package ghc'])
+test('LexNegLit', normal, compile_and_run, [''])