diff options
author | Björn Gustavsson <[email protected]> | 2015-02-18 12:51:57 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2015-02-18 12:51:57 +0100 |
commit | 9d8327c62a981bcc436e5f9fc5466f5539dce3dc (patch) | |
tree | 13c8fe46f845d5079d688d7dfedc57e6fb3e4feb /lib/stdlib/test | |
parent | 34d000d6cd35b3ae3a8b37b8dcf494d8ed5840c1 (diff) | |
parent | 53288b441ec721ce3bbdcc4ad65b75e11acc5e1b (diff) | |
download | otp-9d8327c62a981bcc436e5f9fc5466f5539dce3dc.tar.gz otp-9d8327c62a981bcc436e5f9fc5466f5539dce3dc.tar.bz2 otp-9d8327c62a981bcc436e5f9fc5466f5539dce3dc.zip |
Merge branch 'bjorn/stdlib/string-tokens/OTP-12422'
* bjorn/stdlib/string-tokens/OTP-12422:
Optimize string:tokens/2
Modernize and strengthen the test case for string:tokens/2
Diffstat (limited to 'lib/stdlib/test')
-rw-r--r-- | lib/stdlib/test/string_SUITE.erl | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/lib/stdlib/test/string_SUITE.erl b/lib/stdlib/test/string_SUITE.erl index fccd1bef95..a55c710d50 100644 --- a/lib/stdlib/test/string_SUITE.erl +++ b/lib/stdlib/test/string_SUITE.erl @@ -217,21 +217,39 @@ substr(Config) when is_list(Config) -> ?line {'EXIT',_} = (catch string:substr("1234", "1")), ok. -tokens(suite) -> - []; -tokens(doc) -> - []; tokens(Config) when is_list(Config) -> - ?line [] = string:tokens("",""), - ?line [] = string:tokens("abc","abc"), - ?line ["abc"] = string:tokens("abc", ""), - ?line ["1","2 34","4","5"] = string:tokens("1,2 34,4;5", ";,"), - %% invalid arg type - ?line {'EXIT',_} = (catch string:tokens('x,y', ",")), + [] = string:tokens("",""), + [] = string:tokens("abc","abc"), + ["abc"] = string:tokens("abc", ""), + ["1","2 34","45","5","6","7"] = do_tokens("1,2 34,45;5,;6;,7", ";,"), + %% invalid arg type - ?line {'EXIT',_} = (catch string:tokens("x,y", ',')), + {'EXIT',_} = (catch string:tokens('x,y', ",")), + {'EXIT',_} = (catch string:tokens("x,y", ',')), ok. +do_tokens(S0, Sep0) -> + [H|T] = Sep0, + S = [replace_sep(C, T, H) || C <- S0], + Sep = [H], + io:format("~p ~p\n", [S0,Sep0]), + io:format("~p ~p\n", [S,Sep]), + + Res = string:tokens(S0, Sep0), + Res = string:tokens(Sep0++S0, Sep0), + Res = string:tokens(S0++Sep0, Sep0), + + Res = string:tokens(S, Sep), + Res = string:tokens(Sep++S, Sep), + Res = string:tokens(S++Sep, Sep), + + Res. + +replace_sep(C, Seps, New) -> + case lists:member(C, Seps) of + true -> New; + false -> C + end. chars(suite) -> []; |