Skip to content

Commit 7443c9d

Browse files
committed
elli_bstr_tests: init
1 parent a072bab commit 7443c9d

File tree

2 files changed

+41
-49
lines changed

2 files changed

+41
-49
lines changed

src/elli_bstr.erl

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -128,52 +128,3 @@ equal_ci(<<C1, Rest1/binary>>, <<C2, Rest2/binary>>) ->
128128
false ->
129129
false
130130
end.
131-
132-
133-
-ifdef(TEST).
134-
135-
-include_lib("eunit/include/eunit.hrl").
136-
137-
case_insensitive_equal_test() ->
138-
?assertEqual(true, is_equal_ci(<<>>, <<>>)),
139-
?assertEqual(true, is_equal_ci(<<"abc">>, <<"abc">>)),
140-
?assertEqual(true, is_equal_ci(<<"123">>, <<"123">>)),
141-
142-
?assertEqual(false, is_equal_ci(<<"abcd">>, <<"abc">>)),
143-
?assertEqual(false, is_equal_ci(<<"1234">>, <<"123">>)),
144-
145-
?assertEqual(true, is_equal_ci(<<"aBc">>, <<"abc">>)),
146-
?assertEqual(true, is_equal_ci(<<"123AB">>, <<"123ab">>)),
147-
148-
?assertEqual(false, is_equal_ci(<<"1">>, <<"123ab">>)),
149-
?assertEqual(false, is_equal_ci(<<"">>, <<"123ab">>)),
150-
?assertEqual(false, is_equal_ci(<<"">>, <<" ">>)),
151-
152-
ok.
153-
154-
%% Test if to_lower works.
155-
ascii_to_lower_test() ->
156-
?assertEqual(<<>>, to_lower(<<>>)),
157-
?assertEqual(<<"abc">>, to_lower(<<"abc">>)),
158-
?assertEqual(<<"abc">>, to_lower(<<"ABC">>)),
159-
?assertEqual(<<"1234567890abcdefghijklmnopqrstuvwxyz!@#$%^&*()">>,
160-
to_lower(<<"1234567890abcdefghijklmnopqrstuvwxyz!@#$%^&*()">>)),
161-
?assertEqual(<<"1234567890abcdefghijklmnopqrstuvwxyz!@#$%^&*()">>,
162-
to_lower(<<"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()">>)),
163-
ok.
164-
165-
trim_test() ->
166-
?assertEqual(<<"check">>, trim(<<"check">>)),
167-
?assertEqual(<<"check">>, trim(<<" check">>)),
168-
?assertEqual(<<"check">>, trim(<<" check ">>)),
169-
170-
?assertEqual(<<"">>, trim(<<" ">>)),
171-
?assertEqual(<<>>, trim(<<>>)),
172-
173-
?assertEqual(<<"">>, trim(<<"\t\r\n">>)),
174-
175-
ok.
176-
177-
178-
-endif.
179-

test/elli_bstr_tests.erl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
-module(elli_bstr_tests).
2+
3+
-include_lib("eunit/include/eunit.hrl").
4+
5+
6+
case_insensitive_equal_test() ->
7+
?assert(elli_bstr:is_equal_ci(<<>>, <<>>)),
8+
?assert(elli_bstr:is_equal_ci(<<"abc">>, <<"abc">>)),
9+
?assert(elli_bstr:is_equal_ci(<<"123">>, <<"123">>)),
10+
11+
?assertNot(elli_bstr:is_equal_ci(<<"abcd">>, <<"abc">>)),
12+
?assertNot(elli_bstr:is_equal_ci(<<"1234">>, <<"123">>)),
13+
14+
?assert(elli_bstr:is_equal_ci(<<"aBc">>, <<"abc">>)),
15+
?assert(elli_bstr:is_equal_ci(<<"123AB">>, <<"123ab">>)),
16+
17+
?assertNot(elli_bstr:is_equal_ci(<<"1">>, <<"123ab">>)),
18+
?assertNot(elli_bstr:is_equal_ci(<<"">>, <<"123ab">>)),
19+
?assertNot(elli_bstr:is_equal_ci(<<"">>, <<" ">>)).
20+
21+
22+
%% Test if to_lower works.
23+
ascii_to_lower_test() ->
24+
?assertMatch(<<>>, elli_bstr:to_lower(<<>>)),
25+
?assertMatch(<<"abc">>, elli_bstr:to_lower(<<"abc">>)),
26+
?assertMatch(<<"abc">>, elli_bstr:to_lower(<<"ABC">>)),
27+
?assertMatch(<<"1234567890abcdefghijklmnopqrstuvwxyz!@#$%^&*()">>,
28+
elli_bstr:to_lower(<<"1234567890abcdefghijklmnopqrstuvwxyz!@#$%^&*()">>)),
29+
?assertMatch(<<"1234567890abcdefghijklmnopqrstuvwxyz!@#$%^&*()">>,
30+
elli_bstr:to_lower(<<"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()">>)).
31+
32+
33+
trim_test() ->
34+
?assertMatch(<<"check">>, elli_bstr:trim(<<"check">>)),
35+
?assertMatch(<<"check">>, elli_bstr:trim(<<" check">>)),
36+
?assertMatch(<<"check">>, elli_bstr:trim(<<" check ">>)),
37+
38+
?assertMatch(<<"">>, elli_bstr:trim(<<" ">>)),
39+
?assertMatch(<<>>, elli_bstr:trim(<<>>)),
40+
41+
?assertMatch(<<"">>, elli_bstr:trim(<<"\t\r\n">>)).

0 commit comments

Comments
 (0)