Debian Codegraph @

third_party/rust/ron/tests/comments.rs

raw
1 use ron::de::{from_str, Error, Position, SpannedError as RonErr};
2
3 #[test]
4 fn test_simple() {
5 assert_eq!(
6 from_str(
7 "/*
8 * We got a hexadecimal number here!
9 *
10 */0x507"
11 ),
12 Ok(0x507)
13 );
14 }
15
16 #[test]
17 fn test_nested() {
18 assert_eq!(
19 from_str(
20 "/*
21 /* quite * some * nesting * going * on * /* here /* (yeah, maybe a bit too much) */ */ */
22 */
23 // The actual value comes.. /*
24 // very soon, these are just checks that */
25 // multi-line comments don't trigger in line comments /*
26 \"THE VALUE\" /* This is the value /* :) */ */
27 "
28 ),
29 Ok("THE VALUE".to_owned())
30 );
31 }
32
33 #[test]
34 fn test_unclosed() {
35 assert_eq!(
36 from_str::<String>("\"hi\" /*"),
37 Err(RonErr {
38 code: Error::UnclosedBlockComment,
39 position: Position { line: 1, col: 8 }
40 })
41 );
42 assert_eq!(
43 from_str::<String>(
44 "/*
45 /* quite * some * nesting * going * on * /* here /* (yeah, maybe a bit too much) */ */ */
46 */
47 // The actual value comes.. /*
48 // very soon, these are just checks that */
49 // multi-line comments don't trigger in line comments /*
50 /* Unfortunately, this comment won't get closed :(
51 \"THE VALUE (which is invalid)\"
52 "
53 ),
54 Err(RonErr {
55 code: Error::UnclosedBlockComment,
56 position: Position { line: 9, col: 1 }
57 })
58 );
59 }
60
61 #[test]
62 fn test_unexpected_byte() {
63 assert_eq!(
64 from_str::<u8>("42 /q"),
65 Err(RonErr {
66 code: Error::UnexpectedChar('q'),
67 position: Position { line: 1, col: 6 },
68 })
69 );
70 }