1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-21 04:31:32 +03:00
vimr/RxPack/RxMsgpackRpcTests/RxMsgpackRpcTests.swift

85 lines
2.0 KiB
Swift
Raw Normal View History

2019-03-27 10:19:25 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import XCTest
import RxSwift
class RxMsgpackRpcTests: XCTestCase {
2019-03-27 11:02:43 +03:00
2019-03-27 10:19:25 +03:00
private var connection: MsgpackRpc!
private let disposeBag = DisposeBag()
2019-03-27 11:02:43 +03:00
2019-03-27 10:19:25 +03:00
override func setUp() {
super.setUp()
2019-03-27 11:02:43 +03:00
2019-03-27 10:19:25 +03:00
// $ NVIM_LISTEN_ADDRESS=/tmp/nvim.sock nvim --headless $SOMEFILE
connection = MsgpackRpc()
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)
2019-03-27 11:02:43 +03:00
2019-03-27 10:19:25 +03:00
_ = connection.run(at: "/tmp/nvim.sock")
.andThen(connection.request(
2019-03-27 11:02:43 +03:00
method: "nvim_ui_attach",
params: [.int(40), .int(40), .map([:])],
expectsReturnValue: true
))
2019-03-27 10:19:25 +03:00
.syncValue()
}
2019-03-27 11:02:43 +03:00
2019-03-27 10:19:25 +03:00
override func tearDown() {
super.tearDown()
2019-03-27 11:02:43 +03:00
try? self.connection
.request(
method: "nvim_command", params: [.string("q!")],
expectsReturnValue: false
)
.asCompletable()
.wait()
2019-03-27 10:19:25 +03:00
try? self.connection.stop().wait()
}
2019-03-27 11:02:43 +03:00
2019-03-27 10:19:25 +03:00
func testExample() {
let disposeBag = DisposeBag()
2019-03-27 11:02:43 +03:00
2019-03-27 10:19:25 +03:00
let lineCount = connection
2019-03-27 11:02:43 +03:00
.request(
method: "nvim_buf_line_count",
params: [.int(0)],
expectsReturnValue: true
)
2019-03-27 10:19:25 +03:00
.syncValue()
print(lineCount ?? "???")
2019-03-27 11:02:43 +03:00
2019-03-27 10:19:25 +03:00
let formatter = DateFormatter()
formatter.dateFormat = "mm:ss.SSS"
for i in 0...100 {
let date = Date()
connection
2019-03-27 11:02:43 +03:00
.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) }
)
2019-03-27 10:19:25 +03:00
.disposed(by: disposeBag)
}
2019-03-27 11:02:43 +03:00
sleep(1)
2019-03-27 10:19:25 +03:00
}
}