Skip to content

Commit

Permalink
std: test a variety of ways to extend a Wtf8Buf
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Jun 26, 2024
1 parent e5167fe commit 5aac249
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions library/std/src/sys_common/wtf8/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,3 +725,27 @@ fn wtf8_utf8_boundary_between_surrogates() {
string.push(CodePoint::from_u32(0xD800).unwrap());
check_utf8_boundary(&string, 3);
}

#[test]
fn wobbled_wtf8_plus_bytes_isnt_utf8() {
let mut string: Wtf8Buf = unsafe { Wtf8::from_bytes_unchecked(b"\xED\xA0\x80").to_owned() };
assert!(!string.is_known_utf8);
string.extend_from_slice(b"some utf-8");
assert!(!string.is_known_utf8);
}

#[test]
fn wobbled_wtf8_plus_str_isnt_utf8() {
let mut string: Wtf8Buf = unsafe { Wtf8::from_bytes_unchecked(b"\xED\xA0\x80").to_owned() };
assert!(!string.is_known_utf8);
string.push_str("some utf-8");
assert!(!string.is_known_utf8);
}

#[test]
fn unwobbly_wtf8_plus_utf8_is_utf8() {
let mut string: Wtf8Buf = Wtf8Buf::from_str("hello world");
assert!(string.is_known_utf8);
string.push_str("some utf-8");
assert!(string.is_known_utf8);
}

0 comments on commit 5aac249

Please sign in to comment.