@@ -422,6 +422,88 @@ more text with spaces
422
422
}
423
423
}
424
424
425
+ mod render_markdown_with_abs_path {
426
+ use super :: super :: render_markdown_with_abs_path;
427
+ use std:: path:: Path ;
428
+
429
+ #[ test]
430
+ fn preserves_external_links ( ) {
431
+ assert_eq ! (
432
+ render_markdown_with_abs_path(
433
+ "[example](https://www.rust-lang.org/)" ,
434
+ false ,
435
+ None ,
436
+ Some ( & "ABS_PATH" . to_string( ) )
437
+ ) ,
438
+ "<p><a href=\" https://www.rust-lang.org/\" >example</a></p>\n "
439
+ ) ;
440
+ }
441
+
442
+ #[ test]
443
+ fn replace_root_links ( ) {
444
+ assert_eq ! (
445
+ render_markdown_with_abs_path(
446
+ "[example](/testing)" ,
447
+ false ,
448
+ None ,
449
+ Some ( & "ABS_PATH" . to_string( ) )
450
+ ) ,
451
+ "<p><a href=\" ABS_PATH/testing\" >example</a></p>\n "
452
+ ) ;
453
+ }
454
+
455
+ #[ test]
456
+ fn replace_root_links_using_path ( ) {
457
+ assert_eq ! (
458
+ render_markdown_with_abs_path(
459
+ "[example](bar.md)" ,
460
+ false ,
461
+ Some ( Path :: new( "foo/chapter.md" ) ) ,
462
+ Some ( & "ABS_PATH" . to_string( ) )
463
+ ) ,
464
+ "<p><a href=\" ABS_PATH/foo/bar.html\" >example</a></p>\n "
465
+ ) ;
466
+ assert_eq ! (
467
+ render_markdown_with_abs_path(
468
+ "[example](/bar.md)" ,
469
+ false ,
470
+ Some ( Path :: new( "foo/chapter.md" ) ) ,
471
+ Some ( & "ABS_PATH" . to_string( ) )
472
+ ) ,
473
+ "<p><a href=\" ABS_PATH/foo/bar.html\" >example</a></p>\n "
474
+ ) ;
475
+ assert_eq ! (
476
+ render_markdown_with_abs_path(
477
+ "[example](/bar.html)" ,
478
+ false ,
479
+ Some ( Path :: new( "foo/chapter.md" ) ) ,
480
+ None
481
+ ) ,
482
+ "<p><a href=\" foo/bar.html\" >example</a></p>\n "
483
+ ) ;
484
+ }
485
+
486
+ #[ test]
487
+ fn preserves_relative_links ( ) {
488
+ assert_eq ! (
489
+ render_markdown_with_abs_path(
490
+ "[example](../testing)" ,
491
+ false ,
492
+ None ,
493
+ Some ( & "ABS_PATH" . to_string( ) )
494
+ ) ,
495
+ "<p><a href=\" ../testing\" >example</a></p>\n "
496
+ ) ;
497
+ }
498
+
499
+ #[ test]
500
+ fn preserves_root_links ( ) {
501
+ assert_eq ! (
502
+ render_markdown_with_abs_path( "[example](/testing)" , false , None , None ) ,
503
+ "<p><a href=\" /testing\" >example</a></p>\n "
504
+ ) ;
505
+ }
506
+ }
425
507
#[ allow( deprecated) ]
426
508
mod id_from_content {
427
509
use super :: super :: id_from_content;
0 commit comments