on master help sign in
Added test file for Erlang.
commit4064b8ff145521c06989f122d9491385ad7dbb6f authorJacky Hui <halojax@hotmail.com> dateThu 8 Oct 2020, 23:09 (6 years ago) parent83ecc3d
2 files changed+144
tests/syntax-tests/highlighted/Erlang/bat_erlang.erl+72 tests/syntax-tests/source/Erlang/bat_erlang.erl+72
tests/syntax-tests/highlighted/Erlang/bat_erlang.erlnew file+72
@@ -0,0 +1,72 @@
1+-module(bat_erlang).
2+
3+-export([main/0]).
4+
5+-record(test, {
6+ name :: list(),
7+ data :: binary()
8+}).
9+
10+-define(TESTMACRO, "testmacro").
11+
12+-spec main() -> ok.
13+main() ->
14+ %% Handling Lists and Numbers
15+ List = [1, 2, 3, 4, $6, 2#00111],
16+ _Sum = lists:sum(List),
17+ _ = [(N * N) + N / N - N || N <- List, N > 2],
18+ [_Head, _SecondHead | _Tail] = List,
19+ _ = [1, atom, [list], <<"binary">>, {tuple, tuple}, #{map => key}, #test{name = "record"}],
20+
21+ %% Handling Binaries 
22+ BinHelloWorld = <<"Hello World">>,
23+ <<X || <<X:1/binary>> <= BinHelloWorld >>,
24+ <<0,0,0,0,0,0,0,151>> = <<151:64/signed-integer>>,
25+
26+ %% Handling Boolean and Atoms
27+ true = true andalso true,
28+ true = false orelse true,
29+ _ = true =:= true,
30+ _ = false =/= true,
31+ _ = 'HELLO' /= hello,
32+ _ = hello == world,
33+
34+ %% Handling Maps and Records
35+ TestMap = #{a => 1, b => 2, c => 3},
36+ #{a := _Value, c := _} = TestMap,
37+ _ = TestMap#{d => 4},
38+ Record = #test{name = ?TESTMACRO},
39+ _ = Record#test.name,
40+
41+ %% Conditionals
42+ case TestMap of
43+ #{b := B} ->
44+ B;
45+ _ ->
46+ ok
47+ end,
48+ if
49+ erlang:is_map(TestMap) ->
50+ map;
51+ true ->
52+ test_function(1)
53+ end,
54+
55+ %% Messaging
56+ Self = erlang:self(),
57+ Self ! hello_world,
58+ receive
59+ hello_world ->
60+ ok;
61+ _ ->
62+ io:format("unknown message")
63+ after 1000 ->
64+ timeout
65+ end,
66+ ok.
67+
68+test_function(N) when erlang:is_integer(N) -> integer;
69+test_function([_|_]) -> list;
70+test_function(<<_/binary>>) -> binary;
71+test_function(_) ->
72+ undefined.
tests/syntax-tests/source/Erlang/bat_erlang.erlnew file+72
@@ -0,0 +1,72 @@
1+-module(bat_erlang).
2+
3+-export([main/0]).
4+
5+-record(test, {
6+ name :: list(),
7+ data :: binary()
8+}).
9+
10+-define(TESTMACRO, "testmacro").
11+
12+-spec main() -> ok.
13+main() ->
14+ %% Handling Lists and Numbers
15+ List = [1, 2, 3, 4, $6, 2#00111],
16+ _Sum = lists:sum(List),
17+ _ = [(N * N) + N / N - N || N <- List, N > 2],
18+ [_Head, _SecondHead | _Tail] = List,
19+ _ = [1, atom, [list], <<"binary">>, {tuple, tuple}, #{map => key}, #test{name = "record"}],
20+
21+ %% Handling Binaries
22+ BinHelloWorld = <<"Hello World">>,
23+ <<X || <<X:1/binary>> <= BinHelloWorld >>,
24+ <<0,0,0,0,0,0,0,151>> = <<151:64/signed-integer>>,
25+
26+ %% Handling Boolean and Atoms
27+ true = true andalso true,
28+ true = false orelse true,
29+ _ = true =:= true,
30+ _ = false =/= true,
31+ _ = 'HELLO' /= hello,
32+ _ = hello == world,
33+
34+ %% Handling Maps and Records
35+ TestMap = #{a => 1, b => 2, c => 3},
36+ #{a := _Value, c := _} = TestMap,
37+ _ = TestMap#{d => 4},
38+ Record = #test{name = ?TESTMACRO},
39+ _ = Record#test.name,
40+
41+ %% Conditionals
42+ case TestMap of
43+ #{b := B} ->
44+ B;
45+ _ ->
46+ ok
47+ end,
48+ if
49+ erlang:is_map(TestMap) ->
50+ map;
51+ true ->
52+ test_function(1)
53+ end,
54+
55+ %% Messaging
56+ Self = erlang:self(),
57+ Self ! hello_world,
58+ receive
59+ hello_world ->
60+ ok;
61+ _ ->
62+ io:format("unknown message")
63+ after 1000 ->
64+ timeout
65+ end,
66+ ok.
67+
68+test_function(N) when erlang:is_integer(N) -> integer;
69+test_function([_|_]) -> list;
70+test_function(<<_/binary>>) -> binary;
71+test_function(_) ->
72+ undefined.