From 5ae4e06770d4671ddb301c8564308d5496be8078 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Sat, 5 Nov 2011 11:14:09 -0400 Subject: [PATCH] cake test: change `eq` to use egal semantics, paralleling `arrayEq` --- Cakefile | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Cakefile b/Cakefile index f7545f35..f6e85b3c 100644 --- a/Cakefile +++ b/Cakefile @@ -164,7 +164,6 @@ runTests = (CoffeeScript) -> global[name] = func for name, func of require 'assert' # Convenience aliases. - global.eq = global.strictEqual global.CoffeeScript = CoffeeScript # Our test helper function for delimiting different test cases. @@ -178,21 +177,23 @@ runTests = (CoffeeScript) -> e.source = fn.toString() if fn.toString? failures.push filename: currentFile, error: e - # A recursive functional equivalence helper; uses egal for testing equivalence. # See http://wiki.ecmascript.org/doku.php?id=harmony:egal - arrayEqual = (a, b) -> + egal = (a, b) -> if a is b - # 0 isnt -0 a isnt 0 or 1/a is 1/b - else if a instanceof Array and b instanceof Array - return no unless a.length is b.length - return no for el, idx in a when not arrayEqual el, b[idx] - yes else - # NaN is NaN a isnt a and b isnt b - global.arrayEq = (a, b, msg) -> ok arrayEqual(a,b), msg + # A recursive functional equivalence helper; uses egal for testing equivalence. + arrayEgal = (a, b) -> + if egal a, b then yes + else if a instanceof Array and b instanceof Array + return no unless a.length is b.length + return no for el, idx in a when not arrayEgal el, b[idx] + yes + + global.eq = (a, b, msg) -> ok egal(a, b), msg + global.arrayEq = (a, b, msg) -> ok arrayEgal(a,b), msg # When all the tests have run, collect and print errors. # If a stacktrace is available, output the compiled function source.