@@ -9,10 +9,10 @@ use std::io::{Read, Seek};
99use std:: path:: { Path , PathBuf } ;
1010use std:: time:: Duration ;
1111use tmc_langs_framework:: {
12- nom:: { branch, bytes, character, combinator , error:: VerboseError , multi , sequence, IResult } ,
12+ nom:: { branch, bytes, character, error:: VerboseError , sequence, IResult } ,
1313 LanguagePlugin , TmcCommand , TmcError , { ExerciseDesc , RunResult , TestDesc } ,
1414} ;
15- use tmc_langs_util:: file_util;
15+ use tmc_langs_util:: { file_util, parse_util } ;
1616use zip:: ZipArchive ;
1717
1818#[ derive( Default ) ]
@@ -143,13 +143,16 @@ impl LanguagePlugin for RPlugin {
143143 }
144144
145145 fn points_parser ( i : & str ) -> IResult < & str , Vec < & str > , VerboseError < & str > > {
146- let mut test_parser = sequence:: preceded (
146+ let test_parser = sequence:: preceded (
147147 sequence:: tuple ( (
148148 bytes:: complete:: tag ( "test" ) ,
149149 character:: complete:: multispace0,
150150 character:: complete:: char ( '(' ) ,
151151 character:: complete:: multispace0,
152- arg_parser,
152+ parse_util:: string, // parses the first argument which should be a string
153+ character:: complete:: multispace0,
154+ character:: complete:: char ( ',' ) ,
155+ character:: complete:: multispace0,
153156 ) ) ,
154157 c_parser,
155158 ) ;
@@ -163,48 +166,19 @@ impl LanguagePlugin for RPlugin {
163166 c_parser,
164167 ) ;
165168
166- // todo: currently cannot handle function calls with multiple parameters, probably not a problem
167- fn arg_parser ( i : & str ) -> IResult < & str , & str , VerboseError < & str > > {
168- combinator:: value (
169- "" ,
170- sequence:: tuple ( (
171- bytes:: complete:: take_till ( |c : char | c == ',' ) ,
172- character:: complete:: char ( ',' ) ,
173- character:: complete:: multispace0,
174- ) ) ,
175- ) ( i)
176- }
177-
178169 fn c_parser ( i : & str ) -> IResult < & str , Vec < & str > , VerboseError < & str > > {
179- combinator :: map (
170+ sequence :: delimited (
180171 sequence:: tuple ( (
181172 character:: complete:: char ( 'c' ) ,
182173 character:: complete:: multispace0,
183174 character:: complete:: char ( '(' ) ,
184175 character:: complete:: multispace0,
185- multi:: separated_list1 (
186- sequence:: tuple ( (
187- character:: complete:: multispace0,
188- character:: complete:: char ( ',' ) ,
189- character:: complete:: multispace0,
190- ) ) ,
191- string_parser,
192- ) ,
193- character:: complete:: multispace0,
194- character:: complete:: char ( ')' ) ,
195176 ) ) ,
196- |t| t. 4 ,
197- ) ( i)
198- }
199-
200- fn string_parser ( i : & str ) -> IResult < & str , & str , VerboseError < & str > > {
201- combinator:: map (
177+ parse_util:: comma_separated_strings,
202178 sequence:: tuple ( (
203- character:: complete:: char ( '"' ) ,
204- bytes:: complete:: is_not ( "\" " ) ,
205- character:: complete:: char ( '"' ) ,
179+ character:: complete:: multispace0,
180+ character:: complete:: char ( ')' ) ,
206181 ) ) ,
207- |r| str:: trim ( r. 1 ) ,
208182 ) ( i)
209183 }
210184
556530 let points = RPlugin :: get_available_points ( temp. path ( ) ) . unwrap ( ) ;
557531 assert_eq ! ( points, & [ "r1" , "r2" , "r3" ] ) ;
558532 }
533+
534+ #[ test]
535+ fn parses_first_arg_with_comma_regression ( ) {
536+ init ( ) ;
537+
538+ let temp = tempfile:: tempdir ( ) . unwrap ( ) ;
539+ file_to (
540+ & temp,
541+ "tests/testthat/testExercise.R" ,
542+ r#"
543+ something
544+ test("some test, with a comma", c("r1", "r2", "r3"))
545+ etc
546+ "# ,
547+ ) ;
548+
549+ let points = RPlugin :: get_available_points ( temp. path ( ) ) . unwrap ( ) ;
550+ assert_eq ! ( points, & [ "r1" , "r2" , "r3" ] ) ;
551+ }
559552}
0 commit comments