Add tests.
This commit is contained in:
parent
ec2fb7023c
commit
b5220cbfe3
|
@ -2,6 +2,17 @@ import XCTest
|
||||||
@testable import NSStringUtils
|
@testable import NSStringUtils
|
||||||
|
|
||||||
final class NSStringUtilsTests: XCTestCase {
|
final class NSStringUtilsTests: XCTestCase {
|
||||||
|
|
||||||
|
func testNextNormal_0() {
|
||||||
|
let s = NSString("中文")
|
||||||
|
XCTAssertEqual(s.nextUtf16Position(for: 0), 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testNextNormal_1() {
|
||||||
|
let s = NSString("中文")
|
||||||
|
XCTAssertEqual(s.nextUtf16Position(for: 1), 2)
|
||||||
|
}
|
||||||
|
|
||||||
func testNextWith🌳_0() {
|
func testNextWith🌳_0() {
|
||||||
let s = NSString("🌳🌳")
|
let s = NSString("🌳🌳")
|
||||||
XCTAssertEqual(s.nextUtf16Position(for: 0), 2)
|
XCTAssertEqual(s.nextUtf16Position(for: 0), 2)
|
||||||
|
@ -32,6 +43,16 @@ final class NSStringUtilsTests: XCTestCase {
|
||||||
XCTAssertEqual(s.nextUtf16Position(for: 4), 6)
|
XCTAssertEqual(s.nextUtf16Position(for: 4), 6)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testPrevNormal_0() {
|
||||||
|
let s = NSString("中文")
|
||||||
|
XCTAssertEqual(s.previousUtf16Position(for: 1), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testPrevNormal_1() {
|
||||||
|
let s = NSString("中文")
|
||||||
|
XCTAssertEqual(s.previousUtf16Position(for: 2), 1)
|
||||||
|
}
|
||||||
|
|
||||||
func testPrevWith🌳_0() {
|
func testPrevWith🌳_0() {
|
||||||
let s = NSString("🌳🌳")
|
let s = NSString("🌳🌳")
|
||||||
XCTAssertEqual(s.previousUtf16Position(for: 0), 0)
|
XCTAssertEqual(s.previousUtf16Position(for: 0), 0)
|
||||||
|
@ -42,17 +63,17 @@ final class NSStringUtilsTests: XCTestCase {
|
||||||
XCTAssertEqual(s.previousUtf16Position(for: 1), 0)
|
XCTAssertEqual(s.previousUtf16Position(for: 1), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testINextWith🌳_2() {
|
func testPrevWith🌳_2() {
|
||||||
let s = NSString("🌳🌳")
|
let s = NSString("🌳🌳")
|
||||||
XCTAssertEqual(s.previousUtf16Position(for: 2), 0)
|
XCTAssertEqual(s.previousUtf16Position(for: 2), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testINextWith🌳_3() {
|
func testPrevWith🌳_3() {
|
||||||
let s = NSString("🌳🌳")
|
let s = NSString("🌳🌳")
|
||||||
XCTAssertEqual(s.previousUtf16Position(for: 3), 0)
|
XCTAssertEqual(s.previousUtf16Position(for: 3), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testINextWith🌳_4() {
|
func testPrevWith🌳_4() {
|
||||||
let s = NSString("🌳🌳")
|
let s = NSString("🌳🌳")
|
||||||
XCTAssertEqual(s.previousUtf16Position(for: 4), 2)
|
XCTAssertEqual(s.previousUtf16Position(for: 4), 2)
|
||||||
}
|
}
|
||||||
|
|
|
@ -577,7 +577,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
if ([input isShiftHold]) {
|
if ([input isShiftHold]) {
|
||||||
// Shift + left
|
// Shift + left
|
||||||
if (currentState.cursorIndex > 0) {
|
if (currentState.cursorIndex > 0) {
|
||||||
NSInteger previousPosition = [currentState.composingBuffer nextUtf16PositionFor:currentState.cursorIndex];
|
NSInteger previousPosition = [currentState.composingBuffer previousUtf16PositionFor:currentState.cursorIndex];
|
||||||
InputStateMarking *marking = [[InputStateMarking alloc] initWithComposingBuffer:currentState.composingBuffer cursorIndex:currentState.cursorIndex markerIndex:previousPosition readings:[self _currentReadings]];
|
InputStateMarking *marking = [[InputStateMarking alloc] initWithComposingBuffer:currentState.composingBuffer cursorIndex:currentState.cursorIndex markerIndex:previousPosition readings:[self _currentReadings]];
|
||||||
marking.tooltipForInputting = currentState.tooltip;
|
marking.tooltipForInputting = currentState.tooltip;
|
||||||
stateCallback(marking);
|
stateCallback(marking);
|
||||||
|
|
Loading…
Reference in New Issue