]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
moved unit tests to separate modules and folder
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 27 Oct 2017 14:47:41 +0000 (10:47 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 27 Oct 2017 14:47:41 +0000 (10:47 -0400)
Makefile
lib/buf.ml
lib/rope.ml
lib/scrollmap.ml
tests.ml [deleted file]
tests/rope_tests.ml [new file with mode: 0644]
tests/scrollmap_tests.ml [new file with mode: 0644]
tests/test.ml [moved from lib/test.ml with 100% similarity]
unittests.ml [new file with mode: 0644]

index a904b9a65c5d22a3579f490b1f5bf1246739945d..e5c12f8c308966541be427c52078f80c33a9ef59 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 # Toolchain Configuration
 #-------------------------------------------------------------------------------
-INCS = -I . -I lib -I /usr/X11R6/include -I /usr/include/freetype2 -I /usr/X11R6/include/freetype2
+INCS = -I . -I lib -I tests -I /usr/X11R6/include -I /usr/include/freetype2 -I /usr/X11R6/include/freetype2
 LIBS = -L/usr/X11R6/lib -lX11 -lXft -lfontconfig
 
 ifeq ($(NATIVE), 1)
@@ -23,9 +23,8 @@ endif
 
 # Target Definitions
 #-------------------------------------------------------------------------------
-BINS = edit tests
+BINS = edit unittests
 LIBOBJS = \
-    lib/test.$(OBJEXT) \
     lib/misc.$(OBJEXT) \
     lib/x11.$(OBJEXT) \
     lib/cfg.$(OBJEXT) \
@@ -37,17 +36,22 @@ LIBOBJS = \
     lib/misc_prims.o \
     lib/utf8.o
 
+TESTOBJS = \
+    tests/test.$(OBJEXT) \
+    tests/rope_tests.$(OBJEXT) \
+    tests/scrollmap_tests.$(OBJEXT)
+
 .PHONY: all clean
 
 all: $(BINS)
-       ./tests
+       ./unittests
 
 clean:
        $(RM) deps.mk $(BINS) *.cm* *.o *.a *.so lib/*.cm* lib/*.o
 
 # Executable targets
 edit: tide.$(LIBEXT) edit.$(OBJEXT)
-tests: tide.$(LIBEXT) tests.$(OBJEXT)
+unittests: tide.$(LIBEXT) $(TESTOBJS) unittests.$(OBJEXT)
 
 # Library targets
 tide.$(LIBEXT): $(LIBOBJS)
index acade5f0fa4f9bab517ffaf7f167cf2bb2234199..c19f6d8595ed76c4fb2e063b92228081fb06ec67 100644 (file)
@@ -17,9 +17,3 @@ let iter_from fn buf i =
 
 let iteri_from fn buf i =
   Rope.iteri_from fn buf.rope i
-
-(* Unit Tests *****************************************************************)
-
-let run_unit_tests () =
-  let open Test in
-  ()
index 9c6f076e6ec0275a7b3de2c500c9975c2375b36f..2423259af73eb6b3b5627d83718a4da2bb3e540a 100644 (file)
@@ -135,151 +135,6 @@ let gets rope i j =
 let to_string rope =
   gets rope 0 (length rope)
 
-(* Unit Tests *****************************************************************)
-
-let run_unit_tests () =
-  let open Test in
-  (* length() tests *)
-  test "length : 0 for empty string" (fun () ->
-    let rope = Leaf("", 0, 0) in
-    assert( length rope == 0 )
-  );
-  test "length : equal to length of leaf" (fun () ->
-    let rope = Leaf("a", 0, 1) in
-    assert( length rope == 1 )
-  );
-  test "length : equal to sum of leaf lengths" (fun () ->
-    let rope = (join (Leaf("a", 0, 1)) (Leaf("a", 0, 1))) in
-    assert( length rope == 2 )
-  );
-
-  (* join() tests *)
-  test "join : join two leaves into rope" (fun () ->
-    let left  = Leaf("a", 0, 1) in
-    let right =  Leaf("a", 0, 1) in
-    let rope  = (join left right) in
-    assert( match rope with
-    | Node (l,r,2) -> (l == left && r == right)
-    | _ -> false)
-  );
-  test "join : join a rope with a leaf (l to r)" (fun () ->
-    let left  = join (Leaf("a", 0, 1)) (Leaf("a", 0, 1)) in
-    let right =  Leaf("a", 0, 1) in
-    let rope  = (join left right) in
-    assert( match rope with
-    | Node (l,r,3) -> (l == left && r == right)
-    | _ -> false)
-  );
-  test "join : join a rope with a leaf (r to l)" (fun () ->
-    let left  =  Leaf("a", 0, 1) in
-    let right = join (Leaf("a", 0, 1)) (Leaf("a", 0, 1)) in
-    let rope  = (join left right) in
-    assert( match rope with
-    | Node (l,r,3) -> (l == left && r == right)
-    | _ -> false)
-  );
-
-  (* getc() tests *)
-  test "getc : raise Out_of_bounds on negative index" (fun () ->
-    let rope = Leaf("a", 0, 1) in
-    try getc rope (-1); assert false
-    with Out_of_bounds _ -> assert true
-  );
-  test "getc : raise Out_of_bounds on out of bounds index" (fun () ->
-    let rope = Leaf("a", 0, 1) in
-    try getc rope (2); assert false
-    with Out_of_bounds _ -> assert true
-  );
-  test "getc : return index 0 of leaf" (fun () ->
-    let rope = Leaf("abc", 0, 3) in
-    assert( (getc rope (0)) == Char.code 'a' );
-  );
-  test "getc : return index 1 of leaf" (fun () ->
-    let rope = Leaf("abc", 0, 3) in
-    assert( (getc rope (1)) == Char.code 'b' );
-  );
-  test "getc : return index 2 of leaf" (fun () ->
-    let rope = Leaf("abc", 0, 3) in
-    assert( (getc rope (2)) == Char.code 'c' );
-  );
-  test "getc : return index 0 of rope" (fun () ->
-    let rope = Node((Leaf("a", 0, 1)), (Leaf("b", 0, 1)), 2) in
-    assert( (getc rope (0)) == Char.code 'a' );
-  );
-  test "getc : return index 1 of rope" (fun () ->
-    let rope = Node((Leaf("a", 0, 1)), (Leaf("b", 0, 1)), 2) in
-    assert( (getc rope (1)) == Char.code 'b' );
-  );
-
-  (* puts() tests *)
-  test "puts : insert at index 0" (fun () ->
-    let rope = Leaf("bc", 0, 2) in
-    let rope = (puts rope "a" 0) in
-    assert( (length rope) == 3 );
-    assert( (getc rope (0)) == Char.code 'a' );
-    assert( (getc rope (1)) == Char.code 'b' );
-    assert( (getc rope (2)) == Char.code 'c' );
-  );
-  test "puts : insert at index 1" (fun () ->
-    let rope = Leaf("ac", 0, 2) in
-    let rope = (puts rope "b" 1) in
-    assert( (length rope) == 3 );
-    assert( (getc rope (0)) == Char.code 'a' );
-    assert( (getc rope (1)) == Char.code 'b' );
-    assert( (getc rope (2)) == Char.code 'c' );
-  );
-  test "puts : insert index at 2" (fun () ->
-    let rope = Leaf("ab", 0, 2) in
-    let rope = (puts rope "c" 2) in
-    assert( (length rope) == 3 );
-    assert( (getc rope (0)) == Char.code 'a' );
-    assert( (getc rope (1)) == Char.code 'b' );
-    assert( (getc rope (2)) == Char.code 'c' );
-  );
-
-  (* is_bol() tests *)
-  test "is_bol : should return true if pos is 0" (fun () ->
-    let rope = Leaf("abc", 0, 3) in
-    assert( is_bol rope 0 );
-  );
-  test "is_bol : should return true if pos is first char of line" (fun () ->
-    let rope = Leaf("\nabc", 0, 3) in
-    assert( is_bol rope 1 );
-  );
-  test "is_bol : should return false if pos is not first char of line" (fun () ->
-    let rope = Leaf("\nabc", 0, 3) in
-    assert( (is_bol rope 2) == false );
-  );
-  test "is_bol : should return false if previous char is not \n" (fun () ->
-    let rope = Leaf("\rabc", 0, 3) in
-    assert( (is_bol rope 1) == false );
-  );
-
-  (* is_eol() tests *)
-  test "is_eol : should return true if pos is Rope.last" (fun () ->
-    let rope = Leaf("abc", 0, 3) in
-    assert( is_eol rope 2 );
-  );
-  test "is_eol : should return true if pos is last char of line with \n ending" (fun () ->
-    let rope = Leaf("abc\n", 0, 4) in
-    assert( is_eol rope 2 );
-  );
-  test "is_eol : should return true if pos is last char of line with \r\n ending" (fun () ->
-    let rope = Leaf("abc\r\n", 0, 5) in
-    assert( is_eol rope 3 );
-  );
-  test "is_eol : should return false if pos is not last char of line" (fun () ->
-    let rope = Leaf("abcd\n", 0, 5) in
-    assert( (is_eol rope 2) == false );
-  );
-
-  (* to_bol() tests *)
-  test "to_bol : should return index of first char on the line" (fun () ->
-    let rope = Leaf("\nabc\n", 0, 5) in
-    assert( (to_bol rope 2) == 1 );
-  );
-  ()
-
 (*
 
 size_t buf_lscan(Buf* buf, size_t pos, Rune r);
index b180ae8d1dd1cc14fa155a1e2ca55a6f9ac0b331..12b27fef93189e4171776597927a35cefdf223cf 100644 (file)
@@ -14,7 +14,6 @@ let make buf width off =
   let csr = Draw.Cursor.make (width, 0) 0 0 in
   let bol = (Rope.to_bol (Buf.rope buf) off) in
   let lines = ref [bol] in
-  let csr = Draw.Cursor.make (width, 0) 0 0 in
   let process_glyph i c =
     if (Draw.Cursor.next_glyph csr c) then
       lines := i :: !lines;
@@ -26,10 +25,6 @@ let make buf width off =
   { width = width; lines = lines; index = index }
 
 let first map =
-  (*
-  Printf.printf "%d: %d" map.index map.lines.(map.index);
-  print_endline "";
-  *)
   map.lines.(map.index)
 
 let bopl buf off =
diff --git a/tests.ml b/tests.ml
deleted file mode 100644 (file)
index def58ab..0000000
--- a/tests.ml
+++ /dev/null
@@ -1,4 +0,0 @@
-let () =
-  Rope.run_unit_tests ();
-  Scrollmap.run_unit_tests ();
-  Test.report_results ()
diff --git a/tests/rope_tests.ml b/tests/rope_tests.ml
new file mode 100644 (file)
index 0000000..c5d0a1b
--- /dev/null
@@ -0,0 +1,144 @@
+open Test
+open Rope
+
+let  () =
+  (* length() tests *)
+  test "length : 0 for empty string" (fun () ->
+    let rope = Leaf("", 0, 0) in
+    assert( length rope == 0 )
+  );
+  test "length : equal to length of leaf" (fun () ->
+    let rope = Leaf("a", 0, 1) in
+    assert( length rope == 1 )
+  );
+  test "length : equal to sum of leaf lengths" (fun () ->
+    let rope = (join (Leaf("a", 0, 1)) (Leaf("a", 0, 1))) in
+    assert( length rope == 2 )
+  );
+
+  (* join() tests *)
+  test "join : join two leaves into rope" (fun () ->
+    let left  = Leaf("a", 0, 1) in
+    let right =  Leaf("a", 0, 1) in
+    let rope  = (join left right) in
+    assert( match rope with
+    | Node (l,r,2) -> (l == left && r == right)
+    | _ -> false)
+  );
+  test "join : join a rope with a leaf (l to r)" (fun () ->
+    let left  = join (Leaf("a", 0, 1)) (Leaf("a", 0, 1)) in
+    let right =  Leaf("a", 0, 1) in
+    let rope  = (join left right) in
+    assert( match rope with
+    | Node (l,r,3) -> (l == left && r == right)
+    | _ -> false)
+  );
+  test "join : join a rope with a leaf (r to l)" (fun () ->
+    let left  =  Leaf("a", 0, 1) in
+    let right = join (Leaf("a", 0, 1)) (Leaf("a", 0, 1)) in
+    let rope  = (join left right) in
+    assert( match rope with
+    | Node (l,r,3) -> (l == left && r == right)
+    | _ -> false)
+  );
+
+  (* getc() tests *)
+  test "getc : raise Out_of_bounds on negative index" (fun () ->
+    let rope = Leaf("a", 0, 1) in
+    try getc rope (-1); assert false
+    with Out_of_bounds _ -> assert true
+  );
+  test "getc : raise Out_of_bounds on out of bounds index" (fun () ->
+    let rope = Leaf("a", 0, 1) in
+    try getc rope (2); assert false
+    with Out_of_bounds _ -> assert true
+  );
+  test "getc : return index 0 of leaf" (fun () ->
+    let rope = Leaf("abc", 0, 3) in
+    assert( (getc rope (0)) == Char.code 'a' );
+  );
+  test "getc : return index 1 of leaf" (fun () ->
+    let rope = Leaf("abc", 0, 3) in
+    assert( (getc rope (1)) == Char.code 'b' );
+  );
+  test "getc : return index 2 of leaf" (fun () ->
+    let rope = Leaf("abc", 0, 3) in
+    assert( (getc rope (2)) == Char.code 'c' );
+  );
+  test "getc : return index 0 of rope" (fun () ->
+    let rope = Node((Leaf("a", 0, 1)), (Leaf("b", 0, 1)), 2) in
+    assert( (getc rope (0)) == Char.code 'a' );
+  );
+  test "getc : return index 1 of rope" (fun () ->
+    let rope = Node((Leaf("a", 0, 1)), (Leaf("b", 0, 1)), 2) in
+    assert( (getc rope (1)) == Char.code 'b' );
+  );
+
+  (* puts() tests *)
+  test "puts : insert at index 0" (fun () ->
+    let rope = Leaf("bc", 0, 2) in
+    let rope = (puts rope "a" 0) in
+    assert( (length rope) == 3 );
+    assert( (getc rope (0)) == Char.code 'a' );
+    assert( (getc rope (1)) == Char.code 'b' );
+    assert( (getc rope (2)) == Char.code 'c' );
+  );
+  test "puts : insert at index 1" (fun () ->
+    let rope = Leaf("ac", 0, 2) in
+    let rope = (puts rope "b" 1) in
+    assert( (length rope) == 3 );
+    assert( (getc rope (0)) == Char.code 'a' );
+    assert( (getc rope (1)) == Char.code 'b' );
+    assert( (getc rope (2)) == Char.code 'c' );
+  );
+  test "puts : insert index at 2" (fun () ->
+    let rope = Leaf("ab", 0, 2) in
+    let rope = (puts rope "c" 2) in
+    assert( (length rope) == 3 );
+    assert( (getc rope (0)) == Char.code 'a' );
+    assert( (getc rope (1)) == Char.code 'b' );
+    assert( (getc rope (2)) == Char.code 'c' );
+  );
+
+  (* is_bol() tests *)
+  test "is_bol : should return true if pos is 0" (fun () ->
+    let rope = Leaf("abc", 0, 3) in
+    assert( is_bol rope 0 );
+  );
+  test "is_bol : should return true if pos is first char of line" (fun () ->
+    let rope = Leaf("\nabc", 0, 3) in
+    assert( is_bol rope 1 );
+  );
+  test "is_bol : should return false if pos is not first char of line" (fun () ->
+    let rope = Leaf("\nabc", 0, 3) in
+    assert( (is_bol rope 2) == false );
+  );
+  test "is_bol : should return false if previous char is not \n" (fun () ->
+    let rope = Leaf("\rabc", 0, 3) in
+    assert( (is_bol rope 1) == false );
+  );
+
+  (* is_eol() tests *)
+  test "is_eol : should return true if pos is Rope.last" (fun () ->
+    let rope = Leaf("abc", 0, 3) in
+    assert( is_eol rope 2 );
+  );
+  test "is_eol : should return true if pos is last char of line with \n ending" (fun () ->
+    let rope = Leaf("abc\n", 0, 4) in
+    assert( is_eol rope 2 );
+  );
+  test "is_eol : should return true if pos is last char of line with \r\n ending" (fun () ->
+    let rope = Leaf("abc\r\n", 0, 5) in
+    assert( is_eol rope 3 );
+  );
+  test "is_eol : should return false if pos is not last char of line" (fun () ->
+    let rope = Leaf("abcd\n", 0, 5) in
+    assert( (is_eol rope 2) == false );
+  );
+
+  (* to_bol() tests *)
+  test "to_bol : should return index of first char on the line" (fun () ->
+    let rope = Leaf("\nabc\n", 0, 5) in
+    assert( (to_bol rope 2) == 1 );
+  );
+  ()
diff --git a/tests/scrollmap_tests.ml b/tests/scrollmap_tests.ml
new file mode 100644 (file)
index 0000000..343efaa
--- /dev/null
@@ -0,0 +1,2 @@
+open Test
+open Scrollmap
similarity index 100%
rename from lib/test.ml
rename to tests/test.ml
diff --git a/unittests.ml b/unittests.ml
new file mode 100644 (file)
index 0000000..7f3f2fe
--- /dev/null
@@ -0,0 +1,5 @@
+open Rope_tests
+open Scrollmap_tests
+
+let () =
+  Test.report_results ()