Introduction
Introduction Statistics Contact Development Disclaimer Help
sl_test.c - lchat - A line oriented chat front end for ii.
git clone git://git.suckless.org/lchat
Log
Files
Refs
README
---
sl_test.c (2244B)
---
1 #include <assert.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 #include "slackline.h"
7
8 static void
9 strokes(struct slackline *sl, const char *str)
10 {
11 for (const char *c = str; *c != '\0'; c++)
12 sl_keystroke(sl, *c);
13 }
14
15 static void
16 check_init(struct slackline *sl)
17 {
18 assert(sl != NULL);
19 assert(sl->buf != NULL);
20 assert(sl->ptr == sl->buf);
21 assert(sl->rlen == 0);
22 assert(sl->blen == 0);
23 assert(sl->rcur == 0);
24 assert(sl->bcur == 0);
25 assert(sl->last == sl->buf);
26 }
27
28 static void
29 check_ascii(struct slackline *sl)
30 {
31 strokes(sl, "abc");
32 assert(sl->blen == 3);
33 assert(sl->rlen == 3);
34 assert(sl->bcur == 3);
35 assert(sl->rcur == 3);
36 assert(sl->last - sl->buf == sl->blen);
37
38 strokes(sl, "\x08"); /* backspace */
39 assert(sl->blen == 2);
40 assert(sl->rlen == 2);
41 assert(sl->bcur == 2);
42 assert(sl->rcur == 2);
43 assert(sl->last - sl->buf == sl->blen);
44
45 strokes(sl, "\x1b[D"); /* left arrow key */
46 assert(sl->blen == 2);
47 assert(sl->rlen == 2);
48 assert(sl->bcur == 1);
49 assert(sl->rcur == 1);
50 assert(sl->last - sl->buf == sl->blen);
51 }
52
53 static void
54 check_utf8(struct slackline *sl)
55 {
56 /* ae | oe | ue | ss */
57 strokes(sl, "\xC3\xA4\xC3\xBC\xC3\xB6\xC3\x9F");
58 assert(sl->blen == 8);
59 assert(sl->rlen == 4);
60 assert(sl->bcur == 8);
61 assert(sl->rcur == 4);
62 assert(sl->last - sl->buf == sl->blen);
63
64 strokes(sl, "\x08"); /* backspace */
65 assert(sl->blen == 6);
66 assert(sl->rlen == 3);
67 assert(sl->bcur == 6);
68 assert(sl->rcur == 3);
69 assert(sl->last - sl->buf == sl->blen);
70
71 strokes(sl, "\x1b[D"); /* left arrow key */
72 assert(sl->blen == 6);
73 assert(sl->rlen == 3);
74 assert(sl->bcur == 4);
75 assert(sl->rcur == 2);
76 assert(sl->last - sl->buf == sl->blen);
77
78 strokes(sl, "\x08"); /* backspace */
79 assert(sl->blen == 4);
80 assert(sl->rlen == 2);
81 assert(sl->bcur == 2);
82 assert(sl->rcur == 1);
83 assert(sl->last - sl->buf == sl->blen);
84
85 strokes(sl, "\x1b[C"); /* right arrow key */
86 assert(sl->blen == 4);
87 assert(sl->rlen == 2);
88 assert(sl->bcur == 4);
89 assert(sl->rcur == 2);
90 assert(sl->last - sl->buf == sl->blen);
91 }
92
93 int
94 main(void)
95 {
96 struct slackline *sl;
97
98 sl = sl_init();
99 check_init(sl);
100 check_ascii(sl);
101
102 sl_reset(sl);
103 check_init(sl);
104 check_utf8(sl);
105
106 sl_free(sl);
107
108 return EXIT_SUCCESS;
109 }
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.