mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-24 03:25:03 +03:00
Re-add RxPack tests
This commit is contained in:
parent
ca77228249
commit
a15fbbf435
3
Cartfile
3
Cartfile
@ -4,6 +4,3 @@ github "sparkle-project/Sparkle" == 1.23.0
|
||||
|
||||
# included directly
|
||||
github "sindresorhus/github-markdown-css" == 4.0.0
|
||||
|
||||
# for testing only
|
||||
github "Quick/Nimble" == 8.1.1
|
||||
|
@ -6,15 +6,13 @@ let package = Package(
|
||||
name: "RxPack",
|
||||
platforms: [.macOS(.v10_13)],
|
||||
products: [
|
||||
.library(
|
||||
name: "RxPack",
|
||||
targets: ["RxPack"]
|
||||
),
|
||||
.library(name: "RxPack", targets: ["RxPack"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/ReactiveX/RxSwift", .upToNextMinor(from: "5.1.1")),
|
||||
.package(name: "MessagePack", url: "https://github.com/a2/MessagePack.swift", .upToNextMinor(from: "4.0.0")),
|
||||
.package(name: "Socket", url: "https://github.com/IBM-Swift/BlueSocket", .upToNextMinor(from: "1.0.52")),
|
||||
.package(url: "https://github.com/Quick/Nimble", .upToNextMinor(from: "8.1.1")),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
@ -23,7 +21,7 @@ let package = Package(
|
||||
),
|
||||
.testTarget(
|
||||
name: "RxPackTests",
|
||||
dependencies: ["RxPack"]
|
||||
dependencies: ["RxPack", "Nimble"]
|
||||
),
|
||||
]
|
||||
)
|
||||
|
85
RxPack/Tests/RxPackTests/RxMsgpackRpcTests.swift
Normal file
85
RxPack/Tests/RxPackTests/RxMsgpackRpcTests.swift
Normal file
@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Tae Won Ha - http://taewon.de - @hataewon
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
import RxSwift
|
||||
import XCTest
|
||||
|
||||
@testable import RxPack
|
||||
|
||||
class RxMsgpackRpcTests: XCTestCase {
|
||||
private var connection: RxMsgpackRpc!
|
||||
private let disposeBag = DisposeBag()
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
// $ NVIM_LISTEN_ADDRESS=/tmp/nvim.sock nvim --headless $SOMEFILE
|
||||
self.connection = RxMsgpackRpc()
|
||||
self.connection.stream
|
||||
.subscribe(onNext: { msg in
|
||||
switch msg {
|
||||
case let .notification(method, params):
|
||||
print("NOTIFICATION: \(method): array of \(params.count) elements")
|
||||
case let .error(value, msg):
|
||||
print("ERROR: \(msg) with \(value)")
|
||||
default:
|
||||
print("???")
|
||||
}
|
||||
}, onError: { print("ERROR: \($0)") })
|
||||
.disposed(by: self.disposeBag)
|
||||
|
||||
_ = self.connection.run(at: "/tmp/nvim.sock")
|
||||
.andThen(self.connection.request(
|
||||
method: "nvim_ui_attach",
|
||||
params: [.int(40), .int(40), .map([:])],
|
||||
expectsReturnValue: true
|
||||
))
|
||||
.syncValue()
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
super.tearDown()
|
||||
try? self.connection
|
||||
.request(
|
||||
method: "nvim_command", params: [.string("q!")],
|
||||
expectsReturnValue: false
|
||||
)
|
||||
.asCompletable()
|
||||
.wait()
|
||||
try? self.connection.stop().wait()
|
||||
}
|
||||
|
||||
func testExample() {
|
||||
let disposeBag = DisposeBag()
|
||||
|
||||
let lineCount = self.connection
|
||||
.request(
|
||||
method: "nvim_buf_line_count",
|
||||
params: [.int(0)],
|
||||
expectsReturnValue: true
|
||||
)
|
||||
.syncValue()
|
||||
print(lineCount ?? "???")
|
||||
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "mm:ss.SSS"
|
||||
for i in 0 ... 100 {
|
||||
let date = Date()
|
||||
connection
|
||||
.request(
|
||||
method: "nvim_command_output",
|
||||
params: [.string("echo '\(i) \(formatter.string(from: date))'")],
|
||||
expectsReturnValue: true
|
||||
)
|
||||
.subscribe(
|
||||
onSuccess: { response in print(response) },
|
||||
onError: { error in print(error) }
|
||||
)
|
||||
.disposed(by: disposeBag)
|
||||
}
|
||||
|
||||
sleep(1)
|
||||
}
|
||||
}
|
101
RxPack/Tests/RxPackTests/RxNeovimApiTests.swift
Normal file
101
RxPack/Tests/RxPackTests/RxNeovimApiTests.swift
Normal file
@ -0,0 +1,101 @@
|
||||
/**
|
||||
* Tae Won Ha - http://taewon.de - @hataewon
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
import MessagePack
|
||||
import RxSwift
|
||||
import XCTest
|
||||
|
||||
@testable import RxPack
|
||||
|
||||
|
||||
class NvimMsgPackTests: XCTestCase {
|
||||
var nvim = RxNeovimApi()
|
||||
let disposeBag = DisposeBag()
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
// $ NVIM_LISTEN_ADDRESS=/tmp/nvim.sock nvim $SOME_FILES
|
||||
try? self.nvim.run(at: "/tmp/nvim.sock").wait()
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
super.tearDown()
|
||||
try? self.nvim
|
||||
.command(command: "q!")
|
||||
.wait()
|
||||
try? self.nvim.stop().wait()
|
||||
}
|
||||
|
||||
func testSth() {
|
||||
let colorNames = [
|
||||
"Normal", // color and background-color
|
||||
"Directory", // a
|
||||
"StatusLine", // code background and foreground
|
||||
"NonText", // hr and block quote border
|
||||
"Question", // blockquote foreground
|
||||
]
|
||||
|
||||
typealias HlResult = [String: RxNeovimApi.Value]
|
||||
typealias ColorNameHlResultTuple = (colorName: String, hlResult: HlResult)
|
||||
typealias ColorNameObservableTuple = (colorName: String, observable: Observable<HlResult>)
|
||||
|
||||
Observable
|
||||
.from(colorNames.map { colorName -> ColorNameObservableTuple in
|
||||
(
|
||||
colorName: colorName,
|
||||
observable: self.nvim
|
||||
.getHlByName(name: colorName, rgb: true)
|
||||
.asObservable()
|
||||
)
|
||||
})
|
||||
.flatMap { tuple -> Observable<(String, HlResult)> in
|
||||
Observable.zip(Observable.just(tuple.colorName), tuple.observable)
|
||||
}
|
||||
.subscribe(onNext: { (tuple: ColorNameHlResultTuple) in
|
||||
print(tuple)
|
||||
})
|
||||
.disposed(by: self.disposeBag)
|
||||
|
||||
// Observable
|
||||
// .concat(colorNames.map { colorName in
|
||||
// self.nvim
|
||||
// .getHlByName(name: colorName, rgb: true)
|
||||
// .asObservable()
|
||||
// })
|
||||
// .enumerated()
|
||||
// .subscribe(onNext: { dict in print(dict) })
|
||||
// .disposed(by: self.disposeBag)
|
||||
|
||||
// self.nvim
|
||||
// .getHlByName(name: "Normal", rgb: true)
|
||||
// .subscribe(onSuccess: { dict in
|
||||
// guard let f = dict["foreground"]?.uint64Value,
|
||||
// let b = dict["background"]?.uint64Value else { return }
|
||||
// print(String(format: "%06X %06X", f, b))
|
||||
// }, onError: { err in print(err) })
|
||||
// .disposed(by: self.disposeBag)
|
||||
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
func testExample() {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .short
|
||||
formatter.timeStyle = .full
|
||||
let now = Date()
|
||||
let dispose = DisposeBag()
|
||||
for i in 0 ... 5 {
|
||||
self.nvim
|
||||
.command(
|
||||
command: "echo '\(formatter.string(from: now)) \(i)'"
|
||||
)
|
||||
.subscribe(onCompleted: { print("\(i) handled") })
|
||||
.disposed(by: dispose)
|
||||
}
|
||||
|
||||
sleep(1)
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
import XCTest
|
||||
|
||||
#if !canImport(ObjectiveC)
|
||||
public func allTests() -> [XCTestCaseEntry] {
|
||||
return [
|
||||
testCase(RxPackTests.allTests),
|
||||
]
|
||||
}
|
||||
#endif
|
@ -51,10 +51,19 @@
|
||||
"repositoryURL": "https://github.com/qvacua/neovim",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "13be312e380e7f93878486c8851a605a4e7af0eb",
|
||||
"revision": "246da2521cdf3720b11a5045720d2ae1497a9268",
|
||||
"version": "0.1.0-types"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "Nimble",
|
||||
"repositoryURL": "https://github.com/Quick/Nimble",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "2b1809051b4a65c1d7f5233331daa24572cd7fca",
|
||||
"version": "8.1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "PureLayout",
|
||||
"repositoryURL": "https://github.com/PureLayout/PureLayout",
|
||||
|
Loading…
Reference in New Issue
Block a user