Support strikethrough

This commit is contained in:
jpirnay
2026-04-29 09:08:07 +02:00
parent 93f5bdb492
commit b83482e732
11 changed files with 242 additions and 44 deletions
+5
View File
@@ -9,3 +9,8 @@ in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
Example test runners in this repository:
- test/run_url_utils_test.sh
- test/run_opds_parser_test.sh
- test/run_epub_css_test.sh
+62
View File
@@ -0,0 +1,62 @@
#include <cstdio>
#include <string>
#include "../../lib/Epub/Epub/css/CssParser.h"
static int testsPassed = 0;
static int testsFailed = 0;
#define ASSERT_EQ(a, b) \
do { \
if ((a) != (b)) { \
fprintf(stderr, " FAIL: %s:%d: %s != %s\n", __FILE__, __LINE__, #a, #b); \
testsFailed++; \
return; \
} \
} while (0)
#define ASSERT_TRUE(cond) \
do { \
if (!(cond)) { \
fprintf(stderr, " FAIL: %s:%d: %s is false\n", __FILE__, __LINE__, #cond); \
testsFailed++; \
return; \
} \
} while (0)
#define PASS() testsPassed++
void testInlineLineThrough() {
printf("testInlineLineThrough...\n");
const CssStyle style = CssParser::parseInlineStyle("text-decoration: line-through");
ASSERT_TRUE(style.hasTextDecoration());
ASSERT_EQ(style.textDecoration, CssTextDecoration::LineThrough);
PASS();
}
void testInlineUnderlineLineThrough() {
printf("testInlineUnderlineLineThrough...\n");
const CssStyle style = CssParser::parseInlineStyle("text-decoration: underline line-through");
ASSERT_TRUE(style.hasTextDecoration());
ASSERT_EQ(style.textDecoration, CssTextDecoration::UnderlineLineThrough);
PASS();
}
void testInlineTextDecorationNormalization() {
printf("testInlineTextDecorationNormalization...\n");
const CssStyle style = CssParser::parseInlineStyle("TEXT-DECORATION : LINE-THROUGH ;");
ASSERT_TRUE(style.hasTextDecoration());
ASSERT_EQ(style.textDecoration, CssTextDecoration::LineThrough);
PASS();
}
int main() {
printf("=== EPUB CSS Parser Tests ===\n\n");
testInlineLineThrough();
testInlineUnderlineLineThrough();
testInlineTextDecorationNormalization();
printf("\n=== Results: %d passed, %d failed ===\n", testsPassed, testsFailed);
return testsFailed > 0 ? 1 : 0;
}
+10
View File
@@ -69,6 +69,15 @@ void testAsteriskEmphasisStillWorks() {
PASS();
}
void testStrikethroughWorks() {
printf("testStrikethroughWorks...\n");
auto spans = MdParser::parseInline("foo ~~bar~~ baz");
ASSERT_EQ(flattenText(spans), "foo bar baz");
ASSERT_EQ(spans.size(), 3);
ASSERT_EQ(spans[1].style, EpdFontFamily::STRIKETHROUGH);
PASS();
}
void testUnderscoreBoldWorks() {
printf("testUnderscoreBoldWorks...\n");
auto spans = MdParser::parseInline("foo __bar__ baz");
@@ -105,6 +114,7 @@ int main() {
testUnderscoreWithinExpressionRemainsLiteral();
testUnderscoreEmphasisStillWorks();
testAsteriskEmphasisStillWorks();
testStrikethroughWorks();
testUnderscoreBoldWorks();
testNestedUnorderedListIndentLevel();
testNestedOrderedListIndentLevel();
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BUILD_DIR="$ROOT_DIR/build/epub_css"
BINARY="$BUILD_DIR/CssParserTest"
PLATFORMIO_DIR="${PLATFORMIO_CORE_DIR:-$HOME/.platformio}"
ARDUINO_FRAMEWORK_DIR="$PLATFORMIO_DIR/packages/framework-arduinoespressif32"
mkdir -p "$BUILD_DIR"
SOURCES=(
"$ROOT_DIR/test/epub_css/CssParserTest.cpp"
"$ROOT_DIR/lib/Epub/Epub/css/CssParser.cpp"
"$ROOT_DIR/lib/hal/HalStorage.cpp"
"$ROOT_DIR/lib/Logging/Logging.cpp"
)
CXXFLAGS=(
-std=c++20
-O2
-Wall
-Wextra
-pedantic
-fno-exceptions
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1
-DDESTRUCTOR_CLOSES_FILE=1
-I"$ROOT_DIR/test/shims"
-I"$ROOT_DIR"
-I"$ROOT_DIR/lib"
-I"$ROOT_DIR/lib/hal"
-I"$ROOT_DIR/lib/Logging"
-I"$ARDUINO_FRAMEWORK_DIR/cores/esp32"
-I"$ARDUINO_FRAMEWORK_DIR/variants/esp32c3"
)
c++ "${CXXFLAGS[@]}" "${SOURCES[@]}" -o "$BINARY"
"$BINARY" "$@"