summaryrefslogtreecommitdiff
path: root/lib/stdlib/test/unicode_util_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stdlib/test/unicode_util_SUITE.erl')
-rw-r--r--lib/stdlib/test/unicode_util_SUITE.erl47
1 files changed, 45 insertions, 2 deletions
diff --git a/lib/stdlib/test/unicode_util_SUITE.erl b/lib/stdlib/test/unicode_util_SUITE.erl
index e4f3e5f379..42a119fba9 100644
--- a/lib/stdlib/test/unicode_util_SUITE.erl
+++ b/lib/stdlib/test/unicode_util_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2017-2020. All Rights Reserved.
+%% Copyright Ericsson AB 2017-2023. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
nfd/1, nfc/1, nfkd/1, nfkc/1,
whitespace/1,
get/1,
+ lookup/1,
count/1]).
-export([debug/0, id/1, bin_split/1, uc_loaded_size/0,
@@ -45,6 +46,7 @@ all() ->
nfd, nfc, nfkd, nfkc,
whitespace,
get,
+ lookup,
count
].
@@ -90,7 +92,7 @@ casefold(_) ->
whitespace(_) ->
WS = unicode_util:whitespace(),
WS = lists:filter(fun unicode_util:is_whitespace/1, WS),
- %% TODO add more tests
+ false = unicode_util:is_whitespace($A),
ok.
cp(_) ->
@@ -101,6 +103,15 @@ cp(_) ->
"hejsan" = fetch(["hej"|<<"san">>], Get),
{error, <<128>>} = Get(<<128>>),
{error, [<<128>>, 0]} = Get([<<128>>, 0]),
+
+ {'EXIT', _} = catch Get([-1]),
+ {'EXIT', _} = catch Get([-1, $a]),
+ {'EXIT', _} = catch Get([foo, $a]),
+ {'EXIT', _} = catch Get([-1, $a]),
+ {'EXIT', _} = catch Get([[], -1]),
+ {'EXIT', _} = catch Get([[-1], $a]),
+ {'EXIT', _} = catch Get([[-1, $a], $a]),
+
ok.
gc(Config) ->
@@ -113,6 +124,15 @@ gc(Config) ->
{error, <<128>>} = Get(<<128>>),
{error, [<<128>>, 0]} = Get([<<128>>, 0]),
+ {'EXIT', _} = catch Get([-1]),
+ {'EXIT', _} = catch Get([-1, $a]),
+ {'EXIT', _} = catch Get([foo, $a]),
+ {'EXIT', _} = catch Get([-1, $a]),
+ {'EXIT', _} = catch Get([[], -1]),
+ {'EXIT', _} = catch Get([[-1], $a]),
+ {'EXIT', _} = catch Get([[-1, $a], $a]),
+ {'EXIT', _} = catch Get([<<$a>>, [-1, $a], $a]), %% Current impl
+
0 = fold(fun verify_gc/3, 0, DataDir ++ "/GraphemeBreakTest.txt"),
ok.
@@ -324,6 +344,29 @@ verify_nfkc(Data0, LineNo, _Acc) ->
get(_) ->
add_get_tests.
+lookup(Config) ->
+ DataDir = proplists:get_value(data_dir, Config),
+ {ok, Bin} = file:read_file(filename:join(DataDir, "unicode_table.bin")),
+ 0 = check_category(0, binary_to_term(Bin), 0),
+ ok.
+
+check_category(Id, [{Id, {_, _, _, What}}|Rest], Es) ->
+ case maps:get(category, unicode_util:lookup(Id)) of
+ What -> check_category(Id+1, Rest, Es);
+ _Err ->
+ io:format("~w Exp: ~w Got ~w~n",[Id, What, _Err]), exit(_Err),
+ check_category(Id+1, Rest, Es+1)
+ end;
+check_category(Id, [{Next,_}|_] = Rest, Es) ->
+ case maps:get(category, unicode_util:lookup(Id)) of
+ {other, not_assigned} -> check_category(max(Id+1,Next-1), Rest, Es);
+ Err -> io:format("~w Exp: {other, not_assigned} Got ~w~n",[Id,Err]),
+ check_category(max(Id+1,Next-1), Rest, Es+1)
+ end;
+check_category(_Id, [], Es) ->
+ Es.
+
+
count(Config) ->
Parent = self(),
Exec = fun() ->