Skip to content

Commit

Permalink
Add char tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Mar 6, 2017
1 parent 3279a8d commit 1d6a1c6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions json_tests/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,25 @@ fn test_write_bool() {
test_pretty_encode_ok(tests);
}

#[test]
fn test_write_char() {
let tests = &[
('n', "\"n\""),
('"', "\"\\\"\""),
('\\', "\"\\\\\""),
('/', "\"/\""),
('\x08', "\"\\b\""),
('\x0C', "\"\\f\""),
('\n', "\"\\n\""),
('\r', "\"\\r\""),
('\t', "\"\\t\""),
('\x0B', "\"\\u000b\""),
('\u{3A3}', "\"\u{3A3}\""),
];
test_encode_ok(tests);
test_pretty_encode_ok(tests);
}

#[test]
fn test_write_list() {
test_encode_ok(&[
Expand Down Expand Up @@ -801,6 +820,29 @@ fn test_parse_bool() {
]);
}

#[test]
fn test_parse_char() {
test_parse_err::<char>(vec![
("\"ab\"", "invalid value: string \"ab\", expected a character at line 1 column 4"),
("10", "invalid type: integer `10`, expected a character at line 1 column 2"),
]);

test_parse_ok(vec![
("\"n\"", 'n'),
("\"\\\"\"", '"'),
("\"\\\\\"", '\\'),
("\"/\"", '/'),
("\"\\b\"", '\x08'),
("\"\\f\"", '\x0C'),
("\"\\n\"", '\n'),
("\"\\r\"", '\r'),
("\"\\t\"", '\t'),
("\"\\u000b\"", '\x0B'),
("\"\\u000B\"", '\x0B'),
("\"\u{3A3}\"", '\u{3A3}'),
]);
}

#[test]
fn test_parse_number_errors() {
test_parse_err::<f64>(vec![
Expand Down

0 comments on commit 1d6a1c6

Please sign in to comment.