String.prototype.slice.js 866 B

12345678910111213141516171819202122
  1. load("test-common.js");
  2. try {
  3. assert(String.prototype.slice.length === 2);
  4. assert("hello friends".slice() === "hello friends");
  5. assert("hello friends".slice(1) === "ello friends");
  6. assert("hello friends".slice(0, 5) === "hello");
  7. assert("hello friends".slice(13, 6) === "");
  8. assert("hello friends".slice('', 5) === "hello");
  9. assert("hello friends".slice(3, 3) === "");
  10. assert("hello friends".slice(-1, 13) === "s");
  11. assert("hello friends".slice(0, 50) === "hello friends");
  12. assert("hello friends".slice(0, "5") === "hello");
  13. assert("hello friends".slice("6", "13") === "friends");
  14. assert("hello friends".slice(-7) === "friends");
  15. assert("hello friends".slice(1000) === "");
  16. assert("hello friends".slice(-1000) === "hello friends");
  17. console.log("PASS");
  18. } catch (err) {
  19. console.log("FAIL: " + err);
  20. }