Skip to content

Commit 0b13310

Browse files
JasperDeSutteralerque
authored andcommitted
test: Test ownership in unescape_unicode_test
1 parent 4370cf4 commit 0b13310

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

fluent-syntax/tests/unicode.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1+
use std::borrow::Cow;
2+
13
use fluent_syntax::unicode::{unescape_unicode, unescape_unicode_to_string};
24

3-
fn test_unescape_unicode(input: &str, output: &str) {
5+
/// Asserts that decoding unicode escape sequences in `input` matches `output`.
6+
/// When `borrowed` = true, asserts that the escaped value is passed back by reference.
7+
fn test_unescape_unicode(input: &str, output: &str, borrowed: bool) {
48
let mut s = String::new();
59
unescape_unicode(&mut s, input).expect("Failed to write.");
6-
assert_eq!(&s, output);
10+
assert_eq!(s, output);
711
let result = unescape_unicode_to_string(input);
8-
assert_eq!(&result, output);
12+
assert_eq!(result, output);
13+
14+
assert_eq!(matches!(result, Cow::Borrowed(_)), borrowed);
915
}
1016

1117
#[test]
1218
fn unescape_unicode_test() {
13-
test_unescape_unicode("foo", "foo");
14-
test_unescape_unicode("foo \\\\", "foo \\");
15-
test_unescape_unicode("foo \\\"", "foo \"");
16-
test_unescape_unicode("foo \\\\ faa", "foo \\ faa");
17-
test_unescape_unicode("foo \\\\ faa \\\\ fii", "foo \\ faa \\ fii");
18-
test_unescape_unicode("foo \\\\\\\" faa \\\"\\\\ fii", "foo \\\" faa \"\\ fii");
19-
test_unescape_unicode("\\u0041\\u004F", "AO");
20-
test_unescape_unicode("\\uA", "�");
21-
test_unescape_unicode("\\uA0Pl", "�");
22-
test_unescape_unicode("\\d Foo", "� Foo");
19+
test_unescape_unicode("foo", "foo", true);
20+
test_unescape_unicode("foo \\\\", "foo \\", false);
21+
test_unescape_unicode("foo \\\"", "foo \"", false);
22+
test_unescape_unicode("foo \\\\ faa", "foo \\ faa", false);
23+
test_unescape_unicode("foo \\\\ faa \\\\ fii", "foo \\ faa \\ fii", false);
24+
test_unescape_unicode(
25+
"foo \\\\\\\" faa \\\"\\\\ fii",
26+
"foo \\\" faa \"\\ fii",
27+
false,
28+
);
29+
test_unescape_unicode("\\u0041\\u004F", "AO", false);
30+
test_unescape_unicode("\\uA", "�", false);
31+
test_unescape_unicode("\\uA0Pl", "�", false);
32+
test_unescape_unicode("\\d Foo", "� Foo", false);
2333
}

0 commit comments

Comments
 (0)