cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TestInput.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 #include "cdstd.h"
4 #include <UnitTest++.h>
5 #include "cddefines.h"
6 #include "input.h"
7 
8 namespace {
9  TEST(TestLgIsCommentSeq)
10  {
11  CHECK( !lgIsCommentSeq( "# comment", false, false ) );
12  CHECK( lgIsCommentSeq( "## comment", false, false ) );
13  CHECK( lgIsCommentSeq( "// comment", false, false ) );
14  CHECK( lgIsCommentSeq( "% comment", false, false ) );
15  CHECK( !lgIsCommentSeq( "* comment", false, false ) );
16  CHECK( lgIsCommentSeq( "; comment", false, false ) );
17  CHECK( !lgIsCommentSeq( "c omment", false, false ) );
18  CHECK( !lgIsCommentSeq( "hden", false, false ) );
19 
20  CHECK( !lgIsCommentSeq( "# comment", true, false ) );
21  CHECK( lgIsCommentSeq( "## comment", true, false ) );
22  CHECK( lgIsCommentSeq( "// comment", true, false ) );
23  CHECK( lgIsCommentSeq( "% comment", true, false ) );
24  CHECK( lgIsCommentSeq( "* comment", true, false ) );
25  CHECK( !lgIsCommentSeq( "; comment", true, false ) );
26  CHECK( !lgIsCommentSeq( "c omment", true, false ) );
27  CHECK( !lgIsCommentSeq( "hden", true, false ) );
28 
29  CHECK( lgIsCommentSeq( "# comment", false, true ) );
30  CHECK( lgIsCommentSeq( "## comment", false, true ) );
31  CHECK( lgIsCommentSeq( "// comment", false, true ) );
32  CHECK( lgIsCommentSeq( "% comment", false, true ) );
33  CHECK( !lgIsCommentSeq( "* comment", false, true ) );
34  CHECK( lgIsCommentSeq( "; comment", false, true ) );
35  CHECK( !lgIsCommentSeq( "c omment", false, true ) );
36  CHECK( !lgIsCommentSeq( "hden", false, true ) );
37 
38  CHECK( lgIsCommentSeq( "# comment", true, true ) );
39  CHECK( lgIsCommentSeq( "## comment", true, true ) );
40  CHECK( lgIsCommentSeq( "// comment", true, true ) );
41  CHECK( lgIsCommentSeq( "% comment", true, true ) );
42  CHECK( lgIsCommentSeq( "* comment", true, true ) );
43  CHECK( !lgIsCommentSeq( "; comment", true, true ) );
44  CHECK( !lgIsCommentSeq( "c omment", true, true ) );
45  CHECK( !lgIsCommentSeq( "hden", true, true ) );
46  }
47 
48  TEST(TestLgInputComment)
49  {
50  CHECK( lgInputComment( "# comment" ) );
51  CHECK( lgInputComment( "## comment" ) );
52  CHECK( lgInputComment( "// comment" ) );
53  CHECK( lgInputComment( "% comment" ) );
54  CHECK( lgInputComment( "* comment" ) );
55  CHECK( !lgInputComment( "; comment" ) );
56  CHECK( !lgInputComment( "c omment" ) );
57  CHECK( !lgInputComment( "hden" ) );
58  }
59 
60  TEST(TestLgInputEOF)
61  {
62  CHECK( lgInputEOF( "" ) );
63  CHECK( lgInputEOF( " text" ) );
64  CHECK( lgInputEOF( "***" ) );
65  CHECK( !lgInputEOF( "**" ) );
66  CHECK( !lgInputEOF( "command" ) );
67  }
68 
69  TEST(TestStripComment)
70  {
71  string line = "command # comment\n";
72  StripComment( line, false );
73  CHECK( line == "command # comment" );
74 
75  line = "command ## comment\n";
76  StripComment( line, false );
77  CHECK( line == "command " );
78 
79  line = "command // comment\n";
80  StripComment( line, false );
81  CHECK( line == "command " );
82 
83  line = "command % comment\n";
84  StripComment( line, false );
85  CHECK( line == "command " );
86 
87  line = "command * comment\n";
88  StripComment( line, false );
89  CHECK( line == "command * comment" );
90 
91  line = "command ; comment\n";
92  StripComment( line, false );
93  CHECK( line == "command " );
94 
95  line = "command c comment\n";
96  StripComment( line, false );
97  CHECK( line == "command c comment" );
98 
99  line = "command # comment\n";
100  StripComment( line, true );
101  CHECK( line == "command " );
102 
103  line = "command ## comment\n";
104  StripComment( line, true );
105  CHECK( line == "command " );
106 
107  line = "command // comment\n";
108  StripComment( line, true );
109  CHECK( line == "command " );
110 
111  line = "command % comment\n";
112  StripComment( line, true );
113  CHECK( line == "command " );
114 
115  line = "command * comment\n";
116  StripComment( line, true );
117  CHECK( line == "command * comment" );
118 
119  line = "command ; comment\n";
120  StripComment( line, true );
121  CHECK( line == "command " );
122 
123  line = "command c comment\n";
124  StripComment( line, true );
125  CHECK( line == "command c comment" );
126 
127  line = "command \"# ## // % * ; c text\"\n";
128  StripComment( line, true );
129  CHECK( line == "command \"# ## // % * ; c text\"" );
130 
131  line = "command #\"# ## // % * ; c text\"\n";
132  StripComment( line, true );
133  CHECK( line == "command " );
134 
135  line = "command \"# ## // % * ; c text\n";
136  StripComment( line, true );
137  CHECK( line == "command \"# ## // % * ; c text" );
138 
139  line = "command # \"# ## // % * ; c text\n";
140  StripComment( line, true );
141  CHECK( line == "command " );
142 
143  line = "command # \"# ## // % * ; c text\n";
144  StripComment( line, false );
145  CHECK( line == "command # \"# ## // % * ; c text" );
146 
147  input.lgUnderscoreFound = false;
148  input.lgBracketFound = false;
149 
150  line = "command \"file_name[]\" _on_ # comment _ [ ]\n";
151  StripComment( line, false );
152  CHECK( line == "command \"file_name[]\" on # comment _ [ ]" );
154 
155  line = "command param\r";
156  StripComment( line, true );
157  CHECK( line == "command param" );
158 
159  line = "# comment ## another comment\r";
160  StripComment( line, false );
161  CHECK( line == "# comment ## another comment" );
162 
163  line = "command # comment ## another comment\n";
164  StripComment( line, false );
165  CHECK( line == "command # comment ## another comment" );
166  }
167 
168  TEST(TestGetString)
169  {
170  string line = "\"label \\ # ## // % * ; c text_23[]\"";
171  string label;
172  size_t p = GetString(line, 0, label);
173  CHECK( label == "label \\ # ## // % * ; c text_23[]" );
174  CHECK( p == line.length() );
175 
176  line = "\"text";
177  p = GetString(line, 0, label);
178  CHECK( label == "" );
179  CHECK( p == string::npos );
180 
181  line = " \"text\"";
182  CHECK_THROW( GetString(line, 0, label), bad_assert );
183  }
184 }
t_input input
Definition: input.cpp:12
bool lgInputEOF(const char *chLine)
Definition: input.cpp:84
size_t GetString(const string &s, size_t p, string &buf)
Definition: input.cpp:152
bool lgIsCommentSeq(const char *s, bool lgColumn0, bool lgReportVisible)
Definition: input.cpp:31
void StripComment(string &s, bool lgStripVisible)
Definition: input.cpp:98
bool lgUnderscoreFound
Definition: input.h:112
bool lgBracketFound
Definition: input.h:116
bool lgInputComment(const char *chLine)
Definition: input.cpp:72