Skip to content

Commit

Permalink
Emoji tests
Browse files Browse the repository at this point in the history
Out of range tests
Starting on accents
  • Loading branch information
jdunkerley committed Feb 21, 2022
1 parent aa26c94 commit bc7ed35
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,9 @@ range_to_char_indices text range =
valid = (Range 0 len+1).contains

case (Pair (valid start) (valid end)) of
Pair False False -> Error.throw Index_Out_Of_Bounds_Error range.start len
Pair False True -> Error.throw Index_Out_Of_Bounds_Error range.start len
Pair True False -> Error.throw Index_Out_Of_Bounds_Error range.end len
Pair False False -> Error.throw (Index_Out_Of_Bounds_Error range.start len)
Pair False True -> Error.throw (Index_Out_Of_Bounds_Error range.start len)
Pair True False -> Error.throw (Index_Out_Of_Bounds_Error range.end len)
Pair True True ->
if start>=end then (Range 0 0) else
iterator = BreakIterator.getCharacterInstance
Expand Down
45 changes: 44 additions & 1 deletion test/Tests/src/Data/Text_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,30 @@ spec =
"Hello World!".take (Range 5 12) . should_equal " World!"
"Hello World!".take (Range 12 12) . should_equal ""

Test.specify "take should report Index_Out_Of_Bounds_Error for invalid Ranges" <|
"Hello World!".take (Range 0 14) . should_fail_with Index_Out_Of_Bounds_Error
"Hello World!".take (Range 13 12) . should_fail_with Index_Out_Of_Bounds_Error
"Hello World!".take (Range -13 10) . should_fail_with Index_Out_Of_Bounds_Error
"Hello World!".take (Range 0 -20) . should_fail_with Index_Out_Of_Bounds_Error

Test.specify "take should work on grapheme clusters" <|
'Hello World!'.take First.new . should_equal "H"
'He\u{302}llo World!'.take (First 2) . should_equal 'He\u{302}'
'He\u{302}llo World!'.take (Before "e") . should_equal 'He\u{302}llo World!'

Test.specify "take should work on emojis" <|
'✨🚀🚧😍😃😎😙😉☺'.take First.new . should_equal '✨'
'✨🚀🚧😍😃😎😙😉☺'.take (First 2) . should_equal '✨🚀'
'✨🚀🚧😍😃😎😙😉☺'.take Last.new . should_equal '☺'
'✨🚀🚧😍😃😎😙😉☺'.take (Last 3) . should_equal '😙😉☺'
'✨🚀🚧😍😃😍😎😙😉☺'.take (Before '😍') . should_equal '✨🚀🚧'
'✨🚀🚧😍😃😍😎😙😉☺'.take (Before_Last '😍') . should_equal '✨🚀🚧😍😃'
'✨🚀🚧😍😃😍😎😙😉☺'.take (After '😍') . should_equal '😃😍😎😙😉☺'
'✨🚀🚧😍😃😍😎😙😉☺'.take (After_Last '😍') . should_equal '😎😙😉☺'
'✨🚀🚧😍😃😍😎😙😉☺'.take (While c->c!="😃") . should_equal '✨🚀🚧😍'
'✨🚀🚧😍😃😍😎😙😉☺'.take (Range 3 6) . should_equal '😍😃😍'
'✨🚀🚧😍😃😍😎😙😉☺'.take (Range 3 Nothing) . should_equal '😍😃😍😎😙😉☺'
'✨🚀🚧😍😃😍😎😙😉☺'.take (Range -3 Nothing) . should_equal '😙😉☺'
'✨🚀🚧😍😃😍😎😙😉☺'.take (Range -3 -1) . should_equal '😙😉'

Test.specify "drop should work as in the examples" <|
"Hello World!".drop First.new . should_equal "ello World!"
Expand All @@ -197,6 +219,27 @@ spec =
"Hello World!".drop (Range 5 12) . should_equal "Hello"
"Hello World!".drop (Range 12 12) . should_equal "Hello World!"

Test.specify "drop should report Index_Out_Of_Bounds_Error for invalid Ranges" <|
"Hello World!".drop (Range 0 14) . should_fail_with Index_Out_Of_Bounds_Error
"Hello World!".drop (Range 13 12) . should_fail_with Index_Out_Of_Bounds_Error
"Hello World!".drop (Range -13 10) . should_fail_with Index_Out_Of_Bounds_Error
"Hello World!".drop (Range 0 -20) . should_fail_with Index_Out_Of_Bounds_Error

Test.specify "drop should work on emojis" <|
'✨🚀🚧😍😃😎😙😉☺'.drop First.new . should_equal '🚀🚧😍😃😎😙😉☺'
'✨🚀🚧😍😃😎😙😉☺'.drop (First 2) . should_equal '🚧😍😃😎😙😉☺'
'✨🚀🚧😍😃😎😙😉☺'.drop Last.new . should_equal '✨🚀🚧😍😃😎😙😉'
'✨🚀🚧😍😃😎😙😉☺'.drop (Last 3) . should_equal '✨🚀🚧😍😃😎'
'✨🚀🚧😍😃😍😎😙😉☺'.drop (Before '😍') . should_equal '😍😃😍😎😙😉☺'
'✨🚀🚧😍😃😍😎😙😉☺'.drop (Before_Last '😍') . should_equal '😍😎😙😉☺'
'✨🚀🚧😍😃😍😎😙😉☺'.drop (After '😍') . should_equal '✨🚀🚧😍'
'✨🚀🚧😍😃😍😎😙😉☺'.drop (After_Last '😍') . should_equal '✨🚀🚧😍😃😍'
'✨🚀🚧😍😃😍😎😙😉☺'.drop (While c->c!="😃") . should_equal '😃😍😎😙😉☺'
'✨🚀🚧😍😃😍😎😙😉☺'.drop (Range 3 6) . should_equal '✨🚀🚧😎😙😉☺'
'✨🚀🚧😍😃😍😎😙😉☺'.drop (Range 3 Nothing) . should_equal '✨🚀🚧'
'✨🚀🚧😍😃😍😎😙😉☺'.drop (Range -3 Nothing) . should_equal '✨🚀🚧😍😃😍😎'
'✨🚀🚧😍😃😍😎😙😉☺'.drop (Range -3 -1) . should_equal '✨🚀🚧😍😃😍😎☺'

Test.specify "should correctly convert character case" <|
"FooBar Baz".to_lower_case.should_equal "foobar baz"
"FooBar Baz".to_upper_case.should_equal "FOOBAR BAZ"
Expand Down

0 comments on commit bc7ed35

Please sign in to comment.