Skip to content

Commit

Permalink
Test primitives
Browse files Browse the repository at this point in the history
Uncomment lines when fixed
  • Loading branch information
chambart committed Mar 12, 2014
1 parent b572ae8 commit 908eafa
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
116 changes: 116 additions & 0 deletions test/samples/semantics.ml
@@ -0,0 +1,116 @@

let () =
assert true;
assert( not false );
assert( true && true );
assert(not ( true && false ) );
assert(not ( false && true ) );
assert(not ( false && false ) );
assert( true || true );
assert( true || false );
assert( false || true );
assert(not ( false || false ));
()

let () =
assert( 1 = 1 );
assert( not( 1 = 2 ) );
assert( 1 <> 2 );
assert( not( 1 <> 1 ) );
assert( 1 == 1 );
assert( not( 1 == 2 ) );
assert( 1 != 2 );
assert( not( 1 != 1 ) );
assert( 1 < 2 );
assert( not( 2 < 2 ) );
assert( 2 > 1 );
assert( not( 2 > 2 ) );
assert( 2 <= 2 );
assert( not( 3 <= 2 ) );
assert( 2 >= 2 );
(* assert( not( 2 >= 3 ) ); *)
()

let () =
(* assert( compare 0 0 = 0 ); *)
(* assert( compare 0 1 < 0 ); *)
(* assert( compare 1 0 > 0 ); *)
()

let () =
assert( ~- 1 = -1 );
assert( ~+ 1 = 1 );
assert( succ 1 = 2 );
assert( pred 1 = 0 );
assert( 1 + 1 = 2 );
assert( 1 - 1 = 0 );
assert( 1 * 2 = 2 );
(* assert( 1 / 1 = 1 ); *)
(* assert( 3 mod 2 = 1 ); *)
assert( abs (-1) = 1 );
(* assert( -1 land 3 = 3 ); *)
(* assert( -1 lor 3 = -1 ); *)
(* assert( -1 lxor 3 = -4 ); *)
(* assert( lnot (-1) = 0 ); *)
(* assert( 1 lsl 2 = 4 ); *)
(* assert( 1 lsr 1 = 0 ); *)
(* assert( 1 asr 1 = 0 ); *)
()

let () =
(* assert( ~- min_int = min_int ); *)
(* assert( ~- max_int = min_int + 1 ); *)
()

let () =
let f x = x + x in
assert( 1 |> f = 2 );
(* assert( 1 |> f |> f = 4 ); *)
assert( f @@ 1 = 2 );
(* assert( f @@ f @@ 1 = 4 ); *)
()

let () =
let a = "a" in
let b = "b" in
(* assert( a == a ); *)
(* assert( a != b ); *)
(* assert( "a" = "a" ); *)
(* assert( "a" <> "b" ); *)
(* assert( "a" ^ "b" = "ab" ); *)
(* assert( "a" ^ "c" <> "ab" ); *)
()

let () =
(* assert( ignore 1 = () ); *)
(* assert( string_of_bool true = "true" ); *)
()

let () =
assert( fst (1,2) = 1 );
assert( snd (1,2) = 2 );
()


let () =
let r = ref 0 in
assert( !r = 0 );
r := 1;
assert( !r = 1 );
incr r;
assert( !r = 2 );
decr r;
assert( !r = 1 );
()

let () =
let r = ref 0 in
ignore( r == r ); (* forbid promotion to variable *)
(* assert( !r = 0 ); *)
r := 1;
(* assert( !r = 1 ); *)
(* incr r; *)
(* assert( !r = 2 ); *)
(* decr r; *)
(* assert( !r = 1 ); *)
()
1 change: 1 addition & 0 deletions test/tests.ocp
Expand Up @@ -103,6 +103,7 @@ begin test "tmain"
"minicycle" ( test_args = [ "-counter" "-dtlambda" "minicycle.ml" "-dot" "minicycle" ] )
"loop_no_rec" ( test_args = [ "-counter" "-dtlambda" "loop_no_rec.ml" "-dot" "loop_no_rec" ] test_exit = 1 )
"functions" ( test_args = [ "-counter" "-dtlambda" "pervasives.ml" "-open" "Pervasives" "functions.ml" "-dot" "functions" ] )
"semantics" ( test_args = [ "-counter" "-dtlambda" "pervasives.ml" "-open" "Pervasives" "semantics.ml" "-dot" "semantics" ] )
]

end

0 comments on commit 908eafa

Please sign in to comment.