From 1d92666865b35341e076efbefddf6e73b5e1542e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 7 Sep 2022 15:53:06 +0200 Subject: Add support for recoverable syntax errors --- tests/gfm_footnote.rs | 103 ++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 50 deletions(-) (limited to 'tests/gfm_footnote.rs') diff --git a/tests/gfm_footnote.rs b/tests/gfm_footnote.rs index 8c6cc54..d371455 100644 --- a/tests/gfm_footnote.rs +++ b/tests/gfm_footnote.rs @@ -3,7 +3,7 @@ use micromark::{micromark, micromark_with_options, Constructs, Options}; use pretty_assertions::assert_eq; #[test] -fn gfm_footnote() { +fn gfm_footnote() -> Result<(), String> { let gfm = Options { constructs: Constructs::gfm(), ..Options::default() @@ -16,7 +16,7 @@ fn gfm_footnote() { ); assert_eq!( - micromark_with_options("A call.[^a]\n\n[^a]: whatevs", &gfm), + micromark_with_options("A call.[^a]\n\n[^a]: whatevs", &gfm)?, "

A call.1

Footnotes

    @@ -28,6 +28,7 @@ fn gfm_footnote() { ", "should support footnotes" ); + assert_eq!( micromark_with_options( "Noot.[^a]\n\n[^a]: dingen", @@ -37,7 +38,7 @@ fn gfm_footnote() { gfm_footnote_back_label: Some("Terug naar de inhoud".to_string()), ..Options::default() } - ), + )?, "

    Noot.1

    Voetnoten

      @@ -58,7 +59,7 @@ fn gfm_footnote() { gfm_footnote_label_tag_name: Some("h1".to_string()), ..Options::default() } - ), + )?, "

      1

      Footnotes

        @@ -79,7 +80,7 @@ fn gfm_footnote() { gfm_footnote_label_attributes: Some("class=\"footnote-heading\"".to_string()), ..Options::default() } - ), + )?, "

        1

        Footnotes

          @@ -100,7 +101,7 @@ fn gfm_footnote() { gfm_footnote_clobber_prefix: Some("".to_string()), ..Options::default() } - ), + )?, "

          1

          Footnotes

            @@ -114,19 +115,19 @@ fn gfm_footnote() { ); assert_eq!( - micromark_with_options("A paragraph.\n\n[^a]: whatevs", &gfm), + micromark_with_options("A paragraph.\n\n[^a]: whatevs", &gfm)?, "

            A paragraph.

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

            a[^b]

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

            a1

            Footnotes

              @@ -140,7 +141,7 @@ fn gfm_footnote() { ); assert_eq!( - micromark_with_options("a[^b], c[^b]\n\n[^b]: d", &gfm), + micromark_with_options("a[^b], c[^b]\n\n[^b]: d", &gfm)?, "

              a1, c1

              Footnotes

                @@ -154,32 +155,32 @@ fn gfm_footnote() { ); assert_eq!( - micromark_with_options("![^a](b)", &gfm), + micromark_with_options("![^a](b)", &gfm)?, "

                !^a

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

                !^a

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

                ^

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

                !^

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

                Call.1.

                Footnotes

                  @@ -193,7 +194,7 @@ fn gfm_footnote() { ); assert_eq!( - micromark_with_options("Call.[^a©b].\n\n[^a©b]: y", &gfm), + micromark_with_options("Call.[^a©b].\n\n[^a©b]: y", &gfm)?, "

                  Call.1.

                  Footnotes

                    @@ -209,7 +210,7 @@ fn gfm_footnote() { // // assert_eq!( - micromark_with_options("Call.[^a\\]b].\n\n[^a\\]b]: y", &gfm), + micromark_with_options("Call.[^a\\]b].\n\n[^a\\]b]: y", &gfm)?, "

                    Call.1.

                    Footnotes

                      @@ -223,7 +224,7 @@ fn gfm_footnote() { ); assert_eq!( - micromark_with_options("Call.[^a[b].\n\n[^a[b]: y", &gfm), + micromark_with_options("Call.[^a[b].\n\n[^a[b]: y", &gfm)?, "

                      Call.1.

                      Footnotes

                        @@ -237,19 +238,19 @@ fn gfm_footnote() { ); assert_eq!( - micromark_with_options("Call.[^a\\+b].\n\n[^a+b]: y", &gfm), + micromark_with_options("Call.[^a\\+b].\n\n[^a+b]: y", &gfm)?, "

                        Call.[^a+b].

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

                        Call.[^a[b].

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

                        1.

                        Footnotes

                          @@ -264,7 +265,7 @@ b [^1]: a\nb", &gfm), + micromark_with_options("[^1].\n\n> [^1]: a\nb", &gfm)?, "

                          1.

                          @@ -281,7 +282,7 @@ b [^1]: a\n> b", &gfm), + micromark_with_options("[^1].\n\n> [^1]: a\n> b", &gfm)?, "

                          1.

                          @@ -298,7 +299,7 @@ b b", &gfm), + micromark_with_options("[^1].\n\n[^1]: a\n\n > b", &gfm)?, "

                          1.

                          Footnotes

                            @@ -319,7 +320,7 @@ b Call.1.

                            Footnotes

                              @@ -336,7 +337,7 @@ b Call.[^a{}].

                              \n

                              [^a{}]: y

                              ", max, max), "should not support 1000 characters in a call / definition" ); @@ -354,7 +355,7 @@ a![^1] [i]: c"###, &gfm - ), + )?, r###"

                              ai a!i ai @@ -373,7 +374,7 @@ a!a![^1]

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

                              Footnotes

                                @@ -424,7 +425,7 @@ even another caret. [^^]: caret "###, &gfm - ), + )?, r###"

                                Calls may not be empty: ^.

                                Calls cannot contain whitespace only: ^ .

                                Calls cannot contain whitespace at all: ^ , ^ , ^ @@ -482,7 +483,7 @@ even another caret.

                                [^![image](#)]: a "###, &gfm - ), + )?, // Note: // * GH does not support colons. // See: @@ -541,7 +542,7 @@ even another caret.

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

                                Call1234

                                More.

                                @@ -598,7 +599,7 @@ even another caret.

                                - list "###, &gfm - ), + )?, r###"

                                1234

                                Heading

                                @@ -655,7 +656,7 @@ Lazy? Lazy! "###, &gfm - ), + )?, r###"

                                Call12345.

                                Lazy?

                                Lazy!

                                @@ -711,7 +712,7 @@ Lazy! [^10]:- - - kilo "###, &gfm - ), + )?, r###"

                                Note!1234567891011

                                Footnotes

                                  @@ -784,7 +785,7 @@ indented delta Call11

                                  Footnotes

                                    @@ -806,7 +807,7 @@ indented delta Call1

                                    Footnotes

                                      @@ -848,7 +849,7 @@ indented delta emphasis1

                                      strong2

                                      code[^3]

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

                                      Footnotes

                                        @@ -927,7 +928,7 @@ indented delta 123456

                                        Heading

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

                                        Footnotes

                                          @@ -1030,7 +1031,7 @@ indented delta 1234

                                          Heading

                                          @@ -1092,7 +1093,7 @@ indented delta 1234

                                          Footnotes

                                            @@ -1141,7 +1142,7 @@ more code [^3]: [^4]: Paragraph "###, &gfm - ), + )?, r###"

                                            Note!1234

                                            • @@ -1191,7 +1192,7 @@ more code - list "###, &gfm - ), + )?, r###"

                                              1234

                                              Heading

                                              @@ -1245,7 +1246,7 @@ more code - list "###, &gfm - ), + )?, r###"

                                              1234

                                              Footnotes

                                                @@ -1303,7 +1304,7 @@ This paragraph won’t be part of the note, because it isn’t indented. "###, &gfm - ), + )?, r###"

                                                Here is a footnote reference,1 and another.2

                                                This paragraph won’t be part of the note, because it isn’t indented.

                                                @@ -1371,7 +1372,7 @@ multi-paragraph list items. Call[^1][^2]12345678910.

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

                                                3

                                                2

                                                @@ -1522,9 +1523,11 @@ multi-paragraph list items. Here is a short reference,1, a collapsed one,2, and a full one.

                                                "###, "should match references and definitions like GitHub" ); + + Ok(()) } -- cgit