소스 검색

LibJS: Add tests for String.prototype.repeat()

Linus Groh 5 년 전
부모
커밋
d3e3f5b421
1개의 변경된 파일37개의 추가작업 그리고 0개의 파일을 삭제
  1. 37 0
      Libraries/LibJS/Tests/String.prototype.repeat.js

+ 37 - 0
Libraries/LibJS/Tests/String.prototype.repeat.js

@@ -0,0 +1,37 @@
+load("test-common.js");
+
+try {
+    assert(String.prototype.repeat.length === 1);
+
+    try {
+        "foo".repeat(-1);
+        assertNotReached();
+    } catch (e) {
+        assert(e.name === "RangeError");
+        assert(e.message === "repeat count must be a positive number");
+    }
+
+    try {
+        "foo".repeat(Infinity);
+        assertNotReached();
+    } catch (e) {
+        assert(e.name === "RangeError");
+        assert(e.message === "repeat count must be a finite number");
+    }
+
+    assert("foo".repeat(0) === "");
+    assert("foo".repeat(1) === "foo");
+    assert("foo".repeat(2) === "foofoo");
+    assert("foo".repeat(3) === "foofoofoo");
+    assert("foo".repeat(3.1) === "foofoofoo");
+    assert("foo".repeat(3.5) === "foofoofoo");
+    assert("foo".repeat(3.9) === "foofoofoo");
+    assert("foo".repeat(null) === "");
+    assert("foo".repeat(undefined) === "");
+    assert("foo".repeat([]) === "");
+    assert("foo".repeat("") === "");
+
+    console.log("PASS");
+} catch (e) {
+    console.log("FAIL: " + e);
+}