mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-10-27 03:19:49 +03:00
Improve unit tests
This commit is contained in:
parent
df3e50ddd6
commit
4accfe56aa
@ -207,7 +207,7 @@ extension String {
|
||||
|
||||
|
||||
|
||||
enum FuzzyLocationError: Error {
|
||||
enum FuzzyLocationError: Error, Equatable {
|
||||
|
||||
case invalidLine(Int)
|
||||
case invalidColumn(Int)
|
||||
|
@ -30,11 +30,13 @@ import Testing
|
||||
|
||||
struct EncodingDetectionTests {
|
||||
|
||||
@Test func utf8BOM() throws {
|
||||
@Test(.bug("https://bugs.swift.org/browse/SR-10173")) func utf8BOM() throws {
|
||||
|
||||
// -> String(data:encoding:) preserves BOM since Swift 5 (2019-03)
|
||||
// cf. https://bugs.swift.org/browse/SR-10173
|
||||
let data = try self.dataForFileName("UTF-8 BOM")
|
||||
withKnownIssue {
|
||||
#expect(String(decoding: data, as: UTF8.self) == "0")
|
||||
}
|
||||
#expect(String(decoding: data, as: UTF8.self) == "\u{FEFF}0")
|
||||
#expect(String(bomCapableData: data, encoding: .utf8) == "0")
|
||||
|
||||
@ -49,6 +51,35 @@ struct EncodingDetectionTests {
|
||||
}
|
||||
|
||||
|
||||
/// Tests if the U+FEFF omitting bug on Swift 5 still exists.
|
||||
@Test(.bug("https://bugs.swift.org/browse/SR-10896")) func feff() {
|
||||
|
||||
let bom = "\u{feff}"
|
||||
#expect(bom.count == 1)
|
||||
#expect(("\(bom)abc").count == 4)
|
||||
|
||||
#expect(NSString(string: "a\(bom)bc").length == 4)
|
||||
withKnownIssue {
|
||||
#expect(NSString(string: bom) as String == bom)
|
||||
#expect(NSString(string: bom).length == 1)
|
||||
#expect(NSString(string: "\(bom)\(bom)").length == 2)
|
||||
#expect(NSString(string: "\(bom)abc").length == 4)
|
||||
}
|
||||
|
||||
// -> These test cases must fail if the bug fixed.
|
||||
#expect(NSString(string: bom).length == 0)
|
||||
#expect(NSString(string: "\(bom)\(bom)").length == 1)
|
||||
#expect(NSString(string: "\(bom)abc").length == 3)
|
||||
|
||||
let string = "\(bom)abc"
|
||||
|
||||
// Implicit NSString cast is fixed.
|
||||
// -> However, still crashes when `string.immutable.enumerateSubstrings(in:)`
|
||||
let middleIndex = string.index(string.startIndex, offsetBy: 2)
|
||||
string.enumerateSubstrings(in: middleIndex..<string.endIndex, options: .byLines) { (_, _, _, _) in }
|
||||
}
|
||||
|
||||
|
||||
@Test func utf16() throws {
|
||||
|
||||
var encoding: String.Encoding?
|
||||
|
@ -76,17 +76,19 @@ import Testing
|
||||
counter.invalidateContent()
|
||||
counter.invalidateSelection()
|
||||
|
||||
// #expect(counter.result.lines.entire == 3)
|
||||
// #expect(counter.result.characters.entire == 31)
|
||||
// #expect(counter.result.words.entire == 6)
|
||||
|
||||
// #expect(counter.result.characters.selected == 9)
|
||||
// #expect(counter.result.lines.selected == 1)
|
||||
// #expect(counter.result.words.selected == 2)
|
||||
|
||||
// #expect(counter.result.location == 10)
|
||||
// #expect(counter.result.column == 0)
|
||||
// #expect(counter.result.line == 2)
|
||||
withKnownIssue("values will be updated asynchronously (This is the issue on the test side.)") {
|
||||
#expect(counter.result.lines.entire == 3)
|
||||
#expect(counter.result.characters.entire == 31)
|
||||
#expect(counter.result.words.entire == 6)
|
||||
|
||||
#expect(counter.result.characters.selected == 9)
|
||||
#expect(counter.result.lines.selected == 1)
|
||||
#expect(counter.result.words.selected == 2)
|
||||
|
||||
#expect(counter.result.location == 10)
|
||||
#expect(counter.result.column == 0)
|
||||
#expect(counter.result.line == 2)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -103,13 +105,15 @@ import Testing
|
||||
#expect(counter.result.characters.entire == nil)
|
||||
#expect(counter.result.words.entire == nil)
|
||||
|
||||
// #expect(counter.result.lines.selected == 1)
|
||||
// #expect(counter.result.characters.selected == 9)
|
||||
// #expect(counter.result.words.selected == 2)
|
||||
|
||||
// #expect(counter.result.location == 10)
|
||||
// #expect(counter.result.column == 0)
|
||||
// #expect(counter.result.line == 2)
|
||||
withKnownIssue("values will be updated asynchronously (This is the issue on the test side.)") {
|
||||
#expect(counter.result.lines.selected == 1)
|
||||
#expect(counter.result.characters.selected == 9)
|
||||
#expect(counter.result.words.selected == 2)
|
||||
|
||||
#expect(counter.result.location == 10)
|
||||
#expect(counter.result.column == 0)
|
||||
#expect(counter.result.line == 2)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,7 +44,9 @@ struct FontExtensionTests {
|
||||
let boldFont = try #require(NSFont(name: "Menlo-Bold", size: 11))
|
||||
|
||||
#expect(regularFont.weight == .regular)
|
||||
// #expect(boldFont.weight.rawValue == NSFont.Weight.bold.rawValue) // accuracy: 0.00001
|
||||
withKnownIssue("Test-side issue") {
|
||||
#expect(boldFont.weight.rawValue == NSFont.Weight.bold.rawValue) // accuracy: 0.00001
|
||||
}
|
||||
|
||||
// The const value is (unfortunately) not exact equal...
|
||||
#expect(boldFont.weight.rawValue == 0.4)
|
||||
@ -59,6 +61,8 @@ struct FontExtensionTests {
|
||||
|
||||
let avenirNextCondensed = try #require(NSFont(named: .avenirNextCondensed, weight: .bold, size: 11))
|
||||
#expect(avenirNextCondensed == NSFont(name: "AvenirNextCondensed-Bold", size: 11))
|
||||
// #expect(avenirNextCondensed.weight.rawValue == NSFont.Weight.bold.rawValue) // accuracy: 0.00001
|
||||
withKnownIssue("Test-side issue") {
|
||||
#expect(avenirNextCondensed.weight.rawValue == NSFont.Weight.bold.rawValue) // accuracy: 0.00001
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,13 +117,13 @@ struct FuzzyRangeTests {
|
||||
#expect(try string.fuzzyLocation(line: -1) == 13)
|
||||
#expect(try string.fuzzyLocation(line: -2) == 9)
|
||||
#expect(try string.fuzzyLocation(line: -5) == 0)
|
||||
#expect(throws: FuzzyLocationError.self) { try string.fuzzyLocation(line: -6) }
|
||||
#expect(throws: FuzzyLocationError.invalidLine(-6)) { try string.fuzzyLocation(line: -6) }
|
||||
|
||||
// line with a line ending
|
||||
#expect(try string.fuzzyLocation(line: 4, column: 0) == 9)
|
||||
#expect(try string.fuzzyLocation(line: 4, column: 1) == 10)
|
||||
#expect(try string.fuzzyLocation(line: 4, column: 3) == 12)
|
||||
#expect(throws: FuzzyLocationError.self) { try string.fuzzyLocation(line: 4, column: 4) }
|
||||
#expect(throws: FuzzyLocationError.invalidColumn(4)) { try string.fuzzyLocation(line: 4, column: 4) }
|
||||
#expect(try string.fuzzyLocation(line: 4, column: -1) == 12)
|
||||
#expect(try string.fuzzyLocation(line: 4, column: -2) == 11)
|
||||
|
||||
@ -131,7 +131,7 @@ struct FuzzyRangeTests {
|
||||
#expect(try string.fuzzyLocation(line: 5, column: 0) == 13)
|
||||
#expect(try string.fuzzyLocation(line: 5, column: 1) == 14)
|
||||
#expect(try string.fuzzyLocation(line: 5, column: 3) == 16)
|
||||
#expect(throws: FuzzyLocationError.self) { try string.fuzzyLocation(line: 5, column: 4) }
|
||||
#expect(throws: FuzzyLocationError.invalidColumn(4)) { try string.fuzzyLocation(line: 5, column: 4) }
|
||||
#expect(try string.fuzzyLocation(line: 5, column: -1) == 16)
|
||||
#expect(try string.fuzzyLocation(line: 5, column: -2) == 15)
|
||||
}
|
||||
|
@ -31,25 +31,15 @@ import Testing
|
||||
struct StringExtensionsTests {
|
||||
|
||||
/// Tests if the U+FEFF omitting bug on Swift 5 still exists.
|
||||
@Test(.bug("https://bugs.swift.org/browse/SR-10896")) func feff() {
|
||||
@Test(.bug("https://bugs.swift.org/browse/SR-10896")) func immutable() {
|
||||
|
||||
#expect("abc".immutable == "abc")
|
||||
|
||||
let bom = "\u{feff}"
|
||||
|
||||
// -> Some of these test cases must fail if the bug fixed.
|
||||
#expect(bom.count == 1)
|
||||
#expect(("\(bom)abc").count == 4)
|
||||
#expect(NSString(string: bom).length == 0) // correct: 1
|
||||
#expect(NSString(string: "\(bom)\(bom)").length == 1) // correct: 2
|
||||
#expect(NSString(string: "\(bom)abc").length == 3) // correct: 4
|
||||
#expect(NSString(string: "a\(bom)bc").length == 4)
|
||||
|
||||
let string = "\(bom)abc"
|
||||
#expect(string.immutable != string) // -> This test must fail if the bug fixed.
|
||||
|
||||
// Implicit NSString cast is fixed.
|
||||
// -> However, still crashes when `string.immutable.enumerateSubstrings(in:)`
|
||||
let middleIndex = string.index(string.startIndex, offsetBy: 2)
|
||||
string.enumerateSubstrings(in: middleIndex..<string.endIndex, options: .byLines) { (_, _, _, _) in }
|
||||
withKnownIssue {
|
||||
#expect(string.immutable == string)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,9 +42,13 @@ actor ThemeTests {
|
||||
#expect(theme.name == themeName)
|
||||
#expect(theme.text.color == NSColor.black.usingColorSpace(.genericRGB))
|
||||
#expect(theme.insertionPoint.color == NSColor.black.usingColorSpace(.genericRGB))
|
||||
// #expect(theme.invisibles.color.brightnessComponent == 0.725) // accuracy: 0.01
|
||||
withKnownIssue("Test-side issue") {
|
||||
#expect(theme.invisibles.color.brightnessComponent == 0.725) // accuracy: 0.01
|
||||
}
|
||||
#expect(theme.background.color == NSColor.white.usingColorSpace(.genericRGB))
|
||||
// #expect(theme.lineHighlight.color.brightnessComponent == 0.929) // accuracy: 0.01
|
||||
withKnownIssue("Test-side issue") {
|
||||
#expect(theme.lineHighlight.color.brightnessComponent == 0.929) // accuracy: 0.01
|
||||
}
|
||||
#expect(theme.effectiveSecondarySelectionColor(for: NSAppearance(named: .aqua)!) == .unemphasizedSelectedContentBackgroundColor)
|
||||
#expect(!theme.isDarkTheme)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user