Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ permissions:
jobs:
build-and-test:
name: Build and Test
runs-on: macOS-latest
if: github.event.pull_request.draft == false
runs-on: macos-15

env:
WORKSPACE: CDMarkdownKit.xcworkspace
DESTINATION: platform=iOS Simulator,name=iPhone 14,OS=16.2
DESTINATION: platform=iOS Simulator,name=iPhone 16,OS=18.0
SCHEME: "CDMarkdownKit iOS"

steps:
Expand Down
4 changes: 4 additions & 0 deletions CDMarkdownKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
1F02B85A2A90D60D0023148B /* TestSyntax.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F02B8592A90D60D0023148B /* TestSyntax.swift */; };
1F02B85C2A90D6210023148B /* TestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F02B85B2A90D6210023148B /* TestHelpers.swift */; };
1F549C1B2D3EF78C00E9AA9E /* TestStrikethrough.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F549C1A2D3EF78C00E9AA9E /* TestStrikethrough.swift */; };
1F66CB672A8EB04C00FC7BA7 /* TestItalic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F66CB662A8EB04C00FC7BA7 /* TestItalic.swift */; };
1F66CB682A8EB04C00FC7BA7 /* CDMarkdownKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2B365B71F3245800078B962 /* CDMarkdownKit.framework */; };
1F66CB7A2A8FBC1000FC7BA7 /* TestBold.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F66CB792A8FBC1000FC7BA7 /* TestBold.swift */; };
Expand Down Expand Up @@ -178,6 +179,7 @@
/* Begin PBXFileReference section */
1F02B8592A90D60D0023148B /* TestSyntax.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestSyntax.swift; sourceTree = "<group>"; };
1F02B85B2A90D6210023148B /* TestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestHelpers.swift; sourceTree = "<group>"; };
1F549C1A2D3EF78C00E9AA9E /* TestStrikethrough.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestStrikethrough.swift; sourceTree = "<group>"; };
1F66CB642A8EB04C00FC7BA7 /* CDMarkdownKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CDMarkdownKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
1F66CB662A8EB04C00FC7BA7 /* TestItalic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestItalic.swift; sourceTree = "<group>"; };
1F66CB792A8FBC1000FC7BA7 /* TestBold.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestBold.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -288,6 +290,7 @@
1F8538482ADFE12E0011FE81 /* TestEscape.swift */,
1F9A797C2A98B4AF00E153E3 /* TestHeader.swift */,
1F02B8592A90D60D0023148B /* TestSyntax.swift */,
1F549C1A2D3EF78C00E9AA9E /* TestStrikethrough.swift */,
);
path = CDMarkdownKitTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -715,6 +718,7 @@
1F66CB7A2A8FBC1000FC7BA7 /* TestBold.swift in Sources */,
1F02B85C2A90D6210023148B /* TestHelpers.swift in Sources */,
1F66CB7C2A8FBC8F00FC7BA7 /* TestCode.swift in Sources */,
1F549C1B2D3EF78C00E9AA9E /* TestStrikethrough.swift in Sources */,
1F02B85A2A90D60D0023148B /* TestSyntax.swift in Sources */,
1F66CB672A8EB04C00FC7BA7 /* TestItalic.swift in Sources */,
);
Expand Down
6 changes: 6 additions & 0 deletions CDMarkdownKitTests/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class TestHelpers {
return isHelper(testString: testString, at: location, trait: .traitMonoSpace)
}

static func isStrikethrough(testString: NSAttributedString, at location: Int) -> Bool {
let attributes = testString.attributes(at: location, effectiveRange: nil)

return attributes.contains { $0.key == .strikethroughStyle && NSUnderlineStyle(rawValue: $0.value as! Int) == .single }
}

private static func anyHelper(testString: NSAttributedString, trait: UIFontDescriptor.SymbolicTraits) -> Bool {
var found = false

Expand Down
46 changes: 46 additions & 0 deletions CDMarkdownKitTests/TestStrikethrough.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Copyright (c) 2025 Marcel Müller <marcel-mueller@gmx.de>
//
// Author Marcel Müller <marcel-mueller@gmx.de>
//
// GNU GPL version 3 or any later version
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

import XCTest
import CDMarkdownKit

final class TestStrikethrough: XCTestCase {

func testStrikethrough() throws {
let parser = CDMarkdownParser()

var parsed = parser.parse("~~Test~~")
XCTAssertEqual(parsed.string, "Test")
XCTAssertTrue(TestHelpers.isStrikethrough(testString: parsed, at: 0))

parsed = parser.parse("~Test~")
XCTAssertEqual(parsed.string, "Test")
XCTAssertTrue(TestHelpers.isStrikethrough(testString: parsed, at: 0))
}

func testNonStrikethrough() throws {
let parser = CDMarkdownParser()

let parsed = parser.parse("~~Test~")
XCTAssertEqual(parsed.string, "Test~")
XCTAssertFalse(TestHelpers.isStrikethrough(testString: parsed, at: 0))
}
}
2 changes: 1 addition & 1 deletion Source/CDMarkdownStrikethrough.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

open class CDMarkdownStrikethrough: CDMarkdownCommonElement {

fileprivate static let regex = ["()(~~)(.*?)(\\2)"]
fileprivate static let regex = ["()(~{1,2})(.*?)(\\2)"]

open var font: CDFont?
open var color: CDColor?
Expand Down
Loading