aboutsummaryrefslogtreecommitdiff
path: root/vendor/utf8parse/tests/utf-8-demo.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/utf8parse/tests/utf-8-demo.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/utf8parse/tests/utf-8-demo.rs')
-rw-r--r--vendor/utf8parse/tests/utf-8-demo.rs31
1 files changed, 31 insertions, 0 deletions
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);
+}