Skip to content

Commit e05fa35

Browse files
committed
test: close the preservation review gaps
The review of the pruned suites found contracts that the keepers restated without proving. The iOS view test now undoes and redoes typed text with a real history, and the read-only test types first so the dropped undo has something to drop. The Android read-only test asserts that a vertical move and copy still run, not only a horizontal move. The emoji undo vector checks the restored text, the bad-query registry test counts the provider read so the null cannot come from an unknown id, and the docs fixture lists its captures out of order so the sort is exercised.
1 parent 915d14f commit e05fa35

5 files changed

Lines changed: 27 additions & 11 deletions

File tree

‎android/src/test/java/me/sectiontn/codepad/syntax/LanguageRegistryTest.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ class LanguageRegistryTest {
2828
assertNull(LanguageRegistry.resolve("no_such_language"))
2929
assertNull(LanguageRegistry.resolveInjection("c_sharp"))
3030
assertTrue(LanguageRegistry.resolveInjection("js") === LanguageRegistry.resolve("javascript"))
31+
var reads = 0
3132
LanguageRegistry.register(object : LanguageProvider {
3233
override val id = "javascript_bad"
33-
override val languagePointer = base.pointer
34+
override val languagePointer: Long get() { reads++; return base.pointer }
3435
override val highlights = "(no_such_node) @x"
3536
override val injections = ""
3637
})
3738
assertNull("a highlights query naming a missing node fails the load", LanguageRegistry.resolve("javascript_bad"))
39+
assertEquals("the provider was asked, so the null is the bad query and not an unknown id", 1, reads)
3840
}
3941
}

‎example/android/app/src/androidTest/java/codepad/example/HardwareKeysTest.kt‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package codepad.example
22

3+
import android.content.ClipboardManager
34
import android.os.SystemClock
45
import android.view.KeyEvent
56
import android.view.View
@@ -77,17 +78,23 @@ class HardwareKeysTest {
7778
launch().use { s ->
7879
val editor = s.editor()
7980
onMain {
80-
editor.setInitialText("ab")
81+
editor.setInitialText("ab\ncd")
82+
layout(editor)
8183
editor.setReadOnly(true)
8284
key(editor, KeyEvent.KEYCODE_DEL)
8385
key(editor, KeyEvent.KEYCODE_Q)
8486
key(editor, KeyEvent.KEYCODE_ENTER)
8587
key(editor, KeyEvent.KEYCODE_TAB)
86-
assertEquals("ab", editor.core.document.text())
88+
assertEquals("ab\ncd", editor.core.document.text())
8789
key(editor, KeyEvent.KEYCODE_DPAD_RIGHT)
8890
assertEquals(Selection(1, 1), editor.core.selection)
91+
key(editor, KeyEvent.KEYCODE_DPAD_DOWN)
92+
assertEquals("a vertical move still runs", Selection(4, 4), editor.core.selection)
8993
key(editor, KeyEvent.KEYCODE_A, ctrl)
90-
assertEquals(Selection(0, 2), editor.core.selection)
94+
assertEquals(Selection(0, 5), editor.core.selection)
95+
key(editor, KeyEvent.KEYCODE_C, ctrl)
96+
val clip = editor.context.getSystemService(ClipboardManager::class.java)?.primaryClip
97+
assertEquals("copy still runs", "ab\ncd", clip?.getItemAt(0)?.text?.toString())
9198
}
9299
}
93100
}

‎example/ios/CodepadTests/ToolbarApiTests.swift‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ final class ToolbarApiTests: XCTestCase {
4040
XCTAssertEqual(editor.core.document.text(), "(){\n \n}")
4141
editor.setText("", keepHistory: false)
4242
editor.typeText("ab")
43-
editor.core.undo()
44-
XCTAssertEqual(editor.core.document.text(), "", "two typed chars undo as one group")
43+
editor.perform(.undo)
44+
XCTAssertEqual(editor.core.document.text(), "", "two typed chars undo as one group through the view")
45+
editor.perform(.redo)
46+
XCTAssertEqual(editor.core.document.text(), "ab", "redo runs through the view")
47+
editor.perform(.undo)
4548
editor.typeText("[")
4649
editor.perform(.backspace)
4750
XCTAssertEqual(editor.core.document.text(), "", "backspace removes the empty pair")
@@ -52,8 +55,11 @@ final class ToolbarApiTests: XCTestCase {
5255

5356
func testReadOnlyIgnoresEditsAndStillMoves() {
5457
let editor = launch()
55-
editor.setInitialText("ab")
58+
editor.setInitialText("a")
5659
layout(editor)
60+
editor.core.setSelection(anchor: 1, head: 1)
61+
editor.typeText("b")
62+
XCTAssertEqual(editor.core.document.text(), "ab")
5763
editor.setReadOnly(true)
5864
editor.typeText("x")
5965
editor.perform(.backspace)
@@ -62,7 +68,8 @@ final class ToolbarApiTests: XCTestCase {
6268
editor.perform(.newline)
6369
editor.perform(.tab)
6470
editor.perform(.undo)
65-
XCTAssertEqual(editor.core.document.text(), "ab")
71+
XCTAssertEqual(editor.core.document.text(), "ab", "read-only drops the edits and the undo of the typed b")
72+
editor.core.setSelection(anchor: 0, head: 0)
6673
editor.perform(.move(unit: .char, forward: true, extend: true))
6774
XCTAssertEqual(editor.core.selection, Selection(anchor: 0, head: 1))
6875
editor.perform(.selectAll)

‎languages/generator/docs.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ test('languagesPage lists every generated package with its grammar, scanner, inj
1717
codepad: { generated: true, grammar: 'org/tree-sitter-foo@abc' },
1818
}),
1919
);
20-
// The capture list drops private captures, dedupes and sorts.
20+
// The capture list drops private captures, dedupes and sorts, so the fixture lists them out of order.
2121
writeFileSync(
2222
path.join(pkg, 'queries/foo/highlights.scm'),
23-
'(a) @keyword\n((b) @_hidden @string.special)\n(c) @keyword\n',
23+
'(a) @string.special\n((b) @_hidden @keyword)\n(c) @string.special\n',
2424
);
2525
writeFileSync(
2626
path.join(pkg, 'queries/foo/injections.scm'),

‎tests/vectors/undo.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
{ "name": "backspace at the start is a no-op", "text": "ab", "ops": [{ "op": "backspace" }], "expect": { "revision": 0 } },
7676
{ "name": "backspace removes a whole emoji", "text": "a\uD83D\uDE00", "ops": [
7777
{ "op": "setSelection", "anchor": 3, "head": 3 }, { "op": "backspace", "expect": { "text": "a", "selection": { "anchor": 1, "head": 1 } } },
78-
{ "op": "undo", "expect": { "length": 3, "selection": { "anchor": 3, "head": 3 } } }
78+
{ "op": "undo", "expect": { "text": "a😀", "length": 3, "selection": { "anchor": 3, "head": 3 } } }
7979
] },
8080
{ "name": "backspace with a selection deletes it", "text": "abcd", "ops": [
8181
{ "op": "setSelection", "anchor": 1, "head": 3 }, { "op": "backspace" }

0 commit comments

Comments
 (0)