aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hipe/test/basic_SUITE_data/basic_bifs.erl
diff options
context:
space:
mode:
authorKostis Sagonas <[email protected]>2014-03-03 01:40:39 +0100
committerKostis Sagonas <[email protected]>2015-12-16 22:08:32 +0100
commit9fd2f21c38944c8a605020d6662bb5935c5bbee2 (patch)
tree8f2dd4a13315d93e54eae79b2e1645fc439c1d58 /lib/hipe/test/basic_SUITE_data/basic_bifs.erl
parent82a835d94be7ee5e98d101a29999fedaf6cd75fe (diff)
downloadotp-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_bifs.erl')
-rw-r--r--lib/hipe/test/basic_SUITE_data/basic_bifs.erl41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/hipe/test/basic_SUITE_data/basic_bifs.erl b/lib/hipe/test/basic_SUITE_data/basic_bifs.erl
new file mode 100644
index 0000000000..d6f21ceb52
--- /dev/null
+++ b/lib/hipe/test/basic_SUITE_data/basic_bifs.erl
@@ -0,0 +1,41 @@
+%%% -*- erlang-indent-level: 2 -*-
+%%%-------------------------------------------------------------------
+%%% Author: Kostis Sagonas
+%%%
+%%% Contains tests for handling of BIFs in guards and body calls.
+%%%-------------------------------------------------------------------
+-module(basic_bifs).
+
+-export([test/0]).
+
+test() ->
+ ok = test_element(),
+ ok = test_binary_part().
+
+%%--------------------------------------------------------------------
+
+test_element() ->
+ true = elem({a, b}),
+ false = elem({a, c}),
+ other = elem(gazonk),
+ ok.
+
+elem(T) when element(1, T) == a -> element(2, T) == b;
+elem(_) -> other.
+
+%%--------------------------------------------------------------------
+%% Checks that 2-ary and 3-ary BIFs can be compiled to native code.
+
+test_binary_part() ->
+ Bin = <<1,2,3,4,5,6,7,8,9,10>>,
+ BinPart = bp3(Bin),
+ <<7,8>> = bp2(BinPart),
+ ok.
+
+bp2(Bin) ->
+ binary_part(Bin, {1, 2}).
+
+bp3(Bin) ->
+ binary_part(Bin, byte_size(Bin), -5).
+
+%%--------------------------------------------------------------------