Strings.Regexp.errors.compilation.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Test: Nette\Utils\Strings and RegexpException compile error.
  4. */
  5. declare(strict_types=1);
  6. use Nette\Utils\Strings;
  7. use Tester\Assert;
  8. require __DIR__ . '/../bootstrap.php';
  9. Assert::exception(
  10. fn() => Strings::split('0123456789', '#*#'),
  11. Nette\Utils\RegexpException::class,
  12. 'Compilation failed: %a% in pattern: #*#',
  13. );
  14. Assert::exception(
  15. fn() => Strings::match('0123456789', '#*#'),
  16. Nette\Utils\RegexpException::class,
  17. 'Compilation failed: %a% in pattern: #*#',
  18. );
  19. Assert::exception(
  20. fn() => Strings::matchAll('0123456789', '#*#'),
  21. Nette\Utils\RegexpException::class,
  22. 'Compilation failed: %a% in pattern: #*#',
  23. );
  24. Assert::exception(
  25. fn() => Strings::replace('0123456789', '#*#', 'x'),
  26. Nette\Utils\RegexpException::class,
  27. 'Compilation failed: %a% in pattern: #*#',
  28. );
  29. Assert::exception(
  30. fn() => Strings::replace('0123456789', ['##', '#*#'], 'x'),
  31. Nette\Utils\RegexpException::class,
  32. 'Compilation failed: %a% in pattern: ## or #*#',
  33. );
  34. function cb()
  35. {
  36. return 'x';
  37. }
  38. Assert::exception(
  39. fn() => Strings::replace('0123456789', '#*#', Closure::fromCallable('cb')),
  40. Nette\Utils\RegexpException::class,
  41. 'Compilation failed: %a% in pattern: #*#',
  42. );
  43. Assert::exception(
  44. fn() => Strings::replace('0123456789', ['##', '#*#'], Closure::fromCallable('cb')),
  45. Nette\Utils\RegexpException::class,
  46. 'Compilation failed: %a% in pattern: ## or #*#',
  47. );