Skip to content

Commit 35cefaa

Browse files
author
Joe Grund
authored
Preserve leading 0s for disjoint items. (#9)
Signed-off-by: Joe Grund <jgrund@whamcloud.io>
1 parent 339af12 commit 35cefaa

16 files changed

Lines changed: 211 additions & 66 deletions

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description = "Parses hostlist expressions into a Vec of Strings"
44
repository = "https://github.com/whamcloud/hostlist-parser"
55
keywords = ["hostlist", "pdsh", "hpc", "cluster"]
66
license = "MIT"
7-
version = "0.1.4"
7+
version = "0.1.5"
88
authors = ["EMF Team <emf@whamcloud.com>"]
99
edition = "2021"
1010

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# hostlist-parser
22

3-
![Crates.io](https://img.shields.io/crates/v/hostlist-parser) ![docs.rs](https://docs.rs/hostlist-parser/badge.svg?version=0.1.4)
3+
![Crates.io](https://img.shields.io/crates/v/hostlist-parser) ![docs.rs](https://docs.rs/hostlist-parser/badge.svg?version=0.1.5)
44

55
Parses hostlist expressions into a deduped `Vec` of Strings
66

src/lib.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ where
7777
many1(digit())
7878
}
7979

80-
fn parsed_digits<I>() -> impl Parser<I, Output = u64>
81-
where
82-
I: Stream<Token = char>,
83-
I::Error: ParseError<I::Token, I::Range, I::Position>,
84-
{
85-
digits().and_then(|x| x.parse::<u64>().map_err(StreamErrorFor::<I>::other))
86-
}
87-
8880
fn leading_zeros<I>() -> impl Parser<I, Output = (usize, u64)>
8981
where
9082
I: Stream<Token = char>,
@@ -156,7 +148,7 @@ where
156148

157149
sep_by1(
158150
optional_spaces()
159-
.with(parsed_digits())
151+
.with(leading_zeros())
160152
.skip(optional_spaces()),
161153
attempt(comma().skip(not_name)),
162154
)
@@ -285,6 +277,7 @@ mod tests {
285277
fn test_disjoint_digits() {
286278
assert_debug_snapshot!(disjoint_digits().easy_parse("1,2,3,4,5]"));
287279
assert_debug_snapshot!(disjoint_digits().easy_parse("1,2,3-5"));
280+
assert_debug_snapshot!(disjoint_digits().easy_parse("1,2,006,0007,3-5"));
288281
}
289282

290283
#[test]
@@ -484,4 +477,10 @@ mod tests {
484477
parse("hostname]00[asdf")
485478
);
486479
}
480+
481+
#[test]
482+
483+
fn test_parse_osts() {
484+
assert_debug_snapshot!("Leading 0s", parse("OST01[00,01]"));
485+
}
487486
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: src/lib.rs
3+
expression: "parse(\"OST01[00,01]\")"
4+
---
5+
Ok(
6+
[
7+
"OST0100",
8+
"OST0101",
9+
],
10+
)

src/snapshots/hostlist_parser__tests__disjoint_digits-2.snap

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ Ok(
66
(
77
Disjoint(
88
[
9-
1,
10-
2,
9+
(
10+
0,
11+
1,
12+
),
13+
(
14+
0,
15+
2,
16+
),
1117
],
1218
),
1319
",3-5",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
source: src/lib.rs
3+
expression: "disjoint_digits().easy_parse(\"1,2,006,0007,3-5\")"
4+
---
5+
Ok(
6+
(
7+
Disjoint(
8+
[
9+
(
10+
0,
11+
1,
12+
),
13+
(
14+
0,
15+
2,
16+
),
17+
(
18+
2,
19+
6,
20+
),
21+
(
22+
3,
23+
7,
24+
),
25+
],
26+
),
27+
",3-5",
28+
),
29+
)

src/snapshots/hostlist_parser__tests__disjoint_digits.snap

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,26 @@ Ok(
66
(
77
Disjoint(
88
[
9-
1,
10-
2,
11-
3,
12-
4,
13-
5,
9+
(
10+
0,
11+
1,
12+
),
13+
(
14+
0,
15+
2,
16+
),
17+
(
18+
0,
19+
3,
20+
),
21+
(
22+
0,
23+
4,
24+
),
25+
(
26+
0,
27+
5,
28+
),
1429
],
1530
),
1631
"]",

src/snapshots/hostlist_parser__tests__hostlist-2.snap

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ Ok(
1212
[
1313
Disjoint(
1414
[
15-
1,
16-
2,
15+
(
16+
0,
17+
1,
18+
),
19+
(
20+
0,
21+
2,
22+
),
1723
],
1824
),
1925
],

src/snapshots/hostlist_parser__tests__hostlist-3.snap

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@ Ok(
1212
[
1313
Disjoint(
1414
[
15-
2,
16-
6,
17-
7,
15+
(
16+
0,
17+
2,
18+
),
19+
(
20+
0,
21+
6,
22+
),
23+
(
24+
0,
25+
7,
26+
),
1827
],
1928
),
2029
],

src/snapshots/hostlist_parser__tests__hostlists-2.snap

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ Ok(
1313
[
1414
Disjoint(
1515
[
16-
1,
17-
2,
16+
(
17+
0,
18+
1,
19+
),
20+
(
21+
0,
22+
2,
23+
),
1824
],
1925
),
2026
],

0 commit comments

Comments
 (0)