From 246063fb7cd21a83beae5934f95b2795fb85df51 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 14 Oct 2022 10:49:28 +0200 Subject: Refactor to use default trait in tests --- tests/gfm_footnote.rs | 142 ++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 81 deletions(-) (limited to 'tests/gfm_footnote.rs') diff --git a/tests/gfm_footnote.rs b/tests/gfm_footnote.rs index f5ae0cb..e036857 100644 --- a/tests/gfm_footnote.rs +++ b/tests/gfm_footnote.rs @@ -3,20 +3,12 @@ use markdown::{ mdast::{FootnoteDefinition, FootnoteReference, Node, Paragraph, Root, Text}, to_html, to_html_with_options, to_mdast, unist::Position, - CompileOptions, Constructs, Options, ParseOptions, + CompileOptions, Options, ParseOptions, }; use pretty_assertions::assert_eq; #[test] fn gfm_footnote() -> Result<(), String> { - let gfm = Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, - ..Options::default() - }; - assert_eq!( to_html("A call.[^a]\n\n[^a]: whatevs"), "

A call.^a

\n", @@ -24,7 +16,7 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("A call.[^a]\n\n[^a]: whatevs", &gfm)?, + to_html_with_options("A call.[^a]\n\n[^a]: whatevs", &Options::gfm())?, "

A call.1

