Skip to content

Commit c1bc101

Browse files
committed
proper point parsing for R
1 parent 86bfa70 commit c1bc101

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

plugins/r/src/plugin.rs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tmc_langs_framework::{
1212
command::TmcCommand,
1313
domain::{ExerciseDesc, RunResult, TestDesc},
1414
io::file_util,
15-
nom::IResult,
15+
nom::{bytes, character, combinator, sequence, IResult},
1616
zip::ZipArchive,
1717
LanguagePlugin, TmcError,
1818
};
@@ -134,9 +134,28 @@ impl LanguagePlugin for RPlugin {
134134
vec![PathBuf::from("tests")]
135135
}
136136

137-
fn points_parser<'a>(_i: &'a str) -> IResult<&'a str, &'a str> {
138-
// no points annotations
139-
Ok(("", ""))
137+
fn points_parser<'a>(i: &'a str) -> IResult<&'a str, &'a str> {
138+
combinator::map(
139+
sequence::delimited(
140+
sequence::tuple((
141+
bytes::complete::tag("test"),
142+
character::complete::multispace0,
143+
character::complete::char('('),
144+
bytes::complete::take_until(","),
145+
bytes::complete::take_until("\""),
146+
)),
147+
sequence::delimited(
148+
character::complete::char('"'),
149+
bytes::complete::is_not("\""),
150+
character::complete::char('"'),
151+
),
152+
sequence::tuple((
153+
character::complete::multispace0,
154+
character::complete::char(')'),
155+
)),
156+
),
157+
str::trim,
158+
)(i)
140159
}
141160
}
142161

@@ -283,4 +302,20 @@ mod test {
283302
let dir = RPlugin::find_project_dir_in_zip(&mut zip);
284303
assert!(dir.is_err());
285304
}
305+
306+
#[test]
307+
fn parses_points() {
308+
let target = "asd";
309+
assert!(RPlugin::points_parser(target).is_err());
310+
311+
let target = "test ( \"first arg\", \"second arg but no brace\"";
312+
assert!(RPlugin::points_parser(target).is_err());
313+
314+
let target = r#"test("1d and 1e are solved correctly", c("W1A.1.2"), {
315+
expect_equivalent(z, z_correct, tolerance=1e-5)
316+
expect_true(areEqual(res, res_correct))
317+
})
318+
"#;
319+
assert_eq!(RPlugin::points_parser(target).unwrap().1, "W1A.1.2");
320+
}
286321
}

0 commit comments

Comments
 (0)