mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
add failing tests
* SIGSEGV for non-empty strings
This commit is contained in:
parent
e7523ad41d
commit
46365da73a
3 changed files with 46 additions and 9 deletions
|
@ -1504,14 +1504,12 @@ test "isWhitespace" {
|
||||||
try expect(!isWhitespace('x'));
|
try expect(!isWhitespace('x'));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn strTrim(string: RocStr) callconv(.C) RocStr {
|
|
||||||
return @call(.{ .modifier = always_inline }, trim, .{string});
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO GIESCH
|
// TODO GIESCH
|
||||||
// ask & read about small & large strings
|
// ask & read about small & large strings
|
||||||
fn trim(string: RocStr) RocStr {
|
pub fn strTrim(string: RocStr) callconv(.C) RocStr {
|
||||||
if (string.isEmpty()) return RocStr.empty();
|
if (string.isEmpty()) {
|
||||||
|
return RocStr.empty();
|
||||||
|
}
|
||||||
|
|
||||||
const leading_bytes = countLeadingWhitespaceBytes(string);
|
const leading_bytes = countLeadingWhitespaceBytes(string);
|
||||||
const trailing_bytes = countTrailingWhitespaceBytes(string);
|
const trailing_bytes = countTrailingWhitespaceBytes(string);
|
||||||
|
@ -1525,6 +1523,8 @@ fn trim(string: RocStr) RocStr {
|
||||||
// should this just use isUnique? (are all small strings safe for mutation?)
|
// should this just use isUnique? (are all small strings safe for mutation?)
|
||||||
// should we rename isUnique to isUnleakable or something?
|
// should we rename isUnique to isUnleakable or something?
|
||||||
// could also just inline the unsafe reallocate call
|
// could also just inline the unsafe reallocate call
|
||||||
|
|
||||||
|
// SIGSEGV is not from this branch
|
||||||
if (string.isRefcountOne()) {
|
if (string.isRefcountOne()) {
|
||||||
const dest = string.str_bytes orelse unreachable;
|
const dest = string.str_bytes orelse unreachable;
|
||||||
const source = dest + leading_bytes;
|
const source = dest + leading_bytes;
|
||||||
|
@ -1645,6 +1645,3 @@ test "strTrim: unique hello world" {
|
||||||
|
|
||||||
try expect(trimmed.eq(expected));
|
try expect(trimmed.eq(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO GIESCH
|
|
||||||
// add top level roc tests
|
|
||||||
|
|
|
@ -3733,6 +3733,18 @@ mod solve_expr {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim() {
|
||||||
|
infer_eq_without_problem(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
Str.trim
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
"Str -> Str",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn function_that_captures_nothing_is_not_captured() {
|
fn function_that_captures_nothing_is_not_captured() {
|
||||||
// we should make sure that a function that doesn't capture anything it not itself captured
|
// we should make sure that a function that doesn't capture anything it not itself captured
|
||||||
|
|
|
@ -977,3 +977,31 @@ fn str_repeat_empty_string() {
|
||||||
fn str_repeat_zero_times() {
|
fn str_repeat_zero_times() {
|
||||||
assert_evals_to!(indoc!(r#"Str.repeat "Roc" 0"#), RocStr::from(""), RocStr);
|
assert_evals_to!(indoc!(r#"Str.repeat "Roc" 0"#), RocStr::from(""), RocStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_empty_string() {
|
||||||
|
assert_evals_to!(indoc!(r#"Str.trim """#), RocStr::from(""), RocStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_blank_string() {
|
||||||
|
assert_evals_to!(indoc!(r#"Str.trim " ""#), RocStr::from(""), RocStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_blank_string_large() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(r#"Str.trim " " "#),
|
||||||
|
RocStr::from(""),
|
||||||
|
RocStr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_hello_world() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(r#"Str.trim " hello world ""#),
|
||||||
|
RocStr::from("hello world"),
|
||||||
|
RocStr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue