Add tests for OverloadedLists
authorSimon Peyton Jones <simonpj@microsoft.com>
Thu, 14 Feb 2013 14:52:43 +0000 (14:52 +0000)
committerSimon Peyton Jones <simonpj@microsoft.com>
Thu, 14 Feb 2013 14:52:43 +0000 (14:52 +0000)
27 files changed:
testsuite/tests/overloadedlists/Makefile [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/Makefile [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/all.T [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.hs [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/overloadedlistsfail02.hs [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/overloadedlistsfail02.stderr [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/overloadedlistsfail03.hs [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/overloadedlistsfail03.stderr [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/overloadedlistsfail04.hs [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/overloadedlistsfail04.stderr [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/overloadedlistsfail05.hs [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/overloadedlistsfail05.stderr [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/overloadedlistsfail06.hs [new file with mode: 0644]
testsuite/tests/overloadedlists/should_fail/overloadedlistsfail06.stderr [new file with mode: 0644]
testsuite/tests/overloadedlists/should_run/Makefile [new file with mode: 0644]
testsuite/tests/overloadedlists/should_run/all.T [new file with mode: 0644]
testsuite/tests/overloadedlists/should_run/overloadedlistsrun01.hs [new file with mode: 0644]
testsuite/tests/overloadedlists/should_run/overloadedlistsrun01.stdout [new file with mode: 0644]
testsuite/tests/overloadedlists/should_run/overloadedlistsrun02.hs [new file with mode: 0644]
testsuite/tests/overloadedlists/should_run/overloadedlistsrun02.stdout [new file with mode: 0644]
testsuite/tests/overloadedlists/should_run/overloadedlistsrun03.hs [new file with mode: 0644]
testsuite/tests/overloadedlists/should_run/overloadedlistsrun03.stdout [new file with mode: 0644]
testsuite/tests/overloadedlists/should_run/overloadedlistsrun04.hs [new file with mode: 0644]
testsuite/tests/overloadedlists/should_run/overloadedlistsrun04.stdout [new file with mode: 0644]
testsuite/tests/overloadedlists/should_run/overloadedlistsrun05.hs [new file with mode: 0644]
testsuite/tests/overloadedlists/should_run/overloadedlistsrun05.stdout [new file with mode: 0644]

diff --git a/testsuite/tests/overloadedlists/Makefile b/testsuite/tests/overloadedlists/Makefile
new file mode 100644 (file)
index 0000000..9a36a1c
--- /dev/null
@@ -0,0 +1,3 @@
+TOP=../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
diff --git a/testsuite/tests/overloadedlists/should_fail/Makefile b/testsuite/tests/overloadedlists/should_fail/Makefile
new file mode 100644 (file)
index 0000000..9101fbd
--- /dev/null
@@ -0,0 +1,3 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
diff --git a/testsuite/tests/overloadedlists/should_fail/all.T b/testsuite/tests/overloadedlists/should_fail/all.T
new file mode 100644 (file)
index 0000000..771035d
--- /dev/null
@@ -0,0 +1,6 @@
+test('overloadedlistsfail01', normal, compile_fail, [''])
+test('overloadedlistsfail02', normal, compile_fail, [''])
+test('overloadedlistsfail03', normal, compile_fail, [''])
+test('overloadedlistsfail04', normal, compile_fail, [''])
+test('overloadedlistsfail05', normal, compile_fail, [''])
+test('overloadedlistsfail06', normal, compile_fail, [''])
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.hs b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.hs
new file mode 100644 (file)
index 0000000..ec49acc
--- /dev/null
@@ -0,0 +1,5 @@
+{-# LANGUAGE OverloadedLists #-}
+
+-- This will fail because there is no type defaulting implemented as of yet.
+
+main = print [1]
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail01.stderr
new file mode 100644 (file)
index 0000000..a08985f
--- /dev/null
@@ -0,0 +1,36 @@
+
+overloadedlistsfail01.hs:5:8:
+    No instance for (Show a0) arising from a use of `print'
+    The type variable `a0' is ambiguous
+    Note: there are several potential instances:
+      instance Show Double -- Defined in `GHC.Float'
+      instance Show Float -- Defined in `GHC.Float'
+      instance (Integral a, Show a) => Show (GHC.Real.Ratio a)
+        -- Defined in `GHC.Real'
+      ...plus 23 others
+    In the expression: print [1]
+    In an equation for `main': main = print [1]
+
+overloadedlistsfail01.hs:5:14:
+    No instance for (GHC.Exts.IsList a0)
+      arising from an overloaded list
+    The type variable `a0' is ambiguous
+    Note: there is a potential instance available:
+      instance GHC.Exts.IsList [a] -- Defined in `GHC.Exts'
+    In the first argument of `print', namely `[1]'
+    In the expression: print [1]
+    In an equation for `main': main = print [1]
+
+overloadedlistsfail01.hs:5:15:
+    No instance for (Num (GHC.Exts.Item a0))
+      arising from the literal `1'
+    The type variable `a0' is ambiguous
+    Note: there are several potential instances:
+      instance Num Double -- Defined in `GHC.Float'
+      instance Num Float -- Defined in `GHC.Float'
+      instance Integral a => Num (GHC.Real.Ratio a)
+        -- Defined in `GHC.Real'
+      ...plus three others
+    In the expression: 1
+    In the first argument of `print', namely `[1]'
+    In the expression: print [1]
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail02.hs b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail02.hs
new file mode 100644 (file)
index 0000000..54ca2db
--- /dev/null
@@ -0,0 +1,8 @@
+{-# LANGUAGE OverloadedLists #-}
+
+data Foo = Foo
+
+test :: Foo
+test = [7]
+
+main = return ()
\ No newline at end of file
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail02.stderr b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail02.stderr
new file mode 100644 (file)
index 0000000..49e6b9e
--- /dev/null
@@ -0,0 +1,13 @@
+
+overloadedlistsfail02.hs:6:8:
+    No instance for (GHC.Exts.IsList Foo)
+      arising from an overloaded list
+    In the expression: [7]
+    In an equation for `test': test = [7]
+
+overloadedlistsfail02.hs:6:9:
+    No instance for (Num (GHC.Exts.Item Foo))
+      arising from the literal `7'
+    In the expression: 7
+    In the expression: [7]
+    In an equation for `test': test = [7]
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail03.hs b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail03.hs
new file mode 100644 (file)
index 0000000..d198184
--- /dev/null
@@ -0,0 +1,3 @@
+{-# LANGUAGE OverloadedLists #-}
+
+main = print (length ['a',"b"])
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail03.stderr b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail03.stderr
new file mode 100644 (file)
index 0000000..099d79f
--- /dev/null
@@ -0,0 +1,9 @@
+
+overloadedlistsfail03.hs:3:27:
+    Couldn't match expected type `Char' with actual type `[Char]'
+    In the expression: "b"
+    In the first argument of `length', namely `['a', "b"]'
+    In the first argument of `print', namely `(length ['a', "b"])'
+
+
+
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail04.hs b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail04.hs
new file mode 100644 (file)
index 0000000..811c051
--- /dev/null
@@ -0,0 +1,3 @@
+{-# LANGUAGE OverloadedLists #-}
+
+main = print (["a".."b"] :: [String])
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail04.stderr b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail04.stderr
new file mode 100644 (file)
index 0000000..cfa0519
--- /dev/null
@@ -0,0 +1,12 @@
+
+overloadedlistsfail04.hs:3:15:
+    No instance for (Enum [Char])
+      arising from the arithmetic sequence `"a" .. "b"'
+    In the first argument of `print', namely
+      `(["a" .. "b"] :: [String])'
+    In the expression: print (["a" .. "b"] :: [String])
+    In an equation for `main': main = print (["a" .. "b"] :: [String])
+
+
+
+
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail05.hs b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail05.hs
new file mode 100644 (file)
index 0000000..3601c6e
--- /dev/null
@@ -0,0 +1,3 @@
+{-# LANGUAGE OverloadedLists #-}
+
+main = print (length ['a'..(10 :: Int)])
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail05.stderr b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail05.stderr
new file mode 100644 (file)
index 0000000..6e4d3db
--- /dev/null
@@ -0,0 +1,7 @@
+
+overloadedlistsfail05.hs:3:29:
+    Couldn't match expected type `Char' with actual type `Int'
+    In the expression: (10 :: Int)
+    In the first argument of `length', namely `['a' .. (10 :: Int)]'
+    In the first argument of `print', namely
+      `(length ['a' .. (10 :: Int)])'
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail06.hs b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail06.hs
new file mode 100644 (file)
index 0000000..c8cf5ae
--- /dev/null
@@ -0,0 +1,4 @@
+{-# LANGUAGE OverloadedLists, RebindableSyntax #-}
+
+f [] = []
+f x = x
diff --git a/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail06.stderr b/testsuite/tests/overloadedlists/should_fail/overloadedlistsfail06.stderr
new file mode 100644 (file)
index 0000000..2cd0c3f
--- /dev/null
@@ -0,0 +1,7 @@
+
+overloadedlistsfail06.hs:3:3:
+    Not in scope: `toList'
+
+overloadedlistsfail06.hs:3:8:
+    Not in scope: `fromListN'
+
diff --git a/testsuite/tests/overloadedlists/should_run/Makefile b/testsuite/tests/overloadedlists/should_run/Makefile
new file mode 100644 (file)
index 0000000..9101fbd
--- /dev/null
@@ -0,0 +1,3 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
diff --git a/testsuite/tests/overloadedlists/should_run/all.T b/testsuite/tests/overloadedlists/should_run/all.T
new file mode 100644 (file)
index 0000000..be654e3
--- /dev/null
@@ -0,0 +1,5 @@
+test('overloadedlistsrun01', normal, compile_and_run, [''])
+test('overloadedlistsrun02', normal, compile_and_run, [''])
+test('overloadedlistsrun03', normal, compile_and_run, [''])
+test('overloadedlistsrun04', normal, compile_and_run, [''])
+test('overloadedlistsrun05', normal, compile_and_run, [''])
diff --git a/testsuite/tests/overloadedlists/should_run/overloadedlistsrun01.hs b/testsuite/tests/overloadedlists/should_run/overloadedlistsrun01.hs
new file mode 100644 (file)
index 0000000..00852b9
--- /dev/null
@@ -0,0 +1,6 @@
+{-# LANGUAGE OverloadedLists #-}
+
+main = do print ([] :: [Int])
+          print ([1,2,3] :: [Int])
+          print ((take 10 [1..]) :: [Int])
+          print (['a'..'e'] :: [Char])
diff --git a/testsuite/tests/overloadedlists/should_run/overloadedlistsrun01.stdout b/testsuite/tests/overloadedlists/should_run/overloadedlistsrun01.stdout
new file mode 100644 (file)
index 0000000..4a75bae
--- /dev/null
@@ -0,0 +1,4 @@
+[]
+[1,2,3]
+[1,2,3,4,5,6,7,8,9,10]
+"abcde"
diff --git a/testsuite/tests/overloadedlists/should_run/overloadedlistsrun02.hs b/testsuite/tests/overloadedlists/should_run/overloadedlistsrun02.hs
new file mode 100644 (file)
index 0000000..8567db3
--- /dev/null
@@ -0,0 +1,13 @@
+{-# LANGUAGE OverloadedLists, TypeFamilies #-}
+
+import qualified Data.Set as S
+import GHC.Exts
+
+main = do print ([] :: (S.Set Int))
+          print (['a','b','c'] :: (S.Set Char))
+          print (['a','c'..'g'] :: (S.Set Char))
+          
+instance Ord a => IsList (S.Set a) where
+ type (Item (S.Set a)) = a
+ fromList = S.fromList
+ toList = S.toList
diff --git a/testsuite/tests/overloadedlists/should_run/overloadedlistsrun02.stdout b/testsuite/tests/overloadedlists/should_run/overloadedlistsrun02.stdout
new file mode 100644 (file)
index 0000000..08fffbf
--- /dev/null
@@ -0,0 +1,3 @@
+fromList []
+fromList "abc"
+fromList "aceg"
diff --git a/testsuite/tests/overloadedlists/should_run/overloadedlistsrun03.hs b/testsuite/tests/overloadedlists/should_run/overloadedlistsrun03.hs
new file mode 100644 (file)
index 0000000..7d5b7d9
--- /dev/null
@@ -0,0 +1,18 @@
+{-# LANGUAGE OverloadedLists, TypeFamilies #-}
+
+import GHC.Exts
+
+-- This nonsensical instance is used to test if fromListN is used properly in
+-- desugaring of explicit lists.
+
+instance IsList Int where
+ type Item Int = Int
+ fromList _ = 0
+ toList _ = []
+ fromListN n _ = n
+main = do print ([] :: Int)
+          print ([1,2,3,4,5] :: Int)
+          print ([1..3] :: Int)
+          print ([7] :: Int)
+          print ([1,3..] :: Int)
diff --git a/testsuite/tests/overloadedlists/should_run/overloadedlistsrun03.stdout b/testsuite/tests/overloadedlists/should_run/overloadedlistsrun03.stdout
new file mode 100644 (file)
index 0000000..ff973f8
--- /dev/null
@@ -0,0 +1,5 @@
+0
+5
+0
+1
+0
diff --git a/testsuite/tests/overloadedlists/should_run/overloadedlistsrun04.hs b/testsuite/tests/overloadedlists/should_run/overloadedlistsrun04.hs
new file mode 100644 (file)
index 0000000..478d8d2
--- /dev/null
@@ -0,0 +1,28 @@
+{-# LANGUAGE OverloadedLists, TypeFamilies #-}
+
+import qualified Data.Set as S
+import GHC.Exts
+
+main = do putStrLn (f [])       
+          putStrLn (f [1,2])    
+          putStrLn (f [2,0])    
+          putStrLn (f [3,2])     
+          putStrLn (f [2,7])
+          putStrLn (f [2,2])
+          putStrLn (f [1..7])
+
+
+f :: S.Set Int -> String
+f [] = "empty"
+f [_] = "one element"
+f [2,_] = "two elements, the smaller one is 2"
+f [_,2] = "two elements, the bigger one is 2"
+f _ = "else"
+
+          
+instance Ord a => IsList (S.Set a) where
+ type (Item (S.Set a)) = a
+ fromList = S.fromList
+ toList = S.toList
+          
+
diff --git a/testsuite/tests/overloadedlists/should_run/overloadedlistsrun04.stdout b/testsuite/tests/overloadedlists/should_run/overloadedlistsrun04.stdout
new file mode 100644 (file)
index 0000000..0f50db5
--- /dev/null
@@ -0,0 +1,7 @@
+empty
+two elements, the bigger one is 2
+two elements, the bigger one is 2
+two elements, the smaller one is 2
+two elements, the smaller one is 2
+one element
+else
diff --git a/testsuite/tests/overloadedlists/should_run/overloadedlistsrun05.hs b/testsuite/tests/overloadedlists/should_run/overloadedlistsrun05.hs
new file mode 100644 (file)
index 0000000..18d8cc1
--- /dev/null
@@ -0,0 +1,16 @@
+{-# LANGUAGE OverloadedLists, TypeFamilies, RebindableSyntax #-}
+
+import Prelude
+import Data.List
+
+main = do print []       
+          print [0,3..20]    
+          print [3]     
+          print [2..7]
+          print [20,2]
+          print [1,2,37]
+
+fromListN _ = length 
+fromList = length
+          
+
diff --git a/testsuite/tests/overloadedlists/should_run/overloadedlistsrun05.stdout b/testsuite/tests/overloadedlists/should_run/overloadedlistsrun05.stdout
new file mode 100644 (file)
index 0000000..e0777cd
--- /dev/null
@@ -0,0 +1,6 @@
+0
+7
+1
+6
+2
+3