Commits

Paweł Wieczorek committed ba7352f

more tests for managedref

Comments (0)

Files changed (2)

unittests/Utilities/Test_ManagedRef.ml

 Testlist tests begin
 
 test create =
-        ignore (ManagedRef.create ())
+    ignore (ManagedRef.create ())
 
 test is_empty_on_empty = 
-        let mr = ManagedRef.create () in
-        assert_true (ManagedRef.is_empty mr)
+    let mr = ManagedRef.create () in
+    assert_true (ManagedRef.is_empty mr)
 
 test is_initialized_on_empty =
-        let mr = ManagedRef.create () in
-        assert_false (ManagedRef.is_initialized mr)
+    let mr = ManagedRef.create () in
+    assert_false (ManagedRef.is_initialized mr)
 
 test is_empty_on_initialized = 
-        let mr = ManagedRef.create () in
-        ManagedRef.replace mr 5;
-        assert_false (ManagedRef.is_empty mr)
+    let mr = ManagedRef.create () in
+    ManagedRef.replace mr 5;
+    assert_false (ManagedRef.is_empty mr)
 
 test is_initialized_on_initialized = 
-        let mr = ManagedRef.create () in
-        ManagedRef.replace mr "5";
-        assert_true (ManagedRef.is_initialized mr)
-
+    let mr = ManagedRef.create () in
+    ManagedRef.replace mr "5";
+    assert_true (ManagedRef.is_initialized mr)
 
 test release =
-        let mr = ManagedRef.create () in
-        ManagedRef.replace mr true;
-        let y = ManagedRef.release mr in
-        assert_true y
+    let mr = ManagedRef.create () in
+    ManagedRef.replace mr true;
+    let y = ManagedRef.release mr in
+    assert_true y
 
 test is_empty_on_released = 
-        let mr = ManagedRef.create () in
-        ManagedRef.replace mr 'a';
-        ignore (ManagedRef.release mr);
-        assert_true (ManagedRef.is_empty mr)
+    let mr = ManagedRef.create () in
+    ManagedRef.replace mr 'a';
+    ignore (ManagedRef.release mr);
+    assert_true (ManagedRef.is_empty mr)
+
+test is_initialized_on_released =
+    let mr = ManagedRef.create () in
+    ManagedRef.replace mr 'a';
+    ignore (ManagedRef.release mr);
+    assert_false (ManagedRef.is_initialized mr)
+
+test clone_empty =
+    let mr1 = ManagedRef.create () in
+    let mr2 = ManagedRef.clone mr1 in
+    assert_true (ManagedRef.is_empty mr2)
+
+test clone_initialized =
+    let mr1 = ManagedRef.create () in
+    ManagedRef.replace mr1 10;
+    let mr2 = ManagedRef.clone mr1 in
+    assert_true (ManagedRef.is_initialized mr2)
+
+test replace_cloned =
+    let mr1 = ManagedRef.create () in
+    ManagedRef.replace mr1 10;
+    let mr2 = ManagedRef.clone mr1 in
+    ManagedRef.replace mr2 20;
+    let y1 = ManagedRef.release mr1 in
+    let y2 = ManagedRef.release mr2 in
+    assert_equal 10 y1;
+    assert_equal 20 y2
 
 end
 

unittests/pa_ounit.ml

 open Camlp4.PreCast
 open Syntax
 
-
 let create_test_suite _loc identifier test_body =
     let test_func_name  = identifier in
     let test_case_name  = <:expr<$str:identifier$>> in
 
     Ast.stSem_of_list (test_definitions @ [test_list])
 
-
 EXTEND Gram
   GLOBAL: str_item;