Footnotes

    @@ -41,14 +33,11 @@ fn gfm_footnote() -> Result<(), String> { to_html_with_options( "Noot.[^a]\n\n[^a]: dingen", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, + parse: ParseOptions::gfm(), compile: CompileOptions { - gfm_footnote_label: Some("Voetnoten".into()), - gfm_footnote_back_label: Some("Terug naar de inhoud".into()), - ..CompileOptions::default() + gfm_footnote_label: Some("Voetnoten".into()), + gfm_footnote_back_label: Some("Terug naar de inhoud".into()), + ..CompileOptions::gfm() } } )?, @@ -68,13 +57,10 @@ fn gfm_footnote() -> Result<(), String> { to_html_with_options( "[^a]\n\n[^a]: b", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, + parse: ParseOptions::gfm(), compile: CompileOptions { - gfm_footnote_label_tag_name: Some("h1".into()), - ..CompileOptions::default() + gfm_footnote_label_tag_name: Some("h1".into()), + ..CompileOptions::gfm() } } )?, @@ -94,13 +80,10 @@ fn gfm_footnote() -> Result<(), String> { to_html_with_options( "[^a]\n\n[^a]: b", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, + parse: ParseOptions::gfm(), compile: CompileOptions { - gfm_footnote_label_attributes: Some("class=\"footnote-heading\"".into()), - ..CompileOptions::default() + gfm_footnote_label_attributes: Some("class=\"footnote-heading\"".into()), + ..CompileOptions::gfm() } } )?, @@ -120,13 +103,10 @@ fn gfm_footnote() -> Result<(), String> { to_html_with_options( "[^a]\n\n[^a]: b", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, + parse: ParseOptions::gfm(), compile: CompileOptions { gfm_footnote_clobber_prefix: Some("".into()), - ..CompileOptions::default() + ..CompileOptions::gfm() } } )?, @@ -143,19 +123,19 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("A paragraph.\n\n[^a]: whatevs", &gfm)?, + to_html_with_options("A paragraph.\n\n[^a]: whatevs", &Options::gfm())?, "

    A paragraph.

    \n", "should ignore definitions w/o calls" ); assert_eq!( - to_html_with_options("a[^b]", &gfm)?, + to_html_with_options("a[^b]", &Options::gfm())?, "

    a[^b]

    ", "should ignore calls w/o definitions" ); assert_eq!( - to_html_with_options("a[^b]\n\n[^b]: c\n[^b]: d", &gfm)?, + to_html_with_options("a[^b]\n\n[^b]: c\n[^b]: d", &Options::gfm())?, "

    a1

    Footnotes

      @@ -169,7 +149,7 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("a[^b], c[^b]\n\n[^b]: d", &gfm)?, + to_html_with_options("a[^b], c[^b]\n\n[^b]: d", &Options::gfm())?, "

      a1, c1

      Footnotes

        @@ -183,32 +163,32 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("![^a](b)", &gfm)?, + to_html_with_options("![^a](b)", &Options::gfm())?, "

        !^a

        ", "should not support images starting w/ `^` (but see it as a link?!, 1)" ); assert_eq!( - to_html_with_options("![^a][b]\n\n[b]: c", &gfm)?, + to_html_with_options("![^a][b]\n\n[b]: c", &Options::gfm())?, "

        !^a

        \n", "should not support images starting w/ `^` (but see it as a link?!, 2)" ); assert_eq!( - to_html_with_options("[^]()", &gfm)?, + to_html_with_options("[^]()", &Options::gfm())?, "

        ^

        ", "should support an empty link with caret" ); assert_eq!( - to_html_with_options("![^]()", &gfm)?, + to_html_with_options("![^]()", &Options::gfm())?, "

        !^

        ", "should support an empty image with caret (as link)" ); // assert_eq!( - to_html_with_options("Call.[^a\\+b].\n\n[^a\\+b]: y", &gfm)?, + to_html_with_options("Call.[^a\\+b].\n\n[^a\\+b]: y", &Options::gfm())?, "

        Call.1.

        Footnotes

          @@ -222,7 +202,7 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("Call.[^a©b].\n\n[^a©b]: y", &gfm)?, + to_html_with_options("Call.[^a©b].\n\n[^a©b]: y", &Options::gfm())?, "

          Call.1.

          Footnotes

            @@ -238,7 +218,7 @@ fn gfm_footnote() -> Result<(), String> { // // assert_eq!( - to_html_with_options("Call.[^a\\]b].\n\n[^a\\]b]: y", &gfm)?, + to_html_with_options("Call.[^a\\]b].\n\n[^a\\]b]: y", &Options::gfm())?, "

            Call.1.

            Footnotes

              @@ -252,7 +232,7 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("Call.[^a[b].\n\n[^a[b]: y", &gfm)?, + to_html_with_options("Call.[^a[b].\n\n[^a[b]: y", &Options::gfm())?, "

              Call.1.

              Footnotes

                @@ -266,19 +246,19 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("Call.[^a\\+b].\n\n[^a+b]: y", &gfm)?, + to_html_with_options("Call.[^a\\+b].\n\n[^a+b]: y", &Options::gfm())?, "

                Call.[^a+b].

                \n", "should match calls to definitions on the source of the label, not on resolved escapes" ); assert_eq!( - to_html_with_options("Call.[^a[b].\n\n[^a\\[b]: y", &gfm)?, + to_html_with_options("Call.[^a[b].\n\n[^a\\[b]: y", &Options::gfm())?, "

                Call.[^a[b].

                \n", "should match calls to definitions on the source of the label, not on resolved references" ); assert_eq!( - to_html_with_options("[^1].\n\n[^1]: a\nb", &gfm)?, + to_html_with_options("[^1].\n\n[^1]: a\nb", &Options::gfm())?, "

                1.

                Footnotes

                  @@ -293,7 +273,7 @@ b [^1]: a\nb", &gfm)?, + to_html_with_options("[^1].\n\n> [^1]: a\nb", &Options::gfm())?, "

                  1.

                  @@ -310,7 +290,7 @@ b [^1]: a\n> b", &gfm)?, + to_html_with_options("[^1].\n\n> [^1]: a\n> b", &Options::gfm())?, "

                  1.

                  @@ -327,7 +307,7 @@ b b", &gfm)?, + to_html_with_options("[^1].\n\n[^1]: a\n\n > b", &Options::gfm())?, "

                  1.

                  Footnotes

                    @@ -348,7 +328,7 @@ b Call.1.

                    Footnotes

                      @@ -364,7 +344,7 @@ b Call.[^a{}].

                      \n

                      [^a{}]: y

                      ", max, max), "should not support 1000 characters in a call / definition" @@ -373,7 +353,7 @@ b
                      1

                      Footnotes

                      @@ -399,7 +379,7 @@ a![^1] [^1]: b [i]: c"###, - &gfm + &Options::gfm() )?, r###"

                      ai a!i @@ -419,7 +399,7 @@ a!a![^1]

                      ", "should match bang/caret interplay (undefined) like GitHub" ); @@ -430,7 +410,7 @@ a!a!1

                      Footnotes

                      @@ -469,7 +449,7 @@ even another caret. [^^]: caret "###, - &gfm + &Options::gfm() )?, r###"

                      Calls may not be empty: ^.

                      Calls cannot contain whitespace only: ^ .

                      @@ -527,7 +507,7 @@ Some calls.[^ w][^x ][^y][^z] [^x ]: # z "###, - &gfm + &Options::gfm() )?, r###"

                      [^c d]: # e

                      [^f g]: # h

                      @@ -595,7 +575,7 @@ j], [^ l], [^m ]

                      [^![image](#)]: a "###, - &gfm + &Options::gfm() )?, // Note: // * GH does not support colons. @@ -654,7 +634,7 @@ j], [^ l], [^m ]

                      More. [^4]: Directly after a list item. "###, - &gfm + &Options::gfm() )?, r###"

                      Call1234

                      @@ -711,7 +691,7 @@ j], [^ l], [^m ]

                      - list "###, - &gfm + &Options::gfm() )?, r###"

                      1234

                      Heading

                      @@ -768,7 +748,7 @@ Lazy? Lazy! "###, - &gfm + &Options::gfm() )?, r###"

                      Call12345.

                      Lazy?

                      @@ -824,7 +804,7 @@ Lazy! [^10]:- - - kilo "###, - &gfm + &Options::gfm() )?, r###"

                      Note!1234567891011

                      Footnotes

                      @@ -897,7 +877,7 @@ indented delta Call11

                      Footnotes

                      @@ -919,7 +899,7 @@ indented delta Call1

                      Footnotes

                      @@ -961,7 +941,7 @@ indented delta emphasis1

                      strong2

                      @@ -998,7 +978,7 @@ indented delta What are these!1, !2[], and ![this]3.

                      Footnotes

                      @@ -1040,7 +1020,7 @@ indented delta 123456

                      Heading

                      @@ -1093,7 +1073,7 @@ indented delta What are these1, 2[], and [this]3.

                      Footnotes

                      @@ -1143,7 +1123,7 @@ indented delta 1234

                      Heading

                      @@ -1205,7 +1185,7 @@ indented delta 1234

                      Footnotes

                      @@ -1254,7 +1234,7 @@ more code [^3]: [^4]: Paragraph "###, - &gfm + &Options::gfm() )?, r###"

                      Note!1234

                        @@ -1304,7 +1284,7 @@ more code - list "###, - &gfm + &Options::gfm() )?, r###"

                        1234

                        Heading

                        @@ -1358,7 +1338,7 @@ more code - list "###, - &gfm + &Options::gfm() )?, r###"

                        1234

                        Footnotes

                        @@ -1416,7 +1396,7 @@ belong to the previous footnote. This paragraph won’t be part of the note, because it isn’t indented. "###, - &gfm + &Options::gfm() )?, r###"

                        Here is a footnote reference,1 and another.2

                        This paragraph won’t be part of the note, because it @@ -1484,7 +1464,7 @@ multi-paragraph list items. Call[^1][^2]12345678910.

                         [^1]: 5
                        @@ -1576,7 +1556,7 @@ multi-paragraph list items. Call123456789.

                        3

                        @@ -1635,7 +1615,7 @@ multi-paragraph list items. Here is a short reference,1, a collapsed one,2, and a full one.

                        "###, @@ -1643,7 +1623,7 @@ multi-paragraph list items.