Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tonisevener committed Dec 7, 2023
1 parent 3553ec8 commit 91eac86
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,42 @@ final class WKSourceEditorFormatterTests: XCTestCase {
XCTAssertEqual(refClosingAttributes[.foregroundColor] as! UIColor, colors.baseForegroundColor, "Incorrect ref formatting")
}

func testHorizontalNestedTemplate() {
let string = "Ford Island ({{lang-haw|Poka {{okina}}Ailana}}) is an"
let mutAttributedString = NSMutableAttributedString(string: string)

for formatter in formatters {
formatter.addSyntaxHighlighting(to: mutAttributedString, in: NSRange(location: 0, length: string.count))
}

var base1Range = NSRange(location: 0, length: 0)
let base1Attributes = mutAttributedString.attributes(at: 0, effectiveRange: &base1Range)

var templateRange = NSRange(location: 0, length: 0)
let templateAttributes = mutAttributedString.attributes(at: 13, effectiveRange: &templateRange)

var base2Range = NSRange(location: 0, length: 0)
let base2Attributes = mutAttributedString.attributes(at: 46, effectiveRange: &base2Range)

// "Ford Island ("
XCTAssertEqual(base1Range.location, 0, "Incorrect base formatting")
XCTAssertEqual(base1Range.length, 13, "Incorrect base formatting")
XCTAssertEqual(base1Attributes[.font] as! UIFont, fonts.baseFont, "Incorrect base formatting")
XCTAssertEqual(base1Attributes[.foregroundColor] as! UIColor, colors.baseForegroundColor, "Incorrect base formatting")

// "{{lang-haw|Poka {{okina}}Ailana}}"
XCTAssertEqual(templateRange.location, 13, "Incorrect template formatting")
XCTAssertEqual(templateRange.length, 33, "Incorrect template formatting")
XCTAssertEqual(templateAttributes[.font] as! UIFont, fonts.baseFont, "Incorrect template formatting")
XCTAssertEqual(templateAttributes[.foregroundColor] as! UIColor, colors.purpleForegroundColor, "Incorrect template formatting")

// ") is an"
XCTAssertEqual(base2Range.location, 46, "Incorrect base formatting")
XCTAssertEqual(base2Range.length, 7, "Incorrect base formatting")
XCTAssertEqual(base2Attributes[.font] as! UIFont, fonts.baseFont, "Incorrect base formatting")
XCTAssertEqual(base2Attributes[.foregroundColor] as! UIColor, colors.baseForegroundColor, "Incorrect base formatting")
}

func testVerticalStartTemplate1() {
let string = "{{Infobox officeholder"
let mutAttributedString = NSMutableAttributedString(string: string)
Expand Down

0 comments on commit 91eac86

Please sign in to comment.