Skip to content

Commit 079ca09

Browse files
committed
rustell wip
1 parent db321a8 commit 079ca09

File tree

2 files changed

+135
-1
lines changed

2 files changed

+135
-1
lines changed

rust/rustell/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ fn use_parser<'src>()
5454

5555
let group = use_parser
5656
.separated_by(just(','))
57+
.allow_trailing()
5758
.collect::<Vec<_>>()
58-
.delimited_by(just('{'), just('}'))
59+
.delimited_by(just('{').padded(), just('}').padded())
5960
.map(UseExpr::Group);
6061

6162
let glob = just("*").padded().map(|_| UseExpr::Glob);

rust/rustell/tests/integration.rs

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,136 @@ fn test_parser_other_then_use() {
165165
];
166166
assert_eq!(lhs, rhs)
167167
}
168+
169+
#[test]
170+
fn test_parser_multiple() {
171+
let src = r#"
172+
use std::io;
173+
use std::fs;
174+
"#;
175+
let lhs = parser().parse(src).into_result().unwrap();
176+
let rhs = vec![
177+
Expr::Use(UseExpr::Path {
178+
ident: "std",
179+
rename: None,
180+
nested: Some(Box::new(UseExpr::Path {
181+
ident: "io",
182+
rename: None,
183+
nested: None,
184+
})),
185+
}),
186+
Expr::Use(UseExpr::Path {
187+
ident: "std",
188+
rename: None,
189+
nested: Some(Box::new(UseExpr::Path {
190+
ident: "fs",
191+
rename: None,
192+
nested: None,
193+
})),
194+
}),
195+
];
196+
assert_eq!(lhs, rhs)
197+
}
198+
199+
#[test]
200+
fn test_parser_multiple_with_other() {
201+
let src = r#"
202+
use std::io;
203+
fn test() {
204+
println!("Hello");
205+
}
206+
use std::fs;
207+
"#;
208+
let lhs = parser().parse(src).into_result().unwrap();
209+
let rhs = vec![
210+
Expr::Use(UseExpr::Path {
211+
ident: "std",
212+
rename: None,
213+
nested: Some(Box::new(UseExpr::Path {
214+
ident: "io",
215+
rename: None,
216+
nested: None,
217+
})),
218+
}),
219+
Expr::Other(
220+
r#"fn test() {
221+
println!("Hello");
222+
}"#,
223+
),
224+
Expr::Use(UseExpr::Path {
225+
ident: "std",
226+
rename: None,
227+
nested: Some(Box::new(UseExpr::Path {
228+
ident: "fs",
229+
rename: None,
230+
nested: None,
231+
})),
232+
}),
233+
];
234+
assert_eq!(lhs, rhs)
235+
}
236+
237+
#[test]
238+
fn test_parser_mixed_all_cases() {
239+
let src = r#"
240+
use std::{
241+
io::{self, Read as R},
242+
fs::*,
243+
};
244+
use crate::module::Type as T;
245+
246+
fn hello() {
247+
println!("Hello");
248+
}
249+
"#;
250+
let lhs = parser().parse(src).into_result().unwrap();
251+
let rhs = vec![
252+
Expr::Use(UseExpr::Path {
253+
ident: "std",
254+
rename: None,
255+
nested: Some(Box::new(UseExpr::Group(vec![
256+
UseExpr::Path {
257+
ident: "io",
258+
rename: None,
259+
nested: Some(Box::new(UseExpr::Group(vec![
260+
UseExpr::Path {
261+
ident: "self",
262+
rename: None,
263+
nested: None,
264+
},
265+
UseExpr::Path {
266+
ident: "Read",
267+
rename: Some("R"),
268+
nested: None,
269+
},
270+
]))),
271+
},
272+
UseExpr::Path {
273+
ident: "fs",
274+
rename: None,
275+
nested: Some(Box::new(UseExpr::Glob)),
276+
},
277+
]))),
278+
}),
279+
Expr::Use(UseExpr::Path {
280+
ident: "crate",
281+
rename: None,
282+
nested: Some(Box::new(UseExpr::Path {
283+
ident: "module",
284+
rename: None,
285+
nested: Some(Box::new(UseExpr::Path {
286+
ident: "Type",
287+
rename: Some("T"),
288+
nested: None,
289+
})),
290+
})),
291+
}),
292+
Expr::Other(
293+
r#"fn hello() {
294+
println!("Hello");
295+
}
296+
"#,
297+
),
298+
];
299+
assert_eq!(lhs, rhs)
300+
}

0 commit comments

Comments
 (0)