diff options
Diffstat (limited to 'gen')
-rw-r--r-- | gen/src/gleam@string.erl | 8 | ||||
-rw-r--r-- | gen/test/gleam@string_test.erl | 38 |
2 files changed, 44 insertions, 2 deletions
diff --git a/gen/src/gleam@string.erl b/gen/src/gleam@string.erl index c0557fd..1b914c9 100644 --- a/gen/src/gleam@string.erl +++ b/gen/src/gleam@string.erl @@ -1,7 +1,7 @@ -module(gleam@string). -compile(no_auto_import). --export([is_empty/1, length/1, reverse/1, replace/3, lowercase/1, uppercase/1, compare/2, contains/2, split/2, append/2, concat/1, repeat/2, join/2, trim/1, trim_left/1, trim_right/1]). +-export([is_empty/1, length/1, reverse/1, replace/3, lowercase/1, uppercase/1, compare/2, contains/2, starts_with/2, ends_with/2, split/2, append/2, concat/1, repeat/2, join/2, trim/1, trim_left/1, trim_right/1]). is_empty(Str) -> Str =:= <<""/utf8>>. @@ -32,6 +32,12 @@ erl_contains(A, B) -> contains(Haystack, Needle) -> erl_contains(Haystack, Needle). +starts_with(A, B) -> + gleam_stdlib:string_starts_with(A, B). + +ends_with(A, B) -> + gleam_stdlib:string_ends_with(A, B). + split(X, Substring) -> gleam@list:map( gleam@iodata:split(gleam@iodata:new(X), Substring), diff --git a/gen/test/gleam@string_test.erl b/gen/test/gleam@string_test.erl index 07f3f9b..c6fe92f 100644 --- a/gen/test/gleam@string_test.erl +++ b/gen/test/gleam@string_test.erl @@ -1,7 +1,7 @@ -module(gleam@string_test). -compile(no_auto_import). --export([length_test/0, lowercase_test/0, uppercase_test/0, reverse_test/0, split_test/0, replace_test/0, append_test/0, compare_test/0, contains_test/0, concat_test/0, repeat_test/0, join_test/0, trim_test/0, trim_left_test/0, trim_right_test/0]). +-export([length_test/0, lowercase_test/0, uppercase_test/0, reverse_test/0, split_test/0, replace_test/0, append_test/0, compare_test/0, contains_test/0, concat_test/0, repeat_test/0, join_test/0, trim_test/0, trim_left_test/0, trim_right_test/0, starts_with_test/0, ends_with_test/0]). length_test() -> gleam@should:equal(gleam@string:length(<<"ß↑e̊"/utf8>>), 3), @@ -116,3 +116,39 @@ trim_right_test() -> gleam@string:trim_right(<<" hats \n"/utf8>>), <<" hats"/utf8>> ). + +starts_with_test() -> + gleam@should:equal( + gleam@string:starts_with(<<"theory"/utf8>>, <<""/utf8>>), + true + ), + gleam@should:equal( + gleam@string:starts_with(<<"theory"/utf8>>, <<"the"/utf8>>), + true + ), + gleam@should:equal( + gleam@string:starts_with(<<"theory"/utf8>>, <<"ory"/utf8>>), + false + ), + gleam@should:equal( + gleam@string:starts_with(<<"theory"/utf8>>, <<"theory2"/utf8>>), + false + ). + +ends_with_test() -> + gleam@should:equal( + gleam@string:ends_with(<<"theory"/utf8>>, <<""/utf8>>), + true + ), + gleam@should:equal( + gleam@string:ends_with(<<"theory"/utf8>>, <<"ory"/utf8>>), + true + ), + gleam@should:equal( + gleam@string:ends_with(<<"theory"/utf8>>, <<"the"/utf8>>), + false + ), + gleam@should:equal( + gleam@string:ends_with(<<"theory"/utf8>>, <<"theory2"/utf8>>), + false + ). |