mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-25 06:43:24 +03:00
Fix some tests
- The font from Typesetter does not equal to the input font... Why?
This commit is contained in:
parent
6c1882094d
commit
36cc213841
@ -11,6 +11,7 @@
|
||||
1929B06F50B2585777FFBE48 /* NvimApiCommons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B002A03693B14B14BE34 /* NvimApiCommons.swift */; };
|
||||
1929B14D2EBC34BCFEC78ACB /* CellAttributesCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BB19DD03ECD6ECC35F94 /* CellAttributesCollection.swift */; };
|
||||
1929B2DB631E6EB5C3452B68 /* MyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BAF033A398BFBC2A7890 /* MyView.swift */; };
|
||||
1929B2E9F089A9E2800B67F2 /* NimbleCommons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BF88DE64FC62AFFCBC84 /* NimbleCommons.swift */; };
|
||||
1929B36C51BCDFCCEE974EA2 /* SwiftCommons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B9C55A79D97272894F5D /* SwiftCommons.swift */; };
|
||||
1929B3B70C96A78FD63DE737 /* NvimView+Debug.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BDC8F32F4A0D2299B5C5 /* NvimView+Debug.swift */; };
|
||||
1929B40A751BDA2882D4FC94 /* NvimView+Objects.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B22A0CAD417EC3790F02 /* NvimView+Objects.swift */; };
|
||||
@ -197,6 +198,7 @@
|
||||
1929BDE2C6003A6EDC02129C /* ColorUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorUtils.swift; sourceTree = "<group>"; };
|
||||
1929BE45756C88F8B43804D2 /* CellAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellAttributes.swift; sourceTree = "<group>"; };
|
||||
1929BF14AE831C6832659B66 /* Defs.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Defs.swift; sourceTree = "<group>"; };
|
||||
1929BF88DE64FC62AFFCBC84 /* NimbleCommons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NimbleCommons.swift; sourceTree = "<group>"; };
|
||||
1929BFCCDE5C7145BE5A7387 /* TypesetterTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypesetterTest.swift; sourceTree = "<group>"; };
|
||||
4B0A1B112129F49500F1E02F /* NvimViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NvimViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
4B0A1B132129F49500F1E02F /* SwiftCommonsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftCommonsTest.swift; sourceTree = "<group>"; };
|
||||
@ -330,6 +332,7 @@
|
||||
1929BFCCDE5C7145BE5A7387 /* TypesetterTest.swift */,
|
||||
1929BBA08E4195666290EC6A /* UGridTest.swift */,
|
||||
1929B0B60CCAA00B08ACAB15 /* CellAttributesCollectionTest.swift */,
|
||||
1929BF88DE64FC62AFFCBC84 /* NimbleCommons.swift */,
|
||||
);
|
||||
path = NvimViewTests;
|
||||
sourceTree = "<group>";
|
||||
@ -644,6 +647,7 @@
|
||||
1929BB552C9D99E9ED938759 /* CellAttributesCollectionTest.swift in Sources */,
|
||||
1929B90E2CFEAADE0CEE1562 /* CursorModeShape.swift in Sources */,
|
||||
1929BDC146B699BF49116CAB /* Defs.swift in Sources */,
|
||||
1929B2E9F089A9E2800B67F2 /* NimbleCommons.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
29
NvimView/NvimViewTests/NimbleCommons.swift
Normal file
29
NvimView/NvimViewTests/NimbleCommons.swift
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Tae Won Ha - http://taewon.de - @hataewon
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
import Cocoa
|
||||
import Nimble
|
||||
|
||||
// I don't know why the font returned by Typesetter is not equal to the font
|
||||
// it should be equal to. This is a workaround.
|
||||
func equalFont(_ expectedValue: NSFont?) -> Predicate<NSFont> {
|
||||
return Predicate { actualExpression in
|
||||
let msg = ExpectationMessage.expectedActualValueTo(
|
||||
"equal <\(String(describing: expectedValue))>"
|
||||
)
|
||||
if let actualValue = try actualExpression.evaluate() {
|
||||
return PredicateResult(
|
||||
bool: NSFont(name: actualValue.fontName,
|
||||
size: actualValue.pointSize) == expectedValue!,
|
||||
message: msg
|
||||
)
|
||||
} else {
|
||||
return PredicateResult(
|
||||
status: .fail,
|
||||
message: msg.appendedBeNilHint()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(2))
|
||||
|
||||
let run = runs[0]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(3))
|
||||
expect(run.positions).to(equal(
|
||||
(10..<13).map {
|
||||
@ -45,7 +45,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(2))
|
||||
|
||||
let run = runs[0]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(3))
|
||||
expect(run.positions).to(equal(
|
||||
(20..<23).map {
|
||||
@ -70,7 +70,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(6))
|
||||
|
||||
var run = runs[0]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(1))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
@ -79,7 +79,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
))
|
||||
|
||||
run = runs[1]
|
||||
expect(run.font).to(equal(courierNew))
|
||||
expect(run.font).to(equalFont(courierNew))
|
||||
expect(run.glyphs).to(haveCount(2))
|
||||
expect(run.positions[0])
|
||||
.to(equal(CGPoint(x: offset.x + 11 * defaultWidth, y: offset.y)))
|
||||
@ -88,7 +88,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
expect(run.positions[1].y).to(beCloseTo(offset.y + 0.305, within: 0.001))
|
||||
|
||||
run = runs[2]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(2))
|
||||
expect(run.positions[0])
|
||||
.to(equal(CGPoint(x: offset.x + 12 * defaultWidth, y: offset.y)))
|
||||
@ -97,7 +97,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
expect(run.positions[1].y).to(beCloseTo(offset.y - 0.279, within: 0.001))
|
||||
|
||||
run = runs[3]
|
||||
expect(run.font).to(equal(monaco))
|
||||
expect(run.font).to(equalFont(monaco))
|
||||
expect(run.glyphs).to(haveCount(2))
|
||||
expect(run.positions[0])
|
||||
.to(equal(CGPoint(x: offset.x + 13 * defaultWidth, y: offset.y)))
|
||||
@ -106,7 +106,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
expect(run.positions[1].y).to(beCloseTo(offset.y + 2.446, within: 0.001))
|
||||
|
||||
run = runs[4]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(2))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
@ -130,7 +130,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(3))
|
||||
|
||||
var run = runs[0]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(2))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
@ -140,7 +140,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
))
|
||||
|
||||
run = runs[1]
|
||||
expect(run.font).to(equal(emoji))
|
||||
expect(run.font).to(equalFont(emoji))
|
||||
expect(run.glyphs).to(haveCount(2))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
@ -164,7 +164,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(3))
|
||||
|
||||
var run = runs[0]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(1))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
@ -173,7 +173,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
))
|
||||
|
||||
run = runs[1]
|
||||
expect(run.font).to(equal(emoji))
|
||||
expect(run.font).to(equalFont(emoji))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
CGPoint(x: offset.x + 2 * defaultWidth, y: offset.y),
|
||||
@ -194,7 +194,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(3))
|
||||
|
||||
var run = runs[0]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(2))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
@ -204,7 +204,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
))
|
||||
|
||||
run = runs[1]
|
||||
expect(run.font).to(equal(gothic))
|
||||
expect(run.font).to(equalFont(gothic))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
CGPoint(x: offset.x + 3 * defaultWidth, y: offset.y),
|
||||
@ -227,7 +227,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(3))
|
||||
|
||||
var run = runs[0]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(2))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
@ -237,7 +237,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
))
|
||||
|
||||
run = runs[1]
|
||||
expect(run.font).to(equal(gothic))
|
||||
expect(run.font).to(equalFont(gothic))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
CGPoint(x: offset.x + 3 * defaultWidth, y: offset.y),
|
||||
@ -260,7 +260,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(4))
|
||||
|
||||
var run = runs[0]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(1))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
@ -269,7 +269,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
))
|
||||
|
||||
run = runs[1]
|
||||
expect(run.font).to(equal(baskerville))
|
||||
expect(run.font).to(equalFont(baskerville))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
CGPoint(x: offset.x + 2 * defaultWidth, y: offset.y),
|
||||
@ -277,7 +277,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
))
|
||||
|
||||
run = runs[2]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(1))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
@ -300,7 +300,7 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(2))
|
||||
|
||||
let run = runs[0]
|
||||
expect(run.font).to(equal(fira))
|
||||
expect(run.font).to(equalFont(fira))
|
||||
expect(run.glyphs).to(equal([133, 1023, 1023, 1148, 133]))
|
||||
expect(run.positions).to(equal(
|
||||
(1..<6).map {
|
||||
@ -312,12 +312,12 @@ class TypesetterWithoutLigaturesTest: XCTestCase {
|
||||
}
|
||||
|
||||
private func assertAsciiMarker(run: FontGlyphRun, xPosition: CGFloat) {
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.positions).to(equal([CGPoint(x: xPosition, y: offset.y)]))
|
||||
}
|
||||
|
||||
private func assertEmojiMarker(run: FontGlyphRun, xPosition: CGFloat) {
|
||||
expect(run.font).to(equal(emoji))
|
||||
expect(run.font).to(equalFont(emoji))
|
||||
expect(run.positions).to(equal([CGPoint(x: xPosition, y: offset.y)]))
|
||||
}
|
||||
}
|
||||
@ -335,7 +335,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(2))
|
||||
|
||||
let run = runs[0]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(20))
|
||||
expect(run.positions).to(equal(
|
||||
(1..<21).map {
|
||||
@ -359,7 +359,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(2))
|
||||
|
||||
let run = runs[0]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(3))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
@ -385,7 +385,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
// The positions of the combining characters are copied from print outputs
|
||||
// and they are visually checked by drawing them and inspecting them...
|
||||
var run = runs[0]
|
||||
expect(run.font).to(equal(courierNew))
|
||||
expect(run.font).to(equalFont(courierNew))
|
||||
expect(run.glyphs).to(haveCount(2))
|
||||
expect(run.positions[0])
|
||||
.to(equal(CGPoint(x: offset.x + 1 * defaultWidth, y: offset.y)))
|
||||
@ -394,7 +394,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
expect(run.positions[1].y).to(beCloseTo(offset.y + 0.305, within: 0.001))
|
||||
|
||||
run = runs[1]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.glyphs).to(haveCount(2))
|
||||
expect(run.positions[0])
|
||||
.to(equal(CGPoint(x: offset.x + 2 * defaultWidth, y: offset.y)))
|
||||
@ -403,7 +403,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
expect(run.positions[1].y).to(beCloseTo(offset.y - 0.279, within: 0.001))
|
||||
|
||||
run = runs[2]
|
||||
expect(run.font).to(equal(monaco))
|
||||
expect(run.font).to(equalFont(monaco))
|
||||
expect(run.glyphs).to(haveCount(2))
|
||||
expect(run.positions[0])
|
||||
.to(equal(CGPoint(x: offset.x + 3 * defaultWidth, y: offset.y)))
|
||||
@ -425,7 +425,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(2))
|
||||
|
||||
let run = runs[0]
|
||||
expect(run.font).to(equal(emoji))
|
||||
expect(run.font).to(equalFont(emoji))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
CGPoint(x: offset.x + 0, y: offset.y),
|
||||
@ -450,7 +450,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(2))
|
||||
|
||||
let run = runs[0]
|
||||
expect(run.font).to(equal(emoji))
|
||||
expect(run.font).to(equalFont(emoji))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
CGPoint(x: offset.x + 0, y: offset.y),
|
||||
@ -477,7 +477,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(2))
|
||||
|
||||
let run = runs[0]
|
||||
expect(run.font).to(equal(emoji))
|
||||
expect(run.font).to(equalFont(emoji))
|
||||
expect(run.glyphs).to(haveCount(1))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
@ -499,7 +499,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(2))
|
||||
|
||||
let run = runs[0]
|
||||
expect(run.font).to(equal(gothic))
|
||||
expect(run.font).to(equalFont(gothic))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
CGPoint(x: offset.x + 1 * defaultWidth, y: offset.y),
|
||||
@ -522,7 +522,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(2))
|
||||
|
||||
let run = runs[0]
|
||||
expect(run.font).to(equal(gothic))
|
||||
expect(run.font).to(equalFont(gothic))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
CGPoint(x: offset.x + 1 * defaultWidth, y: offset.y),
|
||||
@ -545,7 +545,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(3))
|
||||
|
||||
var run = runs[0]
|
||||
expect(run.font).to(equal(baskerville))
|
||||
expect(run.font).to(equalFont(baskerville))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
CGPoint(x: offset.x + 0, y: offset.y),
|
||||
@ -553,7 +553,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
))
|
||||
|
||||
run = runs[1]
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
CGPoint(x: offset.x + 1 * defaultWidth, y: offset.y),
|
||||
@ -574,7 +574,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
expect(runs).to(haveCount(2))
|
||||
|
||||
let run = runs[0]
|
||||
expect(run.font).to(equal(fira))
|
||||
expect(run.font).to(equalFont(fira))
|
||||
// Ligatures of popular monospace fonts like Fira Code seem to be composed
|
||||
// of multiple characters with the same advance as other normal characters.
|
||||
expect(run.glyphs).to(equal([1614, 1614, 1063, 133]))
|
||||
@ -588,7 +588,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
}
|
||||
|
||||
private func assertAsciiMarker(run: FontGlyphRun, xPosition: CGFloat) {
|
||||
expect(run.font).to(equal(defaultFont))
|
||||
expect(run.font).to(equalFont(defaultFont))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
CGPoint(x: xPosition, y: offset.y),
|
||||
@ -597,7 +597,7 @@ class TypesetterWithLigaturesTest: XCTestCase {
|
||||
}
|
||||
|
||||
private func assertEmojiMarker(run: FontGlyphRun, xPosition: CGFloat) {
|
||||
expect(run.font).to(equal(emoji))
|
||||
expect(run.font).to(equalFont(emoji))
|
||||
expect(run.positions).to(equal(
|
||||
[
|
||||
CGPoint(x: xPosition, y: offset.y),
|
||||
|
Loading…
Reference in New Issue
Block a user