-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.rs
66 lines (58 loc) · 1.42 KB
/
mod.rs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::fmt::Display;
mod ini;
mod rwini;
pub use self::ini::*;
pub use self::rwini::*;
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct Position {
pub row: usize,
pub col: usize,
}
impl Display for Position {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}, {})", self.row, self.col)
}
}
impl From<(usize, usize)> for Position {
fn from(value: (usize, usize)) -> Self {
Self {
row: value.0,
col: value.1,
}
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct Range {
pub start: Position,
pub end: Position,
}
impl Display for Range {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}, {})", self.start, self.end)
}
}
#[cfg(test)]
mod test {
mod ini_parser {
use crate::parser::IniParser;
#[test]
fn test_parse() {
let parser = IniParser::default();
assert_eq!(parser.parse("[core]"), Ok([("core", []).into(),].into()));
assert_eq!(
parser.parse("[core]\nname: abc\nprice: '''1\n2\n'''"),
Ok([("core", [("name", "abc"), ("price", "12"),]).into(),].into())
);
assert_eq!(
parser.parse("[core]\nname: abc\nprice: '''1\n2\n'''\n[abc]\ndef:abc"),
Ok(
[
("core", [("name", "abc"), ("price", "12"),]).into(),
("abc", [("def", "abc")]).into(),
]
.into()
)
);
}
}
}