summaryrefslogtreecommitdiffstats
path: root/vendor/utf8parse/tests/utf-8-demo.rs
blob: 51df49273061ffb59807eead1c4547af995c5d18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);
}