Skip to content

Commit

Permalink
Introduce Numerics package to unit tests for CotEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Jul 5, 2024
1 parent a95dfcd commit e09f13c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
27 changes: 27 additions & 0 deletions CotEditor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@
2AB857EF2B930B070079CFA2 /* Syntax+Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB857ED2B930B070079CFA2 /* Syntax+Localization.swift */; };
2AB9E4C02B830902004E5BDC /* FormatSettings.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 2AB9E4C22B830902004E5BDC /* FormatSettings.xcstrings */; };
2AB9E4C12B830902004E5BDC /* FormatSettings.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 2AB9E4C22B830902004E5BDC /* FormatSettings.xcstrings */; };
2ABB27D22C38268300AFCD0B /* Numerics in Frameworks */ = {isa = PBXBuildFile; productRef = 2ABB27CD2C3824DE00AFCD0B /* Numerics */; };
2ABBACA11E3F1D1C00A080E7 /* NSTextStorage+ScriptingSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ABBACA01E3F1D1C00A080E7 /* NSTextStorage+ScriptingSupport.swift */; };
2ABBACA21E3F1D1C00A080E7 /* NSTextStorage+ScriptingSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ABBACA01E3F1D1C00A080E7 /* NSTextStorage+ScriptingSupport.swift */; };
2ABC76241909BF5200D2B592 /* Themes in Resources */ = {isa = PBXBuildFile; fileRef = 2A7846DA18FE035E006BDF00 /* Themes */; };
Expand Down Expand Up @@ -1239,6 +1240,14 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
2ABB27CE2C38250A00AFCD0B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2ABB27D22C38268300AFCD0B /* Numerics in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
8D15AC330486D014006FF6A4 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -2301,6 +2310,7 @@
buildPhases = (
2AC71DDB1BF0BDBC002E1434 /* Sources */,
2AC71DDD1BF0BDBC002E1434 /* Resources */,
2ABB27CE2C38250A00AFCD0B /* Frameworks */,
);
buildRules = (
);
Expand All @@ -2309,6 +2319,9 @@
2AA2C6F7243996EC0017D1EC /* PBXTargetDependency */,
);
name = Tests;
packageProductDependencies = (
2ABB27CD2C3824DE00AFCD0B /* Numerics */,
);
productName = CotEditorTests;
productReference = 2AC71DDF1BF0BDBC002E1434 /* Tests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
Expand Down Expand Up @@ -2421,6 +2434,7 @@
2AA2C6FA24399A920017D1EC /* XCRemoteSwiftPackageReference "Yams" */,
2AAAE6E326DB82F800C5F0AC /* XCRemoteSwiftPackageReference "Sparkle" */,
2AB756AF2C25BBA4005E04C3 /* XCRemoteSwiftPackageReference "SwiftLint" */,
2ABB27CC2C3824DE00AFCD0B /* XCRemoteSwiftPackageReference "swift-numerics" */,
);
preferredProjectObjectVersion = 73;
projectDirPath = "";
Expand Down Expand Up @@ -3748,6 +3762,14 @@
minimumVersion = 0.55.1;
};
};
2ABB27CC2C3824DE00AFCD0B /* XCRemoteSwiftPackageReference "swift-numerics" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apple/swift-numerics.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.0.2;
};
};
2ACD02BB22A87CED00893051 /* XCRemoteSwiftPackageReference "WFColorCode" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/1024jp/WFColorCode";
Expand Down Expand Up @@ -3806,6 +3828,11 @@
package = 2AB756AF2C25BBA4005E04C3 /* XCRemoteSwiftPackageReference "SwiftLint" */;
productName = "plugin:SwiftLintBuildToolPlugin";
};
2ABB27CD2C3824DE00AFCD0B /* Numerics */ = {
isa = XCSwiftPackageProductDependency;
package = 2ABB27CC2C3824DE00AFCD0B /* XCRemoteSwiftPackageReference "swift-numerics" */;
productName = Numerics;
};
2ACAAC1B2B85E74C0041B095 /* SyntaxMap */ = {
isa = XCSwiftPackageProductDependency;
productName = SyntaxMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "247f0d04adc9817c29e92211f8fa6bb3f91a51a18fd6c33e614c884f5e57757d",
"originHash" : "620b10ecabe74244a92197744310a0d5f5fba33a38fde10e34c1bcfca649708e",
"pins" : [
{
"identity" : "collectionconcurrencykit",
Expand Down Expand Up @@ -46,6 +46,15 @@
"version" : "1.4.0"
}
},
{
"identity" : "swift-numerics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-numerics.git",
"state" : {
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
"version" : "1.0.2"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
Expand Down
9 changes: 3 additions & 6 deletions Tests/FontExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import AppKit.NSFont
import Testing
import Numerics
@testable import CotEditor

struct FontExtensionTests {
Expand All @@ -44,9 +45,7 @@ struct FontExtensionTests {
let boldFont = try #require(NSFont(name: "Menlo-Bold", size: 11))

#expect(regularFont.weight == .regular)
withKnownIssue("Test-side issue") {
#expect(boldFont.weight.rawValue == NSFont.Weight.bold.rawValue) // accuracy: 0.00001
}
#expect(boldFont.weight.rawValue.isApproximatelyEqual(to: NSFont.Weight.bold.rawValue, relativeTolerance: 0.00001))

// The const value is (unfortunately) not exact equal...
#expect(boldFont.weight.rawValue == 0.4)
Expand All @@ -61,8 +60,6 @@ struct FontExtensionTests {

let avenirNextCondensed = try #require(NSFont(named: .avenirNextCondensed, weight: .bold, size: 11))
#expect(avenirNextCondensed == NSFont(name: "AvenirNextCondensed-Bold", size: 11))
withKnownIssue("Test-side issue") {
#expect(avenirNextCondensed.weight.rawValue == NSFont.Weight.bold.rawValue) // accuracy: 0.00001
}
#expect(avenirNextCondensed.weight.rawValue.isApproximatelyEqual(to: NSFont.Weight.bold.rawValue, relativeTolerance: 0.00001))
}
}
9 changes: 3 additions & 6 deletions Tests/ThemeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import AppKit
import UniformTypeIdentifiers
import Testing
import Numerics
import Syntax
@testable import CotEditor

Expand All @@ -43,13 +44,9 @@ actor ThemeTests {
#expect(theme.name == themeName)
#expect(theme.text.color == NSColor.black.usingColorSpace(.genericRGB))
#expect(theme.insertionPoint.color == NSColor.black.usingColorSpace(.genericRGB))
withKnownIssue("Test-side issue") {
#expect(theme.invisibles.color.brightnessComponent == 0.725) // accuracy: 0.01
}
#expect(theme.invisibles.color.brightnessComponent.isApproximatelyEqual(to: 0.725, relativeTolerance: 0.01))
#expect(theme.background.color == NSColor.white.usingColorSpace(.genericRGB))
withKnownIssue("Test-side issue") {
#expect(theme.lineHighlight.color.brightnessComponent == 0.929) // accuracy: 0.01
}
#expect(theme.lineHighlight.color.brightnessComponent.isApproximatelyEqual(to: 0.929, relativeTolerance: 0.01))
#expect(theme.effectiveSecondarySelectionColor(for: NSAppearance(named: .aqua)!) == .unemphasizedSelectedContentBackgroundColor)
#expect(!theme.isDarkTheme)

Expand Down

0 comments on commit e09f13c

Please sign in to comment.