aboutsummaryrefslogtreecommitdiff
path: root/ttt.jai
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-12-14 01:05:42 +0000
committerdam <dam@gudinoff>2023-12-14 01:05:42 +0000
commit47890a446f1b9827fe2dc8ac370ded9d91ed2247 (patch)
tree1fe10ce134ce6c207fd3cb148c1fb4a10b443719 /ttt.jai
parente3f4ad1b4db98f612f097ba76116ab5d85bed912 (diff)
downloadtask-time-tracker-47890a446f1b9827fe2dc8ac370ded9d91ed2247.tar.zst
task-time-tracker-47890a446f1b9827fe2dc8ac370ded9d91ed2247.zip
Testing Key structures and procedures.
Diffstat (limited to 'ttt.jai')
-rw-r--r--ttt.jai62
1 files changed, 60 insertions, 2 deletions
diff --git a/ttt.jai b/ttt.jai
index b8681ff..9ef7543 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -1185,6 +1185,66 @@ main :: () {
// TODO Test input
+ Key :: union {
+ text: [4] u8;
+ code: u64;
+ }
+
+ // Instead of checking if it's an array or string... check the type is array of u8.
+ to_key :: inline (value: $T) -> Key #modify { return T == u8 || T == string || (T == []u8); } {
+ k: Key;
+ #if T == u8 {
+ k.text[0] = value;
+ }
+ #if T == string || (T == []u8) {
+ assert(value.count <= 4);
+ for 0..value.count-1 k.text[it] = value[it];
+ }
+ return k;
+ }
+
+ operator == :: inline (a: Key, b: Key) -> bool {
+ return a.code == b.code;
+ }
+
+ // Instead of checking if it's an array or string... check the type is array of u8.
+ // We'll need to use "Type_Info" and "Type_Info_Array"
+ // and cast T using `type_info := cast(*Type_Info)T;`
+ operator == :: inline (a: Key, b: $T) -> bool
+ #modify {
+ if T == u8 {
+ return true;
+ }
+ ti := cast(*Type_Info)T;
+ if ti.type == .ARRAY {
+ ti_array := cast(*Type_Info_Array)T;
+ // tia_type := ti_array.element_type.type;
+ return ti_array.element_type.type == .INTEGER && ti_array.element_type.runtime_size == 1;
+ }
+ return false;
+ // return T == u8 || T == string || (T == []u8); } {
+ } {
+ // operator == :: inline (a: Key, b: $T) -> bool #modify { return (T == [4]u8); } {
+ k := to_key(b);
+ return a == k;
+ }
+
+ // k := K. {xx "01"};
+ // k := to_key(xx "\0\0\01");
+ // k := to_key(xx "€");
+ // k := to_key(xx "A");
+ k := to_key("A");
+ // a: u8 = #char "A";
+ a: [4]u8;
+ a[0] = #char "A";
+ print("Is equal to 'A': >%<\n", k == a);
+ // b: u8 = 3;
+ // print("Is equal to 'A': >%<\n", k == #char);
+ print("Text :>%<\n", cast(string)k.text, to_standard_error = true);
+ print("Key :>%<\n", FormatInt.{value=k.code, base=16, minimum_digits=8}, to_standard_error = true);
+ return;
+
+
#if 0 {
print("test 1\n");
TUI.start();
@@ -1284,8 +1344,6 @@ main :: () {
assert(key == #char "y", "Failed to get terminal size.\n");
print("> success\n", to_standard_error = true);
}
-
- // TODO Resizing terminal breaks the tests... try to fix it.
#if 0 {
print("test 5\n", to_standard_error = true);