7 static const char test_string_1
[] = "abcdef\nghijklmno\npqrstuvwx\nz";
8 static const char test_string_2
[] = "\nabcdef\n\nghijklmno\npqrstuvwxz\n";
9 static const char test_string_3
[] = "\342\272\206\342\273\204\351\252\260\n\351\253\200";
10 static const char test_string_4
[] = "\n";
14 test_lookahead_consume (void)
18 char utf8char
[6] = { 0, };
23 printf ("\nTEST - lookahead/consume\n");
27 stream
= st_input_new (test_string_1
);
29 printf ("\n\"%s\"\n", g_strescape (test_string_1
, NULL
));
31 while ((uchar
= st_input_look_ahead (stream
, 1)) != ST_INPUT_EOF
) {
33 g_unichar_to_utf8 (uchar
, utf8char
);
36 printf ("%s %i,%i\n", utf8char
,
37 st_input_get_line (stream
), st_input_get_column (stream
));
40 printf ("%s %i,%i\n", "\\n",
41 st_input_get_line (stream
), st_input_get_column (stream
));
44 st_input_consume (stream
);
48 st_input_destroy (stream
);
49 stream
= st_input_new (test_string_2
);
52 printf ("\n\"%s\"\n", g_strescape (test_string_2
, NULL
));
54 while ((uchar
= st_input_look_ahead (stream
, 1)) != ST_INPUT_EOF
) {
56 g_unichar_to_utf8 (uchar
, utf8char
);
59 printf ("%s %i,%i\n", utf8char
,
60 st_input_get_line (stream
), st_input_get_column (stream
));
63 printf ("%s %i,%i\n", "\\n",
64 st_input_get_line (stream
), st_input_get_column (stream
));
66 st_input_consume (stream
);
71 st_input_destroy (stream
);
72 stream
= st_input_new (test_string_3
);
75 // lookahead up to 4 chars this time, without consuming - line,col numbers not calculated though
76 printf ("\n\"%s\"\n", g_strescape (test_string_3
, NULL
));
80 while ((uchar
= st_input_look_ahead (stream
, i
)) != ST_INPUT_EOF
) {
82 g_unichar_to_utf8 (uchar
, utf8char
);
85 printf ("%s\n", utf8char
);
87 printf ("%s\n", "\\n");
94 st_input_destroy (stream
);
95 stream
= st_input_new (test_string_4
);
98 printf ("\n\"%s\"\n", g_strescape (test_string_4
, NULL
));
100 while ((uchar
= st_input_look_ahead (stream
, 1)) != ST_INPUT_EOF
) {
102 g_unichar_to_utf8 (uchar
, utf8char
);
105 printf ("%s %i,%i\n", utf8char
,
106 st_input_get_line (stream
), st_input_get_column (stream
));
109 printf ("%s %i,%i\n", "\\n",
110 st_input_get_line (stream
), st_input_get_column (stream
));
112 st_input_consume (stream
);
120 test_mark_rewind (void)
122 char buf
[6] = { 0, };
124 st_input_t
*stream
= st_input_new (test_string_1
);
126 printf ("\nTEST - mark/rewind\n");
129 while ((uchar
= st_input_look_ahead (stream
, 1)) != ST_INPUT_EOF
) {
131 st_input_consume (stream
);
133 // add markers at each newline
135 st_input_mark (stream
);
139 st_input_rewind_to_marker (stream
, 1);
141 uchar
= st_input_look_ahead (stream
, 1);
142 g_unichar_to_utf8 (uchar
, buf
);
143 printf ("%s %i,%i\n", buf
,
144 st_input_get_line (stream
), st_input_get_column (stream
));
146 st_input_rewind_to_marker (stream
, 2);
148 uchar
= st_input_look_ahead (stream
, 1);
149 g_unichar_to_utf8 (uchar
, buf
);
150 printf ("%s %i,%i\n", buf
,
151 st_input_get_line (stream
), st_input_get_column (stream
));
159 char buf
[6] = { 0, };
162 st_input_t
*stream
= st_input_new (test_string_2
);
164 printf ("\nTEST - seek\n");
166 st_input_seek (stream
, 6);
168 uchar
= st_input_look_ahead (stream
, 1);
169 g_unichar_to_utf8 (uchar
, buf
);
170 printf ("%s %i,%i\n", buf
,
171 st_input_get_line (stream
), st_input_get_column (stream
));
174 st_input_seek (stream
, 3);
176 uchar
= st_input_look_ahead (stream
, 1);
177 g_unichar_to_utf8 (uchar
, buf
);
178 printf ("%s %i,%i\n", buf
,
179 st_input_get_line (stream
), st_input_get_column (stream
));
181 st_input_seek (stream
, 9);
183 uchar
= st_input_look_ahead (stream
, 1);
184 g_unichar_to_utf8 (uchar
, buf
);
185 printf ("%s %i,%i\n", buf
,
186 st_input_get_line (stream
), st_input_get_column (stream
));
191 test_substring (void)
196 st_input_t
*stream
= st_input_new (test_string_1
);
198 printf ("\nTEST - seek\n");
200 gunichar
*uchars
= st_input_substring (stream
, 3, 27);
202 char *str
= g_ucs4_to_utf8 (uchars
, -1, NULL
, NULL
, NULL
);
204 printf ("%s\n", str
);
208 main (int argc
, char *argv
[])
211 test_lookahead_consume ();