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

View File

@ -279,9 +279,35 @@ void main() {
expect(delta, expected);
});
});
test("stringIndexes", () {
final indexes = stringIndexes('😊');
expect(indexes[0], 0);
expect(indexes[1], 0);
group('runes', () {
test("stringIndexes", () {
final indexes = stringIndexes('😊');
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);
});
});
}