1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-28 08:13:17 +03:00
vimr/RxPack/RxNeovimApiTests/RxNeovimApiTests.swift

97 lines
2.5 KiB
Swift
Raw Normal View History

2019-03-27 11:16:29 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import XCTest
import RxSwift
import MessagePack
class NvimMsgPackTests: XCTestCase {
var nvim = RxNeovimApi()
let disposeBag = DisposeBag()
override func setUp() {
super.setUp()
// $ NVIM_LISTEN_ADDRESS=/tmp/nvim.sock nvim $SOME_FILES
try? nvim.run(at: "/tmp/nvim.sock").wait()
}
override func tearDown() {
super.tearDown()
try? self.nvim.stop().wait()
}
2020-01-26 15:31:25 +03:00
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 = Dictionary<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)
})
2020-01-26 15:31:25 +03:00
.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)
2020-01-26 15:31:25 +03:00
sleep(1)
}
2019-03-27 11:16:29 +03:00
func testExample() {
let formatter = DateFormatter()
formatter.dateStyle = .short
formatter.timeStyle = .full
let now = Date()
let dispose = DisposeBag()
for i in 0...5 {
nvim
.command(
2020-01-26 15:31:25 +03:00
command: "echo '\(formatter.string(from: now)) \(i)'"
2019-03-27 11:16:29 +03:00
)
.subscribe(onCompleted: { print("\(i) handled") })
.disposed(by: dispose)
}
sleep(1)
}
}