From 5ed58ab4eac2abcf8f371ae140110e4b8dd8ba54 Mon Sep 17 00:00:00 2001 From: Etherlink Intern Date: Mon, 1 Jun 2026 01:43:26 +0800 Subject: [PATCH] Resolve smoke test PR overlap --- .github/workflows/ci.yml | 25 +++++++++++++++ README.md | 11 +++++++ Scripts/smoke-test.sh | 31 +++++++++++++++++++ .../Converters/HTMLConverter.swift | 4 +++ Tests/Expected/data.md | 4 +++ Tests/Expected/note.md | 2 ++ Tests/Expected/page.md | 5 +++ Tests/Expected/table.md | 4 +++ Tests/Fixtures/data.json | 1 + Tests/Fixtures/note.txt | 2 ++ Tests/Fixtures/page.html | 13 ++++++++ Tests/Fixtures/table.csv | 3 ++ .../SwiftMarkItDownTests.swift | 2 +- 13 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100755 Scripts/smoke-test.sh create mode 100644 Tests/Expected/data.md create mode 100644 Tests/Expected/note.md create mode 100644 Tests/Expected/page.md create mode 100644 Tests/Expected/table.md create mode 100644 Tests/Fixtures/data.json create mode 100644 Tests/Fixtures/note.txt create mode 100644 Tests/Fixtures/page.html create mode 100644 Tests/Fixtures/table.csv diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f17d392 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: CI + +on: + pull_request: + push: + branches: + - main + workflow_dispatch: + +jobs: + test: + name: Swift tests and smoke tests + runs-on: macos-15 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Show Swift version + run: swift --version + + - name: Run unit tests + run: swift test + + - name: Run CLI smoke tests + run: Scripts/smoke-test.sh diff --git a/README.md b/README.md index 8d25c3d..ce98068 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,17 @@ print(document.markdown) swift run swift-markitdown path/to/file.html ``` +## Testing + +Run the unit test suite and CLI fixture smoke tests before opening a PR: + +```bash +swift test +Scripts/smoke-test.sh +``` + +GitHub Actions runs the same checks on pushes to `main`, pull requests, and manual workflow dispatches. + ## Roadmap 1. Expand the text/HTML/CSV/JSON converters with richer Markdown normalization and metadata extraction. diff --git a/Scripts/smoke-test.sh b/Scripts/smoke-test.sh new file mode 100755 index 0000000..3ca42e4 --- /dev/null +++ b/Scripts/smoke-test.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +BINARY="${ROOT_DIR}/.build/debug/swift-markitdown" + +swift build --package-path "${ROOT_DIR}" --product swift-markitdown + +run_case() { + local name="$1" + local input="${ROOT_DIR}/Tests/Fixtures/${name}" + local expected="${ROOT_DIR}/Tests/Expected/${name%.*}.md" + local actual + actual="$(mktemp)" + + "${BINARY}" "${input}" > "${actual}" + + if ! diff -u "${expected}" "${actual}"; then + echo "Smoke test failed for ${name}" >&2 + rm -f "${actual}" + return 1 + fi + + rm -f "${actual}" + echo "✓ ${name}" +} + +run_case note.txt +run_case page.html +run_case table.csv +run_case data.json diff --git a/Sources/SwiftMarkItDown/Converters/HTMLConverter.swift b/Sources/SwiftMarkItDown/Converters/HTMLConverter.swift index 9b21554..75bfeab 100644 --- a/Sources/SwiftMarkItDown/Converters/HTMLConverter.swift +++ b/Sources/SwiftMarkItDown/Converters/HTMLConverter.swift @@ -10,6 +10,7 @@ public struct HTMLConverter: DocumentConverter { html = html.replacingOccurrences(of: "\r\n", with: "\n") let rules: [(String, String)] = [ + ("(?is)]*>.*?", ""), ("(?is)]*>.*?", ""), ("(?is)]*>.*?", ""), ("(?is)]*>(.*?)", "\n# $1\n"), @@ -36,6 +37,9 @@ public struct HTMLConverter: DocumentConverter { .smid_decodingHTMLEntities() .replacingOccurrences(of: "[ \t]+\n", with: "\n", options: .regularExpression) .replacingOccurrences(of: "\n{3,}", with: "\n\n", options: .regularExpression) + .split(separator: "\n", omittingEmptySubsequences: false) + .map { $0.trimmingCharacters(in: .whitespaces) } + .joined(separator: "\n") .smid_trimmedBlankLines return MarkdownDocument(markdown: markdown, sourceFormat: .html) diff --git a/Tests/Expected/data.md b/Tests/Expected/data.md new file mode 100644 index 0000000..15fd210 --- /dev/null +++ b/Tests/Expected/data.md @@ -0,0 +1,4 @@ +- **formats**: + - txt + - html +- **title**: Roadmap diff --git a/Tests/Expected/note.md b/Tests/Expected/note.md new file mode 100644 index 0000000..edf2c98 --- /dev/null +++ b/Tests/Expected/note.md @@ -0,0 +1,2 @@ +Hello SwiftMarkItDown +This is plain text. diff --git a/Tests/Expected/page.md b/Tests/Expected/page.md new file mode 100644 index 0000000..d4c18ff --- /dev/null +++ b/Tests/Expected/page.md @@ -0,0 +1,5 @@ +# Smoke Test + +Hello **native Swift** & Markdown. + +[Example](https://example.com) diff --git a/Tests/Expected/table.md b/Tests/Expected/table.md new file mode 100644 index 0000000..3327c0c --- /dev/null +++ b/Tests/Expected/table.md @@ -0,0 +1,4 @@ +| Name | Note | +| --- | --- | +| Swift | Native | +| Mark, It Down | CSV \| escaped | diff --git a/Tests/Fixtures/data.json b/Tests/Fixtures/data.json new file mode 100644 index 0000000..25c497f --- /dev/null +++ b/Tests/Fixtures/data.json @@ -0,0 +1 @@ +{"title":"Roadmap","formats":["txt","html"]} diff --git a/Tests/Fixtures/note.txt b/Tests/Fixtures/note.txt new file mode 100644 index 0000000..edf2c98 --- /dev/null +++ b/Tests/Fixtures/note.txt @@ -0,0 +1,2 @@ +Hello SwiftMarkItDown +This is plain text. diff --git a/Tests/Fixtures/page.html b/Tests/Fixtures/page.html new file mode 100644 index 0000000..e1986b5 --- /dev/null +++ b/Tests/Fixtures/page.html @@ -0,0 +1,13 @@ + + + + Ignored title + + + + +

Smoke Test

+

Hello native Swift & Markdown.

+

Example

+ + diff --git a/Tests/Fixtures/table.csv b/Tests/Fixtures/table.csv new file mode 100644 index 0000000..e6f07dd --- /dev/null +++ b/Tests/Fixtures/table.csv @@ -0,0 +1,3 @@ +Name,Note +Swift,Native +"Mark, It Down","CSV | escaped" diff --git a/Tests/SwiftMarkItDownTests/SwiftMarkItDownTests.swift b/Tests/SwiftMarkItDownTests/SwiftMarkItDownTests.swift index ca33aa5..fec71d2 100644 --- a/Tests/SwiftMarkItDownTests/SwiftMarkItDownTests.swift +++ b/Tests/SwiftMarkItDownTests/SwiftMarkItDownTests.swift @@ -20,7 +20,7 @@ struct SwiftMarkItDownTests { @Test("converts simple HTML to Markdown") func convertsHTML() throws { - let html = "

Title

Hello Swift & iOS.

Link" + let html = "Ignored

Title

Hello Swift & iOS.

Link" let request = ConversionRequest(data: Data(html.utf8), fileName: "index.html") let document = try MarkItDown().convert(request) #expect(document.markdown == "# Title\nHello **Swift** & iOS.\n\n[Link](https://example.com)")