Public Access
Add widget kit, input layer with Compose Key, Launcher and demo apps
Steps 5 and 6 of M0. - lib/ui (host-tested): ListModel, LineEditor (UTF-8, byte-limited), wrapText, ToastQueue, DialogModel - lib/input (host-tested): KeyMapper turns keyboard state into logical keys (Fn arrows, ` Back, Fn+` Home) and composes accents with opt - src/ui: off-screen 16-bit frame pushed in one transfer (fixes the flicker), Status Bar, list, text, line editor, dialog, Toast widgets, Notifier (Toast + beep + LED), vendored public-domain Latin-1 fonts - Apps: minimal Launcher, Widget demo, Diagnostics (SD erase now behind a confirmation dialog) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
#include <unity.h>
|
||||
|
||||
#include "line_editor.h"
|
||||
|
||||
using namespace roro;
|
||||
|
||||
void setUp() {}
|
||||
void tearDown() {}
|
||||
|
||||
void test_typing_appends_at_cursor() {
|
||||
LineEditor e(32);
|
||||
e.insert('h');
|
||||
e.insert('i');
|
||||
TEST_ASSERT_EQUAL_STRING("hi", e.text().c_str());
|
||||
TEST_ASSERT_EQUAL(2, e.cursor());
|
||||
}
|
||||
|
||||
void test_accented_characters_are_stored_as_utf8() {
|
||||
LineEditor e(32);
|
||||
e.insert(0xE9); // é
|
||||
TEST_ASSERT_EQUAL_STRING("\xC3\xA9", e.text().c_str());
|
||||
TEST_ASSERT_EQUAL(2, e.cursor());
|
||||
}
|
||||
|
||||
void test_cursor_moves_over_whole_characters() {
|
||||
LineEditor e(32);
|
||||
e.setText("a\xC3\xA9z"); // aéz
|
||||
TEST_ASSERT_EQUAL(4, e.cursor());
|
||||
e.left();
|
||||
TEST_ASSERT_EQUAL(3, e.cursor());
|
||||
e.left();
|
||||
TEST_ASSERT_EQUAL(1, e.cursor()); // skipped both bytes of é
|
||||
e.right();
|
||||
TEST_ASSERT_EQUAL(3, e.cursor());
|
||||
}
|
||||
|
||||
void test_cursor_stops_at_both_ends() {
|
||||
LineEditor e(32);
|
||||
e.setText("ab");
|
||||
e.right();
|
||||
TEST_ASSERT_EQUAL(2, e.cursor());
|
||||
e.home();
|
||||
e.left();
|
||||
TEST_ASSERT_EQUAL(0, e.cursor());
|
||||
e.end();
|
||||
TEST_ASSERT_EQUAL(2, e.cursor());
|
||||
}
|
||||
|
||||
void test_insert_in_the_middle() {
|
||||
LineEditor e(32);
|
||||
e.setText("ac");
|
||||
e.left();
|
||||
e.insert('b');
|
||||
TEST_ASSERT_EQUAL_STRING("abc", e.text().c_str());
|
||||
TEST_ASSERT_EQUAL(2, e.cursor());
|
||||
}
|
||||
|
||||
void test_backspace_removes_the_whole_character_before_the_cursor() {
|
||||
LineEditor e(32);
|
||||
e.setText("a\xC3\xA9");
|
||||
e.backspace();
|
||||
TEST_ASSERT_EQUAL_STRING("a", e.text().c_str());
|
||||
e.home();
|
||||
e.backspace();
|
||||
TEST_ASSERT_EQUAL_STRING("a", e.text().c_str());
|
||||
}
|
||||
|
||||
void test_insert_rejected_when_it_would_exceed_max_bytes() {
|
||||
LineEditor e(3);
|
||||
e.setText("ab");
|
||||
TEST_ASSERT_FALSE(e.insert(0xE9)); // 2 bytes, only 1 left
|
||||
TEST_ASSERT_TRUE(e.insert('c'));
|
||||
TEST_ASSERT_FALSE(e.insert('d'));
|
||||
TEST_ASSERT_EQUAL_STRING("abc", e.text().c_str());
|
||||
}
|
||||
|
||||
void test_set_text_truncates_on_a_character_boundary() {
|
||||
LineEditor e(2);
|
||||
e.setText("a\xC3\xA9");
|
||||
TEST_ASSERT_EQUAL_STRING("a", e.text().c_str());
|
||||
}
|
||||
|
||||
void test_three_and_four_byte_characters() {
|
||||
LineEditor e(32);
|
||||
e.insert(0x20AC); // €
|
||||
e.insert(0x1F600); // 😀
|
||||
TEST_ASSERT_EQUAL(7, e.text().size());
|
||||
e.backspace();
|
||||
TEST_ASSERT_EQUAL_STRING("\xE2\x82\xAC", e.text().c_str());
|
||||
}
|
||||
|
||||
int main() {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_typing_appends_at_cursor);
|
||||
RUN_TEST(test_accented_characters_are_stored_as_utf8);
|
||||
RUN_TEST(test_cursor_moves_over_whole_characters);
|
||||
RUN_TEST(test_cursor_stops_at_both_ends);
|
||||
RUN_TEST(test_insert_in_the_middle);
|
||||
RUN_TEST(test_backspace_removes_the_whole_character_before_the_cursor);
|
||||
RUN_TEST(test_insert_rejected_when_it_would_exceed_max_bytes);
|
||||
RUN_TEST(test_set_text_truncates_on_a_character_boundary);
|
||||
RUN_TEST(test_three_and_four_byte_characters);
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user