diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 1996-05-07 12:23:30 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 1996-05-07 12:23:30 +0000 |
commit | 273162ae77ca32ad818bcc17025511ab447ea469 (patch) | |
tree | 0f19e41c3909d55ca357ef2eb444f88fdfcaa934 | |
parent | be79122e11be62038a2c62ccb8e940e8401f04cf (diff) |
Ajout
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@798 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | test/Moretest/patmatch.ml | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/Moretest/patmatch.ml b/test/Moretest/patmatch.ml new file mode 100644 index 000000000..3e3609dd3 --- /dev/null +++ b/test/Moretest/patmatch.ml @@ -0,0 +1,55 @@ +(* Tests for matchings on integers and characters *) + +(* Dense integer switch *) + +let f = function 1 -> 1 | 2 -> 2 | 3 -> 3 | 4 -> 4 | 5 -> 5 | 6 -> 6 | _ -> 0 + +(* Sparse integer switch *) + +let g = function 303 -> 1 | 401 -> 2 | _ -> 0 + +(* Very sparse integer switch *) + +let iszero = function 0 -> true | _ -> false + +(* Simple matching on characters *) + +let h = function + 'a' -> "a" + | 'e' -> "e" + | 'i' -> "i" + | 'o' -> "o" + | 'u' -> "u" + | _ -> "?" + +(* Matching with orpats *) + +let k = function + ' ' | '\t' | '\n' | '\r' -> "blank" + | 'A'..'Z' | 'a'..'z' | '\192'..'\255' -> "letter" + | '0'..'9' -> "digit" + | '!'|'%'|'&'|'$'|'#'|'+'|'/'|':'|'<'|'='|'>'|'?'|'@'|'\\'| + '~'|'^'|'|'|'*' -> "operator" + | _ -> "other" + +(* The test *) + +open Printf + +let _ = + for i = -5 to 10 do printf "f(%d) = %d\n" i (f i) done; + List.iter (fun i -> printf "g(%d) = %d\n" i (g i)) + [0;300;303;305;400;401;402;999]; + for i = -2 to 2 do printf "iszero(%d) = %b\n" i (iszero i) done; + for i = 97 to 126 do + let c = Char.chr i in + printf "h(%c) = %s\n" c (h c) + done; + for i = 0 to 255 do + let c = Char.chr i in + printf "k(%s) = %s\n" (Char.escaped c) (k c) + done; + exit 0 + + + |