Browse Source

Add termEvent tests

June 2 months ago
parent
commit
b7bac21263
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
2 changed files with 22 additions and 1 deletions
  1. 1
    0
      Makefile
  2. 21
    1
      term.c

+ 1
- 0
Makefile View File

@@ -25,6 +25,7 @@ OBJS += ui.o
25 25
 OBJS += url.o
26 26
 
27 27
 TESTS += format.t
28
+TESTS += term.t
28 29
 
29 30
 all: tags chatte
30 31
 

+ 21
- 1
term.c View File

@@ -21,7 +21,6 @@
21 21
 
22 22
 #include "chat.h"
23 23
 
24
-
25 24
 static bool xterm;
26 25
 
27 26
 void termInit(void) {
@@ -67,3 +66,24 @@ enum TermEvent termEvent(char ch) {
67 66
 		default:        state = 0; return 0;
68 67
 	}
69 68
 }
69
+
70
+#ifdef TEST
71
+#include <assert.h>
72
+
73
+static bool testEvent(const char *str, enum TermEvent event) {
74
+	enum TermEvent e = TermNone;
75
+	for (size_t i = 0; i < strlen(str); ++i) {
76
+		if (e) return false;
77
+		e = termEvent(str[i]);
78
+	}
79
+	return (e == event);
80
+}
81
+
82
+int main() {
83
+	assert(testEvent("\33[I", TermFocusIn));
84
+	assert(testEvent("\33[O", TermFocusOut));
85
+	assert(testEvent("\33[200~", TermPasteStart));
86
+	assert(testEvent("\33[201~", TermPasteEnd));
87
+}
88
+
89
+#endif

Loading…
Cancel
Save