aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hipe/test/basic_SUITE_data/basic_pattern_match.erl
diff options
context:
space:
mode:
authorZandra <[email protected]>2016-01-27 11:44:59 +0100
committerZandra <[email protected]>2016-01-27 11:44:59 +0100
commitf0b7d4797b13a90b4dcee40468a5675a73feb1d4 (patch)
tree44e2832bbe7e7a0c1deaa6bd8685d3d03713a2b2 /lib/hipe/test/basic_SUITE_data/basic_pattern_match.erl
parent6b6828e51300e318b8a3a572b6a5d78ca3756d79 (diff)
parent9722388b2fcec9b7f7e5680335e1bd6392ef11fc (diff)
downloadotp-f0b7d4797b13a90b4dcee40468a5675a73feb1d4.tar.gz
otp-f0b7d4797b13a90b4dcee40468a5675a73feb1d4.tar.bz2
otp-f0b7d4797b13a90b4dcee40468a5675a73feb1d4.zip
Merge branch 'maint'
Diffstat (limited to 'lib/hipe/test/basic_SUITE_data/basic_pattern_match.erl')
-rw-r--r--lib/hipe/test/basic_SUITE_data/basic_pattern_match.erl46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/hipe/test/basic_SUITE_data/basic_pattern_match.erl b/lib/hipe/test/basic_SUITE_data/basic_pattern_match.erl
new file mode 100644
index 0000000000..93240354a7
--- /dev/null
+++ b/lib/hipe/test/basic_SUITE_data/basic_pattern_match.erl
@@ -0,0 +1,46 @@
+%%% -*- erlang-indent-level: 2 -*-
+%%%-------------------------------------------------------------------
+%%% Author: Kostis Sagonas
+%%%
+%%% Contains code examples that test pattern matching against terms of
+%%% various types.
+%%%-------------------------------------------------------------------
+-module(basic_pattern_match).
+
+-export([test/0]).
+
+test() ->
+ ok = test_hello_world(),
+ ok = test_list_plus_plus_match(),
+ ok.
+
+%%--------------------------------------------------------------------
+%% Trivial test to test pattern matching compilation with atoms, the
+%% correct handling of all sorts of alphanumeric types in Erlang, and
+%% conversions between them.
+
+test_hello_world() ->
+ String = gimme(string),
+ String = atom_to_list(gimme(atom)),
+ String = binary_to_list(gimme(binary)),
+ true = (list_to_atom(String) =:= gimme(atom)),
+ true = (list_to_binary(String) =:= gimme(binary)),
+ ok.
+
+gimme(string) ->
+ "hello world";
+gimme(atom) ->
+ 'hello world';
+gimme(binary) ->
+ <<"hello world">>.
+
+%%--------------------------------------------------------------------
+%% Makes sure that pattern matching expressions involving ++ work OK.
+%% The third expression caused a problem in the Erlang shell of R11B-5.
+%% It worked OK in both interpreted and compiled code.
+
+test_list_plus_plus_match() ->
+ ok = (fun("X" ++ _) -> ok end)("X"),
+ ok = (fun([$X | _]) -> ok end)("X"),
+ ok = (fun([$X] ++ _) -> ok end)("X"),
+ ok.