Strings.after().phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Test: Nette\Utils\Strings::after()
  4. */
  5. declare(strict_types=1);
  6. use Nette\Utils\Strings;
  7. use Tester\Assert;
  8. require __DIR__ . '/../bootstrap.php';
  9. test('', function () {
  10. $foo = '0123456789a123456789b123456789c';
  11. Assert::same('123456789a123456789b123456789c', Strings::after($foo, '0', 1));
  12. Assert::same('a123456789b123456789c', Strings::after($foo, '9', 1));
  13. Assert::same('a123456789b123456789c', Strings::after($foo, '789', 1));
  14. Assert::same('0123456789a123456789b123456789c', Strings::after($foo, '', 1));
  15. Assert::same('', Strings::after($foo, '', -1));
  16. Assert::same('', Strings::after($foo, 'c', -1));
  17. Assert::same('c', Strings::after($foo, '9', -1));
  18. Assert::same('c', Strings::after($foo, '789', -1));
  19. Assert::same('c', Strings::after($foo, '9', 3));
  20. Assert::same('c', Strings::after($foo, '789', 3));
  21. Assert::same('a123456789b123456789c', Strings::after($foo, '9', -3));
  22. Assert::same('a123456789b123456789c', Strings::after($foo, '789', -3));
  23. Assert::null(Strings::after($foo, '9', 0));
  24. Assert::null(Strings::after($foo, 'not-in-string'));
  25. Assert::null(Strings::after($foo, 'b', -2));
  26. Assert::null(Strings::after($foo, 'b', 2));
  27. });
  28. test('', function () {
  29. $foo = "I\u{F1}t\u{EB}rn\u{E2}ti\u{F4}n\u{E0}liz\u{E6}ti\u{F8}n"; // Iñtërnâtiônàlizætiøn
  30. Assert::same("\u{F4}n\u{E0}liz\u{E6}ti\u{F8}n", Strings::after($foo, 'ti', 1));
  31. Assert::same("\u{F8}n", Strings::after($foo, 'ti', 2));
  32. });