Skip to content

Commit

Permalink
Fixed up ArrayContains throw
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleEngr committed Mar 13, 2021
1 parent c57ce37 commit fc3ebcc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions gsunit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* $Source: /repo/public.cvs/app/gsunit-test/github/gsunit.js,v $
* @copyright $Date: 2021/03/12 08:45:51 $ UTC
* @version $Revision: 1.22 $
* @copyright $Date: 2021/03/13 17:39:20 $ UTC
* @version $Revision: 1.23 $
* @author TurtleEngr
* @license https://www.gnu.org/licenses/gpl-3.0.txt
* @example see file verify-gsunit.gs
Expand Down Expand Up @@ -73,7 +73,7 @@ class GsUnit {
constructor(pArg) {
this.name = pArg.name !== undefined || pArg.name == '' ? pArg.name : 'UnitTests';
this.debug = pArg.debug !== undefined ? pArg.debug : false;
this.version = '$Revision: 1.22 $';
this.version = '$Revision: 1.23 $';
this.showDefault = true; // Show default messages with user messages.
this.numAsserts = 0; // Count the number of assert tests run.
}
Expand Down Expand Up @@ -198,6 +198,7 @@ class GsUnit {
}

assertArrayEqual(pMsg, pActual, pExpected, pCode = '') {
// Order matters for the comparision. See assertArrayContains for unordered compare.
++this.numAsserts;
// if pactual or pexpected are not arrays, throw
if (!Array.isArray(pActual) || !Array.isArray(pExpected))
Expand Down Expand Up @@ -232,11 +233,11 @@ class GsUnit {
++this.numAsserts;
if (!Array.isArray(pActual))
throw new AssertFail(this._default(pMsg, 'Actual is not an array.'), pActual, pValue, 'ArrayContains', pCode);
// I think this can be replaced with: pActual.includes(pExpected)
// Can this be replaced with: pActual.includes(pValue) (No, because that is a === test)
for (let i in pActual)
if (pActual[i] == pValue)
return true;
throw new AssertFail(this._default(pMsg, 'Array does not contain expected value.'), pActual, pExpected, 'ArrayContains', pCode);
throw new AssertFail(this._default(pMsg, 'Array does not contain expected value: ' + pValue), pActual, pValue, 'ArrayContains', pCode);
}

assertStrContains(pMsg, pActual, pExpected, pCode = '') {
Expand Down Expand Up @@ -295,7 +296,7 @@ class RunTests {
this.name = fDefaultArg(pArg.name, 'UnitTests');
this.debug = fDefaultArg(pArg.debug, false);
this.gsunit = fDefaultArg(pArg.gsunit, null);
this.version = '$Revision: 1.22 $';
this.version = '$Revision: 1.23 $';

this.ss = SpreadsheetApp.getActiveSpreadsheet();
if (this.ss == null)
Expand Down

0 comments on commit fc3ebcc

Please sign in to comment.