summaryrefslogtreecommitdiff
path: root/tests/typing
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2009-01-10 15:21:02 +0100
committerGuillaume Seguin <guillaume@segu.in>2009-01-10 15:21:02 +0100
commit6e6aad66c8c4bff2d94c099b29ba5ae4f4e82896 (patch)
tree3b422fc4ebb859b0b49cd7ebf89eb74a8fe37088 /tests/typing
parentcb167a0eef0ba31cc7e01046333291180887fd1e (diff)
downloadpetitcaml-6e6aad66c8c4bff2d94c099b29ba5ae4f4e82896.tar.gz
petitcaml-6e6aad66c8c4bff2d94c099b29ba5ae4f4e82896.tar.bz2
[petitcaml] Import unit tests
Diffstat (limited to 'tests/typing')
-rw-r--r--tests/typing/base-fail.ml7
-rw-r--r--tests/typing/base-fail2.ml7
-rw-r--r--tests/typing/base-fail3.ml7
-rw-r--r--tests/typing/base-fail4.ml7
-rw-r--r--tests/typing/base-fail5.ml11
-rw-r--r--tests/typing/base-fail6.ml7
-rw-r--r--tests/typing/base.ml16
-rw-r--r--tests/typing/funcs-fail.ml9
-rw-r--r--tests/typing/funcs.ml9
-rw-r--r--tests/typing/lists-fail.ml9
-rw-r--r--tests/typing/lists-fail2.ml7
-rw-r--r--tests/typing/lists.ml11
-rw-r--r--tests/typing/match-fail.ml9
-rw-r--r--tests/typing/match-fail2.ml9
-rw-r--r--tests/typing/match.ml6
-rw-r--r--tests/typing/motif-fail.ml7
-rw-r--r--tests/typing/primitives.ml14
-rw-r--r--tests/typing/test.ml35
18 files changed, 187 insertions, 0 deletions
diff --git a/tests/typing/base-fail.ml b/tests/typing/base-fail.ml
new file mode 100644
index 0000000..a0427bc
--- /dev/null
+++ b/tests/typing/base-fail.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/base-fail.ml", line 7, characters 8-14:
+Erreur dans l'analyse sémantique : Cette expression a le type int * int mais est ici utilisée avec le type int
+*)
+let _ = (1, 2) + 3
diff --git a/tests/typing/base-fail2.ml b/tests/typing/base-fail2.ml
new file mode 100644
index 0000000..efb218d
--- /dev/null
+++ b/tests/typing/base-fail2.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/base-fail2.ml", line 7, characters 12-16:
+Erreur dans l'analyse sémantique : Cette expression a le type bool mais est ici utilisée avec le type int
+*)
+let _ = 1 + true
diff --git a/tests/typing/base-fail3.ml b/tests/typing/base-fail3.ml
new file mode 100644
index 0000000..702062f
--- /dev/null
+++ b/tests/typing/base-fail3.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/base-fail3.ml", line 7, characters 13-19:
+Erreur dans l'analyse sémantique : Cette expression a le type string mais est ici utilisée avec le type int
+*)
+let _ = 42 < "test"
diff --git a/tests/typing/base-fail4.ml b/tests/typing/base-fail4.ml
new file mode 100644
index 0000000..df6e045
--- /dev/null
+++ b/tests/typing/base-fail4.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/base-fail4.ml", line 7, characters 8-13:
+Erreur dans l'analyse sémantique : Cette expression a le type bool mais est ici utilisée avec le type int
+*)
+let _ = false = not true
diff --git a/tests/typing/base-fail5.ml b/tests/typing/base-fail5.ml
new file mode 100644
index 0000000..5373b65
--- /dev/null
+++ b/tests/typing/base-fail5.ml
@@ -0,0 +1,11 @@
+(*
+ return : 1
+ output :
+File "tests/typing/base-fail5.ml", line 11, characters 8-13:
+Erreur dans l'analyse sémantique : Cette expression a le type string mais est ici utilisée avec le type bool
+*)
+let _ =
+ if 42 > 21 then
+ true
+ else
+ "yay"
diff --git a/tests/typing/base-fail6.ml b/tests/typing/base-fail6.ml
new file mode 100644
index 0000000..44a58ca
--- /dev/null
+++ b/tests/typing/base-fail6.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/base-fail6.ml", line 7, characters 10-16:
+Erreur dans l'analyse sémantique : Cette expression a le type string mais est ici utilisée avec le type int
+*)
+let _ = - "test"
diff --git a/tests/typing/base.ml b/tests/typing/base.ml
new file mode 100644
index 0000000..069b4e3
--- /dev/null
+++ b/tests/typing/base.ml
@@ -0,0 +1,16 @@
+(*
+ return : 0
+*)
+let a = 42
+let b = a + 42
+let c = a - b
+let d = a * c
+let e = a / d
+let f = - a
+
+let t = true
+let f = not true
+let l = t && f
+let k = t || f
+let a = 1 < 2
+let b = 42 >= 42
diff --git a/tests/typing/funcs-fail.ml b/tests/typing/funcs-fail.ml
new file mode 100644
index 0000000..7b1fc42
--- /dev/null
+++ b/tests/typing/funcs-fail.ml
@@ -0,0 +1,9 @@
+(*
+ return : 1
+ output :
+File "tests/typing/funcs-fail.ml", line 9, characters 14-18:
+Erreur dans l'analyse sémantique : Identifiant invalide : fact
+*)
+let fact n =
+ if n <= 1 then 1
+ else n * (fact (n - 1))
diff --git a/tests/typing/funcs.ml b/tests/typing/funcs.ml
new file mode 100644
index 0000000..54910e5
--- /dev/null
+++ b/tests/typing/funcs.ml
@@ -0,0 +1,9 @@
+(*
+ return : 0
+*)
+let f x = x + 42
+let g = function x -> x + 42
+let rec fact n =
+ if n <= 1 then 1
+ else n * (fact (n - 1))
+let _ = fact 10
diff --git a/tests/typing/lists-fail.ml b/tests/typing/lists-fail.ml
new file mode 100644
index 0000000..08826d0
--- /dev/null
+++ b/tests/typing/lists-fail.ml
@@ -0,0 +1,9 @@
+(*
+ return : 1
+ output :
+File "tests/typing/lists-fail.ml", line 9, characters 9-10:
+Erreur dans l'analyse sémantique : Cette expression a le type int list mais est ici utilisée avec le type int
+*)
+let a = 42
+let b = a + 42
+let l1 = a::b
diff --git a/tests/typing/lists-fail2.ml b/tests/typing/lists-fail2.ml
new file mode 100644
index 0000000..0d99de5
--- /dev/null
+++ b/tests/typing/lists-fail2.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/lists-fail2.ml", line 7, characters 10-12:
+Erreur dans l'analyse sémantique : Cette expression a le type int mais est ici utilisée avec le type string
+*)
+let l2 = [42 ; "42"]
diff --git a/tests/typing/lists.ml b/tests/typing/lists.ml
new file mode 100644
index 0000000..60bca89
--- /dev/null
+++ b/tests/typing/lists.ml
@@ -0,0 +1,11 @@
+(*
+ return : 0
+*)
+let a = 42
+let b = a + 42
+let f x = x + 42
+let g = function x -> x + 42
+let i x y z = x + y + z + 42
+let j x y z = (x + y)::[z + 42]
+let l1 = a::b::(f a)::(g b)::[]
+let l2 = [a ; b ; (f a) ; (g b) ; (i a b (f a))]
diff --git a/tests/typing/match-fail.ml b/tests/typing/match-fail.ml
new file mode 100644
index 0000000..f3a6e6a
--- /dev/null
+++ b/tests/typing/match-fail.ml
@@ -0,0 +1,9 @@
+(*
+ return : 1
+ output :
+File "tests/typing/match-fail.ml", line 8, characters 4-39:
+Erreur dans l'analyse sémantique : Motif interdit dans le filtrage de la queue de liste
+*)
+let rec h l =
+ match l with
+ [] -> 0 | a::(c, d) -> a + h l2
diff --git a/tests/typing/match-fail2.ml b/tests/typing/match-fail2.ml
new file mode 100644
index 0000000..8477c03
--- /dev/null
+++ b/tests/typing/match-fail2.ml
@@ -0,0 +1,9 @@
+(*
+ return : 1
+ output :
+File "tests/typing/match-fail2.ml", line 9, characters 37-50:
+Erreur dans l'analyse sémantique : Cette expression a le type int mais est ici utilisée avec le type string
+*)
+let rec h l =
+ match l with
+ [] -> "blah" | (a, b)::l2 -> a + 42 + h l2
diff --git a/tests/typing/match.ml b/tests/typing/match.ml
new file mode 100644
index 0000000..b087dfd
--- /dev/null
+++ b/tests/typing/match.ml
@@ -0,0 +1,6 @@
+(*
+ return : 0
+*)
+let rec h l =
+ match l with
+ [] -> 0 | (a, b)::l2 -> a + h l2
diff --git a/tests/typing/motif-fail.ml b/tests/typing/motif-fail.ml
new file mode 100644
index 0000000..1fedbcd
--- /dev/null
+++ b/tests/typing/motif-fail.ml
@@ -0,0 +1,7 @@
+(*
+ return : 1
+ output :
+File "tests/typing/motif-fail.ml", line 7, characters 8-9:
+Erreur dans l'analyse sémantique : Variable t non unique dans ce motif
+*)
+let (t, t) = (1, 2)
diff --git a/tests/typing/primitives.ml b/tests/typing/primitives.ml
new file mode 100644
index 0000000..30ded6b
--- /dev/null
+++ b/tests/typing/primitives.ml
@@ -0,0 +1,14 @@
+(*
+ return : 0
+*)
+let s = "test"
+let i = 42
+let _ = print_string s
+let _ = print_newline ()
+let _ = print_int i
+let _ = print_newline ()
+let a = read_int ()
+let _ = print_int (a + i)
+let _ = print_newline ()
+let _ = print_string (read_line ())
+let _ = print_newline ()
diff --git a/tests/typing/test.ml b/tests/typing/test.ml
new file mode 100644
index 0000000..458f7c0
--- /dev/null
+++ b/tests/typing/test.ml
@@ -0,0 +1,35 @@
+(*
+ return : 0
+*)
+let a = 42
+let b = a + 42
+let f x = x + 42
+let g = function x -> x + 42
+let i x y z = x + y + z + 42
+let _ = f a
+let _ = g b
+let _ = a::b::[]
+let l1 = a::b::(f a)::(g b)::[]
+let l2 = [a ; b ; (f a) ; (g b) ; (i a b (f a))]
+let rec h l =
+ match l with
+ [] -> 0 | a::l2 -> a + h l2
+let k =
+ if a = 42
+ then
+ "oui"
+ else
+ "\\ \\ \\non \"\n"
+let _ =
+ let b x = x * 42
+ in
+ if b 42 = (42 * 42)
+ then
+ "omfg"
+ else
+ "o noes! essai é ç à"
+let rec fact n =
+ if n <= 1 then 1
+ else n * (fact (n - 1))
+let noixdine = "namour"
+let test = - 42