fix List.sublist and add some more refcounting tests

This commit is contained in:
Brendan Hansknecht 2024-07-12 20:21:58 -07:00
parent 6e90052000
commit 9052fbd09c
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
2 changed files with 88 additions and 10 deletions

View file

@ -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() {