2024-02-18 02:07:07 +01:00
|
|
|
# SPDX-FileCopyrightText: 2021-2024 Leroy Hopson <godot-xterm@leroy.nix.nz>
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2024-02-18 01:52:48 +01:00
|
|
|
class_name TerminalTest extends "res://addons/gut/test.gd"
|
2024-02-17 23:50:38 +01:00
|
|
|
|
|
|
|
var terminal: Terminal
|
|
|
|
|
|
|
|
|
|
|
|
func before_each():
|
|
|
|
terminal = Terminal.new()
|
|
|
|
terminal.size = Vector2(400, 200)
|
2024-02-25 09:14:03 +01:00
|
|
|
watch_signals(terminal)
|
2024-02-17 23:50:38 +01:00
|
|
|
add_child_autofree(terminal)
|
|
|
|
|
|
|
|
|
|
|
|
class TestBell:
|
|
|
|
extends TerminalTest
|
|
|
|
|
|
|
|
func test_bell() -> void:
|
|
|
|
watch_signals(terminal)
|
|
|
|
terminal.bell_cooldown = 0
|
|
|
|
terminal.write(char(7))
|
|
|
|
terminal.write(char(0x07))
|
|
|
|
terminal.write("\a")
|
|
|
|
terminal.write("\u0007")
|
|
|
|
terminal.write("'Ask not for whom the \a tolls; it tolls for thee' - John Donne")
|
|
|
|
assert_signal_emit_count(terminal, "bell", 5)
|
|
|
|
|
2024-02-18 02:07:07 +01:00
|
|
|
func test_bell_mute() -> void:
|
|
|
|
watch_signals(terminal)
|
|
|
|
terminal.bell_muted = true
|
|
|
|
terminal.write("\a")
|
|
|
|
assert_signal_emit_count(terminal, "bell", 0)
|
|
|
|
|
|
|
|
func test_bell_cooldown() -> void:
|
|
|
|
watch_signals(terminal)
|
|
|
|
terminal.bell_cooldown = 10000
|
|
|
|
terminal.write("\a")
|
|
|
|
terminal.write("\a")
|
|
|
|
assert_signal_emit_count(terminal, "bell", 1)
|
|
|
|
|
|
|
|
func test_change_cooldown_while_active() -> void:
|
|
|
|
watch_signals(terminal)
|
|
|
|
terminal.bell_cooldown = 10000
|
|
|
|
terminal.write("\a")
|
|
|
|
terminal.bell_cooldown = 0
|
|
|
|
terminal.write("\a")
|
|
|
|
assert_signal_emit_count(terminal, "bell", 2)
|
|
|
|
|
2024-02-17 23:50:38 +01:00
|
|
|
|
|
|
|
class TestCursorPos:
|
|
|
|
extends TerminalTest
|
|
|
|
|
|
|
|
func test_get_cursor_pos_initial():
|
2024-02-18 01:52:48 +01:00
|
|
|
assert_eq(terminal.get_cursor_pos(), Vector2i.ZERO)
|
2024-02-17 23:50:38 +01:00
|
|
|
|
|
|
|
func test_get_cursor_pos_x():
|
|
|
|
terminal.write("_")
|
|
|
|
assert_eq(terminal.get_cursor_pos().x, 1)
|
|
|
|
|
|
|
|
func test_get_cursor_pos_y():
|
|
|
|
terminal.write("_".repeat(terminal.cols + 1))
|
|
|
|
assert_eq(terminal.get_cursor_pos().y, 1)
|
2024-02-25 08:25:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestWrite:
|
|
|
|
extends TerminalTest
|
|
|
|
|
|
|
|
func test_returns_response_when_input_contains_query():
|
|
|
|
var response = terminal.write("\u001b[6n") # Query cursor position.
|
|
|
|
assert_eq(response, "\u001b[1;1R")
|
|
|
|
|
|
|
|
func test_returns_response_to_multiple_queries():
|
|
|
|
var response = terminal.write("\u001b[6n\u001b[5n") # Query cursor position and status.
|
|
|
|
assert_eq(response, "\u001b[1;1R\u001b[0n")
|
|
|
|
|
|
|
|
func test_returns_response_to_multiple_queries_among_other_data():
|
|
|
|
var response = terminal.write("hello\r\nworld\u001b[6nother\r\ndata\u001b[5ntest")
|
|
|
|
assert_eq(response, "\u001b[2;6R\u001b[0n")
|
2024-02-25 09:14:03 +01:00
|
|
|
|
|
|
|
func test_data_sent_emitted_on_query():
|
|
|
|
terminal.write("\u001b[6n")
|
|
|
|
assert_signal_emitted(terminal, "data_sent")
|
|
|
|
|
|
|
|
func test_data_sent_emitted_with_response():
|
|
|
|
terminal.write("\u001b[6n")
|
|
|
|
assert_signal_emitted_with_parameters(
|
|
|
|
terminal, "data_sent", ["\u001b[1;1R".to_utf8_buffer()]
|
|
|
|
)
|
|
|
|
|
|
|
|
func test_data_sent_not_emitted_when_empty_string_written():
|
|
|
|
terminal.write("")
|
|
|
|
assert_signal_emit_count(terminal, "data_sent", 0)
|