mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
reimplement RocList
and RocStr
This commit is contained in:
parent
16e568be76
commit
788c8a6af2
19 changed files with 680 additions and 792 deletions
|
@ -453,10 +453,7 @@ fn list_drop_if_string_eq() {
|
|||
List.dropIf ["x", "y", "x"] (\s -> s == "y")
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
RocStr::from_slice("x".as_bytes()),
|
||||
RocStr::from_slice("x".as_bytes())
|
||||
]),
|
||||
RocList::from_slice(&[RocStr::from("x"), RocStr::from("x")]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -621,7 +618,7 @@ fn list_prepend() {
|
|||
List.prepend init "bar"
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from_slice(b"bar"), RocStr::from_slice(b"foo"),]),
|
||||
RocList::from_slice(&[RocStr::from("bar"), RocStr::from("foo"),]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -874,10 +871,7 @@ fn list_keep_if_str_is_hello() {
|
|||
List.keepIf ["x", "y", "x"] (\x -> x == "x")
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
RocStr::from_slice("x".as_bytes()),
|
||||
RocStr::from_slice("x".as_bytes())
|
||||
]),
|
||||
RocList::from_slice(&[RocStr::from("x"), RocStr::from("x")]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -1060,7 +1054,7 @@ fn list_map4_different_length() {
|
|||
(\a, b, c, d -> Str.concat a (Str.concat b (Str.concat c d)))
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from_slice("hola".as_bytes()),]),
|
||||
RocList::from_slice(&[RocStr::from("hola"),]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -1092,7 +1086,7 @@ fn list_map3_different_length() {
|
|||
(\a, b, c -> Str.concat a (Str.concat b c))
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from_slice("abc".as_bytes()),]),
|
||||
RocList::from_slice(&[RocStr::from("abc"),]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -1124,7 +1118,7 @@ fn list_map2_different_lengths() {
|
|||
(\a, b -> Str.concat a b)
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from_slice("ab".as_bytes()),]),
|
||||
RocList::from_slice(&[RocStr::from("ab"),]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -2552,7 +2546,7 @@ fn empty_list_of_function_type() {
|
|||
Err _ -> "bad!"
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"bar"),
|
||||
RocStr::from("bar"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -2567,11 +2561,11 @@ fn list_join_map() {
|
|||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
RocStr::from_slice("guava".as_bytes()),
|
||||
RocStr::from_slice("apple".as_bytes()),
|
||||
RocStr::from_slice("pear".as_bytes()),
|
||||
RocStr::from_slice("bailey".as_bytes()),
|
||||
RocStr::from_slice("cyrus".as_bytes()),
|
||||
RocStr::from("guava"),
|
||||
RocStr::from("apple"),
|
||||
RocStr::from("pear"),
|
||||
RocStr::from("bailey"),
|
||||
RocStr::from("cyrus"),
|
||||
]),
|
||||
RocList<RocStr>
|
||||
)
|
||||
|
@ -2602,7 +2596,7 @@ fn list_find() {
|
|||
Err _ -> "not found"
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"bc"),
|
||||
RocStr::from("bc"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -2618,7 +2612,7 @@ fn list_find_not_found() {
|
|||
Err _ -> "not found"
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"not found"),
|
||||
RocStr::from("not found"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -2634,7 +2628,7 @@ fn list_find_empty_typed_list() {
|
|||
Err _ -> "not found"
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"not found"),
|
||||
RocStr::from("not found"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2486,29 +2486,21 @@ fn when_on_i16() {
|
|||
fn num_to_str() {
|
||||
use roc_std::RocStr;
|
||||
|
||||
assert_evals_to!(
|
||||
r#"Num.toStr 1234"#,
|
||||
RocStr::from_slice("1234".as_bytes()),
|
||||
RocStr
|
||||
);
|
||||
assert_evals_to!(r#"Num.toStr 0"#, RocStr::from_slice("0".as_bytes()), RocStr);
|
||||
assert_evals_to!(
|
||||
r#"Num.toStr -1"#,
|
||||
RocStr::from_slice("-1".as_bytes()),
|
||||
RocStr
|
||||
);
|
||||
assert_evals_to!(r#"Num.toStr 1234"#, RocStr::from("1234"), RocStr);
|
||||
assert_evals_to!(r#"Num.toStr 0"#, RocStr::from("0"), RocStr);
|
||||
assert_evals_to!(r#"Num.toStr -1"#, RocStr::from("-1"), RocStr);
|
||||
|
||||
let max = format!("{}", i64::MAX);
|
||||
assert_evals_to!(
|
||||
r#"Num.toStr Num.maxI64"#,
|
||||
RocStr::from_slice(max.as_bytes()),
|
||||
RocStr::from(max.as_str()),
|
||||
RocStr
|
||||
);
|
||||
|
||||
let min = format!("{}", i64::MIN);
|
||||
assert_evals_to!(
|
||||
r#"Num.toStr Num.minI64"#,
|
||||
RocStr::from_slice(min.as_bytes()),
|
||||
RocStr::from(min.as_str()),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1468,7 +1468,7 @@ fn rbtree_insert() {
|
|||
show (insert 0 {} Empty)
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice("Node".as_bytes()),
|
||||
RocStr::from("Node"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -1535,7 +1535,7 @@ fn rbtree_layout_issue() {
|
|||
main = show (balance Red zero zero Empty)
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice("Empty".as_bytes()),
|
||||
RocStr::from("Empty"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -1589,7 +1589,7 @@ fn rbtree_balance_mono_problem() {
|
|||
main = show (balance Red 0 0 Empty Empty)
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice("Empty".as_bytes()),
|
||||
RocStr::from("Empty"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -2382,7 +2382,7 @@ fn build_then_apply_closure() {
|
|||
(\_ -> x) {}
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"long string that is malloced"),
|
||||
RocStr::from("long string that is malloced"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -2556,7 +2556,7 @@ fn module_thunk_is_function() {
|
|||
helper = Str.concat
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"foobar"),
|
||||
RocStr::from("foobar"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -2580,7 +2580,7 @@ fn hit_unresolved_type_variable() {
|
|||
\input -> input
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"B"),
|
||||
RocStr::from("B"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -2648,7 +2648,7 @@ fn mirror_llvm_alignment_padding() {
|
|||
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"pass\npass"),
|
||||
RocStr::from("pass\npass"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -2911,7 +2911,7 @@ fn mix_function_and_closure() {
|
|||
(if 1 == 1 then foo else (bar "nope nope nope")) "hello world"
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"hello world"),
|
||||
RocStr::from("hello world"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -2936,7 +2936,7 @@ fn mix_function_and_closure_level_of_indirection() {
|
|||
f "hello world"
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"hello world"),
|
||||
RocStr::from("hello world"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -3012,7 +3012,7 @@ fn do_pass_bool_byte_closure_layout() {
|
|||
main = [test1, test2, test3, test4] |> Str.joinWith ", "
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"PASS, PASS, PASS, PASS"),
|
||||
RocStr::from("PASS, PASS, PASS, PASS"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -3037,7 +3037,7 @@ fn nested_rigid_list() {
|
|||
_ -> "hello world"
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"hello world"),
|
||||
RocStr::from("hello world"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -3064,7 +3064,7 @@ fn nested_rigid_alias() {
|
|||
_ -> "hello world"
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"hello world"),
|
||||
RocStr::from("hello world"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -3089,7 +3089,7 @@ fn nested_rigid_tag_union() {
|
|||
_ -> "hello world"
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"hello world"),
|
||||
RocStr::from("hello world"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -3117,7 +3117,7 @@ fn call_that_needs_closure_parameter() {
|
|||
runTest manyAuxTest
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"FAIL"),
|
||||
RocStr::from("FAIL"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -3138,7 +3138,7 @@ fn alias_defined_out_of_order() {
|
|||
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"foo"),
|
||||
RocStr::from("foo"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -3184,7 +3184,7 @@ fn recursively_build_effect() {
|
|||
e2 {}
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"Hello, World!"),
|
||||
RocStr::from("Hello, World!"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ fn roc_result_err() {
|
|||
result
|
||||
"#
|
||||
),
|
||||
RocResult::err(RocStr::from_slice(b"foo")),
|
||||
RocResult::err(RocStr::from("foo")),
|
||||
RocResult<i64, RocStr>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ fn str_split_str_concat_repeated() {
|
|||
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"JJJJJJJJJJJJJJJJJJJJJJJJJ"),
|
||||
RocStr::from("JJJJJJJJJJJJJJJJJJJJJJJJJ"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ fn str_split_small_str_bigger_delimiter() {
|
|||
_ -> ""
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"JJJ"),
|
||||
RocStr::from("JJJ"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -128,8 +128,8 @@ fn str_split_big_str_small_delimiter() {
|
|||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
RocStr::from_slice(b"01234567789abcdefghi"),
|
||||
RocStr::from_slice(b"01234567789abcdefghi")
|
||||
RocStr::from("01234567789abcdefghi"),
|
||||
RocStr::from("01234567789abcdefghi")
|
||||
]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
|
@ -141,8 +141,8 @@ fn str_split_big_str_small_delimiter() {
|
|||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
RocStr::from_slice(b"01234567789abcdefghi "),
|
||||
RocStr::from_slice(b" 01234567789abcdefghi")
|
||||
RocStr::from("01234567789abcdefghi "),
|
||||
RocStr::from(" 01234567789abcdefghi")
|
||||
]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
|
@ -157,11 +157,7 @@ fn str_split_small_str_small_delimiter() {
|
|||
Str.split "J!J!J" "!"
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
RocStr::from_slice(b"J"),
|
||||
RocStr::from_slice(b"J"),
|
||||
RocStr::from_slice(b"J")
|
||||
]),
|
||||
RocList::from_slice(&[RocStr::from("J"), RocStr::from("J"), RocStr::from("J")]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -177,7 +173,7 @@ fn str_split_bigger_delimiter_big_strs() {
|
|||
"than the delimiter which happens to be very very long"
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from_slice(b"string to split is shorter")]),
|
||||
RocList::from_slice(&[RocStr::from("string to split is shorter")]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -191,7 +187,7 @@ fn str_split_empty_strs() {
|
|||
Str.split "" ""
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from_slice(b"")]),
|
||||
RocList::from_slice(&[RocStr::from("")]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -205,7 +201,7 @@ fn str_split_minimal_example() {
|
|||
Str.split "a," ","
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from_slice(b"a"), RocStr::from_slice(b"")]),
|
||||
RocList::from_slice(&[RocStr::from("a"), RocStr::from("")]),
|
||||
RocList<RocStr>
|
||||
)
|
||||
}
|
||||
|
@ -234,11 +230,7 @@ fn str_split_small_str_big_delimiter() {
|
|||
"---- ---- ---- ---- ----"
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
RocStr::from_slice(b"1"),
|
||||
RocStr::from_slice(b"2"),
|
||||
RocStr::from_slice(b"")
|
||||
]),
|
||||
RocList::from_slice(&[RocStr::from("1"), RocStr::from("2"), RocStr::from("")]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -254,11 +246,7 @@ fn str_split_small_str_20_char_delimiter() {
|
|||
"|-- -- -- -- -- -- |"
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
RocStr::from_slice(b"3"),
|
||||
RocStr::from_slice(b"4"),
|
||||
RocStr::from_slice(b"")
|
||||
]),
|
||||
RocList::from_slice(&[RocStr::from("3"), RocStr::from("4"), RocStr::from("")]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -274,7 +262,7 @@ fn str_concat_big_to_big() {
|
|||
"Second string that is also fairly long. Two long strings test things that might not appear with short strings."
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"First string that is fairly long. Longer strings make for different errors. Second string that is also fairly long. Two long strings test things that might not appear with short strings."),
|
||||
RocStr::from("First string that is fairly long. Longer strings make for different errors. Second string that is also fairly long. Two long strings test things that might not appear with short strings."),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -395,7 +383,7 @@ fn small_str_concat_empty_second_arg() {
|
|||
fn small_str_concat_small_to_big() {
|
||||
assert_evals_to!(
|
||||
r#"Str.concat "abc" " this is longer than 15 chars""#,
|
||||
RocStr::from_slice(b"abc this is longer than 15 chars"),
|
||||
RocStr::from("abc this is longer than 15 chars"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -432,7 +420,7 @@ fn small_str_concat_small_to_small_staying_small() {
|
|||
fn small_str_concat_small_to_small_overflow_to_big() {
|
||||
assert_evals_to!(
|
||||
r#"Str.concat "abcdefghijklm" "nopqrstuvwxyz""#,
|
||||
RocStr::from_slice(b"abcdefghijklmnopqrstuvwxyz"),
|
||||
RocStr::from("abcdefghijklmnopqrstuvwxyz"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -568,7 +556,7 @@ fn str_from_utf8_pass_single_ascii() {
|
|||
Err _ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("a".as_bytes()),
|
||||
roc_std::RocStr::from("a"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -584,7 +572,7 @@ fn str_from_utf8_pass_many_ascii() {
|
|||
Err _ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("abc~".as_bytes()),
|
||||
roc_std::RocStr::from("abc~"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -600,7 +588,7 @@ fn str_from_utf8_pass_single_unicode() {
|
|||
Err _ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("∆".as_bytes()),
|
||||
roc_std::RocStr::from("∆"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -616,7 +604,7 @@ fn str_from_utf8_pass_many_unicode() {
|
|||
Err _ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("∆œ¬".as_bytes()),
|
||||
roc_std::RocStr::from("∆œ¬"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -632,7 +620,7 @@ fn str_from_utf8_pass_single_grapheme() {
|
|||
Err _ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("💖".as_bytes()),
|
||||
roc_std::RocStr::from("💖"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -648,7 +636,7 @@ fn str_from_utf8_pass_many_grapheme() {
|
|||
Err _ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("💖🤠🚀".as_bytes()),
|
||||
roc_std::RocStr::from("💖🤠🚀"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -664,7 +652,7 @@ fn str_from_utf8_pass_all() {
|
|||
Err _ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("💖b∆".as_bytes()),
|
||||
roc_std::RocStr::from("💖b∆"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -684,7 +672,7 @@ fn str_from_utf8_fail_invalid_start_byte() {
|
|||
_ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("a".as_bytes()),
|
||||
roc_std::RocStr::from("a"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -704,7 +692,7 @@ fn str_from_utf8_fail_unexpected_end_of_sequence() {
|
|||
_ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("a".as_bytes()),
|
||||
roc_std::RocStr::from("a"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -724,7 +712,7 @@ fn str_from_utf8_fail_expected_continuation() {
|
|||
_ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("a".as_bytes()),
|
||||
roc_std::RocStr::from("a"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -744,7 +732,7 @@ fn str_from_utf8_fail_overlong_encoding() {
|
|||
_ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("a".as_bytes()),
|
||||
roc_std::RocStr::from("a"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -764,7 +752,7 @@ fn str_from_utf8_fail_codepoint_too_large() {
|
|||
_ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("a".as_bytes()),
|
||||
roc_std::RocStr::from("a"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -784,7 +772,7 @@ fn str_from_utf8_fail_surrogate_half() {
|
|||
_ -> ""
|
||||
"#
|
||||
),
|
||||
roc_std::RocStr::from_slice("a".as_bytes()),
|
||||
roc_std::RocStr::from("a"),
|
||||
roc_std::RocStr
|
||||
);
|
||||
}
|
||||
|
@ -805,9 +793,9 @@ fn str_equality() {
|
|||
#[test]
|
||||
fn str_clone() {
|
||||
use roc_std::RocStr;
|
||||
let long = RocStr::from_slice("loremipsumdolarsitamet".as_bytes());
|
||||
let short = RocStr::from_slice("x".as_bytes());
|
||||
let empty = RocStr::from_slice("".as_bytes());
|
||||
let long = RocStr::from("loremipsumdolarsitamet");
|
||||
let short = RocStr::from("x");
|
||||
let empty = RocStr::from("");
|
||||
|
||||
debug_assert_eq!(long.clone(), long);
|
||||
debug_assert_eq!(short.clone(), short);
|
||||
|
@ -840,7 +828,7 @@ fn nested_recursive_literal() {
|
|||
printExpr expr
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"Add (Add (Val 3) (Val 1)) (Add (Val 1) (Var 1))"),
|
||||
RocStr::from("Add (Add (Val 3) (Val 1)) (Add (Val 1) (Var 1))"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1177,10 +1177,7 @@ fn applied_tag_function() {
|
|||
x
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
RocStr::from_slice("a".as_bytes()),
|
||||
RocStr::from_slice("b".as_bytes())
|
||||
]),
|
||||
RocList::from_slice(&[RocStr::from("a"), RocStr::from("b")]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -1197,10 +1194,7 @@ fn applied_tag_function_result() {
|
|||
List.keepOks x (\y -> y)
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
(RocStr::from_slice("a".as_bytes())),
|
||||
(RocStr::from_slice("b".as_bytes()))
|
||||
]),
|
||||
RocList::from_slice(&[(RocStr::from("a")), (RocStr::from("b"))]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -1297,7 +1291,7 @@ fn monomorphized_applied_tag() {
|
|||
f a
|
||||
"#
|
||||
),
|
||||
RocStr::from_slice(b"abc"),
|
||||
RocStr::from("abc"),
|
||||
RocStr
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use roc_gen_wasm::wasm32_sized::Wasm32Sized;
|
||||
use roc_std::{RocDec, RocList, RocOrder, RocStr};
|
||||
use roc_std::{ReferenceCount, RocDec, RocList, RocOrder, RocStr};
|
||||
|
||||
pub trait FromWasmerMemory: Wasm32Sized {
|
||||
fn decode(memory: &wasmer::Memory, offset: u32) -> Self;
|
||||
|
@ -61,19 +61,19 @@ impl FromWasmerMemory for RocStr {
|
|||
let actual_length = (last_byte ^ 0b1000_0000) as usize;
|
||||
|
||||
let slice = &bytes.to_ne_bytes()[..actual_length as usize];
|
||||
RocStr::from_slice(slice)
|
||||
unsafe { RocStr::from_slice(slice) }
|
||||
} else {
|
||||
// this is a big string
|
||||
let ptr: wasmer::WasmPtr<u8, wasmer::Array> = wasmer::WasmPtr::new(elements);
|
||||
let foobar = (ptr.deref(memory, 0, length)).unwrap();
|
||||
let wasm_slice = unsafe { std::mem::transmute(foobar) };
|
||||
|
||||
RocStr::from_slice(wasm_slice)
|
||||
unsafe { RocStr::from_slice(wasm_slice) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FromWasmerMemory + Clone> FromWasmerMemory for RocList<T> {
|
||||
impl<T: FromWasmerMemory + Clone + ReferenceCount> FromWasmerMemory for RocList<T> {
|
||||
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
|
||||
let bytes = <u64 as FromWasmerMemory>::decode(memory, offset);
|
||||
|
||||
|
|
|
@ -320,7 +320,7 @@ fn small_str_zeroed_literal() {
|
|||
fn long_str_literal() {
|
||||
assert_evals_to!(
|
||||
"\"0123456789 123456789 123456789\"",
|
||||
RocStr::from_slice(b"0123456789 123456789 123456789"),
|
||||
RocStr::from("0123456789 123456789 123456789"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ fn small_str_concat_empty_second_arg() {
|
|||
fn small_str_concat_small_to_big() {
|
||||
assert_evals_to!(
|
||||
r#"Str.concat "abc" " this is longer than 7 chars""#,
|
||||
RocStr::from_slice(b"abc this is longer than 7 chars"),
|
||||
RocStr::from("abc this is longer than 7 chars"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ fn small_str_concat_small_to_small_staying_small() {
|
|||
fn small_str_concat_small_to_small_overflow_to_big() {
|
||||
assert_evals_to!(
|
||||
r#"Str.concat "abcdefg" "hijklmn""#,
|
||||
RocStr::from_slice(b"abcdefghijklmn"),
|
||||
RocStr::from("abcdefghijklmn"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue