ChaiScript / ChaiScript
1
#include <chaiscript/chaiscript_basic.hpp>
2
#include "../static_libs/chaiscript_parser.hpp"
3
#include "../static_libs/chaiscript_stdlib.hpp"
4

5

6
#ifdef CHAISCRIPT_MSVC
7
// ignore errors about negative unsigned integer literals
8
#pragma warning(push)
9
#pragma warning(disable : 4146)
10
#endif
11

12

13
#define TEST_LITERAL(v) test_literal(v, #v)
14
#define TEST_LITERAL_SIGNED(v) test_literal(v, #v, true)
15

16
template<typename T>
17 1
bool test_literal(T val, const std::string &str, bool use_boxed_number = false)
18
{
19 1
  std::cout << '(' << str << ") Comparing : C++ '" << val;
20 1
  chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(),create_chaiscript_parser());
21

22
  // Note, after applying the `-` it's possible that chaiscript has internally converted
23
  // between two equivalently sized types (ie, unsigned long and unsigned long long on a 64bit system)
24
  // so we're going to allow some leeway with the signed tests
25 1
  T val2 = [&](){
26 1
    if (!use_boxed_number) {
27 1
      return chai.eval<T>(str);
28
    } else {
29 1
      return chai.eval<chaiscript::Boxed_Number>(str).get_as_checked<T>();
30
    }
31 1
  }();
32

33 1
  std::cout << "' chai '" << val2 << "'\n";
34 1
  return val == val2;
35
}
36

