@@ -174,7 +174,8 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
174
174
slice:: raw:: buf_as_slice ( ( * lang) . data ,
175
175
( * lang) . size as uint , |rlang| {
176
176
let rlang = str:: from_utf8 ( rlang) . unwrap ( ) ;
177
- if LangString :: parse ( rlang) . notrust {
177
+ let ( _, _, _, notrust) = parse_lang_string ( rlang) ;
178
+ if notrust {
178
179
( my_opaque. dfltblk ) ( ob, & buf, lang,
179
180
opaque as * mut libc:: c_void ) ;
180
181
true
@@ -195,7 +196,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
195
196
stripped_filtered_line ( l) . unwrap_or ( l)
196
197
} ) . collect :: < Vec < & str > > ( ) . connect ( "\n " ) ;
197
198
let krate = krate. as_ref ( ) . map ( |s| s. as_slice ( ) ) ;
198
- let test = test:: maketest ( test. as_slice ( ) , krate, false , false ) ;
199
+ let test = test:: maketest ( test. as_slice ( ) , krate, false ) ;
199
200
s. push_str ( format ! ( "<span id='rust-example-raw-{}' \
200
201
class='rusttest'>{}</span>",
201
202
i, Escape ( test. as_slice( ) ) ) . as_slice ( ) ) ;
@@ -308,16 +309,16 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
308
309
lang : * hoedown_buffer , opaque : * mut libc:: c_void ) {
309
310
unsafe {
310
311
if text. is_null ( ) { return }
311
- let block_info = if lang. is_null ( ) {
312
- LangString :: all_false ( )
312
+ let ( should_fail , no_run , ignore , notrust ) = if lang. is_null ( ) {
313
+ ( false , false , false , false )
313
314
} else {
314
315
slice:: raw:: buf_as_slice ( ( * lang) . data ,
315
316
( * lang) . size as uint , |lang| {
316
317
let s = str:: from_utf8 ( lang) . unwrap ( ) ;
317
- LangString :: parse ( s)
318
+ parse_lang_string ( s)
318
319
} )
319
320
} ;
320
- if block_info . notrust { return }
321
+ if notrust { return }
321
322
slice:: raw:: buf_as_slice ( ( * text) . data , ( * text) . size as uint , |text| {
322
323
let opaque = opaque as * mut hoedown_html_renderer_state ;
323
324
let tests = & mut * ( ( * opaque) . opaque as * mut :: test:: Collector ) ;
@@ -326,9 +327,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
326
327
stripped_filtered_line ( l) . unwrap_or ( l)
327
328
} ) ;
328
329
let text = lines. collect :: < Vec < & str > > ( ) . connect ( "\n " ) ;
329
- tests. add_test ( text. to_string ( ) ,
330
- block_info. should_fail , block_info. no_run ,
331
- block_info. ignore , block_info. test_harness ) ;
330
+ tests. add_test ( text. to_string ( ) , should_fail, no_run, ignore) ;
332
331
} )
333
332
}
334
333
}
@@ -366,52 +365,33 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
366
365
}
367
366
}
368
367
369
- #[ deriving( Eq , PartialEq , Clone , Show ) ]
370
- struct LangString {
371
- should_fail : bool ,
372
- no_run : bool ,
373
- ignore : bool ,
374
- notrust : bool ,
375
- test_harness : bool ,
376
- }
377
-
378
- impl LangString {
379
- fn all_false ( ) -> LangString {
380
- LangString {
381
- should_fail : false ,
382
- no_run : false ,
383
- ignore : false ,
384
- notrust : false ,
385
- test_harness : false ,
368
+ fn parse_lang_string ( string : & str ) -> ( bool , bool , bool , bool ) {
369
+ let mut seen_rust_tags = false ;
370
+ let mut seen_other_tags = false ;
371
+ let mut should_fail = false ;
372
+ let mut no_run = false ;
373
+ let mut ignore = false ;
374
+ let mut notrust = false ;
375
+
376
+ let mut tokens = string. as_slice ( ) . split ( |c : char |
377
+ !( c == '_' || c == '-' || c. is_alphanumeric ( ) )
378
+ ) ;
379
+
380
+ for token in tokens {
381
+ match token {
382
+ "" => { } ,
383
+ "should_fail" => { should_fail = true ; seen_rust_tags = true ; } ,
384
+ "no_run" => { no_run = true ; seen_rust_tags = true ; } ,
385
+ "ignore" => { ignore = true ; seen_rust_tags = true ; } ,
386
+ "notrust" => { notrust = true ; seen_rust_tags = true ; } ,
387
+ "rust" => { notrust = false ; seen_rust_tags = true ; } ,
388
+ _ => { seen_other_tags = true }
386
389
}
387
390
}
388
391
389
- fn parse ( string : & str ) -> LangString {
390
- let mut seen_rust_tags = false ;
391
- let mut seen_other_tags = false ;
392
- let mut data = LangString :: all_false ( ) ;
393
-
394
- let mut tokens = string. as_slice ( ) . split ( |c : char |
395
- !( c == '_' || c == '-' || c. is_alphanumeric ( ) )
396
- ) ;
397
-
398
- for token in tokens {
399
- match token {
400
- "" => { } ,
401
- "should_fail" => { data. should_fail = true ; seen_rust_tags = true ; } ,
402
- "no_run" => { data. no_run = true ; seen_rust_tags = true ; } ,
403
- "ignore" => { data. ignore = true ; seen_rust_tags = true ; } ,
404
- "notrust" => { data. notrust = true ; seen_rust_tags = true ; } ,
405
- "rust" => { data. notrust = false ; seen_rust_tags = true ; } ,
406
- "test_harness" => { data. test_harness = true ; seen_rust_tags = true ; }
407
- _ => { seen_other_tags = true }
408
- }
409
- }
410
-
411
- data. notrust |= seen_other_tags && !seen_rust_tags;
392
+ let notrust = notrust || ( seen_other_tags && !seen_rust_tags) ;
412
393
413
- data
414
- }
394
+ ( should_fail, no_run, ignore, notrust)
415
395
}
416
396
417
397
/// By default this markdown renderer generates anchors for each header in the
@@ -445,32 +425,19 @@ impl<'a> fmt::Show for MarkdownWithToc<'a> {
445
425
446
426
#[ cfg( test) ]
447
427
mod tests {
448
- use super :: LangString ;
428
+ use super :: parse_lang_string ;
449
429
450
430
#[ test]
451
- fn test_lang_string_parse ( ) {
452
- fn t ( s : & str ,
453
- should_fail : bool , no_run : bool , ignore : bool , notrust : bool , test_harness : bool ) {
454
- assert_eq ! ( LangString :: parse( s) , LangString {
455
- should_fail: should_fail,
456
- no_run: no_run,
457
- ignore: ignore,
458
- notrust: notrust,
459
- test_harness: test_harness,
460
- } )
461
- }
462
-
463
- t ( "" , false , false , false , false , false ) ;
464
- t ( "rust" , false , false , false , false , false ) ;
465
- t ( "sh" , false , false , false , true , false ) ;
466
- t ( "notrust" , false , false , false , true , false ) ;
467
- t ( "ignore" , false , false , true , false , false ) ;
468
- t ( "should_fail" , true , false , false , false , false ) ;
469
- t ( "no_run" , false , true , false , false , false ) ;
470
- t ( "test_harness" , false , false , false , false , true ) ;
471
- t ( "{.no_run .example}" , false , true , false , false , false ) ;
472
- t ( "{.sh .should_fail}" , true , false , false , false , false ) ;
473
- t ( "{.example .rust}" , false , false , false , false , false ) ;
474
- t ( "{.test_harness .rust}" , false , false , false , false , true ) ;
431
+ fn test_parse_lang_string ( ) {
432
+ assert_eq ! ( parse_lang_string( "" ) , ( false , false , false , false ) )
433
+ assert_eq ! ( parse_lang_string( "rust" ) , ( false , false , false , false ) )
434
+ assert_eq ! ( parse_lang_string( "sh" ) , ( false , false , false , true ) )
435
+ assert_eq ! ( parse_lang_string( "notrust" ) , ( false , false , false , true ) )
436
+ assert_eq ! ( parse_lang_string( "ignore" ) , ( false , false , true , false ) )
437
+ assert_eq ! ( parse_lang_string( "should_fail" ) , ( true , false , false , false ) )
438
+ assert_eq ! ( parse_lang_string( "no_run" ) , ( false , true , false , false ) )
439
+ assert_eq ! ( parse_lang_string( "{.no_run .example}" ) , ( false , true , false , false ) )
440
+ assert_eq ! ( parse_lang_string( "{.sh .should_fail}" ) , ( true , false , false , false ) )
441
+ assert_eq ! ( parse_lang_string( "{.example .rust}" ) , ( false , false , false , false ) )
475
442
}
476
443
}
0 commit comments