From 22c7af91e3bcae0ae86cbb0938e068fe9dfe2941 Mon Sep 17 00:00:00 2001 From: Mate Dabis Date: Wed, 9 Jan 2019 15:17:07 +0100 Subject: [PATCH] Increase test coverage: Array.prototype.lastIndexOf Branch coverage: Before: 32/40 After: 40/40 JerryScript-DCO-1.0-Signed-off-by: Mate Dabis mdabis@inf.u-szeged.hu --- tests/jerry/array-prototype-lastindexof.js | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/jerry/array-prototype-lastindexof.js b/tests/jerry/array-prototype-lastindexof.js index 4aa2c5f4fb..d9f691155e 100644 --- a/tests/jerry/array-prototype-lastindexof.js +++ b/tests/jerry/array-prototype-lastindexof.js @@ -69,3 +69,51 @@ try { assert(e.message === "foo"); assert(e instanceof ReferenceError); } + +// Checking behavior when there are no arguments except "this" +var a = "This is a sample text string to test this function"; +assert(Array.prototype.lastIndexOf.call(a) == -1); + + +// Checking behavior when value is null +try { + Array.prototype.lastIndexOf.call(null, "asd"); + assert(false); +} catch (e) { + assert(e instanceof TypeError); +} + +// Checking behavior when length is 0 +assert(Array.prototype.lastIndexOf.call("", "chocolate cake") == -1); + +// Checking behavior when length is not a number +try { + var o = {}; + Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } }); + var a = { length : o }; + Array.prototype.lastIndexOf.call(a, function () { }); + assert(false); +} catch (e) { + assert(e instanceof ReferenceError); + assert(e.message == "foo"); +} + +// Checking behavior when the 3rd argument (start index) is not a number +try { + var o = {}; + Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } }); + Array.prototype.lastIndexOf.call("foo", "foo", o); + assert(false); +} catch (e) { + assert(e instanceof ReferenceError); + assert(e.message == "foo"); +} + +// Checking behavior when the 3rd argument (start index) is greater than the length of the first argument +assert(Array.prototype.lastIndexOf.call("foo", "foo", 999) == -1); + +// Checking behavior when the starting index is out of the range of the original array, so it points +// to an empty space, as we modified the length of the array before +var a = [1, 2, 3]; +Object.defineProperty(a, "length", {value: 10}); +assert(Array.prototype.lastIndexOf.call(a, "", 6) == -1);