Skip to content

Commit

Permalink
Add the tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Dec 5, 2011
1 parent cb627ca commit 8583a58
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/i18n_search.erl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ match_all(Searcher, String) ->
-spec test(i18n_searcher(), i18n_string()) -> boolean().

test(Searcher, String) ->
?TRY_ATOM(?IM:search_index(Searcher, String)).
?TRY_ATOM(?IM:search_test(Searcher, String)).


-spec match(i18n_searcher(), i18n_string()) -> i18n_string() | 'false'.
Expand Down
74 changes: 74 additions & 0 deletions src/i18n_search_tests.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
% vim: set filetype=erlang shiftwidth=4 tabstop=4 expandtab tw=80:

%%% =====================================================================
%%% Copyright 2011 Uvarov Michael
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
%%% You may obtain a copy of the License at
%%%
%%% http://www.apache.org/licenses/LICENSE-2.0
%%%
%%% Unless required by applicable law or agreed to in writing, software
%%% distributed under the License is distributed on an "AS IS" BASIS,
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%%% See the License for the specific language governing permissions and
%%% limitations under the License.
%%%
%%% $Id$
%%%
%%% @copyright 2010-2011 Michael Uvarov
%%% @author Michael Uvarov <freeakk@gmail.com>
%%% =====================================================================

%%% @private
-module(i18n_search_tests).
-include_lib("i18n/include/i18n.hrl").


-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-include_lib("triq/include/triq.hrl").



index_test_() ->
C = i18n_collation:open(),
S = i18n_search:open(C, ?ISTR("test")),
F = fun i18n_search:index/2,
[?_assertEqual(F(S, ?ISTR("open test")), [{5, 4}])
,?_assertEqual(F(S, ?ISTR("test test")), [{0, 4}, {5, 4}])
].

match_test_() ->
C = i18n_collation:open(),
S = i18n_search:open(C, ?ISTR("test")),
F = fun i18n_search:match/2,
[?_assertEqual(F(S, ?ISTR("open test")), ?ISTR("test"))
].

nocase_match_test_() ->
C = i18n_collation:open([primary]),
S = i18n_search:open(C, ?ISTR("test")),
F = fun i18n_search:match/2,
[?_assertEqual(F(S, ?ISTR("open Test")), ?ISTR("Test"))
].

nocase_match_all_test_() ->
C = i18n_collation:open([primary]),
S = i18n_search:open(C, ?ISTR("test")),
F = fun i18n_search:match_all/2,
[?_assertEqual(F(S, ?ISTR("test and Test")), [?ISTR("test"), ?ISTR("Test")])
].

nocase_test_() ->
C = i18n_collation:open([primary]),
S = i18n_search:open(C, ?ISTR("test")),
F = fun i18n_search:test/2,
[?_assert(F(S, ?ISTR("Test")))
,?_assert(F(S, ?ISTR("test")))
,?_assert(F(S, ?ISTR("it is a test")))
,?_assert(not F(S, ?ISTR("it is an error")))
].

-endif.
44 changes: 44 additions & 0 deletions src/i18n_transliteration_tests.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
% vim: set filetype=erlang shiftwidth=4 tabstop=4 expandtab tw=80:

%%% =====================================================================
%%% Copyright 2011 Uvarov Michael
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
%%% You may obtain a copy of the License at
%%%
%%% http://www.apache.org/licenses/LICENSE-2.0
%%%
%%% Unless required by applicable law or agreed to in writing, software
%%% distributed under the License is distributed on an "AS IS" BASIS,
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%%% See the License for the specific language governing permissions and
%%% limitations under the License.
%%%
%%% $Id$
%%%
%%% @copyright 2010-2011 Michael Uvarov
%%% @author Michael Uvarov <freeakk@gmail.com>
%%% =====================================================================

%%% @private
-module(i18n_transliteration_tests).
-include_lib("i18n/include/i18n.hrl").


-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-include_lib("triq/include/triq.hrl").



trans_test() ->

lists:foreach(fun(Id) ->
T = i18n_transliteration:open(Id),
i18n_transliteration:do(T, ?ISTR("test")),
ok
end, i18n_transliteration:available_ids()).


-endif.
1 change: 1 addition & 0 deletions start-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ make
exec erl -pa $PWD/ebin edit $PWD/deps/*/ebin \
-boot start_sasl \
-sname i18n \
-s i18n
# -s i18n_nif init \
# -s reloader

0 comments on commit 8583a58

Please sign in to comment.