test: next runes

This commit is contained in:
Vincent Chan 2022-08-10 17:58:01 +08:00
parent c554720dff
commit b5ecd7dedc
2 changed files with 32 additions and 6 deletions

View File

@ -477,7 +477,7 @@ class Delta extends Iterable<TextOperation> {
int prevRunePosition(int pos) { int prevRunePosition(int pos) {
if (pos == 0) { if (pos == 0) {
return pos; return pos - 1;
} }
_rawString ??= _rawString ??=
_operations.whereType<TextInsert>().map((op) => op.content).join(); _operations.whereType<TextInsert>().map((op) => op.content).join();
@ -498,7 +498,7 @@ class Delta extends Iterable<TextOperation> {
} }
} }
return pos; return stringContent.length;
} }
String toRawString() { String toRawString() {

View File

@ -279,9 +279,35 @@ void main() {
expect(delta, expected); expect(delta, expected);
}); });
}); });
test("stringIndexes", () { group('runes', () {
final indexes = stringIndexes('😊'); test("stringIndexes", () {
expect(indexes[0], 0); final indexes = stringIndexes('😊');
expect(indexes[1], 0); expect(indexes[0], 0);
expect(indexes[1], 0);
});
test("next rune 1", () {
final delta = Delta()..insert('😊');
expect(delta.nextRunePosition(0), 2);
});
test("next rune 2", () {
final delta = Delta()..insert('😊a');
expect(delta.nextRunePosition(0), 2);
});
test("next rune 3", () {
final delta = Delta()..insert('😊陈');
expect(delta.nextRunePosition(2), 3);
});
test("prev rune 1", () {
final delta = Delta()..insert('😊陈');
expect(delta.prevRunePosition(2), 0);
});
test("prev rune 2", () {
final delta = Delta()..insert('😊');
expect(delta.prevRunePosition(2), 0);
});
test("prev rune 3", () {
final delta = Delta()..insert('😊');
expect(delta.prevRunePosition(0), -1);
});
}); });
} }