Skip to content

Commit

Permalink
Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Feb 23, 2022
1 parent 9c2712b commit 2ecfe1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,13 @@ Text.from_codepoints codepoints = Text_Utils.from_codepoints codepoints.to_array
'ś' . starts_with 's\u{301}' (Regex_Matcher.new) == True

> Example
See if the text "Hello" starts with the prefix "hi".
See if the text "Hello!" starts with the specified prefix.

"Hello".starts_with "hi"
"Hello!".starts_with "Hello" == True
"Hello!".starts_with "hello" == False
"Hello!".starts_with "hello" (Text_Matcher Case_Insensitive.new) == True
"Hello!".starts_with "[a-z]" Regex_Matcher.new == False
"Hello!".starts_with "[A-Z]" Regex_Matcher.new == True
Text.starts_with : Text -> (Text_Matcher | Regex_Matcher) -> Boolean
Text.starts_with prefix matcher=Text_Matcher.new = case matcher of
Text_Matcher case_sensitivity -> case case_sensitivity of
Expand Down Expand Up @@ -770,8 +774,12 @@ Text.starts_with prefix matcher=Text_Matcher.new = case matcher of
underlying binary representation are considered equal.

> Example
See if the text "Hello" ends with the suffix "low".
"Hello".ends_with "low"
See if the text "Hello World" ends with the specified suffix.

"Hello World".ends_with "World" == True
"Hello World".ends_with "world" == False
"Hello World".ends_with "world" (Text_Matcher Case_Insensitive.new) == True
"Hello World".ends_with "[A-Z][a-z]{4}" Regex_Matcher.new == True
Text.ends_with : Text -> (Text_Matcher | Regex_Matcher) -> Boolean
Text.ends_with suffix matcher=Text_Matcher.new = case matcher of
Text_Matcher case_sensitivity -> case case_sensitivity of
Expand Down
13 changes: 13 additions & 0 deletions test/Tests/src/Data/Text_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,13 @@ spec =

"Hello!".starts_with "he" . should_be_false

Test.specify "starts_with should work as shown in the examples" <|
"Hello!".starts_with "Hello" . should_be_true
"Hello!".starts_with "hello" . should_be_false
"Hello!".starts_with "hello" (Text_Matcher Case_Insensitive.new) . should_be_true
"Hello!".starts_with "[a-z]" Regex_Matcher.new . should_be_false
"Hello!".starts_with "[A-Z]" Regex_Matcher.new . should_be_true

Test.specify "should allow for case-insensitive starts_with checks" <|
"Hello".starts_with "he" (Text_Matcher Case_Insensitive.new) . should_be_true

Expand Down Expand Up @@ -524,6 +531,12 @@ spec =
"" . ends_with "" . should_be_true
"foo foo foo" . ends_with "foo" . should_be_true

Test.specify "ends_with should work as shown in the examples" <|
"Hello World".ends_with "World" . should_be_true
"Hello World".ends_with "world" . should_be_false
"Hello World".ends_with "world" (Text_Matcher Case_Insensitive.new) . should_be_true
"Hello World".ends_with "[A-Z][a-z]{4}" Regex_Matcher.new . should_be_true

Test.specify "should allow for case-insensitive ends_with checks" <|
"Hello".ends_with "LO" (Text_Matcher Case_Insensitive.new) . should_be_true

Expand Down

0 comments on commit 2ecfe1a

Please sign in to comment.