From 1b6a04ca5504955c571d1c97504fb45ea0befee4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 8 Jan 2024 01:21:28 +0400 Subject: Initial vendor packages Signed-off-by: Valentin Popov --- vendor/utf8parse/tests/utf-8-demo.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 vendor/utf8parse/tests/utf-8-demo.rs (limited to 'vendor/utf8parse/tests/utf-8-demo.rs') diff --git a/vendor/utf8parse/tests/utf-8-demo.rs b/vendor/utf8parse/tests/utf-8-demo.rs new file mode 100644 index 0000000..51df492 --- /dev/null +++ b/vendor/utf8parse/tests/utf-8-demo.rs @@ -0,0 +1,31 @@ +use utf8parse::{Parser, Receiver}; + +static UTF8_DEMO: &[u8] = include_bytes!("UTF-8-demo.txt"); + +#[derive(Debug, PartialEq)] +struct StringWrapper(String); + +impl Receiver for StringWrapper { + fn codepoint(&mut self, c: char) { + self.0.push(c); + } + + fn invalid_sequence(&mut self) {} +} + +#[test] +fn utf8parse_test() { + let mut parser = Parser::new(); + + // utf8parse implementation + let mut actual = StringWrapper(String::new()); + + for byte in UTF8_DEMO { + parser.advance(&mut actual, *byte) + } + + // standard library implementation + let expected = String::from_utf8_lossy(UTF8_DEMO); + + assert_eq!(actual.0, expected); +} -- cgit v1.2.3