Skip to content

Commit 83cd17d

Browse files
committed
Increase test coverage: Array.prototype.lastIndexOf
Branch coverage: Before: 32/40 After: 40/40 JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
1 parent 3ee7716 commit 83cd17d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/jerry/array-prototype-lastindexof.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,50 @@ try {
6969
assert(e.message === "foo");
7070
assert(e instanceof ReferenceError);
7171
}
72+
73+
// Checking behavior when there are no arguments except "this"
74+
try {
75+
var a = "This is a sample text string to test this function";
76+
Array.prototype.lastIndexOf.call(a);
77+
} catch (e) {}
78+
79+
// Checking behavior when value is null
80+
try{
81+
Array.prototype.lastIndexOf.call(null, "asd");
82+
} catch (e) { }
83+
84+
// Checking behavior when length is 0
85+
try{
86+
Array.prototype.lastIndexOf.call("", "chocolate cake");
87+
} catch (e) { }
88+
89+
// Checking behavior when length is not a number
90+
try {
91+
var o = {};
92+
Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } });
93+
var a = { length : o }
94+
Array.prototype.lastIndexOf.call(a, function () { })
95+
assert (false);
96+
} catch (e) {
97+
assert (e instanceof ReferenceError);
98+
}
99+
100+
// Checking behavior when the 3rd argument (start index) is not a number
101+
try {
102+
var o = {};
103+
Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } });
104+
Array.prototype.lastIndexOf.call("foo", "foo", o)
105+
} catch (e) {}
106+
107+
// Checking behavior when the 3rd argument (start index) is greater than the length of the first argument
108+
try {
109+
Array.prototype.lastIndexOf.call("foo", "foo", 999)
110+
} catch (e) {}
111+
112+
// Checking behavior when the starting index is out of the range of the original array, so it points
113+
// to an empty space, as we modified the length of the array before
114+
try{
115+
var a = [1, 2, 3];
116+
Object.defineProperty(a, "length", {value: 10});
117+
Array.prototype.lastIndexOf.call(a, "", 6);
118+
} catch (e) {}

0 commit comments

Comments
 (0)