mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-23 19:21:53 +03:00
Reformat using swiftformat
This commit is contained in:
parent
ef0c29b9ef
commit
0e89b99e6f
@ -1,4 +1,4 @@
|
||||
--swiftversion 5.2
|
||||
--swiftversion 5.3
|
||||
|
||||
--exclude Carthage,third-party,**/*.generated.swift
|
||||
|
||||
@ -7,3 +7,4 @@
|
||||
|
||||
--self insert
|
||||
--wraparguments before-first
|
||||
--ranges no-space
|
||||
|
@ -15,7 +15,7 @@ let package = Package(
|
||||
name: "CommonsTests",
|
||||
dependencies: ["Commons", "Nimble"],
|
||||
resources: [
|
||||
.copy("Resources")
|
||||
.copy("Resources"),
|
||||
]
|
||||
),
|
||||
]
|
||||
|
@ -6,7 +6,6 @@
|
||||
import AppKit
|
||||
|
||||
public extension NSAttributedString {
|
||||
|
||||
func draw(at point: CGPoint, angle: CGFloat) {
|
||||
var translation = AffineTransform.identity
|
||||
var rotation = AffineTransform.identity
|
||||
@ -30,7 +29,6 @@ public extension NSAttributedString {
|
||||
}
|
||||
|
||||
public extension NSColor {
|
||||
|
||||
static var random: NSColor {
|
||||
NSColor(
|
||||
calibratedRed: .random(in: 0...1),
|
||||
@ -56,9 +54,9 @@ public extension NSColor {
|
||||
|
||||
convenience init(rgb: Int) {
|
||||
// @formatter:off
|
||||
let red = ((rgb >> 16) & 0xFF).cgf / 255.0;
|
||||
let green = ((rgb >> 8) & 0xFF).cgf / 255.0;
|
||||
let blue = ((rgb ) & 0xFF).cgf / 255.0;
|
||||
let red = ((rgb >> 16) & 0xFF).cgf / 255.0
|
||||
let green = ((rgb >> 8) & 0xFF).cgf / 255.0
|
||||
let blue = (rgb & 0xFF).cgf / 255.0
|
||||
// @formatter:on
|
||||
|
||||
self.init(srgbRed: red, green: green, blue: blue, alpha: 1.0)
|
||||
@ -88,7 +86,6 @@ public extension NSColor {
|
||||
}
|
||||
|
||||
public extension NSImage {
|
||||
|
||||
func tinting(with color: NSColor) -> NSImage {
|
||||
let result = self.copy() as! NSImage
|
||||
|
||||
@ -102,7 +99,6 @@ public extension NSImage {
|
||||
}
|
||||
|
||||
public extension NSButton {
|
||||
|
||||
var boolState: Bool {
|
||||
get { self.state == .on ? true : false }
|
||||
set { self.state = newValue ? .on : .off }
|
||||
@ -110,7 +106,6 @@ public extension NSButton {
|
||||
}
|
||||
|
||||
public extension NSMenuItem {
|
||||
|
||||
var boolState: Bool {
|
||||
get { self.state == .on ? true : false }
|
||||
set { self.state = newValue ? .on : .off }
|
||||
@ -118,17 +113,16 @@ public extension NSMenuItem {
|
||||
}
|
||||
|
||||
public extension NSView {
|
||||
|
||||
func removeAllSubviews() { self.subviews.forEach { $0.removeFromSuperview() } }
|
||||
|
||||
func removeAllConstraints() { self.removeConstraints(self.constraints) }
|
||||
|
||||
func beFirstResponder() { self.window?.makeFirstResponder(self) }
|
||||
|
||||
|
||||
/// - Returns: Rects currently being drawn
|
||||
/// - Warning: Call only in drawRect()
|
||||
func rectsBeingDrawn() -> [CGRect] {
|
||||
var rectsPtr: UnsafePointer<CGRect>? = nil
|
||||
var rectsPtr: UnsafePointer<CGRect>?
|
||||
var count: Int = 0
|
||||
self.getRectsBeingDrawn(&rectsPtr, count: &count)
|
||||
|
||||
@ -137,16 +131,15 @@ public extension NSView {
|
||||
}
|
||||
|
||||
public extension NSEvent.ModifierFlags {
|
||||
|
||||
// Values are from https://github.com/SFML/SFML/blob/master/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm
|
||||
// @formatter:off
|
||||
static let rightShift = NSEvent.ModifierFlags(rawValue: 0x020004)
|
||||
static let leftShift = NSEvent.ModifierFlags(rawValue: 0x020002)
|
||||
static let rightShift = NSEvent.ModifierFlags(rawValue: 0x020004)
|
||||
static let leftShift = NSEvent.ModifierFlags(rawValue: 0x020002)
|
||||
static let rightCommand = NSEvent.ModifierFlags(rawValue: 0x100010)
|
||||
static let leftCommand = NSEvent.ModifierFlags(rawValue: 0x100008)
|
||||
static let rightOption = NSEvent.ModifierFlags(rawValue: 0x080040)
|
||||
static let leftOption = NSEvent.ModifierFlags(rawValue: 0x080020)
|
||||
static let leftCommand = NSEvent.ModifierFlags(rawValue: 0x100008)
|
||||
static let rightOption = NSEvent.ModifierFlags(rawValue: 0x080040)
|
||||
static let leftOption = NSEvent.ModifierFlags(rawValue: 0x080020)
|
||||
static let rightControl = NSEvent.ModifierFlags(rawValue: 0x042000)
|
||||
static let leftControl = NSEvent.ModifierFlags(rawValue: 0x040001)
|
||||
static let leftControl = NSEvent.ModifierFlags(rawValue: 0x040001)
|
||||
// @formatter:on
|
||||
}
|
||||
|
@ -6,14 +6,13 @@
|
||||
import Foundation
|
||||
|
||||
public final class ConditionVariable {
|
||||
|
||||
private(set) var posted: Bool
|
||||
|
||||
public init(posted: Bool = false) {
|
||||
self.posted = posted
|
||||
}
|
||||
|
||||
public func wait(`for` seconds: TimeInterval, then fn: (() -> Void)? = nil) {
|
||||
public func wait(for seconds: TimeInterval, then fn: (() -> Void)? = nil) {
|
||||
self.condition.lock()
|
||||
defer { self.condition.unlock() }
|
||||
|
||||
|
@ -6,23 +6,19 @@
|
||||
import Foundation
|
||||
|
||||
public extension CFRange {
|
||||
|
||||
static let zero = CFRange(location: 0, length: 0)
|
||||
}
|
||||
|
||||
public extension CGSize {
|
||||
|
||||
func scaling(_ factor: CGFloat) -> CGSize {
|
||||
return CGSize(width: self.width * factor, height: self.height * factor)
|
||||
CGSize(width: self.width * factor, height: self.height * factor)
|
||||
}
|
||||
}
|
||||
|
||||
public extension CGRect {
|
||||
|
||||
var hashValue: Int {
|
||||
let o = Int(self.origin.x) << 10 ^ Int(self.origin.y)
|
||||
let s = Int(self.size.width) << 10 ^ Int(self.size.height)
|
||||
return o + s
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,11 +6,9 @@
|
||||
import Foundation
|
||||
|
||||
struct Defs {
|
||||
|
||||
static let loggerSubsystem = "com.qvacua.Commons"
|
||||
|
||||
struct LoggerCategory {
|
||||
|
||||
static let general = "general"
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
import Foundation
|
||||
|
||||
public final class FifoCache<Key: Hashable, Value> {
|
||||
|
||||
public init(count: Int, queueQos: DispatchQoS) {
|
||||
self.count = count
|
||||
self.keyWriteIndex = 0
|
||||
@ -35,9 +34,9 @@ public final class FifoCache<Key: Hashable, Value> {
|
||||
public func valueForKey(_ key: Key) -> Value? { self.queue.sync { self.storage[key] } }
|
||||
|
||||
private let count: Int
|
||||
private var keys: Array<Key?>
|
||||
private var keys: [Key?]
|
||||
private var keyWriteIndex: Int
|
||||
private var storage: Dictionary<Key, Value>
|
||||
private var storage: [Key: Value]
|
||||
|
||||
private let queue: DispatchQueue
|
||||
}
|
||||
|
@ -9,36 +9,36 @@ private let workspace = NSWorkspace.shared
|
||||
private let iconsCache = NSCache<NSURL, NSImage>()
|
||||
|
||||
public final class FileUtils {
|
||||
|
||||
private static let keysToGet: [URLResourceKey] = [
|
||||
.isDirectoryKey,
|
||||
.isHiddenKey,
|
||||
.isAliasFileKey,
|
||||
.isSymbolicLinkKey
|
||||
.isSymbolicLinkKey,
|
||||
]
|
||||
|
||||
|
||||
private static let scanOptions: FileManager.DirectoryEnumerationOptions = [
|
||||
.skipsSubdirectoryDescendants,
|
||||
.skipsPackageDescendants
|
||||
.skipsPackageDescendants,
|
||||
]
|
||||
|
||||
|
||||
private static let fileManager = FileManager.default
|
||||
|
||||
public static let userHomeUrl = URL(fileURLWithPath: NSHomeDirectory(), isDirectory: true)
|
||||
|
||||
public static func tempDir() -> URL { URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) }
|
||||
public static func tempDir()
|
||||
-> URL { URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) }
|
||||
|
||||
public static func directDescendants(of url: URL) -> [URL] {
|
||||
guard let childUrls = try? self.fileManager.contentsOfDirectory(
|
||||
at: url, includingPropertiesForKeys: self.keysToGet, options: self.scanOptions
|
||||
) else {
|
||||
// FIXME error handling
|
||||
// FIXME: error handling
|
||||
return []
|
||||
}
|
||||
|
||||
|
||||
return childUrls
|
||||
}
|
||||
|
||||
|
||||
public static func fileExists(at url: URL) -> Bool {
|
||||
guard url.isFileURL else {
|
||||
return false
|
||||
@ -54,9 +54,9 @@ public final class FileUtils {
|
||||
}
|
||||
|
||||
let pathComps = urls.map { $0.deletingLastPathComponent().pathComponents }
|
||||
let min = pathComps.map { $0.count }.min()!
|
||||
let min = pathComps.map(\.count).min()!
|
||||
let pathCompsOnlyMin = pathComps.map { $0[0..<min] }
|
||||
let commonIdx = (0..<min).reversed().reduce(min - 1) { (result, idx) in
|
||||
let commonIdx = (0..<min).reversed().reduce(min - 1) { result, idx in
|
||||
if Set(pathCompsOnlyMin.map { $0[idx] }).count > 1 {
|
||||
return idx - 1
|
||||
} else {
|
||||
@ -71,7 +71,7 @@ public final class FileUtils {
|
||||
}
|
||||
|
||||
public static func icon(forType type: String) -> NSImage {
|
||||
return workspace.icon(forFileType: type)
|
||||
workspace.icon(forFileType: type)
|
||||
}
|
||||
|
||||
public static func icon(forUrl url: URL) -> NSImage? {
|
||||
|
@ -7,7 +7,6 @@ import Foundation
|
||||
import os
|
||||
|
||||
public extension Array where Element: Hashable {
|
||||
|
||||
// From https://stackoverflow.com/a/46354989/9850227
|
||||
func uniqued() -> [Element] {
|
||||
var seen = Set<Element>()
|
||||
@ -16,14 +15,12 @@ public extension Array where Element: Hashable {
|
||||
}
|
||||
|
||||
public extension Array {
|
||||
|
||||
func data() -> Data {
|
||||
return self.withUnsafeBufferPointer(Data.init)
|
||||
self.withUnsafeBufferPointer(Data.init)
|
||||
}
|
||||
}
|
||||
|
||||
public extension RandomAccessCollection where Index == Int {
|
||||
|
||||
func parallelMap<T>(
|
||||
chunkSize: Int = 1,
|
||||
_ transform: @escaping (Element) -> T
|
||||
@ -31,7 +28,7 @@ public extension RandomAccessCollection where Index == Int {
|
||||
let count = self.count
|
||||
guard count > chunkSize else { return self.map(transform) }
|
||||
|
||||
var result = Array<T?>(repeating: nil, count: count)
|
||||
var result = [T?](repeating: nil, count: count)
|
||||
|
||||
// If we don't use Array.withUnsafeMutableBufferPointer,
|
||||
// then we get crashes.
|
||||
@ -97,16 +94,14 @@ public extension RandomAccessCollection where Index == Int {
|
||||
}
|
||||
|
||||
public extension NSRange {
|
||||
|
||||
static let notFound = NSRange(location: NSNotFound, length: 0)
|
||||
|
||||
var inclusiveEndIndex: Int { self.location + self.length - 1 }
|
||||
}
|
||||
|
||||
public extension URL {
|
||||
|
||||
func isDirectParent(of url: URL) -> Bool {
|
||||
guard self.isFileURL && url.isFileURL else { return false }
|
||||
guard self.isFileURL, url.isFileURL else { return false }
|
||||
|
||||
let myPathComps = self.pathComponents
|
||||
let targetPathComps = url.pathComponents
|
||||
@ -117,7 +112,7 @@ public extension URL {
|
||||
}
|
||||
|
||||
func isParent(of url: URL) -> Bool {
|
||||
guard self.isFileURL && url.isFileURL else { return false }
|
||||
guard self.isFileURL, url.isFileURL else { return false }
|
||||
|
||||
let myPathComps = self.pathComponents
|
||||
let targetPathComps = url.pathComponents
|
||||
@ -165,7 +160,7 @@ public extension URL {
|
||||
do {
|
||||
try (self as NSURL).getResourceValue(&rsrc, forKey: URLResourceKey(rawValue: key))
|
||||
} catch let error as NSError {
|
||||
// FIXME error handling
|
||||
// FIXME: error handling
|
||||
log.error("ERROR while getting \(key): \(error)")
|
||||
return false
|
||||
}
|
||||
@ -177,7 +172,6 @@ public extension URL {
|
||||
}
|
||||
|
||||
public extension ValueTransformer {
|
||||
|
||||
static var keyedUnarchiveFromDataTransformer
|
||||
= ValueTransformer(forName: .keyedUnarchiveFromDataTransformerName)!
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import Foundation
|
||||
import os
|
||||
|
||||
public extension OSLog {
|
||||
|
||||
func trace<T>(
|
||||
file: String = #file,
|
||||
function: String = #function,
|
||||
@ -15,11 +14,11 @@ public extension OSLog {
|
||||
_ msg: T
|
||||
) {
|
||||
#if TRACE
|
||||
self.log(
|
||||
type: .debug,
|
||||
msg: "%{public}@",
|
||||
"[\((file as NSString).lastPathComponent) - \(function):\(line)] [TRACE] \(msg)"
|
||||
)
|
||||
self.log(
|
||||
type: .debug,
|
||||
msg: "%{public}@",
|
||||
"[\((file as NSString).lastPathComponent) - \(function):\(line)] [TRACE] \(msg)"
|
||||
)
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -29,11 +28,11 @@ public extension OSLog {
|
||||
line: Int = #line
|
||||
) {
|
||||
#if DEBUG
|
||||
self.log(
|
||||
type: .debug,
|
||||
msg: "%{public}@",
|
||||
"[\((file as NSString).lastPathComponent) - \(function):\(line)]"
|
||||
)
|
||||
self.log(
|
||||
type: .debug,
|
||||
msg: "%{public}@",
|
||||
"[\((file as NSString).lastPathComponent) - \(function):\(line)]"
|
||||
)
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -44,11 +43,11 @@ public extension OSLog {
|
||||
_ msg: T
|
||||
) {
|
||||
#if DEBUG
|
||||
self.log(
|
||||
type: .debug,
|
||||
msg: "%{public}@",
|
||||
"[\((file as NSString).lastPathComponent) - \(function):\(line)] \(msg)"
|
||||
)
|
||||
self.log(
|
||||
type: .debug,
|
||||
msg: "%{public}@",
|
||||
"[\((file as NSString).lastPathComponent) - \(function):\(line)] \(msg)"
|
||||
)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import Foundation
|
||||
import os
|
||||
|
||||
public final class ProcessUtils {
|
||||
|
||||
public static func envVars(
|
||||
of shellPath: URL, usingInteractiveMode: Bool
|
||||
) -> [String: String] {
|
||||
@ -57,12 +56,16 @@ public final class ProcessUtils {
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.split(separator: "\n")
|
||||
.reduce(into: [:]) { result, entry in
|
||||
let split = entry.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false).map { String($0) }
|
||||
let split = entry
|
||||
.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false)
|
||||
.map { String($0) }
|
||||
guard split.count > 1 else { return }
|
||||
result[split[0]] = split[1]
|
||||
}
|
||||
}
|
||||
|
||||
private static let logger = OSLog(subsystem: Defs.loggerSubsystem,
|
||||
category: Defs.LoggerCategory.general)
|
||||
private static let logger = OSLog(
|
||||
subsystem: Defs.loggerSubsystem,
|
||||
category: Defs.LoggerCategory.general
|
||||
)
|
||||
}
|
||||
|
@ -8,21 +8,18 @@ import Foundation
|
||||
public func identity<T>(_ input: T) -> T { input }
|
||||
|
||||
public extension BinaryFloatingPoint {
|
||||
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
var cgf: CGFloat { CGFloat(self) }
|
||||
}
|
||||
|
||||
public extension FixedWidthInteger {
|
||||
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
var cgf: CGFloat { CGFloat(self) }
|
||||
}
|
||||
|
||||
public extension String {
|
||||
|
||||
func without(prefix: String) -> String {
|
||||
guard self.hasPrefix(prefix) else { return self }
|
||||
|
||||
@ -32,7 +29,6 @@ public extension String {
|
||||
}
|
||||
|
||||
public extension Array where Element: Equatable {
|
||||
|
||||
func removingDuplicatesPreservingFromBeginning() -> [Element] {
|
||||
var result = [Element]()
|
||||
|
||||
@ -62,9 +58,8 @@ public extension Array where Element: Equatable {
|
||||
}
|
||||
|
||||
public extension Array where Element: Hashable {
|
||||
|
||||
func toDict<V>(by mapper: @escaping (Element) -> V) -> Dictionary<Element, V> {
|
||||
var result = Dictionary<Element, V>(minimumCapacity: self.count)
|
||||
func toDict<V>(by mapper: @escaping (Element) -> V) -> [Element: V] {
|
||||
var result = [Element: V](minimumCapacity: self.count)
|
||||
self.forEach { result[$0] = mapper($0) }
|
||||
|
||||
return result
|
||||
@ -78,8 +73,9 @@ public extension Array where Element: Hashable {
|
||||
}
|
||||
|
||||
func tuplesToDict<K: Hashable, V, S: Sequence>(_ sequence: S)
|
||||
-> Dictionary<K, V> where S.Iterator.Element == (K, V) {
|
||||
var result = Dictionary<K, V>(minimumCapacity: sequence.underestimatedCount)
|
||||
-> [K: V] where S.Iterator.Element == (K, V)
|
||||
{
|
||||
var result = [K: V](minimumCapacity: sequence.underestimatedCount)
|
||||
|
||||
for (key, value) in sequence { result[key] = value }
|
||||
|
||||
@ -87,22 +83,22 @@ func tuplesToDict<K: Hashable, V, S: Sequence>(_ sequence: S)
|
||||
}
|
||||
|
||||
public extension Dictionary {
|
||||
|
||||
func mapToDict<K, V>(_ transform: ((key: Key, value: Value)) throws -> (K, V)) rethrows
|
||||
-> Dictionary<K, V> {
|
||||
-> [K: V]
|
||||
{
|
||||
let array = try self.map(transform)
|
||||
return tuplesToDict(array)
|
||||
}
|
||||
|
||||
func flatMapToDict<K, V>(_ transform: ((key: Key, value: Value)) throws -> (K, V)?) rethrows
|
||||
-> Dictionary<K, V> {
|
||||
-> [K: V]
|
||||
{
|
||||
let array = try self.compactMap(transform)
|
||||
return tuplesToDict(array)
|
||||
}
|
||||
}
|
||||
|
||||
public extension Sequence {
|
||||
|
||||
@discardableResult
|
||||
func log() -> Self {
|
||||
self.forEach { Swift.print($0) }
|
||||
|
@ -8,15 +8,14 @@ import Commons
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
@IBOutlet var window: NSWindow!
|
||||
@IBOutlet var textView: NSTextView!
|
||||
|
||||
@IBOutlet weak var window: NSWindow!
|
||||
@IBOutlet weak var textView: NSTextView!
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
func applicationDidFinishLaunching(_: Notification) {
|
||||
let selfEnv = ProcessInfo.processInfo.environment
|
||||
let shellUrl = URL(fileURLWithPath: selfEnv["SHELL"] ?? "/bin/bash")
|
||||
let env = ProcessUtils.envVars(of: shellUrl, usingInteractiveMode: false)
|
||||
|
||||
|
||||
for (k, v) in env {
|
||||
let str = NSAttributedString(string: "\(k): \(v)\n")
|
||||
print(str)
|
||||
|
@ -3,19 +3,18 @@
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
import Nimble
|
||||
import XCTest
|
||||
|
||||
@testable import Commons
|
||||
|
||||
fileprivate class DummyToken: Comparable {
|
||||
|
||||
static func ==(left: DummyToken, right: DummyToken) -> Bool {
|
||||
return left.value == right.value
|
||||
private class DummyToken: Comparable {
|
||||
static func == (left: DummyToken, right: DummyToken) -> Bool {
|
||||
left.value == right.value
|
||||
}
|
||||
|
||||
static func <(left: DummyToken, right: DummyToken) -> Bool {
|
||||
return left.value < right.value
|
||||
static func < (left: DummyToken, right: DummyToken) -> Bool {
|
||||
left.value < right.value
|
||||
}
|
||||
|
||||
let value: String
|
||||
@ -26,18 +25,17 @@ fileprivate class DummyToken: Comparable {
|
||||
}
|
||||
|
||||
class ArrayCommonsTest: XCTestCase {
|
||||
|
||||
func testTuplesToDict() {
|
||||
let tuples = [
|
||||
(1, "1"),
|
||||
(2, "2"),
|
||||
(3, "3")
|
||||
(3, "3"),
|
||||
]
|
||||
expect(tuplesToDict(tuples)).to(equal(
|
||||
[
|
||||
1: "1",
|
||||
2: "2",
|
||||
3: "3"
|
||||
3: "3",
|
||||
]
|
||||
))
|
||||
}
|
||||
@ -49,7 +47,7 @@ class ArrayCommonsTest: XCTestCase {
|
||||
[
|
||||
1: "1",
|
||||
2: "2",
|
||||
3: "3"
|
||||
3: "3",
|
||||
]
|
||||
))
|
||||
}
|
||||
@ -63,7 +61,7 @@ class ArrayCommonsTest: XCTestCase {
|
||||
let substitute = [
|
||||
DummyToken("a0"),
|
||||
DummyToken("a1"),
|
||||
DummyToken("a2")
|
||||
DummyToken("a2"),
|
||||
]
|
||||
|
||||
let array = [
|
||||
@ -88,7 +86,7 @@ class ArrayCommonsTest: XCTestCase {
|
||||
let substitute = [
|
||||
DummyToken("a0"),
|
||||
DummyToken("a1"),
|
||||
DummyToken("a2")
|
||||
DummyToken("a2"),
|
||||
]
|
||||
|
||||
let array = [
|
||||
@ -113,7 +111,7 @@ class ArrayCommonsTest: XCTestCase {
|
||||
let substitute = [
|
||||
DummyToken("a0"),
|
||||
DummyToken("a1"),
|
||||
DummyToken("a2")
|
||||
DummyToken("a2"),
|
||||
]
|
||||
|
||||
let array = [
|
||||
@ -138,7 +136,7 @@ class ArrayCommonsTest: XCTestCase {
|
||||
let substitute = [
|
||||
DummyToken("a0"),
|
||||
DummyToken("a1"),
|
||||
DummyToken("a2")
|
||||
DummyToken("a2"),
|
||||
]
|
||||
|
||||
let array = [
|
||||
|
@ -3,22 +3,21 @@
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
import Nimble
|
||||
import XCTest
|
||||
|
||||
class DictionaryCommonsTest: XCTestCase {
|
||||
|
||||
func testMapToDict() {
|
||||
let dict = [
|
||||
1: "a",
|
||||
2: "b",
|
||||
3: "c"
|
||||
3: "c",
|
||||
]
|
||||
expect(dict.mapToDict { (k, v) in (v, "\(k)-\(v)") }).to(equal(
|
||||
expect(dict.mapToDict { k, v in (v, "\(k)-\(v)") }).to(equal(
|
||||
[
|
||||
"a": "1-a",
|
||||
"b": "2-b",
|
||||
"c": "3-c"
|
||||
"c": "3-c",
|
||||
]
|
||||
))
|
||||
}
|
||||
@ -27,9 +26,9 @@ class DictionaryCommonsTest: XCTestCase {
|
||||
let dict = [
|
||||
1: "a",
|
||||
2: "b",
|
||||
3: "c"
|
||||
3: "c",
|
||||
]
|
||||
expect(dict.flatMapToDict { (k, v) in
|
||||
expect(dict.flatMapToDict { k, v in
|
||||
if k == 2 {
|
||||
return nil
|
||||
}
|
||||
@ -38,7 +37,7 @@ class DictionaryCommonsTest: XCTestCase {
|
||||
}).to(equal(
|
||||
[
|
||||
"a": "1-a",
|
||||
"c": "3-c"
|
||||
"c": "3-c",
|
||||
]
|
||||
))
|
||||
}
|
||||
|
@ -3,13 +3,12 @@
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
import Nimble
|
||||
import XCTest
|
||||
|
||||
@testable import Commons
|
||||
|
||||
class FifoCacheTest: XCTestCase {
|
||||
|
||||
var fifo: FifoCache<Int, Int>!
|
||||
|
||||
override func setUp() {
|
||||
@ -18,15 +17,15 @@ class FifoCacheTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testSimpleGet() {
|
||||
for i in (0...5) { self.fifo.set(i, forKey: i) }
|
||||
for i in 0...5 { self.fifo.set(i, forKey: i) }
|
||||
|
||||
for i in (0...5) { expect(self.fifo.valueForKey(i)).to(equal(i)) }
|
||||
for i in (6..<10) { expect(self.fifo.valueForKey(i)).to(beNil()) }
|
||||
for i in 0...5 { expect(self.fifo.valueForKey(i)).to(equal(i)) }
|
||||
for i in 6..<10 { expect(self.fifo.valueForKey(i)).to(beNil()) }
|
||||
}
|
||||
|
||||
func testGet() {
|
||||
for i in (0..<(10 * 3)) { self.fifo.set(i, forKey: i) }
|
||||
for i in (20..<30) { expect(self.fifo.valueForKey(i)).to(equal(i)) }
|
||||
for i in 0..<(10 * 3) { self.fifo.set(i, forKey: i) }
|
||||
for i in 20..<30 { expect(self.fifo.valueForKey(i)).to(equal(i)) }
|
||||
expect(self.fifo.valueForKey(19)).to(beNil())
|
||||
expect(self.fifo.valueForKey(30)).to(beNil())
|
||||
}
|
||||
|
@ -3,19 +3,22 @@
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
import Nimble
|
||||
import XCTest
|
||||
|
||||
@testable import Commons
|
||||
|
||||
class FileUtilsTest: XCTestCase {
|
||||
|
||||
var fileUtilsRsrcUrl = URL(fileURLWithPath: "/")
|
||||
var a1Dir = URL(fileURLWithPath: "/")
|
||||
|
||||
override func setUp() {
|
||||
fileUtilsRsrcUrl = Bundle.module.url(forResource: "FileUtilsTest", withExtension: "", subdirectory: "Resources")!
|
||||
a1Dir = fileUtilsRsrcUrl.appendingPathComponent("a1")
|
||||
self.fileUtilsRsrcUrl = Bundle.module.url(
|
||||
forResource: "FileUtilsTest",
|
||||
withExtension: "",
|
||||
subdirectory: "Resources"
|
||||
)!
|
||||
self.a1Dir = self.fileUtilsRsrcUrl.appendingPathComponent("a1")
|
||||
}
|
||||
|
||||
func testCommonParentOneDirUrl() {
|
||||
@ -23,7 +26,7 @@ class FileUtilsTest: XCTestCase {
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1"),
|
||||
]
|
||||
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(fileUtilsRsrcUrl))
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl))
|
||||
}
|
||||
|
||||
func testCommonParentOneFileUrl() {
|
||||
@ -31,77 +34,78 @@ class FileUtilsTest: XCTestCase {
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
||||
]
|
||||
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(a1Dir))
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(self.a1Dir))
|
||||
}
|
||||
|
||||
func testCommonParentEmptyParams() {
|
||||
expect(FileUtils.commonParent(of: []) as URL).to(equal(URL(fileURLWithPath: "/", isDirectory: true)))
|
||||
expect(FileUtils.commonParent(of: []) as URL)
|
||||
.to(equal(URL(fileURLWithPath: "/", isDirectory: true)))
|
||||
}
|
||||
|
||||
func testCommonParent1() {
|
||||
let urls = [
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
||||
]
|
||||
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(fileUtilsRsrcUrl))
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl))
|
||||
}
|
||||
|
||||
func testCommonParent2() {
|
||||
let urls = [
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"),
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"),
|
||||
]
|
||||
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(fileUtilsRsrcUrl))
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl))
|
||||
}
|
||||
|
||||
func testBug1() {
|
||||
let paths = [
|
||||
fileUtilsRsrcUrl.appendingPathComponent("Downloads/test2/some/nginx.config"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent(".Trash/nginx.config")
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent(".Trash/nginx.config"),
|
||||
]
|
||||
expect(FileUtils.commonParent(of: paths)).to(equal(fileUtilsRsrcUrl))
|
||||
expect(FileUtils.commonParent(of: paths)).to(equal(self.fileUtilsRsrcUrl))
|
||||
}
|
||||
|
||||
func testBug2() {
|
||||
let paths = [
|
||||
fileUtilsRsrcUrl.appendingPathComponent("Downloads/test2/some/nginx.config"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent(".Trash/nginx.config/de/nginx.config")
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent(".Trash/nginx.config/de/nginx.config"),
|
||||
]
|
||||
expect(FileUtils.commonParent(of: paths)).to(equal(fileUtilsRsrcUrl))
|
||||
expect(FileUtils.commonParent(of: paths)).to(equal(self.fileUtilsRsrcUrl))
|
||||
}
|
||||
|
||||
func testCommonParent3() {
|
||||
let urls = [
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent("b1/b1-file1"),
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"),
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent("b1/b1-file1"),
|
||||
]
|
||||
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(fileUtilsRsrcUrl))
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl))
|
||||
}
|
||||
|
||||
func testCommonParent4() {
|
||||
let urls = [
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent("b1"),
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"),
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent("b1"),
|
||||
]
|
||||
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(fileUtilsRsrcUrl))
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(self.fileUtilsRsrcUrl))
|
||||
}
|
||||
|
||||
func testCommonParent5() {
|
||||
let urls = [
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1/a1-file1"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"),
|
||||
fileUtilsRsrcUrl.appendingPathComponent("a1/a2"),
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2/a1-a2-file1"),
|
||||
self.fileUtilsRsrcUrl.appendingPathComponent("a1/a2"),
|
||||
]
|
||||
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(a1Dir))
|
||||
expect(FileUtils.commonParent(of: urls)).to(equal(self.a1Dir))
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,10 @@
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
import Nimble
|
||||
import XCTest
|
||||
|
||||
class StringCommonsTest: XCTestCase {
|
||||
|
||||
func testWithoutPrefix() {
|
||||
expect("prefixAbc".without(prefix: "prefix")).to(equal("Abc"))
|
||||
expect("prefix".without(prefix: "prefix")).to(equal(""))
|
||||
|
@ -4,19 +4,17 @@
|
||||
*/
|
||||
|
||||
import Cocoa
|
||||
import XCTest
|
||||
import Nimble
|
||||
import XCTest
|
||||
|
||||
@testable import Commons
|
||||
|
||||
struct Dummy {
|
||||
|
||||
var value: Int
|
||||
var marker: Bool
|
||||
}
|
||||
|
||||
class ArraySliceTest: XCTestCase {
|
||||
|
||||
func testArraySliceGroup1() {
|
||||
let grouped = [
|
||||
Dummy(value: 0, marker: true),
|
||||
@ -26,7 +24,7 @@ class ArraySliceTest: XCTestCase {
|
||||
Dummy(value: 2, marker: false),
|
||||
|
||||
Dummy(value: 3, marker: false),
|
||||
][1...3].groupedRanges { i, element in element.marker }
|
||||
][1...3].groupedRanges { _, element in element.marker }
|
||||
|
||||
expect(grouped).to(equal(
|
||||
[
|
||||
@ -45,7 +43,7 @@ class ArraySliceTest: XCTestCase {
|
||||
Dummy(value: 3, marker: true),
|
||||
|
||||
Dummy(value: 3, marker: true),
|
||||
][1...3].groupedRanges { i, element in element.marker }
|
||||
][1...3].groupedRanges { _, element in element.marker }
|
||||
|
||||
expect(grouped).to(equal(
|
||||
[
|
||||
@ -63,11 +61,11 @@ class ArraySliceTest: XCTestCase {
|
||||
Dummy(value: 2, marker: true),
|
||||
|
||||
Dummy(value: 3, marker: true),
|
||||
][1...2].groupedRanges { i, element in element.marker }
|
||||
][1...2].groupedRanges { _, element in element.marker }
|
||||
|
||||
expect(grouped).to(equal(
|
||||
[
|
||||
1...2
|
||||
1...2,
|
||||
]
|
||||
))
|
||||
}
|
||||
@ -83,7 +81,7 @@ class ArraySliceTest: XCTestCase {
|
||||
Dummy(value: 1, marker: true),
|
||||
|
||||
Dummy(value: 1, marker: true),
|
||||
][1...5].groupedRanges { i, element in element.marker }
|
||||
][1...5].groupedRanges { _, element in element.marker }
|
||||
|
||||
expect(grouped).to(equal(
|
||||
[
|
||||
@ -105,7 +103,7 @@ class ArraySliceTest: XCTestCase {
|
||||
Dummy(value: 1, marker: true),
|
||||
|
||||
Dummy(value: 1, marker: true),
|
||||
][1...5].groupedRanges { i, element in element.marker }
|
||||
][1...5].groupedRanges { _, element in element.marker }
|
||||
|
||||
expect(grouped).to(equal(
|
||||
[
|
||||
@ -123,25 +121,24 @@ class ArraySliceTest: XCTestCase {
|
||||
Dummy(value: 0, marker: true),
|
||||
|
||||
Dummy(value: 0, marker: true),
|
||||
][1...1].groupedRanges { i, element in element.marker }
|
||||
][1...1].groupedRanges { _, element in element.marker }
|
||||
|
||||
expect(grouped).to(equal(
|
||||
[
|
||||
1...1
|
||||
1...1,
|
||||
]
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
class SwiftCommonsTest: XCTestCase {
|
||||
|
||||
func testArrayGroup1() {
|
||||
let grouped = [
|
||||
Dummy(value: 0, marker: true),
|
||||
Dummy(value: 1, marker: false),
|
||||
Dummy(value: 2, marker: false),
|
||||
Dummy(value: 3, marker: false),
|
||||
].groupedRanges { i, element in element.marker }
|
||||
].groupedRanges { _, element in element.marker }
|
||||
|
||||
expect(grouped).to(equal(
|
||||
[
|
||||
@ -157,7 +154,7 @@ class SwiftCommonsTest: XCTestCase {
|
||||
Dummy(value: 1, marker: false),
|
||||
Dummy(value: 2, marker: false),
|
||||
Dummy(value: 3, marker: true),
|
||||
].groupedRanges { i, element in element.marker }
|
||||
].groupedRanges { _, element in element.marker }
|
||||
|
||||
expect(grouped).to(equal(
|
||||
[
|
||||
@ -171,11 +168,11 @@ class SwiftCommonsTest: XCTestCase {
|
||||
let grouped = [
|
||||
Dummy(value: 0, marker: true),
|
||||
Dummy(value: 1, marker: true),
|
||||
].groupedRanges { i, element in element.marker }
|
||||
].groupedRanges { _, element in element.marker }
|
||||
|
||||
expect(grouped).to(equal(
|
||||
[
|
||||
0...1
|
||||
0...1,
|
||||
]
|
||||
))
|
||||
}
|
||||
@ -187,7 +184,7 @@ class SwiftCommonsTest: XCTestCase {
|
||||
Dummy(value: 1, marker: false),
|
||||
Dummy(value: 1, marker: true),
|
||||
Dummy(value: 1, marker: true),
|
||||
].groupedRanges { i, element in element.marker }
|
||||
].groupedRanges { _, element in element.marker }
|
||||
|
||||
expect(grouped).to(equal(
|
||||
[
|
||||
@ -205,7 +202,7 @@ class SwiftCommonsTest: XCTestCase {
|
||||
Dummy(value: 1, marker: true),
|
||||
Dummy(value: 1, marker: false),
|
||||
Dummy(value: 1, marker: true),
|
||||
].groupedRanges { i, element in element.marker }
|
||||
].groupedRanges { _, element in element.marker }
|
||||
|
||||
expect(grouped).to(equal(
|
||||
[
|
||||
@ -219,11 +216,11 @@ class SwiftCommonsTest: XCTestCase {
|
||||
func testArrayGroup6() {
|
||||
let grouped = [
|
||||
Dummy(value: 0, marker: true),
|
||||
].groupedRanges { i, element in element.marker }
|
||||
].groupedRanges { _, element in element.marker }
|
||||
|
||||
expect(grouped).to(equal(
|
||||
[
|
||||
0...0
|
||||
0...0,
|
||||
]
|
||||
))
|
||||
}
|
||||
|
@ -3,11 +3,10 @@
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
import Nimble
|
||||
import XCTest
|
||||
|
||||
class UrlCommonsTest: XCTestCase {
|
||||
|
||||
func testIsDirectParent() {
|
||||
let parent = URL(fileURLWithPath: "/some/path")
|
||||
let child = URL(fileURLWithPath: "/some/path/text.txt")
|
||||
@ -47,12 +46,17 @@ class UrlCommonsTest: XCTestCase {
|
||||
|
||||
func testParent() {
|
||||
expect(URL(fileURLWithPath: "/some/path/").parent).to(equal(URL(fileURLWithPath: "/some/")))
|
||||
expect(URL(fileURLWithPath: "/some/path/text.txt").parent).to(equal(URL(fileURLWithPath: "/some/path/")))
|
||||
expect(URL(fileURLWithPath: "/some/path/text.txt").parent)
|
||||
.to(equal(URL(fileURLWithPath: "/some/path/")))
|
||||
expect(URL(fileURLWithPath: "/").parent).to(equal(URL(fileURLWithPath: "/")))
|
||||
}
|
||||
|
||||
func testIsDir() {
|
||||
let resourceUrl = Bundle.module.url(forResource: "UrlCommonsTest", withExtension: "", subdirectory: "Resources")!
|
||||
let resourceUrl = Bundle.module.url(
|
||||
forResource: "UrlCommonsTest",
|
||||
withExtension: "",
|
||||
subdirectory: "Resources"
|
||||
)!
|
||||
let hidden = resourceUrl.appendingPathComponent(".dot-hidden-file")
|
||||
|
||||
expect(resourceUrl.isDir).to(beTrue())
|
||||
@ -60,7 +64,11 @@ class UrlCommonsTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testIsHidden() {
|
||||
let resourceUrl = Bundle.module.url(forResource: "UrlCommonsTest", withExtension: "", subdirectory: "Resources")!
|
||||
let resourceUrl = Bundle.module.url(
|
||||
forResource: "UrlCommonsTest",
|
||||
withExtension: "",
|
||||
subdirectory: "Resources"
|
||||
)!
|
||||
let hidden = resourceUrl.appendingPathComponent(".dot-hidden-file")
|
||||
|
||||
expect(hidden.isHidden).to(beTrue())
|
||||
@ -68,7 +76,11 @@ class UrlCommonsTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testIsPackage() {
|
||||
let resourceUrl = Bundle.module.url(forResource: "UrlCommonsTest", withExtension: "", subdirectory: "Resources")!
|
||||
let resourceUrl = Bundle.module.url(
|
||||
forResource: "UrlCommonsTest",
|
||||
withExtension: "",
|
||||
subdirectory: "Resources"
|
||||
)!
|
||||
let package = resourceUrl.appendingPathComponent("dummy.rtfd")
|
||||
|
||||
expect(package.isPackage).to(beTrue())
|
||||
|
@ -1,9 +1,9 @@
|
||||
import XCTest
|
||||
|
||||
#if !canImport(ObjectiveC)
|
||||
public func allTests() -> [XCTestCaseEntry] {
|
||||
return [
|
||||
testCase(CommonsTests.allTests),
|
||||
public func allTests() -> [XCTestCaseEntry] {
|
||||
[
|
||||
testCase(CommonsTests.allTests),
|
||||
]
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -45,6 +45,6 @@ public struct ModeInfo: CustomStringConvertible {
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
return "ModeInfo<\(name) (\(shortName)) shape: \(cursorShape) attr_id:\(attrId)>"
|
||||
return "ModeInfo<\(name) (\(shortName)) shape: \(cursorShape) attr_id:\(String(describing: attrId))>"
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ final class Typesetter {
|
||||
var columnPosition = 0.cgf
|
||||
var deltaX = 0.cgf
|
||||
|
||||
_ = positions.withUnsafeMutableBufferPointer { positionsPtr -> Void in
|
||||
positions.withUnsafeMutableBufferPointer { positionsPtr -> Void in
|
||||
for i in 0..<positionsPtr.count {
|
||||
let newColumn = cellIndices[indices[i]] + startColumn
|
||||
if newColumn != column {
|
||||
@ -161,8 +161,6 @@ final class Typesetter {
|
||||
) -> [NvimUtf16CellsRun] {
|
||||
if nvimUtf16Cells.isEmpty { return [] }
|
||||
|
||||
let utf16Chars = self.utf16Chars(from: nvimUtf16Cells)
|
||||
|
||||
let hasMoreThanTwoCells = nvimUtf16Cells.count >= 2
|
||||
let firstCharHasSingleUnichar = nvimUtf16Cells[0].count == 1
|
||||
let firstCharHasDoubleWidth = hasMoreThanTwoCells && nvimUtf16Cells[1].isEmpty
|
||||
|
Loading…
Reference in New Issue
Block a user