j
This commit is contained in:
parent
5b65c4c0e4
commit
985aa16236
13 changed files with 1381 additions and 241 deletions
|
|
@ -4,6 +4,7 @@ import "core:fmt"
|
|||
import "core:net"
|
||||
import "core:os"
|
||||
import "core:strconv"
|
||||
import "core:strings"
|
||||
|
||||
main :: proc() {
|
||||
args := os.args
|
||||
|
|
@ -15,6 +16,13 @@ main :: proc() {
|
|||
return
|
||||
}
|
||||
|
||||
if len(args) >= 2 && args[1] == "--editor-selftest" {
|
||||
if !editor_selftest() {
|
||||
os.exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if len(args) >= 3 && args[1] == "--git-status-selftest" {
|
||||
if !git_status_selftest(args[2]) {
|
||||
os.exit(1)
|
||||
|
|
@ -168,6 +176,88 @@ run_buffer_smoke :: proc() {
|
|||
fmt.printf("buffer-cursor: %d:%d\n", line, col)
|
||||
}
|
||||
|
||||
editor_selftest :: proc() -> bool {
|
||||
ok := true
|
||||
|
||||
buffer := buffer_make("one two\nsecond\n")
|
||||
defer buffer_destroy(&buffer)
|
||||
cursor := Cursor{}
|
||||
cursor_move_to_line_col(&buffer, &cursor, 0, 3)
|
||||
cursor_insert(&buffer, &cursor, "!")
|
||||
editor_selftest_check(&ok, "buffer insert", buffer_text_equals(&buffer, "one! two\nsecond\n"))
|
||||
editor_selftest_check(&ok, "buffer undo", buffer_undo(&buffer, &cursor) && buffer_text_equals(&buffer, "one two\nsecond\n"))
|
||||
editor_selftest_check(&ok, "buffer redo", buffer_redo(&buffer, &cursor) && buffer_text_equals(&buffer, "one! two\nsecond\n"))
|
||||
version := buffer.version
|
||||
buffer_replace_range(&buffer, 0, buffer_len(&buffer), "one! two\nsecond\n")
|
||||
editor_selftest_check(&ok, "replace no-op", buffer.version == version)
|
||||
|
||||
editor := Editor{}
|
||||
defer editor_destroy(&editor)
|
||||
original := "alpha beta\n child\n"
|
||||
original_bytes := clone_bytes(transmute([]u8)original)
|
||||
append(&editor.buffers, Editor_Buffer{
|
||||
path = strings.clone("selftest.kt"),
|
||||
daemon_path = strings.clone(""),
|
||||
original_storage = original_bytes[:],
|
||||
buffer = buffer_make(string(original_bytes[:])),
|
||||
saved_version = 0,
|
||||
})
|
||||
editor.active = 0
|
||||
active := editor_active_buffer(&editor)
|
||||
active.selection_active = true
|
||||
active.selection_anchor = 0
|
||||
active.cursor.offset = 5
|
||||
editor_insert_text(active, "omega")
|
||||
editor_selftest_check(&ok, "selection replace", buffer_text_equals(&active.buffer, "omega beta\n child\n") && active.dirty)
|
||||
editor_selftest_check(&ok, "undo returns clean", buffer_undo(&active.buffer, &active.cursor))
|
||||
editor_update_dirty(active)
|
||||
editor_selftest_check(&ok, "dirty tracks saved text", buffer_text_equals(&active.buffer, original) && !active.dirty)
|
||||
|
||||
cursor_move_to_line_col(&active.buffer, &active.cursor, 1, 9)
|
||||
editor_insert_newline_auto_indent(active)
|
||||
editor_selftest_check(&ok, "auto indent newline", buffer_text_equals(&active.buffer, "alpha beta\n child\n \n"))
|
||||
|
||||
rename_path := "/tmp/opencode/native-editor-rename-selftest.txt"
|
||||
_ = os.write_entire_file(rename_path, transmute([]u8)string("alpha beta\n"))
|
||||
rename := Rename_Panel{open = true}
|
||||
append(&rename.edits, Rename_Edit{
|
||||
path = strings.clone(rename_path),
|
||||
line = 1,
|
||||
column = 7,
|
||||
old_text = strings.clone("beta"),
|
||||
new_text = strings.clone("gamma"),
|
||||
label = strings.clone("native-editor-rename-selftest.txt:1:7"),
|
||||
})
|
||||
sync := Daemon_Sync_State{}
|
||||
editor_selftest_check(&ok, "rename apply disk", rename_panel_apply_edits(&rename, &editor, &sync))
|
||||
renamed_data, renamed_err := os.read_entire_file(rename_path, context.allocator)
|
||||
if renamed_err == nil {
|
||||
editor_selftest_check(&ok, "rename disk contents", bytes_equal(renamed_data[:], transmute([]u8)string("alpha gamma\n")))
|
||||
delete(renamed_data)
|
||||
} else {
|
||||
editor_selftest_check(&ok, "rename disk contents", false)
|
||||
}
|
||||
rename_panel_destroy(&rename)
|
||||
|
||||
fmt.println(ok ? "editor selftest: PASS" : "editor selftest: FAIL")
|
||||
return ok
|
||||
}
|
||||
|
||||
editor_selftest_check :: proc(ok: ^bool, name: string, passed: bool) {
|
||||
if passed {
|
||||
fmt.println("ok ", name)
|
||||
} else {
|
||||
fmt.println("FAIL", name)
|
||||
ok^ = false
|
||||
}
|
||||
}
|
||||
|
||||
buffer_text_equals :: proc(buffer: ^Buffer, expected: string) -> bool {
|
||||
text := buffer_bytes(buffer)
|
||||
defer delete(text)
|
||||
return bytes_equal(text[:], transmute([]u8)expected)
|
||||
}
|
||||
|
||||
send_line :: proc(socket: net.TCP_Socket, line: string) {
|
||||
bytes := transmute([]byte)line
|
||||
_, err := net.send_tcp(socket, bytes)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue