diff options
Diffstat (limited to 'app/src/test/java/org/terst/feedreader/data')
| -rw-r--r-- | app/src/test/java/org/terst/feedreader/data/CachedExtractionTest.kt | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/app/src/test/java/org/terst/feedreader/data/CachedExtractionTest.kt b/app/src/test/java/org/terst/feedreader/data/CachedExtractionTest.kt index 72dc73f..fc9c32e 100644 --- a/app/src/test/java/org/terst/feedreader/data/CachedExtractionTest.kt +++ b/app/src/test/java/org/terst/feedreader/data/CachedExtractionTest.kt @@ -33,6 +33,7 @@ class CachedExtractionTest { val result = loadCachedExtraction(content) { cleared = true } assertEquals(content, result.content) assertFalse(result.discardedConsentNotice) + assertFalse(result.discarded) assertFalse("a good cache must not be cleared", cleared) } @@ -54,6 +55,37 @@ class CachedExtractionTest { assertFalse(cleared) } + // Same shape of problem as the consent notice, different cause: this content was + // extracted before extraction knew how to render maths, so it holds the raw TeX source + // Substack ships. A fixed extractor never gets a look at it -- the cached copy is + // returned first and the article is never re-extracted. + @Test + fun `a cached extraction holding raw tex source is discarded and deleted`() = runTest { + var cleared = false + val rawTex = "<div id=\"readability-page-1\"><p>Imagine the following sentence:</p>" + + "<div data-component-name=\"Latex\"><p><span>" + + "\\(p = \\text{\u201Cif }p\\text{ is true, then pigs can fly\u201D}\\)</span></p></div>" + + "<p>" + "Considered as a whole, the statement cannot be true. ".repeat(20) + "</p></div>" + val result = loadCachedExtraction(rawTex) { cleared = true } + assertNull("raw TeX source must not be shown as the article", result.content) + assertTrue(result.discardedUnrenderedTex) + assertTrue("the stale row must be cleared so a re-extract can replace it", cleared) + assertTrue("the caller must be told to extract again", result.discarded) + } + + @Test + fun `an extraction with rendered maths is kept`() = runTest { + var cleared = false + val withMathMl = "<p>A slice of the set looks like this:</p>" + + "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics>" + + "<mrow><mi>p</mi><mo>=</mo></mrow></semantics></math>" + + "<p>" + "The rest of the article continues from there. ".repeat(20) + "</p>" + val result = loadCachedExtraction(withMathMl) { cleared = true } + assertEquals(withMathMl, result.content) + assertFalse(result.discardedUnrenderedTex) + assertFalse("a good cache must not be cleared", cleared) + } + // A blank value is as good as nothing cached -- it is not a consent notice, so // reporting it as a discarded one would make the caller re-extract on a false // premise. |
