2018-08-27 19:44:42 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
import XCTest
|
|
|
|
import Nimble
|
|
|
|
|
|
|
|
@testable import NvimView
|
|
|
|
|
|
|
|
class UGridTest: XCTestCase {
|
|
|
|
|
|
|
|
private let ugrid = UGrid()
|
|
|
|
|
2018-09-30 23:50:42 +03:00
|
|
|
func testFlattenedIndex() {
|
|
|
|
self.ugrid.resize(Size(width: 20, height: 10))
|
|
|
|
expect(
|
|
|
|
self.ugrid.flattenedCellIndex(forPosition: Position(row: 0, column: 0))
|
|
|
|
).to(equal(0))
|
|
|
|
expect(
|
|
|
|
self.ugrid.flattenedCellIndex(forPosition: Position(row: 0, column: 5))
|
|
|
|
).to(equal(5))
|
|
|
|
expect(
|
|
|
|
self.ugrid.flattenedCellIndex(forPosition: Position(row: 1, column: 0))
|
|
|
|
).to(equal(20))
|
|
|
|
expect(
|
|
|
|
self.ugrid.flattenedCellIndex(forPosition: Position(row: 1, column: 5))
|
|
|
|
).to(equal(25))
|
|
|
|
expect(
|
|
|
|
self.ugrid.flattenedCellIndex(forPosition: Position(row: 9, column: 0))
|
|
|
|
).to(equal(180))
|
|
|
|
expect(
|
|
|
|
self.ugrid.flattenedCellIndex(forPosition: Position(row: 9, column: 19))
|
|
|
|
).to(equal(199))
|
|
|
|
}
|
|
|
|
|
|
|
|
func testPositionFromFlattenedIndex() {
|
|
|
|
self.ugrid.resize(Size(width: 20, height: 10))
|
|
|
|
expect(self.ugrid.position(from: 0))
|
|
|
|
.to(equal(Position(row: 0, column: 0)))
|
|
|
|
expect(self.ugrid.position(from: 5))
|
|
|
|
.to(equal(Position(row: 0, column: 5)))
|
|
|
|
expect(self.ugrid.position(from: 20))
|
|
|
|
.to(equal(Position(row: 1, column: 0)))
|
|
|
|
expect(self.ugrid.position(from: 25))
|
|
|
|
.to(equal(Position(row: 1, column: 5)))
|
|
|
|
expect(self.ugrid.position(from: 180))
|
|
|
|
.to(equal(Position(row: 9, column: 0)))
|
|
|
|
expect(self.ugrid.position(from: 199))
|
|
|
|
.to(equal(Position(row: 9, column: 19)))
|
|
|
|
expect(self.ugrid.position(from: 418))
|
|
|
|
.to(equal(Position(row: 9, column: 18)))
|
|
|
|
expect(self.ugrid.position(from: 419))
|
|
|
|
.to(equal(Position(row: 9, column: 19)))
|
2018-08-27 19:44:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testLeftBoundaryOfWord() {
|
2018-09-30 23:50:42 +03:00
|
|
|
self.ugrid.resize(Size(width: 10, height: 2))
|
2018-08-27 19:44:42 +03:00
|
|
|
self.ugrid.update(row: 0,
|
|
|
|
startCol: 0,
|
|
|
|
endCol: 10,
|
|
|
|
clearCol: 10,
|
|
|
|
clearAttr: 0,
|
|
|
|
chunk: " 12 45678 ".compactMap { String($0) },
|
|
|
|
attrIds: Array<Int>(repeating: 0, count: 10))
|
|
|
|
|
2018-09-03 14:01:51 +03:00
|
|
|
expect(self.ugrid.leftBoundaryOfWord(at: Position(row: 0, column: 9)))
|
|
|
|
.to(equal(9))
|
|
|
|
expect(self.ugrid.leftBoundaryOfWord(at: Position(row: 0, column: 8)))
|
|
|
|
.to(equal(4))
|
|
|
|
expect(self.ugrid.leftBoundaryOfWord(at: Position(row: 0, column: 4)))
|
|
|
|
.to(equal(4))
|
|
|
|
expect(self.ugrid.leftBoundaryOfWord(at: Position(row: 0, column: 3)))
|
|
|
|
.to(equal(3))
|
|
|
|
expect(self.ugrid.leftBoundaryOfWord(at: Position(row: 0, column: 0)))
|
|
|
|
.to(equal(0))
|
2018-08-27 19:44:42 +03:00
|
|
|
|
|
|
|
self.ugrid.update(row: 1,
|
|
|
|
startCol: 0,
|
|
|
|
endCol: 10,
|
|
|
|
clearCol: 10,
|
|
|
|
clearAttr: 0,
|
|
|
|
chunk: "0123456789".compactMap { String($0) },
|
|
|
|
attrIds: Array<Int>(repeating: 0, count: 10))
|
|
|
|
|
2018-09-03 14:01:51 +03:00
|
|
|
expect(self.ugrid.leftBoundaryOfWord(at: Position(row: 1, column: 0)))
|
|
|
|
.to(equal(0))
|
2018-08-27 19:44:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testRightBoundaryOfWord() {
|
2018-09-30 23:50:42 +03:00
|
|
|
self.ugrid.resize(Size(width: 10, height: 2))
|
2018-08-27 19:44:42 +03:00
|
|
|
self.ugrid.update(row: 0,
|
|
|
|
startCol: 0,
|
|
|
|
endCol: 10,
|
|
|
|
clearCol: 10,
|
|
|
|
clearAttr: 0,
|
|
|
|
chunk: " 12345 78 ".compactMap { String($0) },
|
|
|
|
attrIds: Array<Int>(repeating: 0, count: 10))
|
|
|
|
|
2018-09-03 14:01:51 +03:00
|
|
|
expect(self.ugrid.rightBoundaryOfWord(at: Position(row: 0, column: 9)))
|
|
|
|
.to(equal(9))
|
|
|
|
expect(self.ugrid.rightBoundaryOfWord(at: Position(row: 0, column: 8)))
|
|
|
|
.to(equal(8))
|
|
|
|
expect(self.ugrid.rightBoundaryOfWord(at: Position(row: 0, column: 7)))
|
|
|
|
.to(equal(8))
|
|
|
|
expect(self.ugrid.rightBoundaryOfWord(at: Position(row: 0, column: 1)))
|
|
|
|
.to(equal(5))
|
|
|
|
expect(self.ugrid.rightBoundaryOfWord(at: Position(row: 0, column: 0)))
|
|
|
|
.to(equal(0))
|
2018-08-27 19:44:42 +03:00
|
|
|
|
|
|
|
self.ugrid.update(row: 1,
|
|
|
|
startCol: 0,
|
|
|
|
endCol: 10,
|
|
|
|
clearCol: 10,
|
|
|
|
clearAttr: 0,
|
|
|
|
chunk: "0123456789".compactMap { String($0) },
|
|
|
|
attrIds: Array<Int>(repeating: 0, count: 10))
|
2018-09-03 14:01:51 +03:00
|
|
|
expect(self.ugrid.rightBoundaryOfWord(at: Position(row: 1, column: 9)))
|
|
|
|
.to(equal(9))
|
2018-08-27 19:44:42 +03:00
|
|
|
}
|
|
|
|
}
|