aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostis Sagonas <[email protected]>2015-11-30 01:59:00 +0100
committerKostis Sagonas <[email protected]>2015-12-16 22:08:34 +0100
commit186868ede408e714afe191c0a40123e4f8b2e847 (patch)
tree0d3f0b14a82f2e6b150e9e0d5f0ba4cbb9e773c2
parent664cfa9f9c0676bdc949b2fd8c92dabcb3f75a09 (diff)
downloadotp-186868ede408e714afe191c0a40123e4f8b2e847.tar.gz
otp-186868ede408e714afe191c0a40123e4f8b2e847.tar.bz2
otp-186868ede408e714afe191c0a40123e4f8b2e847.zip
Add tests for the is_boolean/1 guard
-rw-r--r--lib/hipe/test/basic_SUITE_data/basic_guards.erl42
1 files changed, 42 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
index 4bfe363ed3..b821a05ad5 100644
--- a/lib/hipe/test/basic_SUITE_data/basic_guards.erl
+++ b/lib/hipe/test/basic_SUITE_data/basic_guards.erl
@@ -14,6 +14,7 @@ test() ->
ok = test_guard2(),
ok = test_guard3(),
ok = test_guard4(),
+ ok = test_is_boolean(),
ok.
%%--------------------------------------------------------------------
@@ -73,3 +74,44 @@ is_ref(_Ref) -> no.
an_external_ref(Bin) ->
binary_to_term(Bin).
+
+%%--------------------------------------------------------------------
+
+test_is_boolean() ->
+ ok = is_boolean_in_if(),
+ ok = is_boolean_in_guard().
+
+is_boolean_in_if() ->
+ ok1 = tif(true),
+ ok2 = tif(false),
+ not_bool = tif(other),
+ ok.
+
+is_boolean_in_guard() ->
+ ok = tg(true),
+ ok = tg(false),
+ not_bool = tg(other),
+ ok.
+
+tif(V) ->
+ Yes = yes(), %% just to prevent the optimizer removing this
+ if
+ %% the following line generates an is_boolean instruction
+ V, Yes == yes ->
+ %% while the following one does not (?!)
+ %% Yes == yes, V ->
+ ok1;
+ not(not(not(V))) ->
+ ok2;
+ V ->
+ ok3;
+ true ->
+ not_bool
+ end.
+
+tg(V) when is_boolean(V) ->
+ ok;
+tg(_) ->
+ not_bool.
+
+yes() -> yes.