Skip to content

Commit

Permalink
Add text replacement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Sep 11, 2024
1 parent 5cfcd6d commit 1986834
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -281,6 +282,7 @@ class HtmlNodeRendererTest {
@Test
fun text() {
assertEquals("Foo bar", Text("Foo bar").render())
assertEquals("©", TextSymbol('©').render())
}

@Test
Expand Down
59 changes: 59 additions & 0 deletions core/src/test/kotlin/eu/iamgio/quarkdown/LexerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<TextSymbolToken>(this)
assertEquals(symbol, this.symbol)
}

assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.ELLIPSIS)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.COPYRIGHT)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.EM_DASH)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.EM_DASH)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_RIGHT_APOSTROPHE)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.DOUBLE_RIGHT_ARROW)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.NOT_EQUAL)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.SINGLE_RIGHT_ARROW)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.LESS_EQUAL)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.GREATER_EQUAL)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.SINGLE_LEFT_ARROW)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.ELLIPSIS)
assertIs<PlainTextToken>(tokens.next()) // Soft line break
assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_LEFT_APOSTROPHE)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_RIGHT_APOSTROPHE)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_RIGHT_APOSTROPHE)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_LEFT_APOSTROPHE)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_RIGHT_APOSTROPHE)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_LEFT_QUOTATION_MARK)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_RIGHT_QUOTATION_MARK)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.TRADEMARK)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_LEFT_QUOTATION_MARK)
assertIs<PlainTextToken>(tokens.next())
assertSymbolEquals(TextSymbolReplacement.TYPOGRAPHIC_RIGHT_QUOTATION_MARK)
assertIs<PlainTextToken>(tokens.next())
}

@Test
fun flavors() {
// Quarkdown features are not detected when using BaseMarkdownFlavor
Expand Down
4 changes: 4 additions & 0 deletions core/src/test/resources/lexing/textreplacement.md
Original file line number Diff line number Diff line change
@@ -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".
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ class FullPipelineTest {
assertEquals("<p>Hello, world!</p>", 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(
"<blockquote><p>" +
"This is a <strong>&ldquo;quote&rdquo;</strong> with &lsquo;text <em>replacement</em>&rsquo;.<br />" +
"This is a feature of Quarkdown &mdash; the Turing complete Markdown &mdash; by iamgio &copy; 2024.\n" +
"&rArr; Quarkdown &ne; other Markdown flavors&hellip; &larr;" +
"</p></blockquote>",
it,
)
}

execute(".noautopagebreak\n# Title\n Hello, world!\n## Subtitle\nHello, world!") {
assertEquals(
"<h1>Title</h1><p>Hello, world!</p><h2>Subtitle</h2><p>Hello, world!</p>",
Expand Down Expand Up @@ -455,7 +472,9 @@ class FullPipelineTest {
) {
assertEquals(
(
"<h2>Title 2</h2><h2>Title 2</h2><div class=\"page-break\" data-hidden=\"\"></div><h1>Title 1</h1>".repeat(2) +
"<h2>Title 2</h2><h2>Title 2</h2><div class=\"page-break\" data-hidden=\"\"></div><h1>Title 1</h1>".repeat(
2,
) +
"<p>Some text</p>"
).repeat(2) + "<h3>Title 3</h3>",
it,
Expand Down

0 comments on commit 1986834

Please sign in to comment.