From 198683442d3a6c8dd76d425e14e237c58ce6eed7 Mon Sep 17 00:00:00 2001 From: Giorgio Garofalo Date: Wed, 11 Sep 2024 17:49:30 +0200 Subject: [PATCH] Add text replacement tests --- .../iamgio/quarkdown/HtmlNodeRendererTest.kt | 2 + .../kotlin/eu/iamgio/quarkdown/LexerTest.kt | 59 +++++++++++++++++++ .../test/resources/lexing/textreplacement.md | 4 ++ .../iamgio/quarkdown/test/FullPipelineTest.kt | 21 ++++++- 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 core/src/test/resources/lexing/textreplacement.md diff --git a/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt b/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt index 901c3348..0250aa97 100644 --- a/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt +++ b/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt @@ -38,6 +38,7 @@ import eu.iamgio.quarkdown.ast.quarkdown.block.Collapse import eu.iamgio.quarkdown.ast.quarkdown.block.Math import eu.iamgio.quarkdown.ast.quarkdown.block.PageBreak import eu.iamgio.quarkdown.ast.quarkdown.inline.MathSpan +import eu.iamgio.quarkdown.ast.quarkdown.inline.TextSymbol import eu.iamgio.quarkdown.ast.quarkdown.inline.TextTransform import eu.iamgio.quarkdown.ast.quarkdown.inline.TextTransformData import eu.iamgio.quarkdown.context.BaseContext @@ -281,6 +282,7 @@ class HtmlNodeRendererTest { @Test fun text() { assertEquals("Foo bar", Text("Foo bar").render()) + assertEquals("©", TextSymbol('©').render()) } @Test diff --git a/core/src/test/kotlin/eu/iamgio/quarkdown/LexerTest.kt b/core/src/test/kotlin/eu/iamgio/quarkdown/LexerTest.kt index 9c47e09c..df94ac7b 100644 --- a/core/src/test/kotlin/eu/iamgio/quarkdown/LexerTest.kt +++ b/core/src/test/kotlin/eu/iamgio/quarkdown/LexerTest.kt @@ -6,6 +6,7 @@ import eu.iamgio.quarkdown.flavor.quarkdown.QuarkdownFlavor import eu.iamgio.quarkdown.lexer.Lexer import eu.iamgio.quarkdown.lexer.Token import eu.iamgio.quarkdown.lexer.TokenData +import eu.iamgio.quarkdown.lexer.patterns.TextSymbolReplacement import eu.iamgio.quarkdown.lexer.regex.StandardRegexLexer import eu.iamgio.quarkdown.lexer.regex.pattern.TokenRegexPattern import eu.iamgio.quarkdown.lexer.tokens.BlockCodeToken @@ -39,6 +40,7 @@ import eu.iamgio.quarkdown.lexer.tokens.SetextHeadingToken import eu.iamgio.quarkdown.lexer.tokens.StrongEmphasisToken import eu.iamgio.quarkdown.lexer.tokens.StrongToken import eu.iamgio.quarkdown.lexer.tokens.TableToken +import eu.iamgio.quarkdown.lexer.tokens.TextSymbolToken import eu.iamgio.quarkdown.lexer.tokens.UnorderedListToken import eu.iamgio.quarkdown.lexer.tokens.UrlAutolinkToken import eu.iamgio.quarkdown.lexer.walker.SourceReader @@ -364,6 +366,63 @@ class LexerTest { assertFalse(tokens.hasNext()) } + @Test + fun textReplacement() { + val tokens = inlineLex(readSource("/lexing/textreplacement.md")) + + fun assertSymbolEquals(symbol: TextSymbolReplacement) = + with(tokens.next()) { + assertIs(this) + assertEquals(symbol, this.symbol) + } + + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.ELLIPSIS) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.COPYRIGHT) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.EM_DASH) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.EM_DASH) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_RIGHT_APOSTROPHE) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.DOUBLE_RIGHT_ARROW) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.NOT_EQUAL) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.SINGLE_RIGHT_ARROW) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.LESS_EQUAL) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.GREATER_EQUAL) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.SINGLE_LEFT_ARROW) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.ELLIPSIS) + assertIs(tokens.next()) // Soft line break + assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_LEFT_APOSTROPHE) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_RIGHT_APOSTROPHE) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_RIGHT_APOSTROPHE) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_LEFT_APOSTROPHE) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_RIGHT_APOSTROPHE) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_LEFT_QUOTATION_MARK) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_RIGHT_QUOTATION_MARK) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.TRADEMARK) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_LEFT_QUOTATION_MARK) + assertIs(tokens.next()) + assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_RIGHT_QUOTATION_MARK) + assertIs(tokens.next()) + } + @Test fun flavors() { // Quarkdown features are not detected when using BaseMarkdownFlavor diff --git a/core/src/test/resources/lexing/textreplacement.md b/core/src/test/resources/lexing/textreplacement.md new file mode 100644 index 00000000..a304de5d --- /dev/null +++ b/core/src/test/resources/lexing/textreplacement.md @@ -0,0 +1,4 @@ +Hi... this is some text lexed by the Quarkdown (C) flavor - the Turing complete Markdown - which is iamgio's project. +3-1 is 2, which is not 4 => 2 != 4 -> also, 4 <= 8, and 8 >= 4 <- interesting... +'Quarkdown's' source is available on 'GitHub'! "Stars" are much appreciated (TM) +This is a "test". \ No newline at end of file diff --git a/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt b/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt index 49a9c189..5a762f72 100644 --- a/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt +++ b/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt @@ -127,6 +127,23 @@ class FullPipelineTest { assertEquals("

Hello, world!

", it) } + execute( + """ + > This is a **"quote"** with 'text *replacement*'. + > This is a feature of Quarkdown - the Turing complete Markdown - by iamgio (C) 2024. + > => Quarkdown != other Markdown flavors... <- + """.trimIndent(), + ) { + assertEquals( + "

" + + "This is a “quote” with ‘text replacement’.
" + + "This is a feature of Quarkdown — the Turing complete Markdown — by iamgio © 2024.\n" + + "⇒ Quarkdown ≠ other Markdown flavors… ←" + + "

", + it, + ) + } + execute(".noautopagebreak\n# Title\n Hello, world!\n## Subtitle\nHello, world!") { assertEquals( "

Title

Hello, world!

Subtitle

Hello, world!

", @@ -455,7 +472,9 @@ class FullPipelineTest { ) { assertEquals( ( - "

Title 2

Title 2

Title 1

".repeat(2) + + "

Title 2

Title 2

Title 1

".repeat( + 2, + ) + "

Some text

" ).repeat(2) + "

Title 3

", it,