summaryrefslogtreecommitdiff
path: root/test/identifier.ml
diff options
context:
space:
mode:
Diffstat (limited to 'test/identifier.ml')
-rw-r--r--test/identifier.ml42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/identifier.ml b/test/identifier.ml
new file mode 100644
index 0000000..322f459
--- /dev/null
+++ b/test/identifier.ml
@@ -0,0 +1,42 @@
+let name = __FILE__
+
+let description =
+ "Check the [Model.Identifier] module: validation of the names given as \
+ arguments, their quoted SQL form, the predefined columns and the composite \
+ names"
+
+let speclist () = []
+
+type t = string list
+
+let pp : Format.formatter -> t -> unit =
+ Format.pp_print_list ~pp_sep:Format.pp_print_newline Format.pp_print_string
+
+(** A valid name is printed in its quoted SQL form, an invalid one is
+ reported *)
+let check : string -> string =
+ fun s ->
+ match Model.Identifier.of_string_opt s with
+ | Some id -> Model.Identifier.quote id
+ | None -> "invalid: \"" ^ s ^ "\""
+
+let exec : string list -> t =
+ fun args ->
+ (* The anonymous arguments are collected in reverse order by the test
+ harness *)
+ match List.rev args with
+ | "check" :: names -> List.map check names
+ | "predefined" :: [] ->
+ [
+ "id = " ^ Model.Identifier.quote Model.Identifier.id;
+ "parent = " ^ Model.Identifier.quote Model.Identifier.parent;
+ "target = " ^ Model.Identifier.quote Model.Identifier.target;
+ ]
+ | "dot" :: [ a; b ] ->
+ [
+ Model.Identifier.quote
+ (Model.Identifier.dot
+ (Model.Identifier.of_string a)
+ (Model.Identifier.of_string b));
+ ]
+ | _ -> failwith "Invalid arguments"