test-pattern.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. TEST(pattern) {
  2. {
  3. ensure(!pattern("a").matches(""));
  4. ensure(!pattern("a").matches("b"));
  5. ensure(pattern("a").matches("a"));
  6. ensure(pattern("[^0-9]*").matches(""));
  7. ensure(pattern("[^0-9]*").matches("wertyuiop(*&^%$#@!~"));
  8. ensure(pattern("[^0-9]*").matches("?><"));
  9. ensure(!pattern("[^0-9]*").matches("?>3<"));
  10. ensure(pattern("id-([ac]|b{2})").matches("id-a"));
  11. ensure(pattern("id-([ac]|b{2})").matches("id-c"));
  12. ensure(pattern("id-([ac]|b{2})").matches("id-bb"));
  13. ensure(!pattern("id-([ac]|b{2})").matches("id-aa"));
  14. ensure(!pattern("id-([ac]|b{2})").matches("id-cb"));
  15. ensure(!pattern("id-([ac]|b{2})").matches("id-b"));
  16. ensure(pattern("[0-9][a-z]{1,3}.[!]{0,2}").matches("4me.!"));
  17. ensure(pattern("[0-9][a-z]{1,3}.[!]{0,2}").matches("0z."));
  18. ensure(pattern("[0-9][a-z]{1,3}.[!]{0,2}").matches("9ttt.!!"));
  19. ensure(pattern("[0-9][a-z]{1,3}.[!]{0,2}").matches("7oe."));
  20. ensure(!pattern("[0-9][a-z]{1,3}.[!]{0,2}").matches("4me.!!!"));
  21. ensure(!pattern("[0-9][a-z]{1,3}.[!]{0,2}").matches("rz."));
  22. ensure(!pattern("[0-9][a-z]{1,3}.[!]{0,2}").matches("9A.!!"));
  23. ensure(!pattern("[0-9][a-z]{1,3}.[!]{0,2}").matches("7oe"));
  24. ensure(!pattern("No solution").matches("No solution"));
  25. ensure(pattern("No\\ solution").matches("No solution"));
  26. ensure(!pattern("((aa|ba)|(ac|dd))|yes").matches("No solution"));
  27. ensure(!pattern("oo(x(aa|ba)|y(ac|dd))|yes").matches(""));
  28. ensure(!pattern("oo(x(aa|ba)|y(ac|dd))|yes").matches("ooxbaydd"));
  29. ensure(pattern("oo(x(aa|ba)|y(ac|dd))|yes").matches("ooxba"));
  30. ensure(pattern("oo(x(aa|ba)|y(ac|dd))|yes").matches("ooyac"));
  31. ensure(pattern("oo(x(aa|ba)|y(ac|dd))|yes").matches("ooydd"));
  32. ensure(pattern("oo(x(aa|ba)|y(ac|dd))|yes").matches("ooxaa"));
  33. ensure(pattern("oo(x(aa|ba)|y(ac|dd))|yes").matches("yes"));
  34. ensure(!pattern("oo(x(aa|ba)|y(ac|dd))|yes").matches("ooyes"));
  35. ensure(!pattern("oo(x(aa|ba)|y(ac|dd))|yes").matches("oo"));
  36. ensure(!pattern("oo(x(aa|ba)|y(ac|dd))|yes").matches("ooyaa"));
  37. ensure(!pattern("oo(x(aa|ba)|y(ac|dd))|yes").matches("ooxac"));
  38. ensure(!pattern("oo(x(aa|ba)|y(ac|dd))|yes").matches("ooyddd"));
  39. }
  40. }