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