on master help sign in
Add an OCaml file for syntax tests.
commit203d0bd8ae54cc369faa92c4dc112214831459cd authorDaniil Baturin <daniil@baturin.org> dateSun 4 Oct 2020, 12:46 (6 years ago) parent14092fb
2 files changed+166
tests/syntax-tests/highlighted/OCaml/syntax-test.ml+83 tests/syntax-tests/source/OCaml/syntax-test.ml+83
tests/syntax-tests/highlighted/OCaml/syntax-test.mlnew file+83
@@ -0,0 +1,83 @@
1+let s = "hello world"
2+
3+let n : int = 87
4+
5+let id x = x
6+
7+let add x y = x + y
8+
9+let add' x y =
10+ let left = x in
11+ let right = y in
12+ x + y
13+
14+let add'' : int -> int -> int = fun x -> fun y -> x + y
15+
16+let unwrap_option default opt =
17+ match opt with
18+ | None -> default
19+ | Some v -> v
20+
21+let string_of_bool = function true -> "true" | false -> "false"
22+
23+let is_a c =
24+ if c = 'a' then true
25+ else false
26+
27+let _ = Printf.printf "%s" "hello"
28+let () = Printf.printf "%s\n" "world"
29+
30+let x = ref 0
31+let _ = x := 1
32+
33+type my_bool = True | False
34+
35+type shape = Circle of float | Square of float | Rectangle of (float * float)
36+
37+type user = {
38+ login : string;
39+ password : string;
40+}
41+
42+type 'a my_ref = { mutable ref_value : 'a }
43+
44+let (:=) r v = r.ref_value <- v
45+
46+let (+) 2 2 = 5
47+
48+exception Bad_value of string
49+
50+let bad_value_error () = raise (Bad_value "your value is bad and you should feel bad")
51+
52+let () =
53+ try bad_value_error ()
54+ with Bad_value _ -> ()
55+
56+let () =
57+ try bad_value_error ()
58+ with
59+ | Bad_value _ -> ()
60+ | Not_found -> ()
61+
62+module type FOO = sig
63+ val foo : 'a -> 'a
64+end
65+
66+module Foo : FOO = struct
67+ let foo x = x
68+end
69+
70+let greeter = object
71+ val greeting = "Hello"
72+ method greet name = Printf.sprintf "%s, %s!" greeting name 
73+end
74+
75+let greeting = greeter#greet "world"
76+
77+class greeter_factory greeting_text = object (self)
78+ val greeting = greeting_text
79+ method greet name = Printf.sprintf "%s, %s!" greeting name
80+ initializer Printf.printf "Objects will greet the user with \"%s\"\n" greeting
81+end
82+
83+let g = new greeter_factory "Hi"
tests/syntax-tests/source/OCaml/syntax-test.mlnew file+83
@@ -0,0 +1,83 @@
1+let s = "hello world"
2+
3+let n : int = 87
4+
5+let id x = x
6+
7+let add x y = x + y
8+
9+let add' x y =
10+ let left = x in
11+ let right = y in
12+ x + y
13+
14+let add'' : int -> int -> int = fun x -> fun y -> x + y
15+
16+let unwrap_option default opt =
17+ match opt with
18+ | None -> default
19+ | Some v -> v
20+
21+let string_of_bool = function true -> "true" | false -> "false"
22+
23+let is_a c =
24+ if c = 'a' then true
25+ else false
26+
27+let _ = Printf.printf "%s" "hello"
28+let () = Printf.printf "%s\n" "world"
29+
30+let x = ref 0
31+let _ = x := 1
32+
33+type my_bool = True | False
34+
35+type shape = Circle of float | Square of float | Rectangle of (float * float)
36+
37+type user = {
38+ login : string;
39+ password : string;
40+}
41+
42+type 'a my_ref = { mutable ref_value : 'a }
43+
44+let (:=) r v = r.ref_value <- v
45+
46+let (+) 2 2 = 5
47+
48+exception Bad_value of string
49+
50+let bad_value_error () = raise (Bad_value "your value is bad and you should feel bad")
51+
52+let () =
53+ try bad_value_error ()
54+ with Bad_value _ -> ()
55+
56+let () =
57+ try bad_value_error ()
58+ with
59+ | Bad_value _ -> ()
60+ | Not_found -> ()
61+
62+module type FOO = sig
63+ val foo : 'a -> 'a
64+end
65+
66+module Foo : FOO = struct
67+ let foo x = x
68+end
69+
70+let greeter = object
71+ val greeting = "Hello"
72+ method greet name = Printf.sprintf "%s, %s!" greeting name
73+end
74+
75+let greeting = greeter#greet "world"
76+
77+class greeter_factory greeting_text = object (self)
78+ val greeting = greeting_text
79+ method greet name = Printf.sprintf "%s, %s!" greeting name
80+ initializer Printf.printf "Objects will greet the user with \"%s\"\n" greeting
81+end
82+
83+let g = new greeter_factory "Hi"