summaryrefslogtreecommitdiff
path: root/testsuite/tests
diff options
context:
space:
mode:
authorIsaac Dupree <id@isaac.cedarswampstudios.org>2007-05-26 22:44:05 +0000
committerIsaac Dupree <id@isaac.cedarswampstudios.org>2007-05-26 22:44:05 +0000
commit295263ebfb8cf1e6a6db26aec17dd6cd8adb18c3 (patch)
tree69a761824babee313bc26dfc8a25cd900680d69d /testsuite/tests
parentf83f0223f4df2eb368785840d6f0bd5fae0c9ac7 (diff)
downloadhaskell-295263ebfb8cf1e6a6db26aec17dd6cd8adb18c3.tar.gz
add negative-prim-literal tests
the first for behavior common between their new and old parsings (passes both), the second to test the new behavior (fails before, passes after)
Diffstat (limited to 'testsuite/tests')
-rw-r--r--testsuite/tests/ghc-regress/parser/should_run/all.T2
-rw-r--r--testsuite/tests/ghc-regress/parser/should_run/read002.hs35
-rw-r--r--testsuite/tests/ghc-regress/parser/should_run/read002.stdout7
-rw-r--r--testsuite/tests/ghc-regress/parser/should_run/read003.hs13
-rw-r--r--testsuite/tests/ghc-regress/parser/should_run/read003.stdout4
5 files changed, 61 insertions, 0 deletions
diff --git a/testsuite/tests/ghc-regress/parser/should_run/all.T b/testsuite/tests/ghc-regress/parser/should_run/all.T
index bc97f9241b..769172c9f1 100644
--- a/testsuite/tests/ghc-regress/parser/should_run/all.T
+++ b/testsuite/tests/ghc-regress/parser/should_run/all.T
@@ -2,3 +2,5 @@ test('read001', normal, compile_and_run, [''])
# also make sure that a mere -fglasgow-exts doesn't break
# the default/standard behavior:
test('read001', only_compiler_types(['ghc']), compile_and_run, ['-fglasgow-exts'])
+test('read002', normal, compile_and_run, [''])
+test('read003', normal, compile_and_run, [''])
diff --git a/testsuite/tests/ghc-regress/parser/should_run/read002.hs b/testsuite/tests/ghc-regress/parser/should_run/read002.hs
new file mode 100644
index 0000000000..8082740ca0
--- /dev/null
+++ b/testsuite/tests/ghc-regress/parser/should_run/read002.hs
@@ -0,0 +1,35 @@
+{-# OPTIONS_GHC -fglasgow-exts #-}
+-- !!! Negative unboxed literals, part 1
+-- They don't have to be as standards-compliant
+-- or follow so many weird cases as the normal
+-- boxed version. In particular, normal unboxed
+-- subtraction is -#, `minusFloat#`, -##, `minusInteger#`
+-- and unboxed negation is negate{Int,Float,Double}#
+-- . (-) and negate are kind errors. So we will
+-- assume that we don't need to parse infix (-) nicely
+-- when unboxed numbers are involved (even though someone
+-- "could" hide the Prelude's version and define (-) themself).
+-- Also we won't care here whether having a space (- 3#) works.
+
+-- Make sure the parsing is actually the correct
+-- one by running this after it's compiled.
+
+import GHC.Exts
+
+--is floating-point consistently safe to test like this,
+--if we stick to integral values?
+main = do
+ --These work with any ghc
+ print (I# (negateInt# (-3# -# -4#)))
+ print (F# (negateFloat# (-3.0# `minusFloat#` -4.0#)))
+ print (D# (negateDouble# (-3.0## -## -4.0##)))
+ print (I# (-3# ^# 4#)) --different from (boxed) Haskell98 (-3 ^ 4)
+ print ( case -1# of { -1# -> True } )
+ print ( case 1# of { -1# -> True; _ -> False } )
+ print ( case -0# of { 0# -> True } )
+
+infixr 8 ^# --just like ^, binds tighter than - (which is infixl 6)
+( ^# ) :: Int# -> Int# -> Int#
+base ^# 0# = 1#
+base ^# exponent = base *# (base ^# ( exponent -# 1# ))
+
diff --git a/testsuite/tests/ghc-regress/parser/should_run/read002.stdout b/testsuite/tests/ghc-regress/parser/should_run/read002.stdout
new file mode 100644
index 0000000000..fc761860c4
--- /dev/null
+++ b/testsuite/tests/ghc-regress/parser/should_run/read002.stdout
@@ -0,0 +1,7 @@
+-1
+-1.0
+-1.0
+81
+True
+False
+True
diff --git a/testsuite/tests/ghc-regress/parser/should_run/read003.hs b/testsuite/tests/ghc-regress/parser/should_run/read003.hs
new file mode 100644
index 0000000000..25b871ab68
--- /dev/null
+++ b/testsuite/tests/ghc-regress/parser/should_run/read003.hs
@@ -0,0 +1,13 @@
+{-# OPTIONS_GHC -fglasgow-exts #-}
+-- !!! Negative unboxed literals, part 2
+
+import GHC.Exts
+
+main = do
+ --Newly implemented: don't parse this as subtraction (Prelude.-):
+ print (I# (negateInt# -3#))
+ print (F# (negateFloat# -3.0#))
+ print (D# (negateDouble# -3.0##))
+ --nor this as let (-) f 1# = ...
+ print (let { f -1# = True } in f (-1#))
+
diff --git a/testsuite/tests/ghc-regress/parser/should_run/read003.stdout b/testsuite/tests/ghc-regress/parser/should_run/read003.stdout
new file mode 100644
index 0000000000..5953eb3a28
--- /dev/null
+++ b/testsuite/tests/ghc-regress/parser/should_run/read003.stdout
@@ -0,0 +1,4 @@
+3
+3.0
+3.0
+True