@@ -28,6 +28,7 @@ CATCH_TEMPLATE_TEST_CASE(
28
28
CATCH_CHECK_FALSE (lexer.consume ());
29
29
CATCH_CHECK_FALSE (lexer.consume_if (FLY_CHR (char_type, ' \0 ' )));
30
30
CATCH_CHECK_FALSE (lexer.consume_number ());
31
+ CATCH_CHECK_FALSE (lexer.consume_hex_number ());
31
32
CATCH_CHECK (lexer.position () == 0 );
32
33
}
33
34
@@ -196,7 +197,7 @@ CATCH_TEMPLATE_TEST_CASE(
196
197
CATCH_CHECK (lexer.position () == 2 );
197
198
}
198
199
199
- CATCH_SECTION (" Cannot consume number if no number exists" )
200
+ CATCH_SECTION (" Cannot consume decimal number if no number exists" )
200
201
{
201
202
Lexer lexer (FLY_ARR (char_type, " ab" ));
202
203
CATCH_CHECK (lexer.position () == 0 );
@@ -205,7 +206,7 @@ CATCH_TEMPLATE_TEST_CASE(
205
206
CATCH_CHECK (lexer.position () == 0 );
206
207
}
207
208
208
- CATCH_SECTION (" Cannot consume number past end of lexer" )
209
+ CATCH_SECTION (" Cannot consume decimal number past end of lexer" )
209
210
{
210
211
Lexer lexer (FLY_ARR (char_type, " 1" ));
211
212
CATCH_CHECK (lexer.position () == 0 );
@@ -219,7 +220,7 @@ CATCH_TEMPLATE_TEST_CASE(
219
220
CATCH_CHECK (lexer.position () == 1 );
220
221
}
221
222
222
- CATCH_SECTION (" Cannot consume number if number exists past internal pointer" )
223
+ CATCH_SECTION (" Cannot consume decimal number if number exists past internal pointer" )
223
224
{
224
225
Lexer lexer (FLY_ARR (char_type, " ab1" ));
225
226
CATCH_CHECK (lexer.position () == 0 );
@@ -228,7 +229,7 @@ CATCH_TEMPLATE_TEST_CASE(
228
229
CATCH_CHECK (lexer.position () == 0 );
229
230
}
230
231
231
- CATCH_SECTION (" Number consumption stops at first non-digit character" )
232
+ CATCH_SECTION (" Decimal number consumption stops at first non-digit character" )
232
233
{
233
234
Lexer lexer (FLY_ARR (char_type, " 1ab" ));
234
235
CATCH_CHECK (lexer.position () == 0 );
@@ -244,7 +245,7 @@ CATCH_TEMPLATE_TEST_CASE(
244
245
CATCH_CHECK (lexer.position () == 1 );
245
246
}
246
247
247
- CATCH_SECTION (" Number consumption stops at end of lexer" )
248
+ CATCH_SECTION (" Decimal number consumption stops at end of lexer" )
248
249
{
249
250
Lexer lexer (FLY_ARR (char_type, " 1" ));
250
251
CATCH_CHECK (lexer.position () == 0 );
@@ -257,7 +258,7 @@ CATCH_TEMPLATE_TEST_CASE(
257
258
CATCH_CHECK_FALSE (lexer.peek ());
258
259
}
259
260
260
- CATCH_SECTION (" Number consumption consumes all digits in a row" )
261
+ CATCH_SECTION (" Decimal number consumption consumes all digits in a row" )
261
262
{
262
263
Lexer lexer (FLY_ARR (char_type, " 123" ));
263
264
CATCH_CHECK (lexer.position () == 0 );
@@ -270,7 +271,7 @@ CATCH_TEMPLATE_TEST_CASE(
270
271
CATCH_CHECK_FALSE (lexer.peek ());
271
272
}
272
273
273
- CATCH_SECTION (" Number consumption can succeed multiple times per lexer if separated" )
274
+ CATCH_SECTION (" Decimal number consumption can succeed multiple times per lexer if separated" )
274
275
{
275
276
Lexer lexer (FLY_ARR (char_type, " 123a456" ));
276
277
CATCH_CHECK (lexer.position () == 0 );
@@ -288,4 +289,97 @@ CATCH_TEMPLATE_TEST_CASE(
288
289
CATCH_CHECK (n2.value () == 456 );
289
290
CATCH_CHECK (lexer.position () == 7 );
290
291
}
292
+
293
+ CATCH_SECTION (" Cannot consume hex number if no number exists" )
294
+ {
295
+ Lexer lexer (FLY_ARR (char_type, " xy" ));
296
+ CATCH_CHECK (lexer.position () == 0 );
297
+
298
+ CATCH_CHECK_FALSE (lexer.consume_hex_number ());
299
+ CATCH_CHECK (lexer.position () == 0 );
300
+ }
301
+
302
+ CATCH_SECTION (" Cannot consume hex number past end of lexer" )
303
+ {
304
+ Lexer lexer (FLY_ARR (char_type, " 1" ));
305
+ CATCH_CHECK (lexer.position () == 0 );
306
+
307
+ auto n1 = lexer.consume_hex_number ();
308
+ CATCH_REQUIRE (n1.has_value ());
309
+ CATCH_CHECK (n1.value () == 1 );
310
+ CATCH_CHECK (lexer.position () == 1 );
311
+
312
+ CATCH_CHECK_FALSE (lexer.consume_hex_number ());
313
+ CATCH_CHECK (lexer.position () == 1 );
314
+ }
315
+
316
+ CATCH_SECTION (" Cannot consume hex number if number exists past internal pointer" )
317
+ {
318
+ Lexer lexer (FLY_ARR (char_type, " xy1" ));
319
+ CATCH_CHECK (lexer.position () == 0 );
320
+
321
+ CATCH_CHECK_FALSE (lexer.consume_hex_number ());
322
+ CATCH_CHECK (lexer.position () == 0 );
323
+ }
324
+
325
+ CATCH_SECTION (" Hex number consumption stops at first non-digit character" )
326
+ {
327
+ Lexer lexer (FLY_ARR (char_type, " 1ax" ));
328
+ CATCH_CHECK (lexer.position () == 0 );
329
+
330
+ auto n1 = lexer.consume_hex_number ();
331
+ CATCH_REQUIRE (n1.has_value ());
332
+ CATCH_CHECK (n1.value () == 0x1a );
333
+ CATCH_CHECK (lexer.position () == 2 );
334
+
335
+ auto p1 = lexer.peek ();
336
+ CATCH_REQUIRE (p1.has_value ());
337
+ CATCH_CHECK (p1.value () == FLY_CHR (char_type, ' x' ));
338
+ CATCH_CHECK (lexer.position () == 2 );
339
+ }
340
+
341
+ CATCH_SECTION (" Hex number consumption stops at end of lexer" )
342
+ {
343
+ Lexer lexer (FLY_ARR (char_type, " 1a" ));
344
+ CATCH_CHECK (lexer.position () == 0 );
345
+
346
+ auto n1 = lexer.consume_hex_number ();
347
+ CATCH_REQUIRE (n1.has_value ());
348
+ CATCH_CHECK (n1.value () == 0x1a );
349
+ CATCH_CHECK (lexer.position () == 2 );
350
+
351
+ CATCH_CHECK_FALSE (lexer.peek ());
352
+ }
353
+
354
+ CATCH_SECTION (" Hex number consumption consumes all digits in a row" )
355
+ {
356
+ Lexer lexer (FLY_ARR (char_type, " 123a" ));
357
+ CATCH_CHECK (lexer.position () == 0 );
358
+
359
+ auto n1 = lexer.consume_hex_number ();
360
+ CATCH_REQUIRE (n1.has_value ());
361
+ CATCH_CHECK (n1.value () == 0x123a );
362
+ CATCH_CHECK (lexer.position () == 4 );
363
+
364
+ CATCH_CHECK_FALSE (lexer.peek ());
365
+ }
366
+
367
+ CATCH_SECTION (" Hex number consumption can succeed multiple times per lexer if separated" )
368
+ {
369
+ Lexer lexer (FLY_ARR (char_type, " 123ax456B" ));
370
+ CATCH_CHECK (lexer.position () == 0 );
371
+
372
+ auto n1 = lexer.consume_hex_number ();
373
+ CATCH_REQUIRE (n1.has_value ());
374
+ CATCH_CHECK (n1.value () == 0x123a );
375
+ CATCH_CHECK (lexer.position () == 4 );
376
+
377
+ CATCH_CHECK (lexer.consume_if (FLY_CHR (char_type, ' x' )));
378
+ CATCH_CHECK (lexer.position () == 5 );
379
+
380
+ auto n2 = lexer.consume_hex_number ();
381
+ CATCH_REQUIRE (n2.has_value ());
382
+ CATCH_CHECK (n2.value () == 0x456b );
383
+ CATCH_CHECK (lexer.position () == 9 );
384
+ }
291
385
}
0 commit comments