mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
fix List.sublist and add some more refcounting tests
This commit is contained in:
parent
6e90052000
commit
9052fbd09c
2 changed files with 88 additions and 10 deletions
|
@ -65,6 +65,25 @@ fn str_to_utf8() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "gen-wasm")]
|
||||
fn str_from_utf8() {
|
||||
assert_refcounts!(
|
||||
indoc!(
|
||||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
|
||||
Str.toUtf8 s
|
||||
|> Str.fromUtf8
|
||||
"#
|
||||
),
|
||||
RocStr,
|
||||
&[
|
||||
(StandardRC, Live(1)), // s
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "gen-wasm")]
|
||||
fn str_to_utf8_dealloc() {
|
||||
|
@ -160,7 +179,7 @@ fn list_str_inc() {
|
|||
|
||||
#[test]
|
||||
#[cfg(feature = "gen-wasm")]
|
||||
fn list_str_slice() {
|
||||
fn list_str_drop_first() {
|
||||
assert_refcounts!(
|
||||
indoc!(
|
||||
r#"
|
||||
|
@ -179,6 +198,64 @@ fn list_str_slice() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "gen-wasm")]
|
||||
fn list_str_take_first() {
|
||||
assert_refcounts!(
|
||||
indoc!(
|
||||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
list = [s, s, s]
|
||||
List.takeFirst list 1
|
||||
"#
|
||||
),
|
||||
RocList<RocList<RocStr>>,
|
||||
&[
|
||||
// Take will free tail of a unique list.
|
||||
(StandardRC, Live(1)), // s
|
||||
(AfterSize, Live(1)) // result
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "gen-wasm")]
|
||||
fn list_str_split() {
|
||||
assert_refcounts!(
|
||||
indoc!(
|
||||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
list = [s, s, s]
|
||||
List.split list 1
|
||||
"#
|
||||
),
|
||||
(RocList<RocStr>, RocList<RocStr>),
|
||||
&[
|
||||
(StandardRC, Live(3)), // s
|
||||
(AfterSize, Live(2)), // list
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "gen-wasm")]
|
||||
fn list_str_split_zero() {
|
||||
assert_refcounts!(
|
||||
indoc!(
|
||||
r#"
|
||||
s = Str.concat "A long enough string " "to be heap-allocated"
|
||||
list = [s, s, s]
|
||||
List.split list 0
|
||||
"#
|
||||
),
|
||||
(RocList<RocStr>, RocList<RocStr>),
|
||||
&[
|
||||
(StandardRC, Live(3)), // s
|
||||
(AfterSize, Live(1)), // list
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "gen-wasm")]
|
||||
fn list_get() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue