Add gen tests for Str.toScalars

This commit is contained in:
Richard Feldman 2022-07-01 23:17:08 -04:00
parent 092654c463
commit 348ca970d6
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798

View file

@ -1603,3 +1603,96 @@ fn issue_2811() {
RocStr
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn to_scalar_1_byte() {
assert_evals_to!(
indoc!(
r#"
Str.toScalars "R"
"#
),
RocList::from_slice(&[82u32]),
RocList<u32>
);
assert_evals_to!(
indoc!(
r#"
Str.toScalars "Roc!"
"#
),
RocList::from_slice(&[82u32, 111, 99, 33]),
RocList<u32>
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn to_scalar_2_byte() {
assert_evals_to!(
indoc!(
r#"
Str.toScalars "é"
"#
),
RocList::from_slice(&[233u32]),
RocList<u32>
);
assert_evals_to!(
indoc!(
r#"
Str.toScalars "Cäfés"
"#
),
RocList::from_slice(&[67u32, 228, 102, 233, 115]),
RocList<u32>
);
}
fn to_scalar_3_byte() {
assert_evals_to!(
indoc!(
r#"
Str.toScalars ""
"#
),
RocList::from_slice(&[40527u32]),
RocList<u32>
);
assert_evals_to!(
indoc!(
r#"
Str.toScalars "鹏很有趣"
"#
),
RocList::from_slice(&[40527u32, 24456, 26377, 36259]),
RocList<u32>
);
}
fn to_scalar_4_byte() {
// from https://design215.com/toolbox/utf8-4byte-characters.php
assert_evals_to!(
indoc!(
r#"
Str.toScalars "𒀀"
"#
),
RocList::from_slice(&[73728u32]),
RocList<u32>
);
assert_evals_to!(
indoc!(
r#"
Str.toScalars "𒀀𒀁"
"#
),
RocList::from_slice(&[73728u32, 73729u32]),
RocList<u32>
);
}