summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2020-10-04 12:46:03 +0700
committerDavid Peter <sharkdp@users.noreply.github.com>2020-10-04 11:16:15 +0200
commit203d0bd8ae54cc369faa92c4dc112214831459cd (patch)
treecfa3405a2cea256e089db5f1dfdf8d11a79afc6b /tests
parent14092fbadb8f62695094258ee86afa086f691607 (diff)
Add an OCaml file for syntax tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/syntax-tests/highlighted/OCaml/syntax-test.ml83
-rw-r--r--tests/syntax-tests/source/OCaml/syntax-test.ml83
2 files changed, 166 insertions, 0 deletions
diff --git a/tests/syntax-tests/highlighted/OCaml/syntax-test.ml b/tests/syntax-tests/highlighted/OCaml/syntax-test.ml
new file mode 100644
index 00000000..ae9af823
--- /dev/null
+++ b/tests/syntax-tests/highlighted/OCaml/syntax-test.ml
@@ -0,0 +1,83 @@
+let s = "hello world"
+
+let n : int = 87
+
+let id x = x
+
+let add x y = x + y
+
+let add' x y =
+ let left = x in
+ let right = y in
+ x + y
+
+let add'' : int -> int -> int = fun x -> fun y -> x + y
+
+let unwrap_option default opt =
+ match opt with
+ | None -> default
+ | Some v -> v
+
+let string_of_bool = function true -> "true" | false -> "false"
+
+let is_a c =
+ if c = 'a' then true
+ else false
+
+let _ = Printf.printf "%s" "hello"
+let () = Printf.printf "%s\n" "world"
+
+let x = ref 0
+let _ = x := 1
+
+type my_bool = True | False
+
+type shape = Circle of float | Square of float | Rectangle of (float * float)
+
+type user = {
+ login : string;
+ password : string;
+}
+
+type 'a my_ref = { mutable ref_value : 'a }
+
+let (:=) r v = r.ref_value <- v
+
+let (+) 2 2 = 5
+
+exception Bad_value of string
+
+let bad_value_error () = raise (Bad_value "your value is bad and you should feel bad")
+
+let () =
+ try bad_value_error ()
+ with Bad_value _ -> ()
+
+let () =
+ try bad_value_error ()
+ with
+ | Bad_value _ -> ()
+ | Not_found -> ()
+
+module type FOO = sig
+ val foo : 'a -> 'a
+end
+
+module Foo : FOO = struct
+ let foo x = x
+end
+
+let greeter = object
+ val greeting = "Hello"
+ method greet name = Printf.sprintf "%s, %s!" greeting name 
+end
+
+let greeting = greeter#greet "world"
+
+class greeter_factory greeting_text = object (self)
+ val greeting = greeting_text
+ method greet name = Printf.sprintf "%s, %s!" greeting name
+ initializer Printf.printf "Objects will greet the user with \"%s\"\n" greeting
+end
+
+let g = new greeter_factory "Hi"
diff --git a/tests/syntax-tests/source/OCaml/syntax-test.ml b/tests/syntax-tests/source/OCaml/syntax-test.ml
new file mode 100644
index 00000000..0dfa1edb
--- /dev/null
+++ b/tests/syntax-tests/source/OCaml/syntax-test.ml
@@ -0,0 +1,83 @@
+let s = "hello world"
+
+let n : int = 87
+
+let id x = x
+
+let add x y = x + y
+
+let add' x y =
+ let left = x in
+ let right = y in
+ x + y
+
+let add'' : int -> int -> int = fun x -> fun y -> x + y
+
+let unwrap_option default opt =
+ match opt with
+ | None -> default
+ | Some v -> v
+
+let string_of_bool = function true -> "true" | false -> "false"
+
+let is_a c =
+ if c = 'a' then true
+ else false
+
+let _ = Printf.printf "%s" "hello"
+let () = Printf.printf "%s\n" "world"
+
+let x = ref 0
+let _ = x := 1
+
+type my_bool = True | False
+
+type shape = Circle of float | Square of float | Rectangle of (float * float)
+
+type user = {
+ login : string;
+ password : string;
+}
+
+type 'a my_ref = { mutable ref_value : 'a }
+
+let (:=) r v = r.ref_value <- v
+
+let (+) 2 2 = 5
+
+exception Bad_value of string
+
+let bad_value_error () = raise (Bad_value "your value is bad and you should feel bad")
+
+let () =
+ try bad_value_error ()
+ with Bad_value _ -> ()
+
+let () =
+ try bad_value_error ()
+ with
+ | Bad_value _ -> ()
+ | Not_found -> ()
+
+module type FOO = sig
+ val foo : 'a -> 'a
+end
+
+module Foo : FOO = struct
+ let foo x = x
+end
+
+let greeter = object
+ val greeting = "Hello"
+ method greet name = Printf.sprintf "%s, %s!" greeting name
+end
+
+let greeting = greeter#greet "world"
+
+class greeter_factory greeting_text = object (self)
+ val greeting = greeting_text
+ method greet name = Printf.sprintf "%s, %s!" greeting name
+ initializer Printf.printf "Objects will greet the user with \"%s\"\n" greeting
+end
+
+let g = new greeter_factory "Hi"