Lolly
1.4.28
Loading...
Searching...
No Matches
tests
Kernel
Types
parse_string_test.cpp
Go to the documentation of this file.
1
#include "
a_lolly_test.hpp
"
2
#include "
parse_string.hpp
"
3
4
#include <cassert>
5
#include <iostream>
6
7
TEST_CASE
(
"test for test()"
) {
8
parse_string
s1
,
s2
(
"abc"
),
s3
(
" "
);
9
parse_string
s4
(
"\t\b\0"
);
10
CHECK_EQ
(
test
(
s1
,
""
),
true
);
11
CHECK_EQ
(
test
(
s2
,
"ab"
),
true
);
12
CHECK_EQ
(
test
(
s3
,
" "
),
true
);
13
CHECK_EQ
(
test
(
s4
,
"\t\b"
),
true
);
14
CHECK_EQ
(
test
(
s3
,
""
),
true
);
15
16
CHECK_EQ
(!
test
(
s3
,
"asdf"
),
true
);
17
CHECK_EQ
(!
test
(
s4
,
"1234"
),
true
);
18
}
19
20
TEST_CASE
(
"test for operator[] and getchar()"
) {
21
parse_string
s1
;
22
parse_string
s2
(
" 123456789abcd~!@#$"
);
23
string
str (
'0'
, 300);
24
str <<
"1"
;
25
parse_string
s3
(str);
26
CHECK_EQ
(
s2
[0] ==
' '
,
true
);
27
CHECK_EQ
(
s2
[9] ==
'9'
,
true
);
28
CHECK_EQ
(
s2
[14] ==
'~'
,
true
);
29
CHECK_EQ
(
s3
[300] ==
'1'
,
true
);
30
CHECK_EQ
(
s2
[-1] ==
'\0'
,
true
);
31
32
CHECK_EQ
(
s1
[2] !=
'2'
,
true
);
33
CHECK_EQ
(
s2
[18] !=
'#'
,
true
);
34
CHECK_EQ
(
s2
[0] !=
'0'
,
true
);
35
CHECK_EQ
(
s2
[100] !=
'$'
,
true
);
36
}
37
38
TEST_CASE
(
"test for get_string()"
) {
39
parse_string
s1
(
"\t\b"
),
s2
;
40
s1
->write (
"!@#$"
);
41
s1
->write (
"0123"
);
42
s1
->write (
""
);
43
CHECK_EQ
(
s2
->get_string (0) ==
""
,
true
);
44
CHECK_EQ
(
s1
->get_string (0) ==
""
,
true
);
45
CHECK_EQ
(
s1
->get_string (1) ==
"0"
,
true
);
46
CHECK_EQ
(
s1
->get_string (2) ==
"01"
,
true
);
47
CHECK_EQ
(
s1
->get_string (6) ==
"0123!@"
,
true
);
48
CHECK_EQ
(
s1
->get_string (9) ==
"0123!@#$\t"
,
true
);
49
CHECK_EQ
(
s1
->get_string (12) ==
"0123!@#$\t\b"
,
true
);
50
51
CHECK_EQ
(
s2
->get_string (0) !=
" "
,
true
);
52
CHECK_EQ
(
s1
->get_string (0) !=
"0"
,
true
);
53
CHECK_EQ
(
s1
->get_string (1) !=
""
,
true
);
54
CHECK_EQ
(
s1
->get_string (2) !=
"!@"
,
true
);
55
CHECK_EQ
(
s1
->get_string (15) !=
""
,
true
);
56
}
57
58
TEST_CASE
(
"test for write() and read()"
) {
59
parse_string
s1
(
"\t\b"
);
60
s1
->write (
"!@#$"
);
61
s1
->write (
"0123"
);
62
s1
->write (
""
);
63
CHECK_EQ
(
s1
[4] ==
'!'
,
true
);
64
CHECK_EQ
(
s1
[7] ==
'$'
,
true
);
65
CHECK_EQ
(
test
(
s1
,
"0123!@#$\t\b"
),
true
);
66
67
CHECK_EQ
(
s1
->read (3) ==
"012"
,
true
);
68
CHECK_EQ
(
s1
->read (1) ==
"3"
,
true
);
69
CHECK_EQ
(
s1
->read (5) ==
"!@#$\t"
,
true
);
70
CHECK_EQ
(
s1
->read (2) ==
"\b"
,
true
);
71
CHECK_EQ
(
s1
->read (2) ==
""
,
true
);
72
}
73
74
TEST_CASE
(
"test for bool"
) {
75
parse_string
s1
,
s2
(
"a)3"
),
s3
(
" "
);
76
parse_string
s4
(
"\0"
),
s5
(
"\t"
);
77
CHECK_EQ
(
s2
==
true
,
true
);
78
CHECK_EQ
(
s3
==
true
,
true
);
79
CHECK_EQ
(
s4
==
true
,
true
);
80
CHECK_EQ
(
s5
==
true
,
true
);
81
82
CHECK_EQ
(
s1
==
false
,
true
);
83
}
84
85
TEST_CASE
(
"test for operator+= and advance()"
) {
86
parse_string
s1
(
"\t\b"
);
87
s1
->write (
"!@#$"
);
88
s1
->write (
"0123"
);
89
s1
->write (
""
);
90
s1
+= 1;
91
CHECK_EQ
(
s1
[0] ==
'1'
,
true
);
92
CHECK_EQ
(
s1
[9] ==
'\0'
,
true
);
93
s1
+= 3;
94
CHECK_EQ
(
s1
[0] ==
'!'
,
true
);
95
CHECK_EQ
(
s1
[4] ==
'\t'
,
true
);
96
s1
+= 6;
97
CHECK_EQ
(
s1
[0] ==
'\0'
,
true
);
98
CHECK_EQ
(
s1
[-1] !=
'\b'
,
true
);
99
}
a_lolly_test.hpp
test
bool test(string s, int i, const char *test)
Definition
analyze.cpp:542
list
The list class represents a linked list.
Definition
list.hpp:48
parse_string
Definition
parse_string.hpp:40
parse_string.hpp
TEST_CASE
TEST_CASE("test for operator+= and advance()")
Definition
parse_string_test.cpp:85
Generated by
1.10.0