@@ -673,16 +673,10 @@ pub enum ResolvedWalkthroughElement {
673673mod url_conversion_tests {
674674 use super :: * ;
675675 use pulldown_cmark:: { Parser , Event , Tag } ;
676+ use expect_test:: { expect, Expect } ;
676677
677- #[ test]
678- fn test_markdown_url_conversion ( ) {
679- let markdown = r#"
680- Check out [this function](src/auth.ts?validateToken) and
681- [this line](src/auth.ts#L42) or [this range](src/auth.ts#L42-L50).
682- Also see [the whole file](src/auth.ts) and [this function with spaces](src/auth.rs?fn foo).
683- "# ;
684-
685- let processed = process_markdown_links ( markdown. to_string ( ) ) ;
678+ fn check_extracted_urls ( input : & str , expected : Expect ) {
679+ let processed = process_markdown_links ( input. to_string ( ) ) ;
686680
687681 // Extract URLs using pulldown-cmark parser
688682 let parser = Parser :: new ( & processed) ;
@@ -694,12 +688,26 @@ Also see [the whole file](src/auth.ts) and [this function with spaces](src/auth.
694688 }
695689 }
696690
697- // Verify the converted URLs
698- assert ! ( urls. contains( & "dialectic:src/auth.ts?regex=validateToken" . to_string( ) ) ) ;
699- assert ! ( urls. contains( & "dialectic:src/auth.ts?line=42" . to_string( ) ) ) ;
700- assert ! ( urls. contains( & "dialectic:src/auth.ts?line=42-50" . to_string( ) ) ) ;
701- assert ! ( urls. contains( & "dialectic:src/auth.ts" . to_string( ) ) ) ;
702- assert ! ( urls. contains( & "dialectic:src/auth.rs?regex=fn%20foo" . to_string( ) ) ) ;
691+ expected. assert_debug_eq ( & urls) ;
692+ }
693+
694+ #[ test]
695+ fn test_markdown_url_conversion ( ) {
696+ let markdown = r#"
697+ Check out [this function](src/auth.ts?validateToken) and
698+ [this line](src/auth.ts#L42) or [this range](src/auth.ts#L42-L50).
699+ Also see [the whole file](src/auth.ts) and [this function with spaces](src/auth.rs?fn foo).
700+ "# ;
701+
702+ check_extracted_urls ( markdown, expect ! [ [ r#"
703+ [
704+ "dialectic:src/auth.ts?regex=validateToken",
705+ "dialectic:src/auth.ts?line=42",
706+ "dialectic:src/auth.ts?line=42-50",
707+ "dialectic:src/auth.ts",
708+ "dialectic:src/auth.rs?regex=fn%20foo",
709+ ]
710+ "# ] ] ) ;
703711 }
704712
705713 #[ test]
@@ -716,13 +724,11 @@ But this should be ignored:
716724And this inline code too: `[another fake](src/inline.ts)`
717725"# ;
718726
719- let processed = process_markdown_links ( markdown. to_string ( ) ) ;
720-
721- // Should convert the real link
722- assert ! ( processed. contains( "dialectic:src/real.ts?regex=pattern" ) ) ;
723- // Should NOT convert links in code blocks
724- assert ! ( processed. contains( "[fake link](src/fake.ts?pattern)" ) ) ; // Original unchanged
725- assert ! ( processed. contains( "[another fake](src/inline.ts)" ) ) ; // Original unchanged
727+ check_extracted_urls ( markdown, expect ! [ [ r#"
728+ [
729+ "dialectic:src/real.ts?regex=pattern",
730+ ]
731+ "# ] ] ) ;
726732 }
727733
728734 #[ test]
@@ -732,23 +738,13 @@ Check [file with spaces](src/auth.rs?fn foo) and [file with bracket](src/auth.rs
732738Also [main.rs][] and [utils.ts:42][].
733739"# ;
734740
735- let processed = process_markdown_links ( markdown. to_string ( ) ) ;
736-
737- // Extract URLs using pulldown-cmark parser
738- let parser = Parser :: new ( & processed) ;
739- let mut urls = Vec :: new ( ) ;
740-
741- for event in parser {
742- if let Event :: Start ( Tag :: Link { dest_url, .. } ) = event {
743- urls. push ( dest_url. to_string ( ) ) ;
744- }
745- }
746-
747- // Verify the converted URLs
748- assert ! ( urls. contains( & "dialectic:src/auth.rs?regex=fn%20foo" . to_string( ) ) ) ;
749- assert ! ( urls. contains( & "dialectic:src/auth.rs?regex=fn%7Bbar" . to_string( ) ) ) ; // { encoded
750- // Reference style links should be converted to dialectic: URLs
751- assert ! ( urls. contains( & "dialectic:main.rs" . to_string( ) ) ) ;
752- assert ! ( urls. contains( & "dialectic:utils.ts#L42" . to_string( ) ) ) ;
741+ check_extracted_urls ( markdown, expect ! [ [ r#"
742+ [
743+ "dialectic:src/auth.rs?regex=fn%20foo",
744+ "dialectic:src/auth.rs?regex=fn%7Bbar",
745+ "dialectic:main.rs",
746+ "dialectic:utils.ts#L42",
747+ ]
748+ "# ] ] ) ;
753749 }
754750}
0 commit comments