Skip to content

Commit 6d98bb3

Browse files
committed
Update for tests.
1 parent 4717892 commit 6d98bb3

File tree

4 files changed

+2972
-76
lines changed

4 files changed

+2972
-76
lines changed

regression-tests/pure2-regex.cpp2

Lines changed: 98 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include </home/msagebaum/Kaiserslautern/Programms/cppfront/cppfront/source/regex.h>
21

32
test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, result: std::string) = {
43
context : type == M::context;
@@ -14,21 +13,35 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
1413
status = "Failure: Parsed regex does not match.";
1514
} else {
1615
m : bool = regex.search(str_mod, ctx);
17-
is_pass := !id.starts_with("M");
16+
is_pass := !result.starts_with("NOMATCH");
1817

18+
// Check if we expect a match.
1919
if is_pass != m {
2020
if is_pass {
2121
status = "Failure: Regex should apply.";
2222
}
2323
else {
2424
status = "Failure: Regex should not apply.";
2525
}
26-
} else if result != ctx.print_ranges() {
27-
status = "Failure: Ranges are wrong.";
26+
}
27+
28+
// If we have a match. Check the ranges.
29+
if m {
30+
ranges_match := result == ctx.print_ranges();
31+
should_ranges_match := !id.starts_with("M");
32+
33+
if ranges_match != should_ranges_match {
34+
if ranges_match {
35+
status = "Failure: Ranges should be wrong.";
36+
}
37+
else {
38+
status = "Failure: Ranges are wrong.";
39+
}
40+
}
2841
}
2942
}
3043

31-
std::cout << "(id)$: (status)$ regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result: (ctx.print_ranges())$ expected_results (result)$ " << std::endl;
44+
std::cout << "(id)$: (status)$ regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result: (ctx.print_ranges())$ expected_results (result)$" << std::endl;
3245
}
3346

3447