37 1
int main()
38
{
39 1
  if( 
40 1
      TEST_LITERAL(0xF)
41 1
      && TEST_LITERAL(0xFF)
42 1
      && TEST_LITERAL(0xFFF)
43 1
      && TEST_LITERAL(0xFFFF)
44 1
      && TEST_LITERAL(0xFFFFF)
45 1
      && TEST_LITERAL(0xFFFFFF)
46 1
      && TEST_LITERAL(0xFFFFFFF)
47 1
      && TEST_LITERAL(0xFFFFFFFF)
48 1
      && TEST_LITERAL(0xFFFFFFFFF)
49 1
      && TEST_LITERAL(0xFFFFFFFFFF)
50 1
      && TEST_LITERAL(0xFFFFFFFFFFF)
51 1
      && TEST_LITERAL(0xFFFFFFFFFFFF)
52 1
      && TEST_LITERAL(0xFFFFFFFFFFFFF)
53 1
      && TEST_LITERAL(0xFFFFFFFFFFFFFF)
54 1
      && TEST_LITERAL(0xFFFFFFFFFFFFFFF)
55 1
      && TEST_LITERAL(0xFFFFFFFFFFFFFFFF) 
56

57

58 1
      && TEST_LITERAL(01)
59 1
      && TEST_LITERAL(017)
60 1
      && TEST_LITERAL(0177)
61 1
      && TEST_LITERAL(01777)
62 1
      && TEST_LITERAL(017777)
63 1
      && TEST_LITERAL(0177777)
64 1
      && TEST_LITERAL(01777777)
65 1
      && TEST_LITERAL(017777777)
66 1
      && TEST_LITERAL(0177777777)
67 1
      && TEST_LITERAL(01777777777)
68 1
      && TEST_LITERAL(017777777777)
69 1
      && TEST_LITERAL(0177777777777)
70 1
      && TEST_LITERAL(01777777777777)
71 1
      && TEST_LITERAL(017777777777777)
72 1
      && TEST_LITERAL(0177777777777777)
73 1
      && TEST_LITERAL(01777777777777777)
74 1
      && TEST_LITERAL(017777777777777777)
75 1
      && TEST_LITERAL(0177777777777777777)
76 1
      && TEST_LITERAL(01777777777777777777)
77 1
      && TEST_LITERAL(017777777777777777777)
78 1
      && TEST_LITERAL(0177777777777777777777)
79 1
      && TEST_LITERAL(01777777777777777777777)
80

81 1
      && TEST_LITERAL(1)
82 1
      && TEST_LITERAL(17)
83 1
      && TEST_LITERAL(177)
84 1
      && TEST_LITERAL(1777)
85 1
      && TEST_LITERAL(17777)
86 1
      && TEST_LITERAL(177777)
87 1
      && TEST_LITERAL(1777777)
88 1
      && TEST_LITERAL(17777777)
89 1
      && TEST_LITERAL(177777777)
90 1
      && TEST_LITERAL(1777777777)
91 1
      && TEST_LITERAL(17777777777)
92 1
      && TEST_LITERAL(177777777777)
93 1
      && TEST_LITERAL(1777777777777)
94 1
      && TEST_LITERAL(17777777777777)
95 1
      && TEST_LITERAL(177777777777777)
96 1
      && TEST_LITERAL(1777777777777777)
97 1
      && TEST_LITERAL(17777777777777777)
98 1
      && TEST_LITERAL(177777777777777777)
99 1
      && TEST_LITERAL(1777777777777777777)
100

101 1
      && test_literal(0xF, "0b1111")
102 1
      && test_literal(0xFF, "0b11111111")
103 1
      && test_literal(0xFFF, "0b111111111111")
104 1
      && test_literal(0xFFFF, "0b1111111111111111")
105 1
      && test_literal(0xFFFFF, "0b11111111111111111111")
106 1
      && test_literal(0xFFFFFF, "0b111111111111111111111111")
107 1
      && test_literal(0xFFFFFFF, "0b1111111111111111111111111111")
108 1
      && test_literal(0xFFFFFFFF, "0b11111111111111111111111111111111")
109 1
      && test_literal(0xFFFFFFFFF, "0b111111111111111111111111111111111111")
110 1
      && test_literal(0xFFFFFFFFFF, "0b1111111111111111111111111111111111111111")
111 1
      && test_literal(0xFFFFFFFFFFF, "0b11111111111111111111111111111111111111111111")
112 1
      && test_literal(0xFFFFFFFFFFFF, "0b111111111111111111111111111111111111111111111111")
113 1
      && test_literal(0xFFFFFFFFFFFFF, "0b1111111111111111111111111111111111111111111111111111")
114 1
      && test_literal(0xFFFFFFFFFFFFFF, "0b11111111111111111111111111111111111111111111111111111111")
115 1
      && test_literal(0xFFFFFFFFFFFFFFF, "0b111111111111111111111111111111111111111111111111111111111111")
116 1
      && test_literal(0xFFFFFFFFFFFFFFFF, "0b1111111111111111111111111111111111111111111111111111111111111111")
117

118 1
      && test_literal(0x7, "0b111")
119 1
      && test_literal(0x7F, "0b1111111")
120 1
      && test_literal(0x7FF, "0b11111111111")
121 1
      && test_literal(0x7FFF, "0b111111111111111")
122 1
      && test_literal(0x7FFFF, "0b1111111111111111111")
123 1
      && test_literal(0x7FFFFF, "0b11111111111111111111111")
124 1
      && test_literal(0x7FFFFFF, "0b111111111111111111111111111")
125 1
      && test_literal(0x7FFFFFFF, "0b1111111111111111111111111111111")
126 1
      && test_literal(0x7FFFFFFFF, "0b11111111111111111111111111111111111")
127 1
      && test_literal(0x7FFFFFFFFF, "0b111111111111111111111111111111111111111")
128 1
      && test_literal(0x7FFFFFFFFFF, "0b1111111111111111111111111111111111111111111")
129 1
      && test_literal(0x7FFFFFFFFFFF, "0b11111111111111111111111111111111111111111111111")
130 1
      && test_literal(0x7FFFFFFFFFFFF, "0b111111111111111111111111111111111111111111111111111")
131 1
      && test_literal(0x7FFFFFFFFFFFFF, "0b1111111111111111111111111111111111111111111111111111111")
132 1
      && test_literal(0x7FFFFFFFFFFFFFF, "0b11111111111111111111111111111111111111111111111111111111111")
133 1
      && test_literal(0x7FFFFFFFFFFFFFFF, "0b111111111111111111111111111111111111111111111111111111111111111")
134

135

136 1
      && TEST_LITERAL_SIGNED(-0xF)
137 1
      && TEST_LITERAL_SIGNED(-0xFF)
138 1
      && TEST_LITERAL_SIGNED(-0xFFF)
139 1
      && TEST_LITERAL_SIGNED(-0xFFFF)
140 1
      && TEST_LITERAL_SIGNED(-0xFFFFF)
141 1
      && TEST_LITERAL_SIGNED(-0xFFFFFF)
142 1
      && TEST_LITERAL_SIGNED(-0xFFFFFFF)
143 1
      && TEST_LITERAL_SIGNED(-0xFFFFFFFF)
144 1
      && TEST_LITERAL_SIGNED(-0xFFFFFFFFF)
145 1
      && TEST_LITERAL_SIGNED(-0xFFFFFFFFFF)
146 1
      && TEST_LITERAL_SIGNED(-0xFFFFFFFFFFF)
147 1
      && TEST_LITERAL_SIGNED(-0xFFFFFFFFFFFF)
148 1
      && TEST_LITERAL_SIGNED(-0xFFFFFFFFFFFFF)
149 1
      && TEST_LITERAL_SIGNED(-0xFFFFFFFFFFFFFF)
150 1
      && TEST_LITERAL_SIGNED(-0xFFFFFFFFFFFFFFF)
151 1
      && TEST_LITERAL_SIGNED(-0xFFFFFFFFFFFFFFFF) 
152

153

154 1
      && TEST_LITERAL_SIGNED(-01)
155 1
      && TEST_LITERAL_SIGNED(-017)
156 1
      && TEST_LITERAL_SIGNED(-0177)
157 1
      && TEST_LITERAL_SIGNED(-01777)
158 1
      && TEST_LITERAL_SIGNED(-017777)
159 1
      && TEST_LITERAL_SIGNED(-0177777)
160 1
      && TEST_LITERAL_SIGNED(-01777777)
161 1
      && TEST_LITERAL_SIGNED(-017777777)
162 1
      && TEST_LITERAL_SIGNED(-0177777777)
163 1
      && TEST_LITERAL_SIGNED(-01777777777)
164 1
      && TEST_LITERAL_SIGNED(-017777777777)
165 1
      && TEST_LITERAL_SIGNED(-0177777777777)
166 1
      && TEST_LITERAL_SIGNED(-01777777777777)
167 1
      && TEST_LITERAL_SIGNED(-017777777777777)
168 1
      && TEST_LITERAL_SIGNED(-0177777777777777)
169 1
      && TEST_LITERAL_SIGNED(-01777777777777777)
170 1
      && TEST_LITERAL_SIGNED(-017777777777777777)
171 1
      && TEST_LITERAL_SIGNED(-0177777777777777777)
172 1
      && TEST_LITERAL_SIGNED(-01777777777777777777)
173 1
      && TEST_LITERAL_SIGNED(-017777777777777777777)
174 1
      && TEST_LITERAL_SIGNED(-0177777777777777777777)
175 1
      && TEST_LITERAL_SIGNED(-01777777777777777777777)
176

177 1
      && TEST_LITERAL_SIGNED(-1)
178 1
      && TEST_LITERAL_SIGNED(-17)
179 1
      && TEST_LITERAL_SIGNED(-177)
180 1
      && TEST_LITERAL_SIGNED(-1777)
181 1
      && TEST_LITERAL_SIGNED(-17777)
182 1
      && TEST_LITERAL_SIGNED(-177777)
183 1
      && TEST_LITERAL_SIGNED(-1777777)
184 1
      && TEST_LITERAL_SIGNED(-17777777)
185 1
      && TEST_LITERAL_SIGNED(-177777777)
186 1
      && TEST_LITERAL_SIGNED(-1777777777)
187 1
      && TEST_LITERAL_SIGNED(-17777777777)
188 1
      && TEST_LITERAL_SIGNED(-177777777777)
189 1
      && TEST_LITERAL_SIGNED(-1777777777777)
190 1
      && TEST_LITERAL_SIGNED(-17777777777777)
191 1
      && TEST_LITERAL_SIGNED(-177777777777777)
192 1
      && TEST_LITERAL_SIGNED(-1777777777777777)
193 1
      && TEST_LITERAL_SIGNED(-17777777777777777)
194 1
      && TEST_LITERAL_SIGNED(-177777777777777777)
195 1
      && TEST_LITERAL_SIGNED(-1777777777777777777)
196

197
      // Test 8/16/24/32 bit boundaries for various types
198

199 1
      && TEST_LITERAL(255)
200 1
      && TEST_LITERAL(65535)
201 1
      && TEST_LITERAL(16777215)
202
#ifndef CHAISCRIPT_MSVC
203
        // bug in cl.exe causes this to be incorrectly parsed as an unsigned
204 1
        && TEST_LITERAL(4294967295)
205
#endif
206

207 1
      && TEST_LITERAL_SIGNED(-255)
208 1
      && TEST_LITERAL_SIGNED(-65535)
209 1
      && TEST_LITERAL_SIGNED(-16777215)
210
#ifndef CHAISCRIPT_MSVC
211
        // bug in cl.exe causes this to be incorrectly parsed as an unsigned
212 1
        && TEST_LITERAL_SIGNED(-4294967295)
213
#endif
214

215 1
      && TEST_LITERAL(255u)
216 1
      && TEST_LITERAL(65535u)
217 1
      && TEST_LITERAL(16777215u)
218 1
      && TEST_LITERAL(4294967295u)
219

220 1
      && TEST_LITERAL_SIGNED(-255u)
221 1
      && TEST_LITERAL_SIGNED(-65535u)
222 1
      && TEST_LITERAL_SIGNED(-16777215u)
223 1
      && TEST_LITERAL_SIGNED(-4294967295u)
224

225 1
      && TEST_LITERAL(255l)
226 1
      && TEST_LITERAL(65535l)
227 1
      && TEST_LITERAL(16777215l)
228
#ifndef CHAISCRIPT_MSVC
229
        // bug in cl.exe causes this to be incorrectly parsed as an unsigned
230 1
        && TEST_LITERAL(4294967295l)
231
#endif
232

233 1
      && TEST_LITERAL_SIGNED(-255l)
234 1
      && TEST_LITERAL_SIGNED(-65535l)
235 1
      && TEST_LITERAL_SIGNED(-16777215l)
236
#ifndef CHAISCRIPT_MSVC
237
        // bug in cl.exe causes this to be incorrectly parsed as an unsigned
238 1
        && TEST_LITERAL_SIGNED(-4294967295l)
239
#endif
240

241 1
      && TEST_LITERAL(255ul)
242 1
      && TEST_LITERAL(65535ul)
243 1
      && TEST_LITERAL(16777215ul)
244 1
      && TEST_LITERAL(4294967295ul)
245

246 1
      && TEST_LITERAL_SIGNED(-255ul)
247 1
      && TEST_LITERAL_SIGNED(-65535ul)
248 1
      && TEST_LITERAL_SIGNED(-16777215ul)
249 1
      && TEST_LITERAL_SIGNED(-4294967295ul)
250

251 1
      && TEST_LITERAL(255ull)
252 1
      && TEST_LITERAL(65535ull)
253 1
      && TEST_LITERAL(16777215ull)
254 1
      && TEST_LITERAL(4294967295ull)
255

256 1
      && TEST_LITERAL_SIGNED(-255ull)
257 1
      && TEST_LITERAL_SIGNED(-65535ull)
258 1
      && TEST_LITERAL_SIGNED(-16777215ull)
259 1
      && TEST_LITERAL_SIGNED(-4294967295ull)
260

261 1
      && TEST_LITERAL(255ll)
262 1
      && TEST_LITERAL(65535ll)
263 1
      && TEST_LITERAL(16777215ll)
264 1
      && TEST_LITERAL(4294967295ll)
265

266 1
      && TEST_LITERAL_SIGNED(-255ll)
267 1
      && TEST_LITERAL_SIGNED(-65535ll)
268 1
      && TEST_LITERAL_SIGNED(-16777215ll)
269
      && TEST_LITERAL_SIGNED(-4294967295ll)
270

271

272
      )
273
  {
274 1
    return EXIT_SUCCESS;
275
  } else {
276 0
    return EXIT_FAILURE;
277
  }
278

279
}
280

281

282
#ifdef CHAISCRIPT_MSVC
283
#pragma warning(pop)
284
#endif

Read our documentation on viewing source code .

Loading