File: lib.rs

package info (click to toggle)
rust-unescape 0.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 96 kB
  • sloc: makefile: 4
file content (44 lines) | stat: -rw-r--r-- 1,273 bytes parent folder | download
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
32
33
34
35
36
37
38
39
40
41
42
43
44
extern crate unescape;

use unescape::unescape;

macro_rules! assert_some_string {
    ($s1:expr, $s2:expr) => {
        assert_eq!(Some(String::from($s1)), unescape($s2));
    }
}

#[test]
fn no_escapes() {
    assert_some_string!("", "");
    assert_some_string!("hello", "hello");
    assert_some_string!("these are some pretty crazy strings here", "these are some pretty crazy strings here");
}

#[test]
fn control_chars() {
    assert_some_string!("First line\nSecond line", r"First line\nSecond line");
    assert_some_string!("First line\r\nSecond line", r"First line\r\nSecond line");
    assert_some_string!("Unindented\tIndented", r"Unindented\tIndented");
    assert_some_string!("'This is singly quoted!'", r"\'This is singly quoted!\'");
    assert_some_string!("\"This is doubly quoted!\"", r#"\"This is doubly quoted!\""#);
    assert_some_string!("This is one backslash: \\", r"This is one backslash: \\");
}

#[test]
fn unicode_chars() {
    assert_some_string!("\n", r"\u000A");
    assert_some_string!("\u{1234}", r"\u1234");
}

#[test]
fn byte_chars() {
    assert_some_string!("\n", r"\x0A");
    assert_some_string!("\x23", r"\x23");
}

#[test]
fn octal_chars() {
    assert_some_string!("\n", r"\12");
    assert_some_string!("\u{00C4}", r"\304");
}