@@ -65,7 +78,7 @@ test_basic3: @regex type = {
6578
regex_31 := "(a.|.a.)*|(a|.a...)";
6679
regex_32 := "ab|a";
6780
regex_33 := "ab|a";
68-
regex_34 := "(Ab|cD)*";
81+
regex_M34 := "(Ab|cD)*";
6982
regex_35 := ":::1:::0:|:::1:1:0:";
7083
regex_36 := ":::1:::0:|:::1:1:1:";
7184
regex_37 := "[[:lower:]]+";
@@ -176,7 +189,7 @@ test_basic3: @regex type = {
176189
regex_145 := ".*(\\000).*";
177190
regex_146 := "\\000";
178191
run: (this) = {
179-
std::cout << "Running basic3:\n "<< std::endl;
192+
std::cout << "Running basic3:"<< std::endl;
180193
test(regex_1(), "1", "\\)", "()", "(1,2)");
181194
test(regex_2(), "2", "\\}", "}", "(0,1)");
182195
test(regex_3(), "3", "]", "]", "(0,1)");
@@ -209,7 +222,7 @@ test_basic3: @regex type = {
209222
test(regex_31(), "31", "(a.|.a.)*|(a|.a...)", "aa", "(0,2)(0,2)(?,?)");
210223
test(regex_32(), "32", "ab|a", "xabc", "(1,3)");
211224
test(regex_33(), "33", "ab|a", "xxabc", "(2,4)");
212-
test(regex_34(), "34", "(Ab|cD)*", "aBcD", "(0,4)(2,4)");
225+
test(regex_M34(), "M34", "(Ab|cD)*", "aBcD", "(0,4)(2,4)");
213226
test(regex_35(), "35", ":::1:::0:|:::1:1:0:", ":::0:::1:::1:::0:", "(8,17)");
214227
test(regex_36(), "36", ":::1:::0:|:::1:1:1:", ":::0:::1:::1:::0:", "(8,17)");
215228
test(regex_37(), "37", "[[:lower:]]+", "`az{", "(1,3)");
@@ -319,6 +332,7 @@ test_basic3: @regex type = {
319332
test(regex_144(), "144", ".*(/000).*", "/000", "(0,4)(0,4)");
320333
test(regex_145(), "145", ".*(\\\\000).*", "\\000", "(0,4)(0,4)");
321334
test(regex_146(), "146", "\\\\000", "\\000", "(0,4)");
335+
std::cout << std::endl;
322336
}
323337
}
324338
test_class: @regex type = {
@@ -337,7 +351,7 @@ test_class: @regex type = {
337351
regex_12 := "(a?)((ab)?)(b?)a?(ab)?b?";
338352
regex_M12 := "(a?)((ab)?)(b?)a?(ab)?b?";
339353
run: (this) = {
340-
std::cout << "Running class:\n "<< std::endl;
354+
std::cout << "Running class:"<< std::endl;
341355
test(regex_1(), "1", "aa*", "xaxaax", "(1,2)");
342356
test(regex_2(), "2", "(a*)(ab)*(b*)", "abc", "(0,2)(0,1)(?,?)(1,2)");
343357
test(regex_M2(), "M2", "(a*)(ab)*(b*)", "abc", "(0,2)(0,0)(0,2)(2,2)");
@@ -352,6 +366,7 @@ test_class: @regex type = {
352366
test(regex_11(), "11", ".*(.*)", "ab", "(0,2)(2,2)");
353367
test(regex_12(), "12", "(a?)((ab)?)(b?)a?(ab)?b?", "abab", "(0,4)(0,1)(1,1)(?,?)(1,2)(?,?)");
354368
test(regex_M12(), "M12", "(a?)((ab)?)(b?)a?(ab)?b?", "abab", "(0,4)(0,1)(1,1)(?,?)(1,2)(2,4)");
369+
std::cout << std::endl;
355370
}
356371
}
357372
test_left_assoc: @regex type = {
@@ -368,7 +383,7 @@ test_left_assoc: @regex type = {
368383
regex_M11 := "(ab|a)(c|bcd)(d|.*)";
369384
regex_M12 := "(ab|a)(bcd|c)(d|.*)";
370385
run: (this) = {
371-
std::cout << "Running left_assoc:\n "<< std::endl;
386+
std::cout << "Running left_assoc:"<< std::endl;
372387
test(regex_M1(), "M1", "(a|ab)(c|bcd)(d*)", "abcd", "(0,4)(0,1)(1,4)(4,4)");
373388
test(regex_M2(), "M2", "(a|ab)(bcd|c)(d*)", "abcd", "(0,4)(0,1)(1,4)(4,4)");
374389
test(regex_M3(), "M3", "(ab|a)(c|bcd)(d*)", "abcd", "(0,4)(0,1)(1,4)(4,4)");
@@ -381,6 +396,7 @@ test_left_assoc: @regex type = {
381396
test(regex_M10(), "M10", "(a|ab)(bcd|c)(d|.*)", "abcd", "(0,4)(0,1)(1,4)(4,4)");
382397
test(regex_M11(), "M11", "(ab|a)(c|bcd)(d|.*)", "abcd", "(0,4)(0,1)(1,4)(4,4)");
383398
test(regex_M12(), "M12", "(ab|a)(bcd|c)(d|.*)", "abcd", "(0,4)(0,1)(1,4)(4,4)");
399+
std::cout << std::endl;
384400
}
385401
}
386402
test_right_assoc: @regex type = {
@@ -397,7 +413,7 @@ test_right_assoc: @regex type = {
397413
regex_11 := "(ab|a)(c|bcd)(d|.*)";
398414
regex_12 := "(ab|a)(bcd|c)(d|.*)";
399415
run: (this) = {
400-
std::cout << "Running right_assoc:\n "<< std::endl;
416+
std::cout << "Running right_assoc:"<< std::endl;
401417
test(regex_1(), "1", "(a|ab)(c|bcd)(d*)", "abcd", "(0,4)(0,2)(2,3)(3,4)");
402418
test(regex_2(), "2", "(a|ab)(bcd|c)(d*)", "abcd", "(0,4)(0,2)(2,3)(3,4)");
403419
test(regex_3(), "3", "(ab|a)(c|bcd)(d*)", "abcd", "(0,4)(0,2)(2,3)(3,4)");
@@ -410,6 +426,7 @@ test_right_assoc: @regex type = {
410426
test(regex_10(), "10", "(a|ab)(bcd|c)(d|.*)", "abcd", "(0,4)(0,2)(2,3)(3,4)");
411427
test(regex_11(), "11", "(ab|a)(c|bcd)(d|.*)", "abcd", "(0,4)(0,2)(2,3)(3,4)");
412428
test(regex_12(), "12", "(ab|a)(bcd|c)(d|.*)", "abcd", "(0,4)(0,2)(2,3)(3,4)");
429+
std::cout << std::endl;
413430
}
414431
}
415432
test_forced_assoc: @regex type = {
@@ -442,7 +459,7 @@ test_forced_assoc: @regex type = {
442459
regex_27 := "(a|ab)(b*)";
443460
regex_28 := "(ab|a)(b*)";
444461
run: (this) = {
445-
std::cout << "Running forced_assoc:\n "<< std::endl;
462+
std::cout << "Running forced_assoc:"<< std::endl;
446463
test(regex_1(), "1", "(a|ab)(c|bcd)", "abcd", "(0,4)(0,1)(1,4)");
447464
test(regex_2(), "2", "(a|ab)(bcd|c)", "abcd", "(0,4)(0,1)(1,4)");
448465
test(regex_3(), "3", "(ab|a)(c|bcd)", "abcd", "(0,4)(0,1)(1,4)");
@@ -471,49 +488,50 @@ test_forced_assoc: @regex type = {
471488
test(regex_26(), "26", "(ab|a)", "ab", "(0,2)(0,2)");
472489
test(regex_27(), "27", "(a|ab)(b*)", "ab", "(0,2)(0,2)(2,2)");
473490
test(regex_28(), "28", "(ab|a)(b*)", "ab", "(0,2)(0,2)(2,2)");
491+
std::cout << std::endl;
474492
}
475493
}
476494
test_nullsub3: @regex type = {
477495
regex_1 := "(a*)*";
478-
regex_2 := "SAME";
479-
regex_3 := "SAME";
480-
regex_4 := "SAME";
496+
regex_2 := "(a*)*";
497+
regex_3 := "(a*)*";
498+
regex_4 := "(a*)*";
481499
regex_5 := "(a*)+";
482-
regex_6 := "SAME";
483-
regex_7 := "SAME";
484-
regex_8 := "SAME";
500+
regex_6 := "(a*)+";
501+
regex_7 := "(a*)+";
502+
regex_8 := "(a*)+";
485503
regex_9 := "(a+)*";
486-
regex_10 := "SAME";
487-
regex_11 := "SAME";
488-
regex_12 := "SAME";
504+
regex_10 := "(a+)*";
505+
regex_11 := "(a+)*";
506+
regex_12 := "(a+)*";
489507
regex_13 := "(a+)+";
490-
regex_14 := "SAME";
491-
regex_15 := "SAME";
492-
regex_16 := "SAME";
508+
regex_14 := "(a+)+";
509+
regex_15 := "(a+)+";
510+
regex_16 := "(a+)+";
493511
regex_17 := "([a]*)*";
494-
regex_18 := "SAME";
495-
regex_19 := "SAME";
496-
regex_20 := "SAME";
512+
regex_18 := "([a]*)*";
513+
regex_19 := "([a]*)*";
514+
regex_20 := "([a]*)*";
497515
regex_21 := "([a]*)+";
498-
regex_22 := "SAME";
499-
regex_23 := "SAME";
500-
regex_24 := "SAME";
516+
regex_22 := "([a]*)+";
517+
regex_23 := "([a]*)+";
518+
regex_24 := "([a]*)+";
501519
regex_25 := "([^b]*)*";
502-
regex_26 := "SAME";
503-
regex_27 := "SAME";
504-
regex_28 := "SAME";
520+
regex_26 := "([^b]*)*";
521+
regex_27 := "([^b]*)*";
522+
regex_28 := "([^b]*)*";
505523
regex_29 := "([ab]*)*";
506-
regex_30 := "SAME";
507-
regex_31 := "SAME";
508-
regex_32 := "SAME";
509-
regex_33 := "SAME";
510-
regex_34 := "SAME";
511-
regex_35 := "SAME";
524+
regex_30 := "([ab]*)*";
525+
regex_31 := "([ab]*)*";
526+
regex_32 := "([ab]*)*";
527+
regex_33 := "([ab]*)*";
528+
regex_34 := "([ab]*)*";
529+
regex_35 := "([ab]*)*";
512530
regex_36 := "([^a]*)*";
513-
regex_37 := "SAME";
514-
regex_38 := "SAME";
531+
regex_37 := "([^a]*)*";
532+
regex_38 := "([^a]*)*";
515533
regex_39 := "([^ab]*)*";
516-
regex_40 := "SAME";
534+
regex_40 := "([^ab]*)*";
517535
regex_41 := "((z)+|a)*";
518536
regex_42 := "(a)";
519537
regex_46 := "(a*)*(x)";
@@ -526,47 +544,47 @@ test_nullsub3: @regex type = {
526544
regex_53 := "(a*){2}(x)";
527545
regex_54 := "(a*){2}(x)";
528546
run: (this) = {
529-
std::cout << "Running nullsub3:\n "<< std::endl;
547+
std::cout << "Running nullsub3:"<< std::endl;
530548
test(regex_1(), "1", "(a*)*", "a", "(0,1)(0,1)");
531-
test(regex_2(), "2", "SAME", "x", "(0,0)(0,0)");
532-
test(regex_3(), "3", "SAME", "aaaaaa", "(0,6)(0,6)");
533-
test(regex_4(), "4", "SAME", "aaaaaax", "(0,6)(0,6)");
549+
test(regex_2(), "2", "(a*)*", "x", "(0,0)(0,0)");
550+
test(regex_3(), "3", "(a*)*", "aaaaaa", "(0,6)(0,6)");
551+
test(regex_4(), "4", "(a*)*", "aaaaaax", "(0,6)(0,6)");
534552
test(regex_5(), "5", "(a*)+", "a", "(0,1)(0,1)");
535-
test(regex_6(), "6", "SAME", "x", "(0,0)(0,0)");
536-
test(regex_7(), "7", "SAME", "aaaaaa", "(0,6)(0,6)");
537-
test(regex_8(), "8", "SAME", "aaaaaax", "(0,6)(0,6)");
553+
test(regex_6(), "6", "(a*)+", "x", "(0,0)(0,0)");
554+
test(regex_7(), "7", "(a*)+", "aaaaaa", "(0,6)(0,6)");
555+
test(regex_8(), "8", "(a*)+", "aaaaaax", "(0,6)(0,6)");
538556
test(regex_9(), "9", "(a+)*", "a", "(0,1)(0,1)");
539-
test(regex_10(), "10", "SAME", "x", "(0,0)(?,?)");
540-
test(regex_11(), "11", "SAME", "aaaaaa", "(0,6)(0,6)");
541-
test(regex_12(), "12", "SAME", "aaaaaax", "(0,6)(0,6)");
557+
test(regex_10(), "10", "(a+)*", "x", "(0,0)(?,?)");
558+
test(regex_11(), "11", "(a+)*", "aaaaaa", "(0,6)(0,6)");
559+
test(regex_12(), "12", "(a+)*", "aaaaaax", "(0,6)(0,6)");
542560
test(regex_13(), "13", "(a+)+", "a", "(0,1)(0,1)");
543-
test(regex_14(), "14", "SAME", "x", "NOMATCH");
544-
test(regex_15(), "15", "SAME", "aaaaaa", "(0,6)(0,6)");
545-
test(regex_16(), "16", "SAME", "aaaaaax", "(0,6)(0,6)");
561+
test(regex_14(), "14", "(a+)+", "x", "NOMATCH");
562+
test(regex_15(), "15", "(a+)+", "aaaaaa", "(0,6)(0,6)");
563+
test(regex_16(), "16", "(a+)+", "aaaaaax", "(0,6)(0,6)");
546564
test(regex_17(), "17", "([a]*)*", "a", "(0,1)(0,1)");
547-
test(regex_18(), "18", "SAME", "x", "(0,0)(0,0)");
548-
test(regex_19(), "19", "SAME", "aaaaaa", "(0,6)(0,6)");
549-
test(regex_20(), "20", "SAME", "aaaaaax", "(0,6)(0,6)");
565+
test(regex_18(), "18", "([a]*)*", "x", "(0,0)(0,0)");
566+
test(regex_19(), "19", "([a]*)*", "aaaaaa", "(0,6)(0,6)");
567+
test(regex_20(), "20", "([a]*)*", "aaaaaax", "(0,6)(0,6)");
550568
test(regex_21(), "21", "([a]*)+", "a", "(0,1)(0,1)");
551-
test(regex_22(), "22", "SAME", "x", "(0,0)(0,0)");
552-
test(regex_23(), "23", "SAME", "aaaaaa", "(0,6)(0,6)");
553-
test(regex_24(), "24", "SAME", "aaaaaax", "(0,6)(0,6)");
569+
test(regex_22(), "22", "([a]*)+", "x", "(0,0)(0,0)");
570+
test(regex_23(), "23", "([a]*)+", "aaaaaa", "(0,6)(0,6)");
571+
test(regex_24(), "24", "([a]*)+", "aaaaaax", "(0,6)(0,6)");
554572
test(regex_25(), "25", "([^b]*)*", "a", "(0,1)(0,1)");
555-
test(regex_26(), "26", "SAME", "b", "(0,0)(0,0)");
556-
test(regex_27(), "27", "SAME", "aaaaaa", "(0,6)(0,6)");
557-
test(regex_28(), "28", "SAME", "aaaaaab", "(0,6)(0,6)");
573+
test(regex_26(), "26", "([^b]*)*", "b", "(0,0)(0,0)");
574+
test(regex_27(), "27", "([^b]*)*", "aaaaaa", "(0,6)(0,6)");
575+
test(regex_28(), "28", "([^b]*)*", "aaaaaab", "(0,6)(0,6)");
558576
test(regex_29(), "29", "([ab]*)*", "a", "(0,1)(0,1)");
559-
test(regex_30(), "30", "SAME", "aaaaaa", "(0,6)(0,6)");
560-
test(regex_31(), "31", "SAME", "ababab", "(0,6)(0,6)");
561-
test(regex_32(), "32", "SAME", "bababa", "(0,6)(0,6)");
562-
test(regex_33(), "33", "SAME", "b", "(0,1)(0,1)");
563-
test(regex_34(), "34", "SAME", "bbbbbb", "(0,6)(0,6)");
564-
test(regex_35(), "35", "SAME", "aaaabcde", "(0,5)(0,5)");
577+
test(regex_30(), "30", "([ab]*)*", "aaaaaa", "(0,6)(0,6)");
578+
test(regex_31(), "31", "([ab]*)*", "ababab", "(0,6)(0,6)");
579+
test(regex_32(), "32", "([ab]*)*", "bababa", "(0,6)(0,6)");
580+
test(regex_33(), "33", "([ab]*)*", "b", "(0,1)(0,1)");
581+
test(regex_34(), "34", "([ab]*)*", "bbbbbb", "(0,6)(0,6)");
582+
test(regex_35(), "35", "([ab]*)*", "aaaabcde", "(0,5)(0,5)");
565583
test(regex_36(), "36", "([^a]*)*", "b", "(0,1)(0,1)");
566-
test(regex_37(), "37", "SAME", "bbbbbb", "(0,6)(0,6)");
567-
test(regex_38(), "38", "SAME", "aaaaaa", "(0,0)(0,0)");
584+
test(regex_37(), "37", "([^a]*)*", "bbbbbb", "(0,6)(0,6)");
585+
test(regex_38(), "38", "([^a]*)*", "aaaaaa", "(0,0)(0,0)");
568586
test(regex_39(), "39", "([^ab]*)*", "ccccxx", "(0,6)(0,6)");
569-
test(regex_40(), "40", "SAME", "ababab", "(0,0)(0,0)");
587+
test(regex_40(), "40", "([^ab]*)*", "ababab", "(0,0)(0,0)");
570588
test(regex_41(), "41", "((z)+|a)*", "zabcde", "(0,2)(1,2)(?,?)");
571589
test(regex_42(), "42", "(a)", "aaa", "(0,1)(0,1)");
572590
test(regex_46(), "46", "(a*)*(x)", "x", "(0,1)(0,0)(0,1)");
@@ -578,6 +596,7 @@ test_nullsub3: @regex type = {
578596
test(regex_52(), "52", "(a*){2}(x)", "x", "(0,1)(0,0)(0,1)");
579597
test(regex_53(), "53", "(a*){2}(x)", "ax", "(0,2)(1,1)(1,2)");
580598
test(regex_54(), "54", "(a*){2}(x)", "axa", "(0,2)(1,1)(1,2)");
599+
std::cout << std::endl;
581600
}
582601
}
583602
test_repetition2: @regex type = {
@@ -661,7 +680,7 @@ test_repetition2: @regex type = {
661680
regex_270 := "(a|ab|c|bcd)*(d*)";
662681
regex_271 := "(a|ab|c|bcd)+(d*)";
663682
run: (this) = {
664-
std::cout << "Running repetition2:\n "<< std::endl;
683+
std::cout << "Running repetition2:"<< std::endl;
665684
test(regex_1(), "1", "((..)|(.))", "NULL", "NOMATCH");
666685
test(regex_2(), "2", "((..)|(.))((..)|(.))", "NULL", "NOMATCH");
667686
test(regex_3(), "3", "((..)|(.))((..)|(.))((..)|(.))", "NULL", "NOMATCH");
@@ -741,6 +760,7 @@ test_repetition2: @regex type = {
741760
test(regex_269(), "269", "(a|ab|c|bcd){4,10}(d*)", "ababcd", "NOMATCH");
742761
test(regex_270(), "270", "(a|ab|c|bcd)*(d*)", "ababcd", "(0,6)(3,6)(6,6)");
743762
test(regex_271(), "271", "(a|ab|c|bcd)+(d*)", "ababcd", "(0,6)(3,6)(6,6)");
763+
std::cout << std::endl;
744764
}
745765
}
746766
test_totest: @regex type = {
@@ -824,7 +844,7 @@ test_totest: @regex type = {
824844
regex_250 := "(b(c)|d(e))*";
825845
regex_251 := "(a(b)*)*";
826846
run: (this) = {
827-
std::cout << "Running totest:\n "<< std::endl;
847+
std::cout << "Running totest:"<< std::endl;
828848
test(regex_01(), "01", "a+", "xaax", "(1,3)");
829849
test(regex_03(), "03", "(a?)((ab)?)", "ab", "(0,2)(0,0)(0,2)(0,2)");
830850
test(regex_04(), "04", "(a?)((ab)?)(b?)", "ab", "(0,2)(0,1)(1,1)(?,?)(1,2)");
@@ -904,6 +924,7 @@ test_totest: @regex type = {
904924
test(regex_220(), "220", "ab()c|ab()c()", "abc", "(0,3)(2,2)(-1,-1)(-1,-1)");
905925
test(regex_250(), "250", "(b(c)|d(e))*", "bcde", "(0,4)(2,4)(-1,-1)(3,4)");
906926
test(regex_251(), "251", "(a(b)*)*", "aba", "(0,3)(2,3)(-1,-1)");
927+
std::cout << std::endl;
907928
}
908929
}
909930
test_osx_bsd_critical: @regex type = {
@@ -919,7 +940,7 @@ test_osx_bsd_critical: @regex type = {
919940
regex_M14 := "([ab]|())+b";
920941
regex_20 := "(.?)(b)";
921942
run: (this) = {
922-
std::cout << "Running osx_bsd_critical:\n "<< std::endl;
943+
std::cout << "Running osx_bsd_critical:"<< std::endl;
923944
test(regex_1(), "1", "(()|.)(b)", "ab", "(0,2)(0,1)(?,?)(1,2)");
924945
test(regex_M1(), "M1", "(()|.)(b)", "ab", "(1,2)(1,1)(1,1)(1,2)");
925946
test(regex_2(), "2", "(()|[ab])(b)", "ab", "(0,2)(0,1)(?,?)(1,2)");
@@ -931,6 +952,7 @@ test_osx_bsd_critical: @regex type = {
931952
test(regex_14(), "14", "([ab]|())+b", "aaab", "(0,4)(2,3)(?,?)");
932953
test(regex_M14(), "M14", "([ab]|())+b", "aaab", "(0,4)(3,3)(3,3)");
933954
test(regex_20(), "20", "(.?)(b)", "ab", "(0,2)(0,1)(1,2)");
955+
std::cout << std::endl;
934956
}
935957
}
936958
main: (args) = {

0 commit comments

Comments
 (0)