mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-25 03:05:34 +00:00
168589b832
In particular, fix a panic when the input is not ASCII and we happen to index in something that is not a char boundary. This fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1379380 Source-Repo: https://github.com/servo/servo Source-Revision: 104e0b473073340689b4bca5c128c61632d4e58d --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 14e052469d419b4fd24721fd275047a20527297f
47 lines
1.4 KiB
Rust
47 lines
1.4 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
use style::str::{split_html_space_chars, str_join, starts_with_ignore_ascii_case};
|
|
|
|
#[test]
|
|
pub fn split_html_space_chars_whitespace() {
|
|
assert!(split_html_space_chars("").collect::<Vec<_>>().is_empty());
|
|
assert!(split_html_space_chars("\u{0020}\u{0009}\u{000a}\u{000c}\u{000d}").collect::<Vec<_>>().is_empty());
|
|
}
|
|
|
|
#[test]
|
|
pub fn test_str_join_empty() {
|
|
let slice: [&str; 0] = [];
|
|
let actual = str_join(&slice, "-");
|
|
let expected = "";
|
|
assert_eq!(actual, expected);
|
|
}
|
|
|
|
#[test]
|
|
pub fn test_str_join_one() {
|
|
let slice = ["alpha"];
|
|
let actual = str_join(&slice, "-");
|
|
let expected = "alpha";
|
|
assert_eq!(actual, expected);
|
|
}
|
|
|
|
#[test]
|
|
pub fn test_str_join_many() {
|
|
let slice = ["", "alpha", "", "beta", "gamma", ""];
|
|
let actual = str_join(&slice, "-");
|
|
let expected = "-alpha--beta-gamma-";
|
|
assert_eq!(actual, expected);
|
|
}
|
|
|
|
#[test]
|
|
pub fn test_starts_with_ignore_ascii_case_basic() {
|
|
assert!(starts_with_ignore_ascii_case("-webkit-", "-webkit-"));
|
|
assert!(starts_with_ignore_ascii_case("-webkit-foo", "-webkit-"));
|
|
}
|
|
|
|
#[test]
|
|
pub fn test_starts_with_ignore_ascii_case_char_boundary() {
|
|
assert!(!starts_with_ignore_ascii_case("aaaaa💩", "-webkit-"));
|
|
}
|