Skip to content

Commit 3a1e02a

Browse files
authored
Merge pull request #259 from ajtribick/windows-tests
Fix Windows test cases
2 parents 745341a + f2ed7dd commit 3a1e02a

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

tests/documents/html5-windows.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DocType( html)
2+
Characters(
3+
)
4+
StartElement(a, attr-error: error while parsing attribute at position 7: Attribute value must start with a quote.)
5+
Characters(Hey)
6+
EndElement(a)
7+
InvalidUtf8([13, 10, 38, 110, 98, 115, 112, 59, 13, 10]; invalid utf-8 sequence of 1 bytes from index 2)
8+
EndDocument

tests/unit_tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ fn test_writer_indent() {
255255

256256
let result = writer.into_inner().into_inner();
257257
// println!("{:?}", String::from_utf8_lossy(&result));
258+
259+
#[cfg(windows)]
260+
assert!(result.into_iter().eq(txt.bytes().filter(|b| *b != 13)));
261+
262+
#[cfg(not(windows))]
258263
assert_eq!(result, txt.as_bytes());
259264
}
260265

@@ -274,6 +279,11 @@ fn test_writer_indent_cdata() {
274279
}
275280

276281
let result = writer.into_inner().into_inner();
282+
283+
#[cfg(windows)]
284+
assert!(result.into_iter().eq(txt.bytes().filter(|b| *b != 13)));
285+
286+
#[cfg(not(windows))]
277287
assert_eq!(result, txt.as_bytes());
278288
}
279289

tests/xmlrs_reader_tests.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn sample_2_full() {
4040
);
4141
}
4242

43-
#[cfg(feature = "escape-html")]
43+
#[cfg(all(not(windows), feature = "escape-html"))]
4444
#[test]
4545
fn html5() {
4646
test(
@@ -50,6 +50,17 @@ fn html5() {
5050
);
5151
}
5252

53+
#[cfg(all(windows, feature = "escape-html"))]
54+
#[test]
55+
fn html5() {
56+
test(
57+
include_bytes!("documents/html5.html"),
58+
include_bytes!("documents/html5-windows.txt"),
59+
false,
60+
);
61+
}
62+
63+
5364
// #[test]
5465
// fn sample_3_short() {
5566
// test(
@@ -421,24 +432,23 @@ impl<'a> Iterator for SpecIter<'a> {
421432
let start = self
422433
.0
423434
.iter()
424-
.position(|b| match *b {
425-
b' ' | b'\r' | b'\n' | b'\t' | b'|' | b':' => false,
426-
b'0'..=b'9' => false,
427-
_ => true,
428-
})
435+
.position(|b| !matches!(*b, b' ' | b'\r' | b'\n' | b'\t' | b'|' | b':' | b'0'..=b'9'))
429436
.unwrap_or(0);
430-
if let Some(p) = self.0.windows(2).position(|w| w == b")\n") {
437+
438+
if let Some(p) = self.0.windows(3).position(|w| w == b")\r\n") {
439+
let (prev, next) = self.0.split_at(p + 1);
440+
self.0 = &next[1..];
441+
Some(from_utf8(&prev[start..]).expect("Error decoding to uft8"))
442+
} else if let Some(p) = self.0.windows(2).position(|w| w == b")\n") {
431443
let (prev, next) = self.0.split_at(p + 1);
432444
self.0 = next;
433445
Some(from_utf8(&prev[start..]).expect("Error decoding to uft8"))
446+
} else if self.0.is_empty() {
447+
None
434448
} else {
435-
if self.0.is_empty() {
436-
None
437-
} else {
438-
let p = self.0;
439-
self.0 = &[];
440-
Some(from_utf8(&p[start..]).unwrap())
441-
}
449+
let p = self.0;
450+
self.0 = &[];
451+
Some(from_utf8(&p[start..]).unwrap())
442452
}
443453
}
444454
}

0 commit comments

Comments
 (0)