diff options
author | Kostis Sagonas <[email protected]> | 2014-03-03 01:40:39 +0100 |
---|---|---|
committer | Kostis Sagonas <[email protected]> | 2015-12-16 22:08:32 +0100 |
commit | 9fd2f21c38944c8a605020d6662bb5935c5bbee2 (patch) | |
tree | 8f2dd4a13315d93e54eae79b2e1645fc439c1d58 /lib/hipe/test/basic_SUITE_data/basic_guards.erl | |
parent | 82a835d94be7ee5e98d101a29999fedaf6cd75fe (diff) | |
download | otp-9fd2f21c38944c8a605020d6662bb5935c5bbee2.tar.gz otp-9fd2f21c38944c8a605020d6662bb5935c5bbee2.tar.bz2 otp-9fd2f21c38944c8a605020d6662bb5935c5bbee2.zip |
First part of the basic test suite for the HiPE compiler
Diffstat (limited to 'lib/hipe/test/basic_SUITE_data/basic_guards.erl')
-rw-r--r-- | lib/hipe/test/basic_SUITE_data/basic_guards.erl | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/hipe/test/basic_SUITE_data/basic_guards.erl b/lib/hipe/test/basic_SUITE_data/basic_guards.erl new file mode 100644 index 0000000000..50c0ddd972 --- /dev/null +++ b/lib/hipe/test/basic_SUITE_data/basic_guards.erl @@ -0,0 +1,58 @@ +%%% -*- erlang-indent-level: 2 -*- +%%%------------------------------------------------------------------- +%%% Author: Kostis Sagonas +%%% +%%% Contains tests for correct handling of guards and guard BIFs. +%%%------------------------------------------------------------------- +-module(basic_guards). + +-export([test/0]). + +test() -> + ok = guard0(4.2), + ok = guard1([foo]), + ok = test_guard2(), + ok = test_guard3(), + ok. + +%%-------------------------------------------------------------------- + +guard0(X) when X /= 0, is_float(X) -> + ok. + +guard1(X) when is_atom(X) orelse is_float(X) -> + error1; +guard1(X) when is_reference(hd(X)) -> + error2; +guard1(X) when is_integer(hd(X)) -> + error3; +guard1(X) when hd(X) == foo -> + ok. + +%%-------------------------------------------------------------------- + +test_guard2() -> + ok1 = guard2(true), + not_boolean = guard2(42), + ok2 = guard2(false), + ok. + +guard2(X) when X -> % gets transformed to: is_boolean(X), X =:= true + ok1; +guard2(X) when X =:= false -> + ok2; +guard2(_) -> + not_boolean. + +%%-------------------------------------------------------------------- + +-define(is_foo(X), (is_atom(X) or (is_tuple(X) and (element(1, X) =:= 'foo')))). + +test_guard3() -> + no = f('foo'), + yes = f({'foo', 42}), + no = f(42), + ok. + +f(X) when ?is_foo(X) -> yes; +f(_) -> no. |