Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Mar 2, 2022
1 parent eded935 commit 38dddd7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 3 additions & 4 deletions boa_engine/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub(crate) enum Placement {

pub(crate) fn code_point_at(string: &JsString, position: usize) -> (u32, u8, bool) {
let mut encoded = string.encode_utf16();
let size = encoded.clone().count();

let first = encoded
.nth(position)
Expand All @@ -49,8 +50,6 @@ pub(crate) fn code_point_at(string: &JsString, position: usize) -> (u32, u8, boo
return (u32::from(first), 1, false);
}

let size = encoded.clone().count();

if is_trailing_surrogate(first) || position + 1 == size {
return (u32::from(first), 1, true);
}
Expand Down Expand Up @@ -688,7 +687,7 @@ impl String {
// 4. If n < 0 or n is +∞, throw a RangeError exception.
_ => context.throw_range_error(
"repeat count must be a positive finite number \
that doesn't overflow the maximum string length",
that doesn't overflow the maximum string length (2^32 - 1)",
),
}
}
Expand Down Expand Up @@ -1768,7 +1767,7 @@ impl String {
let substring_utf16: Vec<u16> = string
.encode_utf16()
.skip(int_start)
.take(int_start - int_end)
.take(int_end - int_start)
.collect();
let substring = StdString::from_utf16_lossy(&substring_utf16);

Expand Down
9 changes: 6 additions & 3 deletions boa_engine/src/builtins/string/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ fn repeat_throws_when_count_is_negative() {
}
"#
),
"\"RangeError: repeat count cannot be a negative number\""
"\"RangeError: repeat count must be a positive finite number \
that doesn't overflow the maximum string length (2^32 - 1)\""
);
}

Expand All @@ -166,7 +167,8 @@ fn repeat_throws_when_count_is_infinity() {
}
"#
),
"\"RangeError: repeat count cannot be infinity\""
"\"RangeError: repeat count must be a positive finite number \
that doesn't overflow the maximum string length (2^32 - 1)\""
);
}

Expand All @@ -185,7 +187,8 @@ fn repeat_throws_when_count_overflows_max_length() {
}
"#
),
"\"RangeError: repeat count must not overflow maximum string length\""
"\"RangeError: repeat count must be a positive finite number \
that doesn't overflow the maximum string length (2^32 - 1)\""
);
}

Expand Down

0 comments on commit 38dddd7

Please sign in to comment.