@@ -9,10 +9,10 @@ use std::io::{Read, Seek};
9
9
use std:: path:: { Path , PathBuf } ;
10
10
use std:: time:: Duration ;
11
11
use tmc_langs_framework:: {
12
- nom:: { branch, bytes, character, combinator , error:: VerboseError , multi , sequence, IResult } ,
12
+ nom:: { branch, bytes, character, error:: VerboseError , sequence, IResult } ,
13
13
LanguagePlugin , TmcCommand , TmcError , { ExerciseDesc , RunResult , TestDesc } ,
14
14
} ;
15
- use tmc_langs_util:: file_util;
15
+ use tmc_langs_util:: { file_util, parse_util } ;
16
16
use zip:: ZipArchive ;
17
17
18
18
#[ derive( Default ) ]
@@ -143,13 +143,16 @@ impl LanguagePlugin for RPlugin {
143
143
}
144
144
145
145
fn points_parser ( i : & str ) -> IResult < & str , Vec < & str > , VerboseError < & str > > {
146
- let mut test_parser = sequence:: preceded (
146
+ let test_parser = sequence:: preceded (
147
147
sequence:: tuple ( (
148
148
bytes:: complete:: tag ( "test" ) ,
149
149
character:: complete:: multispace0,
150
150
character:: complete:: char ( '(' ) ,
151
151
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,
153
156
) ) ,
154
157
c_parser,
155
158
) ;
@@ -163,48 +166,19 @@ impl LanguagePlugin for RPlugin {
163
166
c_parser,
164
167
) ;
165
168
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
-
178
169
fn c_parser ( i : & str ) -> IResult < & str , Vec < & str > , VerboseError < & str > > {
179
- combinator :: map (
170
+ sequence :: delimited (
180
171
sequence:: tuple ( (
181
172
character:: complete:: char ( 'c' ) ,
182
173
character:: complete:: multispace0,
183
174
character:: complete:: char ( '(' ) ,
184
175
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 ( ')' ) ,
195
176
) ) ,
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,
202
178
sequence:: tuple ( (
203
- character:: complete:: char ( '"' ) ,
204
- bytes:: complete:: is_not ( "\" " ) ,
205
- character:: complete:: char ( '"' ) ,
179
+ character:: complete:: multispace0,
180
+ character:: complete:: char ( ')' ) ,
206
181
) ) ,
207
- |r| str:: trim ( r. 1 ) ,
208
182
) ( i)
209
183
}
210
184
556
530
let points = RPlugin :: get_available_points ( temp. path ( ) ) . unwrap ( ) ;
557
531
assert_eq ! ( points, & [ "r1" , "r2" , "r3" ] ) ;
558
532
}
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
+ }
559
552
}
0 commit comments