From 186868ede408e714afe191c0a40123e4f8b2e847 Mon Sep 17 00:00:00 2001 From: Kostis Sagonas Date: Mon, 30 Nov 2015 01:59:00 +0100 Subject: Add tests for the is_boolean/1 guard --- lib/hipe/test/basic_SUITE_data/basic_guards.erl | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'lib/hipe/test/basic_SUITE_data/basic_guards.erl') 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. -- cgit v1.2.3