• R/O
  • SSH
  • HTTPS

eirsamples: コミット


コミットメタ情報

リビジョン23 (tree)
日時2019-06-05 05:04:38
作者quiret

ログメッセージ

- added some actual unit tests to bigunittest

変更サマリ

差分

--- bigunittest/src/main.cpp (revision 22)
+++ bigunittest/src/main.cpp (revision 23)
@@ -0,0 +1,156 @@
1+// Main execution file for bigunittest.
2+
3+#include <stdio.h>
4+#include <assert.h>
5+
6+#include <libparse/syntaxutil.h>
7+
8+void SYNTAXUTIL_TEST( void )
9+{
10+ printf( "testing trim_scan_syntax positives..." );
11+ {
12+ // Basic sample for nerds.
13+ {
14+ static const char some_text[] = "meow";
15+
16+ CSyntax <char> syntax( some_text, sizeof(some_text)-1 );
17+
18+ CSyntax <char> trimmed;
19+
20+ bool gotToTrim = trim_scan_syntax( syntax, trimmed );
21+
22+ assert( gotToTrim == true );
23+ assert( trimmed.GetCurrentDataSize() == 4 );
24+ assert( strncmp( trimmed.GetCurrentData(), "meow", 4 ) == 0 );
25+ }
26+
27+ // Trim off the left.
28+ {
29+ static const char some_text[] = " hi";
30+
31+ CSyntax <char> syntax( some_text, sizeof(some_text)-1 );
32+
33+ CSyntax <char> trimmed;
34+
35+ bool gotToTrim = trim_scan_syntax( syntax, trimmed );
36+
37+ assert( gotToTrim == true );
38+ assert( trimmed.GetCurrentDataSize() == 2 );
39+ assert( strncmp( trimmed.GetCurrentData(), "hi", 2 ) == 0 );
40+ }
41+
42+ // Trim off the right.
43+ {
44+ static const char some_text[] = "hi ";
45+
46+ CSyntax <char> syntax( some_text, sizeof(some_text)-1 );
47+
48+ CSyntax <char> trimmed;
49+
50+ bool gotToTrim = trim_scan_syntax( syntax, trimmed );
51+
52+ assert( gotToTrim == true );
53+ assert( trimmed.GetCurrentDataSize() == 2 );
54+ assert( strncmp( trimmed.GetCurrentData(), "hi", 2 ) == 0 );
55+ }
56+
57+ // Do an advanced sample.
58+ {
59+ static const char some_text[] = " \t hello world\t \t";
60+
61+ CSyntax <char> syntax( some_text, sizeof(some_text)-1 );
62+
63+ CSyntax <char> trimmed;
64+
65+ bool gotToTrim = trim_scan_syntax( syntax, trimmed );
66+
67+ assert( gotToTrim == true );
68+ assert( trimmed.GetCurrentDataSize() == 11 );
69+ assert( strncmp( trimmed.GetCurrentData(), "hello world", 11 ) == 0 );
70+ }
71+
72+ // We do not advance past newlines.
73+ {
74+ static const char some_ml_text[] = "hi there \nhow r u";
75+
76+ CSyntax <char> syntax( some_ml_text, sizeof(some_ml_text)-1 );
77+
78+ CSyntax <char> trimmed;
79+
80+ bool gotToTrim = trim_scan_syntax( syntax, trimmed );
81+
82+ assert( gotToTrim == true );
83+ assert( trimmed.GetCurrentDataSize() == 8 );
84+ assert( strncmp( trimmed.GetCurrentData(), "hi there", 8 ) == 0 );
85+ }
86+
87+ // More explicit newline test.
88+ {
89+ static const char some_ml_text[] = "meow\nwoof";
90+
91+ CSyntax <char> syntax( some_ml_text, sizeof(some_ml_text)-1 );
92+
93+ CSyntax <char> trimmed;
94+
95+ bool gotToTrim = trim_scan_syntax( syntax, trimmed );
96+
97+ assert( gotToTrim == true );
98+ assert( trimmed.GetCurrentDataSize() == 4 );
99+ assert( strncmp( trimmed.GetCurrentData(), "meow", 4 ) == 0 );
100+ }
101+ }
102+ printf( "ok.\n" );
103+
104+ printf( "testing trim_scan_syntax negatives..." );
105+ {
106+ // Empty is for suckers.
107+ {
108+ static const char some_text[] = "";
109+
110+ CSyntax <char> syntax( some_text, sizeof(some_text)-1 );
111+
112+ CSyntax <char> trimmed;
113+
114+ bool gotToTrim = trim_scan_syntax( syntax, trimmed );
115+
116+ assert( gotToTrim == false );
117+ }
118+
119+ // Obviously empty with stupid spaces in between.
120+ {
121+ static const char some_text[] = " \t \t\t\t ";
122+
123+ CSyntax <char> syntax( some_text, sizeof(some_text)-1 );
124+
125+ CSyntax <char> trimmed;
126+
127+ bool gotToTrim = trim_scan_syntax( syntax, trimmed );
128+
129+ assert( gotToTrim == false );
130+ }
131+ }
132+ printf( "ok.\n" );
133+
134+ printf( "testing is_string_empty..." );
135+ {
136+ assert( is_string_empty( "" ) == true );
137+ assert( is_string_empty( " \t " ) == true );
138+ assert( is_string_empty( " " ) == true );
139+
140+ assert( is_string_empty( "\nmeow" ) == false );
141+ assert( is_string_empty( "abcdef" ) == false );
142+ assert( is_string_empty( " hi " ) == false );
143+
144+ typedef eir::String <char, CRTHeapAllocator> basicString;
145+
146+ assert( is_string_empty( basicString( "" ) ) == true );
147+ }
148+ printf( "ok.\n" );
149+}
150+
151+int main( int argc, char *argv[] )
152+{
153+ SYNTAXUTIL_TEST();
154+
155+ return 0;
156+}
\ No newline at end of file
旧リポジトリブラウザで表示