aboutsummaryrefslogtreecommitdiff
path: root/utf8parse/tests/utf-8-demo.rs
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2019-11-23 02:01:09 +0100
committerGitHub <noreply@github.com>2019-11-23 02:01:09 +0100
commitea940fcb74abce67b927788e4f9f64fc63073d37 (patch)
treecb0c9db4008e5fec07c9655dea29513614f5f7b9 /utf8parse/tests/utf-8-demo.rs
parenta035f334a108f4a694cf022e063edb9c8ac349ad (diff)
downloadr-alacritty-vte-ea940fcb74abce67b927788e4f9f64fc63073d37.tar.gz
r-alacritty-vte-ea940fcb74abce67b927788e4f9f64fc63073d37.tar.bz2
r-alacritty-vte-ea940fcb74abce67b927788e4f9f64fc63073d37.zip
Update to Rust 2018
This moves all crates in the workspace to the latest Rust standard and resolves various style and formatting issues. Fixes #32.
Diffstat (limited to 'utf8parse/tests/utf-8-demo.rs')
-rw-r--r--utf8parse/tests/utf-8-demo.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/utf8parse/tests/utf-8-demo.rs b/utf8parse/tests/utf-8-demo.rs
new file mode 100644
index 0000000..e60ce22
--- /dev/null
+++ b/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).to_string();
+
+ assert_eq!(actual.0, expected);
+}