mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Progress on updating entire compiler for snake_case
This commit is contained in:
parent
db6cc5a7b1
commit
b56fbd38e1
297 changed files with 8416 additions and 8544 deletions
File diff suppressed because it is too large
Load diff
|
@ -291,10 +291,10 @@ fn eq_expr() {
|
|||
Expr : [Add Expr Expr, Mul Expr Expr, Val I64, Var I64]
|
||||
|
||||
x : Expr
|
||||
x = Val 0
|
||||
x = Val(0)
|
||||
|
||||
y : Expr
|
||||
y = Val 0
|
||||
y = Val(0)
|
||||
|
||||
x == y
|
||||
"#
|
||||
|
@ -331,10 +331,10 @@ fn eq_linked_list() {
|
|||
LinkedList a : [Nil, Cons a (LinkedList a)]
|
||||
|
||||
x : LinkedList I64
|
||||
x = Cons 1 Nil
|
||||
x = Cons(1, Nil)
|
||||
|
||||
y : LinkedList I64
|
||||
y = Cons 1 Nil
|
||||
y = Cons(1, Nil)
|
||||
|
||||
x == y
|
||||
"#
|
||||
|
@ -349,10 +349,10 @@ fn eq_linked_list() {
|
|||
LinkedList a : [Nil, Cons a (LinkedList a)]
|
||||
|
||||
x : LinkedList I64
|
||||
x = Cons 1 (Cons 2 Nil)
|
||||
x = Cons(1, Cons(2, Nil))
|
||||
|
||||
y : LinkedList I64
|
||||
y = Cons 1 (Cons 2 Nil)
|
||||
y = Cons(1, Cons(2, Nil))
|
||||
|
||||
x == y
|
||||
"#
|
||||
|
@ -371,10 +371,10 @@ fn eq_linked_list_false() {
|
|||
LinkedList a : [Nil, Cons a (LinkedList a)]
|
||||
|
||||
x : LinkedList I64
|
||||
x = Cons 1 Nil
|
||||
x = Cons(1, Nil)
|
||||
|
||||
y : LinkedList I64
|
||||
y = Cons 1 (Cons 2 Nil)
|
||||
y = Cons(1, Cons(2, Nil))
|
||||
|
||||
y == x
|
||||
"#
|
||||
|
@ -394,20 +394,20 @@ fn eq_linked_list_long() {
|
|||
|
||||
LinkedList a : [Nil, Cons a (LinkedList a)]
|
||||
|
||||
prependOnes = \n, tail ->
|
||||
prepend_ones = \n, tail ->
|
||||
if n == 0 then
|
||||
tail
|
||||
else
|
||||
prependOnes (n-1) (Cons 1 tail)
|
||||
prepend_ones (n-1) (Cons 1 tail)
|
||||
|
||||
main =
|
||||
n = 100_000 # be careful, can make a noticeble difference to test_gen total time!
|
||||
|
||||
x : LinkedList I64
|
||||
x = prependOnes n (Cons 999 Nil)
|
||||
x = prepend_ones n (Cons 999 Nil)
|
||||
|
||||
y : LinkedList I64
|
||||
y = prependOnes n (Cons 123 Nil)
|
||||
y = prepend_ones n (Cons 123 Nil)
|
||||
|
||||
y == x
|
||||
"#
|
||||
|
|
|
@ -111,7 +111,7 @@ fn dict_nonempty_remove() {
|
|||
empty
|
||||
|> Dict.remove 42
|
||||
|> Dict.len
|
||||
|> Num.toI64
|
||||
|> Num.to_i64
|
||||
"
|
||||
),
|
||||
0,
|
||||
|
@ -128,7 +128,7 @@ fn dict_nonempty_get() {
|
|||
empty : Dict.Dict I64 F64
|
||||
empty = Dict.insert (Dict.empty {}) 42 1.23
|
||||
|
||||
withDefault = \x, def ->
|
||||
with_default = \x, def ->
|
||||
when x is
|
||||
Ok v -> v
|
||||
Err _ -> def
|
||||
|
@ -136,7 +136,7 @@ fn dict_nonempty_get() {
|
|||
empty
|
||||
|> Dict.insert 42 1.23f64
|
||||
|> Dict.get 42
|
||||
|> withDefault 0
|
||||
|> with_default 0
|
||||
"
|
||||
),
|
||||
1.23,
|
||||
|
@ -146,15 +146,15 @@ fn dict_nonempty_get() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
withDefault = \x, def ->
|
||||
when x is
|
||||
with_default = \x, def ->
|
||||
when x is
|
||||
Ok v -> v
|
||||
Err _ -> def
|
||||
|
||||
Dict.empty {}
|
||||
|> Dict.insert 42 1.23f64
|
||||
|> Dict.get 43
|
||||
|> withDefault 0
|
||||
|> with_default 0
|
||||
"
|
||||
),
|
||||
0.0,
|
||||
|
@ -168,15 +168,15 @@ fn keys() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
myDict : Dict.Dict I64 I64
|
||||
myDict =
|
||||
my_dict : Dict.Dict I64 I64
|
||||
my_dict =
|
||||
Dict.empty {}
|
||||
|> Dict.insert 0 100
|
||||
|> Dict.insert 1 100
|
||||
|> Dict.insert 2 100
|
||||
|
||||
|
||||
Dict.keys myDict
|
||||
Dict.keys my_dict
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[0, 1, 2]),
|
||||
|
@ -190,15 +190,15 @@ fn values() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
myDict : Dict.Dict I64 I64
|
||||
myDict =
|
||||
my_dict : Dict.Dict I64 I64
|
||||
my_dict =
|
||||
Dict.empty {}
|
||||
|> Dict.insert 0 100
|
||||
|> Dict.insert 1 200
|
||||
|> Dict.insert 2 300
|
||||
|
||||
|
||||
Dict.values myDict
|
||||
Dict.values my_dict
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[100, 200, 300]),
|
||||
|
@ -212,12 +212,12 @@ fn from_list_with_fold_simple() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
myDict : Dict.Dict I64 I64
|
||||
myDict =
|
||||
my_dict : Dict.Dict I64 I64
|
||||
my_dict =
|
||||
[1,2,3]
|
||||
|> List.walk (Dict.empty {}) (\accum, value -> Dict.insert accum value value)
|
||||
|
||||
Dict.values myDict
|
||||
Dict.values my_dict
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[1, 2, 3]),
|
||||
|
@ -238,13 +238,13 @@ fn from_list_with_fold_reallocates() {
|
|||
else
|
||||
accum
|
||||
|
||||
myDict : Dict.Dict I64 I64
|
||||
myDict =
|
||||
my_dict : Dict.Dict I64 I64
|
||||
my_dict =
|
||||
# 25 elements (8 + 16 + 1) is guaranteed to overflow/reallocate at least twice
|
||||
range 0 25 []
|
||||
|> List.walk (Dict.empty {}) (\accum, value -> Dict.insert accum value value)
|
||||
|
||||
Dict.values myDict
|
||||
Dict.values my_dict
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
|
@ -261,12 +261,12 @@ fn small_str_keys() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
myDict : Dict.Dict Str I64
|
||||
myDict =
|
||||
my_dict : Dict.Dict Str I64
|
||||
my_dict =
|
||||
Dict.empty {}
|
||||
|> Dict.insert "a" 100
|
||||
|
||||
Dict.keys myDict
|
||||
Dict.keys my_dict
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&["a".into()]),
|
||||
|
@ -280,14 +280,14 @@ fn big_str_keys() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
myDict : Dict.Dict Str I64
|
||||
myDict =
|
||||
my_dict : Dict.Dict Str I64
|
||||
my_dict =
|
||||
Dict.empty {}
|
||||
|> Dict.insert "Leverage agile frameworks to provide a robust" 100
|
||||
|> Dict.insert "synopsis for high level overviews. Iterative approaches" 200
|
||||
|> Dict.insert "to corporate strategy foster collaborative thinking to" 300
|
||||
|
||||
Dict.keys myDict
|
||||
Dict.keys my_dict
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
|
@ -305,14 +305,14 @@ fn big_str_values() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
myDict : Dict.Dict I64 Str
|
||||
myDict =
|
||||
my_dict : Dict.Dict I64 Str
|
||||
my_dict =
|
||||
Dict.empty {}
|
||||
|> Dict.insert 100 "Leverage agile frameworks to provide a robust"
|
||||
|> Dict.insert 200 "synopsis for high level overviews. Iterative approaches"
|
||||
|> Dict.insert 300 "to corporate strategy foster collaborative thinking to"
|
||||
|
||||
Dict.values myDict
|
||||
Dict.values my_dict
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
|
@ -330,15 +330,15 @@ fn unit_values() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
myDict : Dict.Dict I64 {}
|
||||
myDict =
|
||||
my_dict : Dict.Dict I64 {}
|
||||
my_dict =
|
||||
Dict.empty {}
|
||||
|> Dict.insert 0 {}
|
||||
|> Dict.insert 1 {}
|
||||
|> Dict.insert 2 {}
|
||||
|> Dict.insert 3 {}
|
||||
|
||||
Num.toI64 (Dict.len myDict)
|
||||
Num.to_i64 (Dict.len my_dict)
|
||||
"
|
||||
),
|
||||
4,
|
||||
|
@ -352,11 +352,11 @@ fn single() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
myDict : Dict.Dict I64 {}
|
||||
myDict =
|
||||
my_dict : Dict.Dict I64 {}
|
||||
my_dict =
|
||||
Dict.single 12345 {}
|
||||
|
||||
Num.toI64 (Dict.len myDict)
|
||||
Num.to_i64 (Dict.len my_dict)
|
||||
"
|
||||
),
|
||||
1,
|
||||
|
@ -370,12 +370,12 @@ fn insert_all() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
myDict : Dict I64 {}
|
||||
myDict =
|
||||
Dict.insertAll (Dict.single 0 {}) (Dict.single 1 {})
|
||||
my_dict : Dict I64 {}
|
||||
my_dict =
|
||||
Dict.insert_all (Dict.single 0 {}) (Dict.single 1 {})
|
||||
|
||||
Dict.len myDict
|
||||
|> Num.toI64
|
||||
Dict.len my_dict
|
||||
|> Num.to_i64
|
||||
"
|
||||
),
|
||||
2,
|
||||
|
@ -389,12 +389,12 @@ fn insert_all_prefer_second() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
myDict : Dict.Dict I64 I64
|
||||
myDict =
|
||||
my_dict : Dict.Dict I64 I64
|
||||
my_dict =
|
||||
(Dict.single 0 100)
|
||||
|> Dict.insertAll (Dict.single 0 200)
|
||||
|> Dict.insert_all (Dict.single 0 200)
|
||||
|
||||
Dict.values myDict
|
||||
Dict.values my_dict
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[200]),
|
||||
|
@ -424,9 +424,9 @@ fn keep_shared() {
|
|||
|> Dict.insert 2 {}
|
||||
|> Dict.insert 4 {}
|
||||
|
||||
Dict.keepShared dict1 dict2
|
||||
Dict.keep_shared dict1 dict2
|
||||
|> Dict.len
|
||||
|> Num.toI64
|
||||
|> Num.to_i64
|
||||
"
|
||||
),
|
||||
2,
|
||||
|
@ -456,7 +456,7 @@ fn keep_shared_value_must_match() {
|
|||
|> Dict.insert 2 2
|
||||
|> Dict.insert 4 300
|
||||
|
||||
Dict.keepShared dict1 dict2
|
||||
Dict.keep_shared dict1 dict2
|
||||
|> Dict.values
|
||||
"
|
||||
),
|
||||
|
@ -487,9 +487,9 @@ fn remove_all() {
|
|||
|> Dict.insert 2 {}
|
||||
|> Dict.insert 4 {}
|
||||
|
||||
Dict.removeAll dict1 dict2
|
||||
Dict.remove_all dict1 dict2
|
||||
|> Dict.len
|
||||
|> Num.toI64
|
||||
|> Num.to_i64
|
||||
"
|
||||
),
|
||||
3,
|
||||
|
@ -519,7 +519,7 @@ fn remove_all_prefer_first() {
|
|||
|> Dict.insert 2 200
|
||||
|> Dict.insert 4 300
|
||||
|
||||
Dict.removeAll dict1 dict2
|
||||
Dict.remove_all dict1 dict2
|
||||
|> Dict.values
|
||||
"
|
||||
),
|
||||
|
|
|
@ -34,7 +34,7 @@ fn multi_branch_capturing() {
|
|||
f = \t, s ->
|
||||
if t
|
||||
then \{} -> 15u64
|
||||
else \{} -> Str.countUtf8Bytes s
|
||||
else \{} -> Str.count_utf8_bytes s
|
||||
|
||||
main = ((f Bool.true "abc") {}, (f Bool.false "abc") {})
|
||||
"#
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -55,14 +55,14 @@ fn crash_in_call() {
|
|||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
getInfallible = \result -> when result is
|
||||
get_infallible = \result -> when result is
|
||||
Ok x -> x
|
||||
_ -> crash "turns out this was fallible"
|
||||
|
||||
main =
|
||||
x : [Ok U64, Err Str]
|
||||
x = Err ""
|
||||
getInfallible x
|
||||
get_infallible x
|
||||
"#
|
||||
),
|
||||
1u64,
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -113,9 +113,9 @@ fn fn_record() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
getRec = \x -> { y: "foo", x, z: 19 }
|
||||
get_rec = \x -> { y: "foo", x, z: 19 }
|
||||
|
||||
(getRec 15).x
|
||||
(get_rec 15).x
|
||||
"#
|
||||
),
|
||||
15,
|
||||
|
@ -1005,10 +1005,10 @@ fn update_the_only_field() {
|
|||
|
||||
foo = 4
|
||||
|
||||
newModel : Model
|
||||
newModel = { model & foo }
|
||||
new_model : Model
|
||||
new_model = { model & foo }
|
||||
|
||||
newModel.foo
|
||||
new_model.foo
|
||||
"
|
||||
),
|
||||
4,
|
||||
|
@ -1095,9 +1095,9 @@ fn generalized_accessor() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
returnFoo = .foo
|
||||
return_foo = .foo
|
||||
|
||||
returnFoo { foo: "foo" }
|
||||
return_foo { foo: "foo" }
|
||||
"#
|
||||
),
|
||||
RocStr::from("foo"),
|
||||
|
@ -1113,11 +1113,11 @@ fn update_record_that_is_a_thunk() {
|
|||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
main = Num.toStr fromOriginal.birds
|
||||
main = Num.to_str from_original.birds
|
||||
|
||||
original = { birds: 5, iguanas: 7, zebras: 2, goats: 1 }
|
||||
|
||||
fromOriginal = { original & birds: 4, iguanas: 3 }
|
||||
from_original = { original & birds: 4, iguanas: 3 }
|
||||
"#
|
||||
),
|
||||
RocStr::from("4"),
|
||||
|
@ -1133,11 +1133,11 @@ fn update_record_that_is_a_thunk_single_field() {
|
|||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
main = Num.toStr fromOriginal.birds
|
||||
main = Num.to_str from_original.birds
|
||||
|
||||
original = { birds: 5 }
|
||||
|
||||
fromOriginal = { original & birds: 4 }
|
||||
from_original = { original & birds: 4 }
|
||||
"#
|
||||
),
|
||||
RocStr::from("4"),
|
||||
|
|
|
@ -39,7 +39,7 @@ fn str_dealloc() {
|
|||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
|
||||
Str.isEmpty s
|
||||
Str.is_empty s
|
||||
"#
|
||||
),
|
||||
bool,
|
||||
|
@ -55,7 +55,7 @@ fn str_to_utf8() {
|
|||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
|
||||
Str.toUtf8 s
|
||||
Str.to_utf8 s
|
||||
"#
|
||||
),
|
||||
RocStr,
|
||||
|
@ -73,8 +73,8 @@ fn str_from_utf8() {
|
|||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
|
||||
Str.toUtf8 s
|
||||
|> Str.fromUtf8
|
||||
Str.to_utf8 s
|
||||
|> Str.from_utf8
|
||||
"#
|
||||
),
|
||||
RocStr,
|
||||
|
@ -92,7 +92,7 @@ fn str_to_utf8_dealloc() {
|
|||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
|
||||
Str.toUtf8 s
|
||||
Str.to_utf8 s
|
||||
|> List.len
|
||||
"#
|
||||
),
|
||||
|
@ -185,7 +185,7 @@ fn list_str_drop_first() {
|
|||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
list = [s, s, s]
|
||||
List.dropFirst list 1
|
||||
List.drop_first list 1
|
||||
"#
|
||||
),
|
||||
RocList<RocList<RocStr>>,
|
||||
|
@ -206,7 +206,7 @@ fn list_str_take_first() {
|
|||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
list = [s, s, s]
|
||||
List.takeFirst list 1
|
||||
List.take_first list 1
|
||||
"#
|
||||
),
|
||||
RocList<RocList<RocStr>>,
|
||||
|
@ -226,7 +226,7 @@ fn list_str_split_on() {
|
|||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
list = [s, s, s]
|
||||
List.splitAt list 1
|
||||
List.split_at list 1
|
||||
"#
|
||||
),
|
||||
(RocList<RocStr>, RocList<RocStr>),
|
||||
|
@ -245,7 +245,7 @@ fn list_str_split_on_zero() {
|
|||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
list = [s, s, s]
|
||||
List.splitAt list 0
|
||||
List.split_at list 0
|
||||
"#
|
||||
),
|
||||
(RocList<RocStr>, RocList<RocStr>),
|
||||
|
@ -265,7 +265,7 @@ fn list_get() {
|
|||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
i1 = [s, s, s]
|
||||
List.get i1 1
|
||||
|> Result.withDefault ""
|
||||
|> Result.with_default ""
|
||||
"#
|
||||
),
|
||||
RocStr,
|
||||
|
@ -284,7 +284,7 @@ fn list_map() {
|
|||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
i1 = [s, s, s]
|
||||
List.map i1 Str.toUtf8
|
||||
List.map i1 Str.to_utf8
|
||||
"#
|
||||
),
|
||||
RocList<RocStr>,
|
||||
|
@ -304,7 +304,7 @@ fn list_map_dealloc() {
|
|||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
i1 = [s, s, s]
|
||||
List.map i1 Str.toUtf8
|
||||
List.map i1 Str.to_utf8
|
||||
|> List.len
|
||||
"#
|
||||
),
|
||||
|
@ -689,17 +689,17 @@ fn union_linked_list_long_dec() {
|
|||
|
||||
LinkedList a : [Nil, Cons a (LinkedList a)]
|
||||
|
||||
prependOnes = \n, tail ->
|
||||
prepend_ones = \n, tail ->
|
||||
if n == 0 then
|
||||
tail
|
||||
else
|
||||
prependOnes (n-1) (Cons 1 tail)
|
||||
prepend_ones (n-1) (Cons 1 tail)
|
||||
|
||||
main =
|
||||
n = 1_000
|
||||
|
||||
linked : LinkedList I64
|
||||
linked = prependOnes n Nil
|
||||
linked = prepend_ones n Nil
|
||||
|
||||
when linked is
|
||||
Cons x _ -> x
|
||||
|
@ -801,8 +801,8 @@ fn reset_reuse_alignment_8() {
|
|||
Val v -> v
|
||||
ZAdd l r -> eval l + eval r
|
||||
|
||||
constFolding : Expr -> Expr
|
||||
constFolding = \e ->
|
||||
const_folding : Expr -> Expr
|
||||
const_folding = \e ->
|
||||
when e is
|
||||
ZAdd e1 e2 ->
|
||||
when Pair e1 e2 is
|
||||
|
@ -817,7 +817,7 @@ fn reset_reuse_alignment_8() {
|
|||
expr = ZAdd (Val 4) (Val 5)
|
||||
|
||||
main : I64
|
||||
main = eval (constFolding expr)
|
||||
main = eval (const_folding expr)
|
||||
"#
|
||||
),
|
||||
i64,
|
||||
|
@ -837,8 +837,8 @@ fn basic_cli_parser() {
|
|||
r#"
|
||||
in =
|
||||
"d"
|
||||
|> Str.toUtf8
|
||||
|> List.keepOks \c -> Str.fromUtf8 [c]
|
||||
|> Str.to_utf8
|
||||
|> List.keep_oks \c -> Str.from_utf8 [c]
|
||||
|
||||
out =
|
||||
when in is
|
||||
|
|
|
@ -21,7 +21,7 @@ fn with_default_ok() {
|
|||
result : Result I64 {}
|
||||
result = Ok 12345
|
||||
|
||||
Result.withDefault result 0
|
||||
Result.with_default result 0
|
||||
"
|
||||
),
|
||||
12345,
|
||||
|
@ -38,7 +38,7 @@ fn with_default_err() {
|
|||
result : Result I64 {}
|
||||
result = Err {}
|
||||
|
||||
Result.withDefault result 0
|
||||
Result.with_default result 0
|
||||
"
|
||||
),
|
||||
0,
|
||||
|
@ -57,7 +57,7 @@ fn result_map() {
|
|||
|
||||
result
|
||||
|> Result.map (\x -> x + 1)
|
||||
|> Result.withDefault 0
|
||||
|> Result.with_default 0
|
||||
"
|
||||
),
|
||||
3,
|
||||
|
@ -72,7 +72,7 @@ fn result_map() {
|
|||
|
||||
result
|
||||
|> Result.map (\x -> x + 1)
|
||||
|> Result.withDefault 0
|
||||
|> Result.with_default 0
|
||||
"
|
||||
),
|
||||
0,
|
||||
|
@ -89,7 +89,7 @@ fn result_map_err() {
|
|||
result : Result {} I64
|
||||
result = Err 2
|
||||
|
||||
when Result.mapErr result (\x -> x + 1) is
|
||||
when Result.map_err result (\x -> x + 1) is
|
||||
Err n -> n
|
||||
Ok _ -> 0
|
||||
"
|
||||
|
@ -104,7 +104,7 @@ fn result_map_err() {
|
|||
result : Result {} I64
|
||||
result = Ok {}
|
||||
|
||||
when Result.mapErr result (\x -> x + 1) is
|
||||
when Result.map_err result (\x -> x + 1) is
|
||||
Err n -> n
|
||||
Ok _ -> 0
|
||||
"
|
||||
|
@ -121,7 +121,7 @@ fn err_type_var() {
|
|||
indoc!(
|
||||
r"
|
||||
Result.map (Ok 3) (\x -> x + 1)
|
||||
|> Result.withDefault -1
|
||||
|> Result.with_default -1
|
||||
"
|
||||
),
|
||||
4,
|
||||
|
@ -139,7 +139,7 @@ fn err_type_var_annotation() {
|
|||
ok = Ok 3
|
||||
|
||||
Result.map ok (\x -> x + 1)
|
||||
|> Result.withDefault -1
|
||||
|> Result.with_default -1
|
||||
"
|
||||
),
|
||||
4,
|
||||
|
@ -157,7 +157,7 @@ fn err_empty_tag_union() {
|
|||
ok = Ok 3
|
||||
|
||||
Result.map ok (\x -> x + 1)
|
||||
|> Result.withDefault -1
|
||||
|> Result.with_default -1
|
||||
"
|
||||
),
|
||||
4,
|
||||
|
@ -174,7 +174,7 @@ fn is_ok() {
|
|||
result : Result I64 {}
|
||||
result = Ok 2
|
||||
|
||||
Result.isOk result
|
||||
Result.is_ok result
|
||||
"
|
||||
),
|
||||
true,
|
||||
|
@ -187,7 +187,7 @@ fn is_ok() {
|
|||
result : Result I64 {}
|
||||
result = Err {}
|
||||
|
||||
Result.isOk result
|
||||
Result.is_ok result
|
||||
"
|
||||
),
|
||||
false,
|
||||
|
@ -204,7 +204,7 @@ fn is_err() {
|
|||
result : Result I64 {}
|
||||
result = Ok 2
|
||||
|
||||
Result.isErr result
|
||||
Result.is_err result
|
||||
"
|
||||
),
|
||||
false,
|
||||
|
@ -217,7 +217,7 @@ fn is_err() {
|
|||
result : Result I64 {}
|
||||
result = Err {}
|
||||
|
||||
Result.isErr result
|
||||
Result.is_err result
|
||||
"
|
||||
),
|
||||
true,
|
||||
|
@ -284,7 +284,7 @@ fn roc_result_err() {
|
|||
fn issue_2583_specialize_errors_behind_unified_branches() {
|
||||
assert_evals_to!(
|
||||
r#"
|
||||
if Bool.true then List.first [15] else Str.toI64 ""
|
||||
if Bool.true then List.first [15] else Str.to_i64 ""
|
||||
"#,
|
||||
RocResult::ok(15i64),
|
||||
RocResult<i64, bool>
|
||||
|
@ -331,7 +331,7 @@ fn roc_result_after_err() {
|
|||
r#"
|
||||
result : Result Str I64
|
||||
result =
|
||||
Result.onErr (Ok "already a string") \num ->
|
||||
Result.on_err (Ok "already a string") \num ->
|
||||
if num < 0 then Ok "negative!" else Err -num
|
||||
|
||||
result
|
||||
|
@ -345,7 +345,7 @@ fn roc_result_after_err() {
|
|||
r#"
|
||||
result : Result Str I64
|
||||
result =
|
||||
Result.onErr (Err 100) \num ->
|
||||
Result.on_err (Err 100) \num ->
|
||||
if num < 0 then Ok "negative!" else Err -num
|
||||
|
||||
result
|
||||
|
@ -364,7 +364,7 @@ fn roc_result_map_both() {
|
|||
result : Result I64 I64
|
||||
result = Ok 42
|
||||
|
||||
result |> Result.mapBoth Num.toStr Num.toStr
|
||||
result |> Result.map_both Num.to_str Num.to_str
|
||||
"#
|
||||
),
|
||||
RocResult::ok(RocStr::from("42")),
|
||||
|
@ -377,7 +377,7 @@ fn roc_result_map_both() {
|
|||
result : Result I64 I64
|
||||
result = Err 24
|
||||
|
||||
result |> Result.mapBoth Num.toStr Num.toStr
|
||||
result |> Result.map_both Num.to_str Num.to_str
|
||||
"#
|
||||
),
|
||||
RocResult::err(RocStr::from("24")),
|
||||
|
|
|
@ -25,13 +25,13 @@ fn early_return_nested_ifs() {
|
|||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
displayN = \n ->
|
||||
first = Num.toStr n
|
||||
display_n = \n ->
|
||||
first = Num.to_str n
|
||||
second =
|
||||
if n == 1 then
|
||||
return "early 1"
|
||||
else
|
||||
third = Num.toStr (n + 1)
|
||||
third = Num.to_str (n + 1)
|
||||
if n == 2 then
|
||||
return "early 2"
|
||||
else
|
||||
|
@ -40,7 +40,7 @@ fn early_return_nested_ifs() {
|
|||
"$(first), $(second)"
|
||||
|
||||
main : List Str
|
||||
main = List.map [1, 2, 3] displayN
|
||||
main = List.map [1, 2, 3] display_n
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
|
@ -60,15 +60,15 @@ fn early_return_nested_whens() {
|
|||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
displayN = \n ->
|
||||
first = Num.toStr n
|
||||
display_n = \n ->
|
||||
first = Num.to_str n
|
||||
second =
|
||||
when n is
|
||||
1 ->
|
||||
return "early 1"
|
||||
|
||||
_ ->
|
||||
third = Num.toStr (n + 1)
|
||||
third = Num.to_str (n + 1)
|
||||
when n is
|
||||
2 ->
|
||||
return "early 2"
|
||||
|
@ -79,7 +79,7 @@ fn early_return_nested_whens() {
|
|||
"$(first), $(second)"
|
||||
|
||||
main : List Str
|
||||
main = List.map [1, 2, 3] displayN
|
||||
main = List.map [1, 2, 3] display_n
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
|
@ -134,18 +134,18 @@ fn early_return_annotated_function() {
|
|||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
failIfLessThanFive : U64 -> Result {} [LessThanFive]
|
||||
failIfLessThanFive = \n ->
|
||||
fail_if_less_than_five : U64 -> Result {} [LessThanFive]
|
||||
fail_if_less_than_five = \n ->
|
||||
if n < 5 then
|
||||
Err LessThanFive
|
||||
else
|
||||
Ok {}
|
||||
|
||||
validateInput : Str -> Result U64 [InvalidNumStr, LessThanFive]
|
||||
validateInput = \str ->
|
||||
num = try Str.toU64 str
|
||||
validate_input : Str -> Result U64 [InvalidNumStr, LessThanFive]
|
||||
validate_input = \str ->
|
||||
num = try Str.to_u64 str
|
||||
|
||||
when failIfLessThanFive num is
|
||||
when fail_if_less_than_five num is
|
||||
Err err ->
|
||||
return Err err
|
||||
|
||||
|
@ -155,8 +155,8 @@ fn early_return_annotated_function() {
|
|||
main : List Str
|
||||
main =
|
||||
["abc", "3", "7"]
|
||||
|> List.map validateInput
|
||||
|> List.map Inspect.toStr
|
||||
|> List.map validate_input
|
||||
|> List.map Inspect.to_str
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
|
@ -176,18 +176,18 @@ fn early_return_nested_annotated_function() {
|
|||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
validateInput : Str -> Result U64 [InvalidNumStr, LessThanFive]
|
||||
validateInput = \str ->
|
||||
failIfLessThanFive : U64 -> Result {} [LessThanFive]
|
||||
failIfLessThanFive = \n ->
|
||||
validate_input : Str -> Result U64 [InvalidNumStr, LessThanFive]
|
||||
validate_input = \str ->
|
||||
fail_if_less_than_five : U64 -> Result {} [LessThanFive]
|
||||
fail_if_less_than_five = \n ->
|
||||
if n < 5 then
|
||||
Err LessThanFive
|
||||
else
|
||||
Ok {}
|
||||
|
||||
num = try Str.toU64 str
|
||||
num = try Str.to_u64 str
|
||||
|
||||
when failIfLessThanFive num is
|
||||
when fail_if_less_than_five num is
|
||||
Err err ->
|
||||
return Err err
|
||||
|
||||
|
@ -197,8 +197,8 @@ fn early_return_nested_annotated_function() {
|
|||
main : List Str
|
||||
main =
|
||||
["abc", "3", "7"]
|
||||
|> List.map validateInput
|
||||
|> List.map Inspect.toStr
|
||||
|> List.map validate_input
|
||||
|> List.map Inspect.to_str
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
|
@ -218,39 +218,39 @@ fn early_return_annotated_recursive_function() {
|
|||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
mightCallSecond : U64 -> Result U64 _
|
||||
mightCallSecond = \num ->
|
||||
nextNum =
|
||||
might_call_second : U64 -> Result U64 _
|
||||
might_call_second = \num ->
|
||||
next_num =
|
||||
if num < 5 then
|
||||
return Err LessThanFive
|
||||
else
|
||||
num - 1
|
||||
|
||||
mightCallFirst nextNum
|
||||
might_call_first next_num
|
||||
|
||||
mightCallFirst : U64 -> Result U64 _
|
||||
mightCallFirst = \num ->
|
||||
nextNum =
|
||||
might_call_first : U64 -> Result U64 _
|
||||
might_call_first = \num ->
|
||||
next_num =
|
||||
if num < 10 then
|
||||
return Err LessThanTen
|
||||
else
|
||||
num * 2
|
||||
|
||||
if nextNum > 25 then
|
||||
Ok nextNum
|
||||
if next_num > 25 then
|
||||
Ok next_num
|
||||
else
|
||||
mightCallSecond nextNum
|
||||
might_call_second next_num
|
||||
|
||||
main : List Str
|
||||
main =
|
||||
[
|
||||
mightCallSecond 3,
|
||||
mightCallSecond 7,
|
||||
mightCallSecond 20,
|
||||
mightCallFirst 7,
|
||||
mightCallFirst 15,
|
||||
might_call_second 3,
|
||||
might_call_second 7,
|
||||
might_call_second 20,
|
||||
might_call_first 7,
|
||||
might_call_first 15,
|
||||
]
|
||||
|> List.map Inspect.toStr
|
||||
|> List.map Inspect.to_str
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
|
|
|
@ -49,7 +49,7 @@ fn single_to_list() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
Set.toList (Set.single 42)
|
||||
Set.to_list (Set.single 42)
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[42]),
|
||||
|
@ -59,7 +59,7 @@ fn single_to_list() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
Set.toList (Set.single 1)
|
||||
Set.to_list (Set.single 1)
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[1]),
|
||||
|
@ -77,7 +77,7 @@ fn insert() {
|
|||
|> Set.insert 0
|
||||
|> Set.insert 1
|
||||
|> Set.insert 2
|
||||
|> Set.toList
|
||||
|> Set.to_list
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[0, 1, 2]),
|
||||
|
@ -96,7 +96,7 @@ fn remove() {
|
|||
|> Set.insert 1
|
||||
|> Set.remove 1
|
||||
|> Set.remove 2
|
||||
|> Set.toList
|
||||
|> Set.to_list
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[0]),
|
||||
|
@ -111,13 +111,13 @@ fn union() {
|
|||
indoc!(
|
||||
r"
|
||||
set1 : Set.Set I64
|
||||
set1 = Set.fromList [1,2]
|
||||
set1 = Set.from_list [1,2]
|
||||
|
||||
set2 : Set.Set I64
|
||||
set2 = Set.fromList [1,3,4]
|
||||
set2 = Set.from_list [1,3,4]
|
||||
|
||||
Set.union set1 set2
|
||||
|> Set.toList
|
||||
|> Set.to_list
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[1, 3, 4, 2]),
|
||||
|
@ -132,13 +132,13 @@ fn difference() {
|
|||
indoc!(
|
||||
r"
|
||||
set1 : Set.Set I64
|
||||
set1 = Set.fromList [1,2]
|
||||
set1 = Set.from_list [1,2]
|
||||
|
||||
set2 : Set.Set I64
|
||||
set2 = Set.fromList [1,3,4]
|
||||
set2 = Set.from_list [1,3,4]
|
||||
|
||||
Set.difference set1 set2
|
||||
|> Set.toList
|
||||
|> Set.to_list
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[2]),
|
||||
|
@ -153,13 +153,13 @@ fn intersection() {
|
|||
indoc!(
|
||||
r"
|
||||
set1 : Set.Set I64
|
||||
set1 = Set.fromList [1,2]
|
||||
set1 = Set.from_list [1,2]
|
||||
|
||||
set2 : Set.Set I64
|
||||
set2 = Set.fromList [1,3,4]
|
||||
set2 = Set.from_list [1,3,4]
|
||||
|
||||
Set.intersection set1 set2
|
||||
|> Set.toList
|
||||
|> Set.to_list
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[1]),
|
||||
|
@ -173,7 +173,7 @@ fn walk_sum() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
Set.walk (Set.fromList [1,2,3]) 0 (\x, y -> x + y)
|
||||
Set.walk (Set.from_list [1,2,3]) 0 (\x, y -> x + y)
|
||||
"
|
||||
),
|
||||
6,
|
||||
|
@ -187,7 +187,7 @@ fn contains() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
Set.contains (Set.fromList [1,3,4]) 4
|
||||
Set.contains (Set.from_list [1,3,4]) 4
|
||||
"
|
||||
),
|
||||
true,
|
||||
|
@ -197,7 +197,7 @@ fn contains() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
Set.contains (Set.fromList [1,3,4]) 2
|
||||
Set.contains (Set.from_list [1,3,4]) 2
|
||||
"
|
||||
),
|
||||
false,
|
||||
|
@ -212,8 +212,8 @@ fn from_list() {
|
|||
indoc!(
|
||||
r"
|
||||
[1,2,2,3,1,4]
|
||||
|> Set.fromList
|
||||
|> Set.toList
|
||||
|> Set.from_list
|
||||
|> Set.to_list
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[1, 2, 3, 4]),
|
||||
|
@ -227,8 +227,8 @@ fn from_list() {
|
|||
empty = []
|
||||
|
||||
empty
|
||||
|> Set.fromList
|
||||
|> Set.toList
|
||||
|> Set.from_list
|
||||
|> Set.to_list
|
||||
"
|
||||
),
|
||||
RocList::<i64>::default(),
|
||||
|
@ -244,8 +244,8 @@ fn from_list_void() {
|
|||
indoc!(
|
||||
r"
|
||||
[]
|
||||
|> Set.fromList
|
||||
|> Set.toList
|
||||
|> Set.from_list
|
||||
|> Set.to_list
|
||||
"
|
||||
),
|
||||
RocList::<i64>::default(),
|
||||
|
@ -259,7 +259,7 @@ fn to_list_empty() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
Set.toList (Set.empty {})
|
||||
Set.to_list (Set.empty {})
|
||||
"
|
||||
),
|
||||
RocList::<std::convert::Infallible>::default(),
|
||||
|
@ -277,10 +277,10 @@ fn from_list_result() {
|
|||
x = Ok "foo"
|
||||
|
||||
[x]
|
||||
|> Set.fromList
|
||||
|> Set.toList
|
||||
|> Set.from_list
|
||||
|> Set.to_list
|
||||
|> List.len
|
||||
|> Num.toI64
|
||||
|> Num.to_i64
|
||||
"#
|
||||
),
|
||||
1,
|
||||
|
@ -298,10 +298,10 @@ fn resolve_set_eq_issue_4671() {
|
|||
|
||||
main =
|
||||
s1 : Set U8
|
||||
s1 = Set.fromList [1, 2, 3]
|
||||
s1 = Set.from_list [1, 2, 3]
|
||||
|
||||
s2 : Set U8
|
||||
s2 = Set.fromList [3, 2, 1]
|
||||
s2 = Set.from_list [3, 2, 1]
|
||||
|
||||
s1 == s2
|
||||
"#
|
||||
|
|
|
@ -55,7 +55,7 @@ fn str_split_on_empty_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
List.len (Str.splitOn "hello" "")
|
||||
List.len (Str.split_on "hello" "")
|
||||
"#
|
||||
),
|
||||
1,
|
||||
|
@ -65,9 +65,9 @@ fn str_split_on_empty_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when List.first (Str.splitOn "JJJ" "") is
|
||||
when List.first (Str.split_on "JJJ" "") is
|
||||
Ok str ->
|
||||
Str.countUtf8Bytes str
|
||||
Str.count_utf8_bytes str
|
||||
|
||||
_ ->
|
||||
1729
|
||||
|
@ -85,7 +85,7 @@ fn str_split_on_bigger_delimiter_small_str() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
List.len (Str.splitOn "hello" "JJJJ there")
|
||||
List.len (Str.split_on "hello" "JJJJ there")
|
||||
"#
|
||||
),
|
||||
1,
|
||||
|
@ -95,9 +95,9 @@ fn str_split_on_bigger_delimiter_small_str() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when List.first (Str.splitOn "JJJ" "JJJJ there") is
|
||||
when List.first (Str.split_on "JJJ" "JJJJ there") is
|
||||
Ok str ->
|
||||
Str.countUtf8Bytes str
|
||||
Str.count_utf8_bytes str
|
||||
|
||||
_ ->
|
||||
1729
|
||||
|
@ -115,7 +115,7 @@ fn str_split_on_str_concat_repeated() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when List.first (Str.splitOn "JJJJJ" "JJJJ there") is
|
||||
when List.first (Str.split_on "JJJJJ" "JJJJ there") is
|
||||
Ok str ->
|
||||
str
|
||||
|> Str.concat str
|
||||
|
@ -137,7 +137,7 @@ fn str_split_on_str_concat_repeated() {
|
|||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_split_on_small_str_bigger_delimiter() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.splitOn "JJJ" "0123456789abcdefghi""#),
|
||||
indoc!(r#"Str.split_on "JJJ" "0123456789abcdefghi""#),
|
||||
RocList::from_slice(&[RocStr::from("JJJ")]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
|
@ -149,7 +149,7 @@ fn str_split_on_big_str_small_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn "01234567789abcdefghi?01234567789abcdefghi" "?"
|
||||
Str.split_on "01234567789abcdefghi?01234567789abcdefghi" "?"
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
|
@ -162,7 +162,7 @@ fn str_split_on_big_str_small_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn "01234567789abcdefghi 3ch 01234567789abcdefghi" "3ch"
|
||||
Str.split_on "01234567789abcdefghi 3ch 01234567789abcdefghi" "3ch"
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
|
@ -179,7 +179,7 @@ fn str_split_on_small_str_small_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn "J!J!J" "!"
|
||||
Str.split_on "J!J!J" "!"
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from("J"), RocStr::from("J"), RocStr::from("J")]),
|
||||
|
@ -193,7 +193,7 @@ fn str_split_on_bigger_delimiter_big_strs() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn
|
||||
Str.split_on
|
||||
"string to split is shorter"
|
||||
"than the delimiter which happens to be very very long"
|
||||
"#
|
||||
|
@ -209,7 +209,7 @@ fn str_split_on_empty_strs() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn "" ""
|
||||
Str.split_on "" ""
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from("")]),
|
||||
|
@ -223,7 +223,7 @@ fn str_split_on_minimal_example() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn "a," ","
|
||||
Str.split_on "a," ","
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from("a"), RocStr::from("")]),
|
||||
|
@ -237,7 +237,7 @@ fn str_split_on_small_str_big_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn
|
||||
Str.split_on
|
||||
"1---- ---- ---- ---- ----2---- ---- ---- ---- ----"
|
||||
"---- ---- ---- ---- ----"
|
||||
|> List.len
|
||||
|
@ -250,7 +250,7 @@ fn str_split_on_small_str_big_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn
|
||||
Str.split_on
|
||||
"1---- ---- ---- ---- ----2---- ---- ---- ---- ----"
|
||||
"---- ---- ---- ---- ----"
|
||||
"#
|
||||
|
@ -266,7 +266,7 @@ fn str_split_on_small_str_20_char_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn
|
||||
Str.split_on
|
||||
"3|-- -- -- -- -- -- |4|-- -- -- -- -- -- |"
|
||||
"|-- -- -- -- -- -- |"
|
||||
"#
|
||||
|
@ -499,14 +499,14 @@ fn str_concat_empty() {
|
|||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn small_str_is_empty() {
|
||||
assert_evals_to!(r#"Str.isEmpty "abc""#, false, bool);
|
||||
assert_evals_to!(r#"Str.is_empty "abc""#, false, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn big_str_is_empty() {
|
||||
assert_evals_to!(
|
||||
r#"Str.isEmpty "this is more than 23 chars long""#,
|
||||
r#"Str.is_empty "this is more than 23 chars long""#,
|
||||
false,
|
||||
bool
|
||||
);
|
||||
|
@ -515,32 +515,32 @@ fn big_str_is_empty() {
|
|||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn empty_str_is_empty() {
|
||||
assert_evals_to!(r#"Str.isEmpty """#, true, bool);
|
||||
assert_evals_to!(r#"Str.is_empty """#, true, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_starts_with() {
|
||||
assert_evals_to!(r#"Str.startsWith "hello world" "hell""#, true, bool);
|
||||
assert_evals_to!(r#"Str.startsWith "hello world" """#, true, bool);
|
||||
assert_evals_to!(r#"Str.startsWith "nope" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.startsWith "hell" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.startsWith "" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "hello world" "hell""#, true, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "hello world" """#, true, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "nope" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "hell" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "" "hello world""#, false, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_ends_with() {
|
||||
assert_evals_to!(r#"Str.endsWith "hello world" "world""#, true, bool);
|
||||
assert_evals_to!(r#"Str.endsWith "nope" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.endsWith "" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.ends_with "hello world" "world""#, true, bool);
|
||||
assert_evals_to!(r#"Str.ends_with "nope" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.ends_with "" "hello world""#, false, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_starts_with_same_big_str() {
|
||||
assert_evals_to!(
|
||||
r#"Str.startsWith "123456789123456789" "123456789123456789""#,
|
||||
r#"Str.starts_with "123456789123456789" "123456789123456789""#,
|
||||
true,
|
||||
bool
|
||||
);
|
||||
|
@ -550,7 +550,7 @@ fn str_starts_with_same_big_str() {
|
|||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_starts_with_different_big_str() {
|
||||
assert_evals_to!(
|
||||
r#"Str.startsWith "12345678912345678910" "123456789123456789""#,
|
||||
r#"Str.starts_with "12345678912345678910" "123456789123456789""#,
|
||||
true,
|
||||
bool
|
||||
);
|
||||
|
@ -559,18 +559,18 @@ fn str_starts_with_different_big_str() {
|
|||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_starts_with_same_small_str() {
|
||||
assert_evals_to!(r#"Str.startsWith "1234" "1234""#, true, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "1234" "1234""#, true, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_starts_with_different_small_str() {
|
||||
assert_evals_to!(r#"Str.startsWith "1234" "12""#, true, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "1234" "12""#, true, bool);
|
||||
}
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_starts_with_false_small_str() {
|
||||
assert_evals_to!(r#"Str.startsWith "1234" "23""#, false, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "1234" "23""#, false, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -579,7 +579,7 @@ fn str_from_utf8_pass_single_ascii() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97] is
|
||||
when Str.from_utf8 [97] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -595,7 +595,7 @@ fn str_from_utf8_pass_many_ascii() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 98, 99, 0x7E] is
|
||||
when Str.from_utf8 [97, 98, 99, 0x7E] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -611,7 +611,7 @@ fn str_from_utf8_pass_single_unicode() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [0xE2, 0x88, 0x86] is
|
||||
when Str.from_utf8 [0xE2, 0x88, 0x86] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -627,7 +627,7 @@ fn str_from_utf8_pass_many_unicode() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [0xE2, 0x88, 0x86, 0xC5, 0x93, 0xC2, 0xAC] is
|
||||
when Str.from_utf8 [0xE2, 0x88, 0x86, 0xC5, 0x93, 0xC2, 0xAC] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -643,7 +643,7 @@ fn str_from_utf8_pass_single_grapheme() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [0xF0, 0x9F, 0x92, 0x96] is
|
||||
when Str.from_utf8 [0xF0, 0x9F, 0x92, 0x96] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -659,7 +659,7 @@ fn str_from_utf8_pass_many_grapheme() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [0xF0, 0x9F, 0x92, 0x96, 0xF0, 0x9F, 0xA4, 0xA0, 0xF0, 0x9F, 0x9A, 0x80] is
|
||||
when Str.from_utf8 [0xF0, 0x9F, 0x92, 0x96, 0xF0, 0x9F, 0xA4, 0xA0, 0xF0, 0x9F, 0x9A, 0x80] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -675,7 +675,7 @@ fn str_from_utf8_pass_all() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [0xF0, 0x9F, 0x92, 0x96, 98, 0xE2, 0x88, 0x86] is
|
||||
when Str.from_utf8 [0xF0, 0x9F, 0x92, 0x96, 98, 0xE2, 0x88, 0x86] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -691,9 +691,9 @@ fn str_from_utf8_fail_invalid_start_byte() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 98, 0x80, 99] is
|
||||
Err (BadUtf8 InvalidStartByte byteIndex) ->
|
||||
if byteIndex == 2 then
|
||||
when Str.from_utf8 [97, 98, 0x80, 99] is
|
||||
Err (BadUtf8 InvalidStartByte byte_index) ->
|
||||
if byte_index == 2 then
|
||||
"a"
|
||||
else
|
||||
"b"
|
||||
|
@ -711,9 +711,9 @@ fn str_from_utf8_fail_unexpected_end_of_sequence() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 98, 99, 0xC2] is
|
||||
Err (BadUtf8 UnexpectedEndOfSequence byteIndex) ->
|
||||
if byteIndex == 3 then
|
||||
when Str.from_utf8 [97, 98, 99, 0xC2] is
|
||||
Err (BadUtf8 UnexpectedEndOfSequence byte_index) ->
|
||||
if byte_index == 3 then
|
||||
"a"
|
||||
else
|
||||
"b"
|
||||
|
@ -731,9 +731,9 @@ fn str_from_utf8_fail_expected_continuation() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 98, 99, 0xC2, 0x00] is
|
||||
Err (BadUtf8 ExpectedContinuation byteIndex) ->
|
||||
if byteIndex == 3 then
|
||||
when Str.from_utf8 [97, 98, 99, 0xC2, 0x00] is
|
||||
Err (BadUtf8 ExpectedContinuation byte_index) ->
|
||||
if byte_index == 3 then
|
||||
"a"
|
||||
else
|
||||
"b"
|
||||
|
@ -751,9 +751,9 @@ fn str_from_utf8_fail_overlong_encoding() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 0xF0, 0x80, 0x80, 0x80] is
|
||||
Err (BadUtf8 OverlongEncoding byteIndex) ->
|
||||
if byteIndex == 1 then
|
||||
when Str.from_utf8 [97, 0xF0, 0x80, 0x80, 0x80] is
|
||||
Err (BadUtf8 OverlongEncoding byte_index) ->
|
||||
if byte_index == 1 then
|
||||
"a"
|
||||
else
|
||||
"b"
|
||||
|
@ -771,9 +771,9 @@ fn str_from_utf8_fail_codepoint_too_large() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 0xF4, 0x90, 0x80, 0x80] is
|
||||
Err (BadUtf8 CodepointTooLarge byteIndex) ->
|
||||
if byteIndex == 1 then
|
||||
when Str.from_utf8 [97, 0xF4, 0x90, 0x80, 0x80] is
|
||||
Err (BadUtf8 CodepointTooLarge byte_index) ->
|
||||
if byte_index == 1 then
|
||||
"a"
|
||||
else
|
||||
"b"
|
||||
|
@ -791,9 +791,9 @@ fn str_from_utf8_fail_surrogate_half() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 98, 0xED, 0xA0, 0x80] is
|
||||
Err (BadUtf8 EncodesSurrogateHalf byteIndex) ->
|
||||
if byteIndex == 2 then
|
||||
when Str.from_utf8 [97, 98, 0xED, 0xA0, 0x80] is
|
||||
Err (BadUtf8 EncodesSurrogateHalf byte_index) ->
|
||||
if byte_index == 2 then
|
||||
"a"
|
||||
else
|
||||
"b"
|
||||
|
@ -841,19 +841,19 @@ fn nested_recursive_literal() {
|
|||
expr : Expr
|
||||
expr = Add (Add (Val 3) (Val 1)) (Add (Val 1) (Var 1))
|
||||
|
||||
printExpr : Expr -> Str
|
||||
printExpr = \e ->
|
||||
print_expr : Expr -> Str
|
||||
print_expr = \e ->
|
||||
when e is
|
||||
Add a b ->
|
||||
"Add ("
|
||||
|> Str.concat (printExpr a)
|
||||
|> Str.concat (print_expr a)
|
||||
|> Str.concat ") ("
|
||||
|> Str.concat (printExpr b)
|
||||
|> Str.concat (print_expr b)
|
||||
|> Str.concat ")"
|
||||
Val v -> "Val " |> Str.concat (Num.toStr v)
|
||||
Var v -> "Var " |> Str.concat (Num.toStr v)
|
||||
Val v -> "Val " |> Str.concat (Num.to_str v)
|
||||
Var v -> "Var " |> Str.concat (Num.to_str v)
|
||||
|
||||
printExpr expr
|
||||
print_expr expr
|
||||
"#
|
||||
),
|
||||
RocStr::from("Add (Add (Val 3) (Val 1)) (Add (Val 1) (Var 1))"),
|
||||
|
@ -865,7 +865,7 @@ fn nested_recursive_literal() {
|
|||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_join_comma_small() {
|
||||
assert_evals_to!(
|
||||
r#"Str.joinWith ["1", "2"] ", " "#,
|
||||
r#"Str.join_with ["1", "2"] ", " "#,
|
||||
RocStr::from("1, 2"),
|
||||
RocStr
|
||||
);
|
||||
|
@ -875,7 +875,7 @@ fn str_join_comma_small() {
|
|||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_join_comma_big() {
|
||||
assert_evals_to!(
|
||||
r#"Str.joinWith ["10000000", "2000000", "30000000"] ", " "#,
|
||||
r#"Str.join_with ["10000000", "2000000", "30000000"] ", " "#,
|
||||
RocStr::from("10000000, 2000000, 30000000"),
|
||||
RocStr
|
||||
);
|
||||
|
@ -884,19 +884,19 @@ fn str_join_comma_big() {
|
|||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_join_comma_single() {
|
||||
assert_evals_to!(r#"Str.joinWith ["1"] ", " "#, RocStr::from("1"), RocStr);
|
||||
assert_evals_to!(r#"Str.join_with ["1"] ", " "#, RocStr::from("1"), RocStr);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_to_utf8() {
|
||||
assert_evals_to!(
|
||||
r#"Str.toUtf8 "hello""#,
|
||||
r#"Str.to_utf8 "hello""#,
|
||||
RocList::from_slice(&[104, 101, 108, 108, 111]),
|
||||
RocList<u8>
|
||||
);
|
||||
assert_evals_to!(
|
||||
r#"Str.toUtf8 "this is a long string""#,
|
||||
r#"Str.to_utf8 "this is a long string""#,
|
||||
RocList::from_slice(&[
|
||||
116, 104, 105, 115, 32, 105, 115, 32, 97, 32, 108, 111, 110, 103, 32, 115, 116, 114,
|
||||
105, 110, 103
|
||||
|
@ -912,10 +912,10 @@ fn str_from_utf8() {
|
|||
indoc!(
|
||||
r#"
|
||||
bytes =
|
||||
Str.toUtf8 "hello"
|
||||
Str.to_utf8 "hello"
|
||||
|
||||
when Str.fromUtf8 bytes is
|
||||
Ok utf8String -> utf8String
|
||||
when Str.from_utf8 bytes is
|
||||
Ok utf8_string -> utf8_string
|
||||
_ -> ""
|
||||
"#
|
||||
),
|
||||
|
@ -931,11 +931,11 @@ fn str_from_utf8_slice() {
|
|||
indoc!(
|
||||
r#"
|
||||
bytes =
|
||||
Str.toUtf8 "hello"
|
||||
Str.to_utf8 "hello"
|
||||
|> List.sublist { start: 1, len: 4 }
|
||||
|
||||
when Str.fromUtf8 bytes is
|
||||
Ok utf8String -> utf8String
|
||||
when Str.from_utf8 bytes is
|
||||
Ok utf8_string -> utf8_string
|
||||
_ -> ""
|
||||
"#
|
||||
),
|
||||
|
@ -951,11 +951,11 @@ fn str_from_utf8_slice_not_end() {
|
|||
indoc!(
|
||||
r#"
|
||||
bytes =
|
||||
Str.toUtf8 "hello"
|
||||
Str.to_utf8 "hello"
|
||||
|> List.sublist { start: 1, len: 3 }
|
||||
|
||||
when Str.fromUtf8 bytes is
|
||||
Ok utf8String -> utf8String
|
||||
when Str.from_utf8 bytes is
|
||||
Ok utf8_string -> utf8_string
|
||||
_ -> ""
|
||||
"#
|
||||
),
|
||||
|
@ -971,12 +971,12 @@ fn str_from_utf8_order_does_not_matter() {
|
|||
indoc!(
|
||||
r#"
|
||||
bytes =
|
||||
Str.toUtf8 "hello"
|
||||
Str.to_utf8 "hello"
|
||||
|> List.sublist { start: 1, len: 3 }
|
||||
|
||||
when Str.fromUtf8 bytes is
|
||||
Ok utf8String -> utf8String
|
||||
Err _ -> "Str.fromUtf8 returned Err instead of Ok!"
|
||||
when Str.from_utf8 bytes is
|
||||
Ok utf8_string -> utf8_string
|
||||
Err _ -> "Str.from_utf8 returned Err instead of Ok!"
|
||||
"#
|
||||
),
|
||||
RocStr::from("ell"),
|
||||
|
@ -1139,14 +1139,14 @@ fn str_trim_small_to_small_shared() {
|
|||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_trim_start_small_blank_string() {
|
||||
assert_evals_to!(indoc!(r#"Str.trimStart " ""#), RocStr::from(""), RocStr);
|
||||
assert_evals_to!(indoc!(r#"Str.trim_start " ""#), RocStr::from(""), RocStr);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_trim_start_small_to_small() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.trimStart " hello world ""#),
|
||||
indoc!(r#"Str.trim_start " hello world ""#),
|
||||
RocStr::from("hello world "),
|
||||
RocStr
|
||||
);
|
||||
|
@ -1156,7 +1156,7 @@ fn str_trim_start_small_to_small() {
|
|||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_trim_start_large_to_large_unique() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.trimStart (Str.concat " " "hello world from a large string ")"#),
|
||||
indoc!(r#"Str.trim_start (Str.concat " " "hello world from a large string ")"#),
|
||||
RocStr::from("hello world from a large string "),
|
||||
RocStr
|
||||
);
|
||||
|
@ -1166,7 +1166,7 @@ fn str_trim_start_large_to_large_unique() {
|
|||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_trim_start_large_to_small_unique() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.trimStart (Str.concat " " "hello world ")"#),
|
||||
indoc!(r#"Str.trim_start (Str.concat " " "hello world ")"#),
|
||||
RocStr::from("hello world "),
|
||||
RocStr
|
||||
);
|
||||
|
@ -1181,7 +1181,7 @@ fn str_trim_start_large_to_large_shared() {
|
|||
original : Str
|
||||
original = " hello world world "
|
||||
|
||||
{ trimmed: Str.trimStart original, original: original }
|
||||
{ trimmed: Str.trim_start original, original: original }
|
||||
"#
|
||||
),
|
||||
(
|
||||
|
@ -1201,7 +1201,7 @@ fn str_trim_start_large_to_small_shared() {
|
|||
original : Str
|
||||
original = " hello world "
|
||||
|
||||
{ trimmed: Str.trimStart original, original: original }
|
||||
{ trimmed: Str.trim_start original, original: original }
|
||||
"#
|
||||
),
|
||||
(
|
||||
|
@ -1221,7 +1221,7 @@ fn str_trim_start_small_to_small_shared() {
|
|||
original : Str
|
||||
original = " hello world "
|
||||
|
||||
{ trimmed: Str.trimStart original, original: original }
|
||||
{ trimmed: Str.trim_start original, original: original }
|
||||
"#
|
||||
),
|
||||
(RocStr::from(" hello world "), RocStr::from("hello world "),),
|
||||
|
@ -1232,14 +1232,14 @@ fn str_trim_start_small_to_small_shared() {
|
|||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_trim_end_small_blank_string() {
|
||||
assert_evals_to!(indoc!(r#"Str.trimEnd " ""#), RocStr::from(""), RocStr);
|
||||
assert_evals_to!(indoc!(r#"Str.trim_end " ""#), RocStr::from(""), RocStr);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_trim_end_small_to_small() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.trimEnd " hello world ""#),
|
||||
indoc!(r#"Str.trim_end " hello world ""#),
|
||||
RocStr::from(" hello world"),
|
||||
RocStr
|
||||
);
|
||||
|
@ -1249,7 +1249,7 @@ fn str_trim_end_small_to_small() {
|
|||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_trim_end_large_to_large_unique() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.trimEnd (Str.concat " hello world from a large string" " ")"#),
|
||||
indoc!(r#"Str.trim_end (Str.concat " hello world from a large string" " ")"#),
|
||||
RocStr::from(" hello world from a large string"),
|
||||
RocStr
|
||||
);
|
||||
|
@ -1259,7 +1259,7 @@ fn str_trim_end_large_to_large_unique() {
|
|||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_trim_end_large_to_small_unique() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.trimEnd (Str.concat " hello world" " ")"#),
|
||||
indoc!(r#"Str.trim_end (Str.concat " hello world" " ")"#),
|
||||
RocStr::from(" hello world"),
|
||||
RocStr
|
||||
);
|
||||
|
@ -1274,7 +1274,7 @@ fn str_trim_end_large_to_large_shared() {
|
|||
original : Str
|
||||
original = " hello world world "
|
||||
|
||||
{ trimmed: Str.trimEnd original, original: original }
|
||||
{ trimmed: Str.trim_end original, original: original }
|
||||
"#
|
||||
),
|
||||
(
|
||||
|
@ -1294,7 +1294,7 @@ fn str_trim_end_large_to_small_shared() {
|
|||
original : Str
|
||||
original = " hello world "
|
||||
|
||||
{ trimmed: Str.trimEnd original, original: original }
|
||||
{ trimmed: Str.trim_end original, original: original }
|
||||
"#
|
||||
),
|
||||
(
|
||||
|
@ -1314,7 +1314,7 @@ fn str_trim_end_small_to_small_shared() {
|
|||
original : Str
|
||||
original = " hello world "
|
||||
|
||||
{ trimmed: Str.trimEnd original, original: original }
|
||||
{ trimmed: Str.trim_end original, original: original }
|
||||
"#
|
||||
),
|
||||
(RocStr::from(" hello world "), RocStr::from(" hello world"),),
|
||||
|
@ -1328,7 +1328,7 @@ fn str_to_nat() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.toU64 "1"
|
||||
Str.to_u64 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(1),
|
||||
|
@ -1342,7 +1342,7 @@ fn str_to_i128() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.toI128 "1"
|
||||
Str.to_i128 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(I128::from(1)),
|
||||
|
@ -1356,7 +1356,7 @@ fn str_to_u128() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.toU128 "1"
|
||||
Str.to_u128 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(U128::from(1)),
|
||||
|
@ -1371,7 +1371,7 @@ fn str_to_i64() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.toI64 "1"
|
||||
Str.to_i64 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(1),
|
||||
|
@ -1385,7 +1385,7 @@ fn str_to_u64() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.toU64 "1"
|
||||
Str.to_u64 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(1),
|
||||
|
@ -1399,7 +1399,7 @@ fn str_to_i32() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.toI32 "1"
|
||||
Str.to_i32 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(1),
|
||||
|
@ -1413,7 +1413,7 @@ fn str_to_u32() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.toU32 "1"
|
||||
Str.to_u32 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(1),
|
||||
|
@ -1427,7 +1427,7 @@ fn str_to_i16() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.toI16 "1"
|
||||
Str.to_i16 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(1),
|
||||
|
@ -1441,7 +1441,7 @@ fn str_to_u16() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.toU16 "1"
|
||||
Str.to_u16 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(1),
|
||||
|
@ -1455,7 +1455,7 @@ fn str_to_i8() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.toI8 "1"
|
||||
Str.to_i8 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(1),
|
||||
|
@ -1469,7 +1469,7 @@ fn str_to_u8() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.toU8 "1"
|
||||
Str.to_u8 "1"
|
||||
"#
|
||||
),
|
||||
RocResult::ok(1),
|
||||
|
@ -1483,7 +1483,7 @@ fn str_to_f64() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toF64 "1.0" is
|
||||
when Str.to_f64 "1.0" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
|
||||
|
@ -1500,7 +1500,7 @@ fn str_to_f32() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toF32 "1.0" is
|
||||
when Str.to_f32 "1.0" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
|
||||
|
@ -1519,7 +1519,7 @@ fn str_to_dec() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toDec "1.0" is
|
||||
when Str.to_dec "1.0" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
|
||||
|
@ -1552,7 +1552,7 @@ fn str_split_on_first_one_char() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitFirst "foo/bar/baz" "/"
|
||||
Str.split_first "foo/bar/baz" "/"
|
||||
"#
|
||||
),
|
||||
// the result is a { before, after } record, and because of
|
||||
|
@ -1568,7 +1568,7 @@ fn str_split_on_first_multiple_chars() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitFirst "foo//bar//baz" "//"
|
||||
Str.split_first "foo//bar//baz" "//"
|
||||
"#
|
||||
),
|
||||
RocResult::ok((RocStr::from("bar//baz"), RocStr::from("foo"))),
|
||||
|
@ -1582,7 +1582,7 @@ fn str_split_on_first_entire_input() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitFirst "foo" "foo"
|
||||
Str.split_first "foo" "foo"
|
||||
"#
|
||||
),
|
||||
RocResult::ok((RocStr::from(""), RocStr::from(""))),
|
||||
|
@ -1596,7 +1596,7 @@ fn str_split_on_first_not_found() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitFirst "foo" "bar"
|
||||
Str.split_first "foo" "bar"
|
||||
"#
|
||||
),
|
||||
RocResult::err(()),
|
||||
|
@ -1610,7 +1610,7 @@ fn str_split_on_last_one_char() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitLast"foo/bar/baz" "/"
|
||||
Str.split_last "foo/bar/baz" "/"
|
||||
"#
|
||||
),
|
||||
RocResult::ok((RocStr::from("baz"), RocStr::from("foo/bar"))),
|
||||
|
@ -1624,7 +1624,7 @@ fn str_split_on_last_multiple_chars() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitLast "foo//bar//baz" "//"
|
||||
Str.split_last "foo//bar//baz" "//"
|
||||
"#
|
||||
),
|
||||
RocResult::ok((RocStr::from("baz"), RocStr::from("foo//bar"))),
|
||||
|
@ -1638,7 +1638,7 @@ fn str_split_on_last_entire_input() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitLast "foo" "foo"
|
||||
Str.split_last "foo" "foo"
|
||||
"#
|
||||
),
|
||||
RocResult::ok((RocStr::from(""), RocStr::from(""))),
|
||||
|
@ -1652,7 +1652,7 @@ fn str_split_on_last_not_found() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitLast "foo" "bar"
|
||||
Str.split_last "foo" "bar"
|
||||
"#
|
||||
),
|
||||
RocResult::err(()),
|
||||
|
@ -1664,7 +1664,7 @@ fn str_split_on_last_not_found() {
|
|||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_split_on_overlapping_substring_1() {
|
||||
assert_evals_to!(
|
||||
r#"Str.splitOn "aaa" "aa""#,
|
||||
r#"Str.split_on "aaa" "aa""#,
|
||||
RocList::from_slice(&[RocStr::from(""), RocStr::from("a")]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
|
@ -1674,7 +1674,7 @@ fn str_split_on_overlapping_substring_1() {
|
|||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
|
||||
fn str_split_on_overlapping_substring_2() {
|
||||
assert_evals_to!(
|
||||
r#"Str.splitOn "aaaa" "aa""#,
|
||||
r#"Str.split_on "aaaa" "aa""#,
|
||||
RocList::from_slice(&[RocStr::from(""), RocStr::from(""), RocStr::from("")]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
|
@ -1688,7 +1688,7 @@ fn str_walk_utf8() {
|
|||
// Reverse the bytes
|
||||
indoc!(
|
||||
r#"
|
||||
Str.walkUtf8 "abcd" [] (\list, byte -> List.prepend list byte)
|
||||
Str.walk_utf8 "abcd" [] (\list, byte -> List.prepend list byte)
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[b'd', b'c', b'b', b'a']),
|
||||
|
@ -1699,7 +1699,7 @@ fn str_walk_utf8() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.walkUtf8 "abcd" [] (\list, byte -> List.prepend list byte)
|
||||
Str.walk_utf8 "abcd" [] (\list, byte -> List.prepend list byte)
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[b'd', b'c', b'b', b'a']),
|
||||
|
@ -1713,7 +1713,7 @@ fn str_walk_utf8_with_index() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.walkUtf8WithIndex "abcd" [] (\list, byte, index -> List.append list (Pair index byte))
|
||||
Str.walk_utf8_with_index "abcd" [] (\list, byte, index -> List.append list (Pair index byte))
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[(0, b'a'), (1, b'b'), (2, b'c'), (3, b'd')]),
|
||||
|
@ -1792,7 +1792,7 @@ fn with_capacity() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.withCapacity 10
|
||||
Str.with_capacity 10
|
||||
"#
|
||||
),
|
||||
RocStr::from(""),
|
||||
|
@ -1806,7 +1806,7 @@ fn with_capacity_concat() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.withCapacity 10 |> Str.concat "Forty-two"
|
||||
Str.with_capacity 10 |> Str.concat "Forty-two"
|
||||
"#
|
||||
),
|
||||
RocStr::from("Forty-two"),
|
||||
|
@ -1820,7 +1820,7 @@ fn str_with_prefix() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.withPrefix "world!" "Hello "
|
||||
Str.with_prefix "world!" "Hello "
|
||||
"#
|
||||
),
|
||||
RocStr::from("Hello world!"),
|
||||
|
@ -1830,7 +1830,7 @@ fn str_with_prefix() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
"two" |> Str.withPrefix "Forty "
|
||||
"two" |> Str.with_prefix "Forty "
|
||||
"#
|
||||
),
|
||||
RocStr::from("Forty two"),
|
||||
|
@ -1888,7 +1888,7 @@ fn release_excess_capacity() {
|
|||
indoc!(
|
||||
r#"
|
||||
Str.reserve "" 50
|
||||
|> Str.releaseExcessCapacity
|
||||
|> Str.release_excess_capacity
|
||||
"#
|
||||
),
|
||||
(RocStr::empty().capacity(), RocStr::empty()),
|
||||
|
@ -1905,7 +1905,7 @@ fn release_excess_capacity_with_len() {
|
|||
r#"
|
||||
"123456789012345678901234567890"
|
||||
|> Str.reserve 50
|
||||
|> Str.releaseExcessCapacity
|
||||
|> Str.release_excess_capacity
|
||||
"#
|
||||
),
|
||||
(30, "123456789012345678901234567890".into()),
|
||||
|
@ -1920,7 +1920,7 @@ fn release_excess_capacity_empty() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.releaseExcessCapacity ""
|
||||
Str.release_excess_capacity ""
|
||||
"#
|
||||
),
|
||||
(RocStr::empty().capacity(), RocStr::empty()),
|
||||
|
@ -1994,7 +1994,7 @@ fn str_contains_self() {
|
|||
fn str_drop_prefix() {
|
||||
assert_evals_to!(
|
||||
r#"
|
||||
Str.dropPrefix "" "foo"
|
||||
Str.drop_prefix "" "foo"
|
||||
"#,
|
||||
RocStr::from(""),
|
||||
RocStr
|
||||
|
@ -2002,7 +2002,7 @@ fn str_drop_prefix() {
|
|||
|
||||
assert_evals_to!(
|
||||
r#"
|
||||
Str.dropPrefix "bar" "foo"
|
||||
Str.drop_prefix "bar" "foo"
|
||||
"#,
|
||||
RocStr::from("bar"),
|
||||
RocStr
|
||||
|
@ -2010,7 +2010,7 @@ fn str_drop_prefix() {
|
|||
|
||||
assert_evals_to!(
|
||||
r#"
|
||||
Str.dropPrefix "foobar" "foo"
|
||||
Str.drop_prefix "foobar" "foo"
|
||||
"#,
|
||||
RocStr::from("bar"),
|
||||
RocStr
|
||||
|
@ -2018,7 +2018,7 @@ fn str_drop_prefix() {
|
|||
|
||||
assert_evals_to!(
|
||||
r#"
|
||||
Str.dropPrefix "fooBarThisIsDefinitelyAReallyLongAndNotaShortString" "foo"
|
||||
Str.drop_prefix "fooBarThisIsDefinitelyAReallyLongAndNotaShortString" "foo"
|
||||
"#,
|
||||
RocStr::from("BarThisIsDefinitelyAReallyLongAndNotaShortString"),
|
||||
RocStr
|
||||
|
@ -2030,7 +2030,7 @@ fn str_drop_prefix() {
|
|||
fn str_drop_suffix() {
|
||||
assert_evals_to!(
|
||||
r#"
|
||||
Str.dropSuffix "" "foo"
|
||||
Str.drop_suffix "" "foo"
|
||||
"#,
|
||||
RocStr::from(""),
|
||||
RocStr
|
||||
|
@ -2038,7 +2038,7 @@ fn str_drop_suffix() {
|
|||
|
||||
assert_evals_to!(
|
||||
r#"
|
||||
Str.dropSuffix "bar" "foo"
|
||||
Str.drop_suffix "bar" "foo"
|
||||
"#,
|
||||
RocStr::from("bar"),
|
||||
RocStr
|
||||
|
@ -2046,7 +2046,7 @@ fn str_drop_suffix() {
|
|||
|
||||
assert_evals_to!(
|
||||
r#"
|
||||
Str.dropSuffix "barfoo" "foo"
|
||||
Str.drop_suffix "barfoo" "foo"
|
||||
"#,
|
||||
RocStr::from("bar"),
|
||||
RocStr
|
||||
|
@ -2054,7 +2054,7 @@ fn str_drop_suffix() {
|
|||
|
||||
assert_evals_to!(
|
||||
r#"
|
||||
Str.dropSuffix "BarThisIsDefinitelyAReallyLongAndNotaShortStringfoo" "foo"
|
||||
Str.drop_suffix "BarThisIsDefinitelyAReallyLongAndNotaShortStringfoo" "foo"
|
||||
"#,
|
||||
RocStr::from("BarThisIsDefinitelyAReallyLongAndNotaShortString"),
|
||||
RocStr
|
||||
|
|
|
@ -349,14 +349,14 @@ fn maybe_is_just_not_nested() {
|
|||
|
||||
Maybe a : [Just a, Nothing]
|
||||
|
||||
isJust : Maybe a -> Bool
|
||||
isJust = \list ->
|
||||
is_just : Maybe a -> Bool
|
||||
is_just = \list ->
|
||||
when list is
|
||||
Nothing -> Bool.false
|
||||
Just _ -> Bool.true
|
||||
|
||||
main =
|
||||
isJust (Just 42)
|
||||
is_just (Just 42)
|
||||
"#
|
||||
),
|
||||
true,
|
||||
|
@ -372,13 +372,13 @@ fn maybe_is_just_nested() {
|
|||
r"
|
||||
Maybe a : [Just a, Nothing]
|
||||
|
||||
isJust : Maybe a -> Bool
|
||||
isJust = \list ->
|
||||
is_just : Maybe a -> Bool
|
||||
is_just = \list ->
|
||||
when list is
|
||||
Nothing -> Bool.false
|
||||
Just _ -> Bool.true
|
||||
|
||||
isJust (Just 42)
|
||||
is_just (Just 42)
|
||||
"
|
||||
),
|
||||
true,
|
||||
|
@ -415,7 +415,7 @@ fn if_guard_vanilla() {
|
|||
r#"
|
||||
when "fooz" is
|
||||
s if s == "foo" -> []
|
||||
s -> Str.toUtf8 s
|
||||
s -> Str.to_utf8 s
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(b"fooz"),
|
||||
|
@ -1078,7 +1078,7 @@ fn applied_tag_function_result() {
|
|||
x : List (Result Str *)
|
||||
x = List.map ["a", "b"] Ok
|
||||
|
||||
List.keepOks x (\y -> y)
|
||||
List.keep_oks x (\y -> y)
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[(RocStr::from("a")), (RocStr::from("b"))]),
|
||||
|
@ -1217,19 +1217,19 @@ fn monomorphized_tag_with_polymorphic_arg() {
|
|||
a = \{} -> A
|
||||
wrap = \{} -> Wrapped (a {})
|
||||
|
||||
useWrap1 : [Wrapped [A], Other] -> U8
|
||||
useWrap1 =
|
||||
use_wrap1 : [Wrapped [A], Other] -> U8
|
||||
use_wrap1 =
|
||||
\w -> when w is
|
||||
Wrapped A -> 2
|
||||
Other -> 3
|
||||
|
||||
useWrap2 : [Wrapped [A, B]] -> U8
|
||||
useWrap2 =
|
||||
use_wrap2 : [Wrapped [A, B]] -> U8
|
||||
use_wrap2 =
|
||||
\w -> when w is
|
||||
Wrapped A -> 5
|
||||
Wrapped B -> 7
|
||||
|
||||
if Bool.true then useWrap1 (wrap {}) else useWrap2 (wrap {})
|
||||
if Bool.true then use_wrap1 (wrap {}) else use_wrap2 (wrap {})
|
||||
"#
|
||||
),
|
||||
2,
|
||||
|
@ -1251,19 +1251,19 @@ fn monomorphized_tag_with_polymorphic_and_monomorphic_arg() {
|
|||
poly = \{} -> A
|
||||
wrap = \{} -> Wrapped (poly {}) mono
|
||||
|
||||
useWrap1 : [Wrapped [A] U8, Other] -> U8
|
||||
useWrap1 =
|
||||
use_wrap1 : [Wrapped [A] U8, Other] -> U8
|
||||
use_wrap1 =
|
||||
\w -> when w is
|
||||
Wrapped A n -> n
|
||||
Other -> 0
|
||||
|
||||
useWrap2 : [Wrapped [A, B] U8] -> U8
|
||||
useWrap2 =
|
||||
use_wrap2 : [Wrapped [A, B] U8] -> U8
|
||||
use_wrap2 =
|
||||
\w -> when w is
|
||||
Wrapped A n -> n
|
||||
Wrapped B _ -> 0
|
||||
|
||||
useWrap1 (wrap {}) * useWrap2 (wrap {})
|
||||
use_wrap1 (wrap {}) * use_wrap2 (wrap {})
|
||||
"#
|
||||
),
|
||||
225,
|
||||
|
@ -1443,8 +1443,8 @@ fn issue_1162() {
|
|||
balance : a, RBTree a -> RBTree a
|
||||
balance = \key, left ->
|
||||
when left is
|
||||
Node _ _ lRight ->
|
||||
Node key lRight Empty
|
||||
Node _ _ l_right ->
|
||||
Node key l_right Empty
|
||||
|
||||
_ ->
|
||||
Empty
|
||||
|
@ -1489,8 +1489,8 @@ fn issue_2725_alias_polymorphic_lambda() {
|
|||
indoc!(
|
||||
r"
|
||||
wrap = \value -> Tag value
|
||||
wrapIt = wrap
|
||||
wrapIt 42
|
||||
wrap_it = wrap
|
||||
wrap_it 42
|
||||
"
|
||||
),
|
||||
42, // Tag is a newtype, it gets unwrapped
|
||||
|
@ -1508,12 +1508,12 @@ fn opaque_assign_to_symbol() {
|
|||
|
||||
Variable := U8
|
||||
|
||||
fromUtf8 : U8 -> Result Variable [InvalidVariableUtf8]
|
||||
fromUtf8 = \char ->
|
||||
from_utf8 : U8 -> Result Variable [InvalidVariableUtf8]
|
||||
from_utf8 = \char ->
|
||||
Ok (@Variable char)
|
||||
|
||||
out =
|
||||
when fromUtf8 98 is
|
||||
when from_utf8 98 is
|
||||
Ok (@Variable n) -> n
|
||||
_ -> 1
|
||||
"#
|
||||
|
@ -1616,9 +1616,9 @@ fn issue_3261_non_nullable_unwrapped_recursive_union_at_index() {
|
|||
foo : Named
|
||||
foo = Named "outer" [Named "inner" []]
|
||||
|
||||
Named name outerList = foo
|
||||
Named name outer_list = foo
|
||||
|
||||
{name, outerList}.name
|
||||
{name, outer_list}.name
|
||||
"#
|
||||
),
|
||||
RocStr::from("outer"),
|
||||
|
@ -1888,7 +1888,7 @@ fn issue_2165_recursive_tag_destructure() {
|
|||
x = Ctor { rec: [] }
|
||||
|
||||
when x is
|
||||
Ctor { rec } -> Num.toStr (List.len rec)
|
||||
Ctor { rec } -> Num.to_str (List.len rec)
|
||||
"
|
||||
),
|
||||
RocStr::from("0"),
|
||||
|
@ -1902,13 +1902,13 @@ fn tag_union_let_generalization() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
manyAux : {} -> [ Loop, Done ]
|
||||
manyAux = \_ ->
|
||||
many_aux : {} -> [ Loop, Done ]
|
||||
many_aux = \_ ->
|
||||
output = Done
|
||||
|
||||
output
|
||||
|
||||
when manyAux {} is
|
||||
when many_aux {} is
|
||||
Loop -> "loop"
|
||||
Done -> "done"
|
||||
"#
|
||||
|
@ -1929,13 +1929,13 @@ fn fit_recursive_union_in_struct_into_recursive_pointer() {
|
|||
Next { item: Str, rest: NonEmpty },
|
||||
]
|
||||
|
||||
nonEmpty =
|
||||
non_empty =
|
||||
a = "abcdefgh"
|
||||
b = @NonEmpty (First "ijkl")
|
||||
c = Next { item: a, rest: b }
|
||||
@NonEmpty c
|
||||
|
||||
when nonEmpty is
|
||||
when non_empty is
|
||||
@NonEmpty (Next r) -> r.item
|
||||
_ -> "<bad>"
|
||||
"#
|
||||
|
@ -2026,15 +2026,15 @@ fn unify_types_with_fixed_fixpoints_outside_fixing_region() {
|
|||
job = \inputs ->
|
||||
@Job (Job inputs)
|
||||
|
||||
helloWorld : Job
|
||||
helloWorld =
|
||||
hello_world : Job
|
||||
hello_world =
|
||||
@Job ( Job [ @Input (FromJob greeting []) ] )
|
||||
|
||||
greeting : Job
|
||||
greeting =
|
||||
job []
|
||||
|
||||
main = (\_ -> "OKAY") helloWorld
|
||||
main = (\_ -> "OKAY") hello_world
|
||||
"#
|
||||
),
|
||||
RocStr::from("OKAY"),
|
||||
|
@ -2137,17 +2137,17 @@ fn nullable_wrapped_with_nullable_not_last_index() {
|
|||
OneOrMore Parser,
|
||||
]
|
||||
|
||||
toIdParser : Parser -> Str
|
||||
toIdParser = \parser ->
|
||||
to_id_parser : Parser -> Str
|
||||
to_id_parser = \parser ->
|
||||
when parser is
|
||||
OneOrMore _ -> "a"
|
||||
Keyword _ -> "b"
|
||||
CharLiteral -> "c"
|
||||
|
||||
main =
|
||||
toIdParser (OneOrMore CharLiteral)
|
||||
|> Str.concat (toIdParser (Keyword "try"))
|
||||
|> Str.concat (toIdParser CharLiteral)
|
||||
to_id_parser (OneOrMore CharLiteral)
|
||||
|> Str.concat (to_id_parser (Keyword "try"))
|
||||
|> Str.concat (to_id_parser CharLiteral)
|
||||
"#
|
||||
),
|
||||
RocStr::from("abc"),
|
||||
|
@ -2165,9 +2165,9 @@ fn refcount_nullable_unwrapped_needing_no_refcount_issue_5027() {
|
|||
|
||||
Effect : {} -> Str
|
||||
|
||||
after = \effect, buildNext ->
|
||||
after = \effect, build_next ->
|
||||
\{} ->
|
||||
when buildNext (effect {}) is
|
||||
when build_next (effect {}) is
|
||||
thunk -> thunk {}
|
||||
|
||||
line : Effect
|
||||
|
|
|
@ -93,9 +93,9 @@ fn fn_tuple() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
getRec = \x -> ("foo", x, 19)
|
||||
get_rec = \x -> ("foo", x, 19)
|
||||
|
||||
(getRec 15).1
|
||||
(get_rec 15).1
|
||||
"#
|
||||
),
|
||||
15,
|
||||
|
|
|
@ -174,7 +174,7 @@
|
|||
|
||||
const rc_encoded = rc_pointers.map((ptr) => ptr && deref(ptr));
|
||||
const rc_encoded_hex = rc_encoded.map((x) =>
|
||||
x ? x.toString(16) : "(deallocated)"
|
||||
x ? x.to_string(16) : "(deallocated)"
|
||||
);
|
||||
const rc_values = rc_encoded.map((x) => x && x - 0x80000000 + 1);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ fn str_split_on_empty_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
List.len (Str.splitOn "hello" "")
|
||||
List.len (Str.split_on "hello" "")
|
||||
"#
|
||||
),
|
||||
1,
|
||||
|
@ -32,7 +32,7 @@ fn str_split_on_bigger_delimiter_small_str() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
List.len (Str.splitOn "hello" "JJJJ there")
|
||||
List.len (Str.split_on "hello" "JJJJ there")
|
||||
"#
|
||||
),
|
||||
1,
|
||||
|
@ -45,7 +45,7 @@ fn str_split_on_str_concat_repeated() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when List.first (Str.splitOn "JJJJJ" "JJJJ there") is
|
||||
when List.first (Str.split_on "JJJJJ" "JJJJ there") is
|
||||
Ok str ->
|
||||
str
|
||||
|> Str.concat str
|
||||
|
@ -70,7 +70,7 @@ fn str_split_on_small_str_bigger_delimiter() {
|
|||
r#"
|
||||
when
|
||||
List.first
|
||||
(Str.splitOn "JJJ" "0123456789abcdefghi")
|
||||
(Str.split_on "JJJ" "0123456789abcdefghi")
|
||||
is
|
||||
Ok str -> str
|
||||
_ -> ""
|
||||
|
@ -86,7 +86,7 @@ fn str_split_on_big_str_small_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn "01234567789abcdefghi?01234567789abcdefghi" "?"
|
||||
Str.split_on "01234567789abcdefghi?01234567789abcdefghi" "?"
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
|
@ -99,7 +99,7 @@ fn str_split_on_big_str_small_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn "01234567789abcdefghi 3ch 01234567789abcdefghi" "3ch"
|
||||
Str.split_on "01234567789abcdefghi 3ch 01234567789abcdefghi" "3ch"
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
|
@ -115,7 +115,7 @@ fn str_split_on_small_str_small_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn "J!J!J" "!"
|
||||
Str.split_on "J!J!J" "!"
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from("J"), RocStr::from("J"), RocStr::from("J")]),
|
||||
|
@ -128,7 +128,7 @@ fn str_split_on_bigger_delimiter_big_strs() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn
|
||||
Str.split_on
|
||||
"string to split is shorter"
|
||||
"than the delimiter which happens to be very very long"
|
||||
"#
|
||||
|
@ -143,7 +143,7 @@ fn str_split_on_empty_strs() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn "" ""
|
||||
Str.split_on "" ""
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from("")]),
|
||||
|
@ -156,7 +156,7 @@ fn str_split_on_minimal_example() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn "a," ","
|
||||
Str.split_on "a," ","
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from("a"), RocStr::from("")]),
|
||||
|
@ -169,7 +169,7 @@ fn str_split_on_small_str_big_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn
|
||||
Str.split_on
|
||||
"1---- ---- ---- ---- ----2---- ---- ---- ---- ----"
|
||||
"---- ---- ---- ---- ----"
|
||||
|> List.len
|
||||
|
@ -182,7 +182,7 @@ fn str_split_on_small_str_big_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn
|
||||
Str.split_on
|
||||
"1---- ---- ---- ---- ----2---- ---- ---- ---- ----"
|
||||
"---- ---- ---- ---- ----"
|
||||
"#
|
||||
|
@ -197,7 +197,7 @@ fn str_split_on_small_str_20_char_delimiter() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.splitOn
|
||||
Str.split_on
|
||||
"3|-- -- -- -- -- -- |4|-- -- -- -- -- -- |"
|
||||
"|-- -- -- -- -- -- |"
|
||||
"#
|
||||
|
@ -245,26 +245,26 @@ fn small_str_zeroed_literal() {
|
|||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
createStr = \isForRealThisTime ->
|
||||
if isForRealThisTime then
|
||||
create_str = \is_for_real_this_time ->
|
||||
if is_for_real_this_time then
|
||||
"J"
|
||||
else
|
||||
"xxxxxxx"
|
||||
|
||||
functionWithReusedSpace = \isForRealThisTime ->
|
||||
function_with_reused_space = \is_for_real_this_time ->
|
||||
# Different string value on each call, at the same memory location
|
||||
# (Can't inline createStr without refcounting, which isn't implemented)
|
||||
reusedSpace = createStr isForRealThisTime
|
||||
# (Can't inline create_str without refcounting, which isn't implemented)
|
||||
reused_space = create_str is_for_real_this_time
|
||||
|
||||
# Unoptimised 'if' ensures that we don't just allocate in the caller's frame
|
||||
if Bool.true then
|
||||
reusedSpace
|
||||
reused_space
|
||||
else
|
||||
reusedSpace
|
||||
reused_space
|
||||
|
||||
main =
|
||||
garbage = functionWithReusedSpace Bool.false
|
||||
functionWithReusedSpace Bool.true
|
||||
garbage = function_with_reused_space Bool.false
|
||||
function_with_reused_space Bool.true
|
||||
"#
|
||||
),
|
||||
[
|
||||
|
@ -346,13 +346,13 @@ fn str_concat_empty() {
|
|||
|
||||
#[test]
|
||||
fn small_str_is_empty() {
|
||||
assert_evals_to!(r#"Str.isEmpty "abc""#, false, bool);
|
||||
assert_evals_to!(r#"Str.is_empty "abc""#, false, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn big_str_is_empty() {
|
||||
assert_evals_to!(
|
||||
r#"Str.isEmpty "this is more than 15 chars long""#,
|
||||
r#"Str.is_empty "this is more than 15 chars long""#,
|
||||
false,
|
||||
bool
|
||||
);
|
||||
|
@ -360,29 +360,29 @@ fn big_str_is_empty() {
|
|||
|
||||
#[test]
|
||||
fn empty_str_is_empty() {
|
||||
assert_evals_to!(r#"Str.isEmpty """#, true, bool);
|
||||
assert_evals_to!(r#"Str.is_empty """#, true, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn str_starts_with() {
|
||||
assert_evals_to!(r#"Str.startsWith "hello world" "hell""#, true, bool);
|
||||
assert_evals_to!(r#"Str.startsWith "hello world" """#, true, bool);
|
||||
assert_evals_to!(r#"Str.startsWith "nope" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.startsWith "hell" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.startsWith "" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "hello world" "hell""#, true, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "hello world" """#, true, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "nope" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "hell" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "" "hello world""#, false, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn str_ends_with() {
|
||||
assert_evals_to!(r#"Str.endsWith "hello world" "world""#, true, bool);
|
||||
assert_evals_to!(r#"Str.endsWith "nope" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.endsWith "" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.ends_with "hello world" "world""#, true, bool);
|
||||
assert_evals_to!(r#"Str.ends_with "nope" "hello world""#, false, bool);
|
||||
assert_evals_to!(r#"Str.ends_with "" "hello world""#, false, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn str_starts_with_same_big_str() {
|
||||
assert_evals_to!(
|
||||
r#"Str.startsWith "123456789123456789" "123456789123456789""#,
|
||||
r#"Str.starts_with "123456789123456789" "123456789123456789""#,
|
||||
true,
|
||||
bool
|
||||
);
|
||||
|
@ -391,7 +391,7 @@ fn str_starts_with_same_big_str() {
|
|||
#[test]
|
||||
fn str_starts_with_different_big_str() {
|
||||
assert_evals_to!(
|
||||
r#"Str.startsWith "12345678912345678910" "123456789123456789""#,
|
||||
r#"Str.starts_with "12345678912345678910" "123456789123456789""#,
|
||||
true,
|
||||
bool
|
||||
);
|
||||
|
@ -399,16 +399,16 @@ fn str_starts_with_different_big_str() {
|
|||
|
||||
#[test]
|
||||
fn str_starts_with_same_small_str() {
|
||||
assert_evals_to!(r#"Str.startsWith "1234" "1234""#, true, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "1234" "1234""#, true, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn str_starts_with_different_small_str() {
|
||||
assert_evals_to!(r#"Str.startsWith "1234" "12""#, true, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "1234" "12""#, true, bool);
|
||||
}
|
||||
#[test]
|
||||
fn str_starts_with_false_small_str() {
|
||||
assert_evals_to!(r#"Str.startsWith "1234" "23""#, false, bool);
|
||||
assert_evals_to!(r#"Str.starts_with "1234" "23""#, false, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -416,7 +416,7 @@ fn str_from_utf8_pass_single_ascii() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97] is
|
||||
when Str.from_utf8 [97] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -431,7 +431,7 @@ fn str_from_utf8_pass_many_ascii() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 98, 99, 0x7E] is
|
||||
when Str.from_utf8 [97, 98, 99, 0x7E] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -446,7 +446,7 @@ fn str_from_utf8_pass_single_unicode() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [0xE2, 0x88, 0x86] is
|
||||
when Str.from_utf8 [0xE2, 0x88, 0x86] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -461,7 +461,7 @@ fn str_from_utf8_pass_many_unicode() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [0xE2, 0x88, 0x86, 0xC5, 0x93, 0xC2, 0xAC] is
|
||||
when Str.from_utf8 [0xE2, 0x88, 0x86, 0xC5, 0x93, 0xC2, 0xAC] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -476,7 +476,7 @@ fn str_from_utf8_pass_single_grapheme() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [0xF0, 0x9F, 0x92, 0x96] is
|
||||
when Str.from_utf8 [0xF0, 0x9F, 0x92, 0x96] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -491,7 +491,7 @@ fn str_from_utf8_pass_many_grapheme() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [0xF0, 0x9F, 0x92, 0x96, 0xF0, 0x9F, 0xA4, 0xA0, 0xF0, 0x9F, 0x9A, 0x80] is
|
||||
when Str.from_utf8 [0xF0, 0x9F, 0x92, 0x96, 0xF0, 0x9F, 0xA4, 0xA0, 0xF0, 0x9F, 0x9A, 0x80] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -506,7 +506,7 @@ fn str_from_utf8_pass_all() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [0xF0, 0x9F, 0x92, 0x96, 98, 0xE2, 0x88, 0x86] is
|
||||
when Str.from_utf8 [0xF0, 0x9F, 0x92, 0x96, 98, 0xE2, 0x88, 0x86] is
|
||||
Ok val -> val
|
||||
Err _ -> ""
|
||||
"#
|
||||
|
@ -521,9 +521,9 @@ fn str_from_utf8_fail_invalid_start_byte() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 98, 0x80, 99] is
|
||||
Err (BadUtf8 InvalidStartByte byteIndex) ->
|
||||
if byteIndex == 2 then
|
||||
when Str.from_utf8 [97, 98, 0x80, 99] is
|
||||
Err (BadUtf8 InvalidStartByte byte_index) ->
|
||||
if byte_index == 2 then
|
||||
"a"
|
||||
else
|
||||
"b"
|
||||
|
@ -540,9 +540,9 @@ fn str_from_utf8_fail_unexpected_end_of_sequence() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 98, 99, 0xC2] is
|
||||
Err (BadUtf8 UnexpectedEndOfSequence byteIndex) ->
|
||||
if byteIndex == 3 then
|
||||
when Str.from_utf8 [97, 98, 99, 0xC2] is
|
||||
Err (BadUtf8 UnexpectedEndOfSequence byte_index) ->
|
||||
if byte_index == 3 then
|
||||
"a"
|
||||
else
|
||||
"b"
|
||||
|
@ -559,9 +559,9 @@ fn str_from_utf8_fail_expected_continuation() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 98, 99, 0xC2, 0x00] is
|
||||
Err (BadUtf8 ExpectedContinuation byteIndex) ->
|
||||
if byteIndex == 3 then
|
||||
when Str.from_utf8 [97, 98, 99, 0xC2, 0x00] is
|
||||
Err (BadUtf8 ExpectedContinuation byte_index) ->
|
||||
if byte_index == 3 then
|
||||
"a"
|
||||
else
|
||||
"b"
|
||||
|
@ -578,9 +578,9 @@ fn str_from_utf8_fail_overlong_encoding() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 0xF0, 0x80, 0x80, 0x80] is
|
||||
Err (BadUtf8 OverlongEncoding byteIndex) ->
|
||||
if byteIndex == 1 then
|
||||
when Str.from_utf8 [97, 0xF0, 0x80, 0x80, 0x80] is
|
||||
Err (BadUtf8 OverlongEncoding byte_index) ->
|
||||
if byte_index == 1 then
|
||||
"a"
|
||||
else
|
||||
"b"
|
||||
|
@ -597,9 +597,9 @@ fn str_from_utf8_fail_codepoint_too_large() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 0xF4, 0x90, 0x80, 0x80] is
|
||||
Err (BadUtf8 CodepointTooLarge byteIndex) ->
|
||||
if byteIndex == 1 then
|
||||
when Str.from_utf8 [97, 0xF4, 0x90, 0x80, 0x80] is
|
||||
Err (BadUtf8 CodepointTooLarge byte_index) ->
|
||||
if byte_index == 1 then
|
||||
"a"
|
||||
else
|
||||
"b"
|
||||
|
@ -616,9 +616,9 @@ fn str_from_utf8_fail_surrogate_half() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.fromUtf8 [97, 98, 0xED, 0xA0, 0x80] is
|
||||
Err (BadUtf8 EncodesSurrogateHalf byteIndex) ->
|
||||
if byteIndex == 2 then
|
||||
when Str.from_utf8 [97, 98, 0xED, 0xA0, 0x80] is
|
||||
Err (BadUtf8 EncodesSurrogateHalf byte_index) ->
|
||||
if byte_index == 2 then
|
||||
"a"
|
||||
else
|
||||
"b"
|
||||
|
@ -645,7 +645,7 @@ fn str_equality() {
|
|||
#[test]
|
||||
fn str_join_comma_small() {
|
||||
assert_evals_to!(
|
||||
r#"Str.joinWith ["1", "2"] ", " "#,
|
||||
r#"Str.join_with ["1", "2"] ", " "#,
|
||||
RocStr::from("1, 2"),
|
||||
RocStr
|
||||
);
|
||||
|
@ -654,7 +654,7 @@ fn str_join_comma_small() {
|
|||
#[test]
|
||||
fn str_join_comma_big() {
|
||||
assert_evals_to!(
|
||||
r#"Str.joinWith ["10000000", "2000000", "30000000"] ", " "#,
|
||||
r#"Str.join_with ["10000000", "2000000", "30000000"] ", " "#,
|
||||
RocStr::from("10000000, 2000000, 30000000"),
|
||||
RocStr
|
||||
);
|
||||
|
@ -662,18 +662,18 @@ fn str_join_comma_big() {
|
|||
|
||||
#[test]
|
||||
fn str_join_comma_single() {
|
||||
assert_evals_to!(r#"Str.joinWith ["1"] ", " "#, RocStr::from("1"), RocStr);
|
||||
assert_evals_to!(r#"Str.join_with ["1"] ", " "#, RocStr::from("1"), RocStr);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn str_to_utf8() {
|
||||
assert_evals_to!(
|
||||
r#"Str.toUtf8 "hello""#,
|
||||
r#"Str.to_utf8 "hello""#,
|
||||
RocList::from_slice(&[104, 101, 108, 108, 111]),
|
||||
RocList<u8>
|
||||
);
|
||||
assert_evals_to!(
|
||||
r#"Str.toUtf8 "this is a long string""#,
|
||||
r#"Str.to_utf8 "this is a long string""#,
|
||||
RocList::from_slice(&[
|
||||
116, 104, 105, 115, 32, 105, 115, 32, 97, 32, 108, 111, 110, 103, 32, 115, 116, 114,
|
||||
105, 110, 103
|
||||
|
@ -688,10 +688,10 @@ fn str_from_utf8() {
|
|||
indoc!(
|
||||
r#"
|
||||
bytes =
|
||||
Str.toUtf8 "hello"
|
||||
Str.to_utf8 "hello"
|
||||
|
||||
when Str.fromUtf8 bytes is
|
||||
Ok utf8String -> utf8String
|
||||
when Str.from_utf8 bytes is
|
||||
Ok utf8_string -> utf8_string
|
||||
_ -> ""
|
||||
"#
|
||||
),
|
||||
|
@ -706,11 +706,11 @@ fn str_from_utf8_slice() {
|
|||
indoc!(
|
||||
r#"
|
||||
bytes =
|
||||
Str.toUtf8 "hello"
|
||||
Str.to_utf8 "hello"
|
||||
|> List.sublist { start: 1, len: 4 }
|
||||
|
||||
when Str.fromUtf8 bytes is
|
||||
Ok utf8String -> utf8String
|
||||
when Str.from_utf8 bytes is
|
||||
Ok utf8_string -> utf8_string
|
||||
_ -> ""
|
||||
"#
|
||||
),
|
||||
|
@ -725,11 +725,11 @@ fn str_from_utf8_slice_not_end() {
|
|||
indoc!(
|
||||
r#"
|
||||
bytes =
|
||||
Str.toUtf8 "hello"
|
||||
Str.to_utf8 "hello"
|
||||
|> List.sublist { start: 1, len: 3 }
|
||||
|
||||
when Str.fromUtf8 bytes is
|
||||
Ok utf8String -> utf8String
|
||||
when Str.from_utf8 bytes is
|
||||
Ok utf8_string -> utf8_string
|
||||
_ -> ""
|
||||
"#
|
||||
),
|
||||
|
@ -744,11 +744,11 @@ fn str_from_utf8_order_does_not_matter() {
|
|||
indoc!(
|
||||
r#"
|
||||
bytes =
|
||||
Str.toUtf8 "hello"
|
||||
Str.to_utf8 "hello"
|
||||
|> List.sublist { start: 1, len: 3 }
|
||||
|
||||
when Str.fromUtf8 bytes is
|
||||
Ok utf8String -> utf8String
|
||||
when Str.from_utf8 bytes is
|
||||
Ok utf8_string -> utf8_string
|
||||
_ -> ""
|
||||
"#
|
||||
),
|
||||
|
@ -875,13 +875,13 @@ fn str_trim_small_to_small_shared() {
|
|||
|
||||
#[test]
|
||||
fn str_trim_start_small_blank_string() {
|
||||
assert_evals_to!(indoc!(r#"Str.trimStart " ""#), RocStr::from(""), RocStr);
|
||||
assert_evals_to!(indoc!(r#"Str.trim_start " ""#), RocStr::from(""), RocStr);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn str_trim_start_small_to_small() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.trimStart " hello ""#),
|
||||
indoc!(r#"Str.trim_start " hello ""#),
|
||||
RocStr::from("hello "),
|
||||
RocStr
|
||||
);
|
||||
|
@ -890,7 +890,7 @@ fn str_trim_start_small_to_small() {
|
|||
#[test]
|
||||
fn str_trim_start_large_to_large_unique() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.trimStart (Str.concat " " "hello world from a large string ")"#),
|
||||
indoc!(r#"Str.trim_start (Str.concat " " "hello world from a large string ")"#),
|
||||
RocStr::from("hello world from a large string "),
|
||||
RocStr
|
||||
);
|
||||
|
@ -899,7 +899,7 @@ fn str_trim_start_large_to_large_unique() {
|
|||
#[test]
|
||||
fn str_trim_start_large_to_small_unique() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.trimStart (Str.concat " " "hello ")"#),
|
||||
indoc!(r#"Str.trim_start (Str.concat " " "hello ")"#),
|
||||
RocStr::from("hello "),
|
||||
RocStr
|
||||
);
|
||||
|
@ -907,13 +907,13 @@ fn str_trim_start_large_to_small_unique() {
|
|||
|
||||
#[test]
|
||||
fn str_trim_end_small_blank_string() {
|
||||
assert_evals_to!(indoc!(r#"Str.trimEnd " ""#), RocStr::from(""), RocStr);
|
||||
assert_evals_to!(indoc!(r#"Str.trim_end " ""#), RocStr::from(""), RocStr);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn str_trim_end_small_to_small() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.trimEnd " hello ""#),
|
||||
indoc!(r#"Str.trim_end " hello ""#),
|
||||
RocStr::from(" hello"),
|
||||
RocStr
|
||||
);
|
||||
|
@ -922,7 +922,7 @@ fn str_trim_end_small_to_small() {
|
|||
#[test]
|
||||
fn str_trim_end_large_to_large_unique() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.trimEnd (Str.concat " hello world from a large string" " ")"#),
|
||||
indoc!(r#"Str.trim_end (Str.concat " hello world from a large string" " ")"#),
|
||||
RocStr::from(" hello world from a large string"),
|
||||
RocStr
|
||||
);
|
||||
|
@ -931,7 +931,7 @@ fn str_trim_end_large_to_large_unique() {
|
|||
#[test]
|
||||
fn str_trim_end_large_to_small_unique() {
|
||||
assert_evals_to!(
|
||||
indoc!(r#"Str.trimEnd (Str.concat " hello" " ")"#),
|
||||
indoc!(r#"Str.trim_end (Str.concat " hello" " ")"#),
|
||||
RocStr::from(" hello"),
|
||||
RocStr
|
||||
);
|
||||
|
@ -945,7 +945,7 @@ fn str_trim_end_large_to_large_shared() {
|
|||
original : Str
|
||||
original = " hello world world "
|
||||
|
||||
{ trimmed: Str.trimEnd original, original: original }
|
||||
{ trimmed: Str.trim_end original, original: original }
|
||||
"#
|
||||
),
|
||||
(
|
||||
|
@ -964,7 +964,7 @@ fn str_trim_end_large_to_small_shared() {
|
|||
original : Str
|
||||
original = " hello "
|
||||
|
||||
{ trimmed: Str.trimEnd original, original: original }
|
||||
{ trimmed: Str.trim_end original, original: original }
|
||||
"#
|
||||
),
|
||||
(RocStr::from(" hello "), RocStr::from(" hello"),),
|
||||
|
@ -980,7 +980,7 @@ fn str_trim_end_small_to_small_shared() {
|
|||
original : Str
|
||||
original = " hello "
|
||||
|
||||
{ trimmed: Str.trimEnd original, original: original }
|
||||
{ trimmed: Str.trim_end original, original: original }
|
||||
"#
|
||||
),
|
||||
(RocStr::from(" hello "), RocStr::from(" hello"),),
|
||||
|
@ -993,7 +993,7 @@ fn str_to_i128() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toI128 "1" is
|
||||
when Str.to_i128 "1" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
@ -1008,7 +1008,7 @@ fn str_to_u128() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toU128 "1" is
|
||||
when Str.to_u128 "1" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
@ -1023,7 +1023,7 @@ fn str_to_i64() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toI64 "1" is
|
||||
when Str.to_i64 "1" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
@ -1038,7 +1038,7 @@ fn str_to_u64() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toU64 "1" is
|
||||
when Str.to_u64 "1" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
@ -1053,7 +1053,7 @@ fn str_to_i32() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toI32 "1" is
|
||||
when Str.to_i32 "1" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
@ -1068,7 +1068,7 @@ fn str_to_u32() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toU32 "1" is
|
||||
when Str.to_u32 "1" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
@ -1083,7 +1083,7 @@ fn str_to_i16() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toI16 "1" is
|
||||
when Str.to_i16 "1" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
@ -1098,7 +1098,7 @@ fn str_to_u16() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toU16 "1" is
|
||||
when Str.to_u16 "1" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
@ -1113,7 +1113,7 @@ fn str_to_i8() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toI8 "1" is
|
||||
when Str.to_i8 "1" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
@ -1128,7 +1128,7 @@ fn str_to_u8() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toU8 "1" is
|
||||
when Str.to_u8 "1" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
@ -1143,7 +1143,7 @@ fn str_to_f64() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toF64 "1.0" is
|
||||
when Str.to_f64 "1.0" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
@ -1158,7 +1158,7 @@ fn str_to_f32() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toF32 "1.0" is
|
||||
when Str.to_f32 "1.0" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
@ -1175,7 +1175,7 @@ fn str_to_dec() {
|
|||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Str.toDec "1.0" is
|
||||
when Str.to_dec "1.0" is
|
||||
Ok n -> n
|
||||
Err _ -> 0
|
||||
"#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue