From 8eadace06be37e5b4aeeae5792e0294e955d9d12 Mon Sep 17 00:00:00 2001 From: Matt Loring Date: Thu, 14 Jan 2016 14:25:14 -0800 Subject: [PATCH] Add testing for map subtract --- lib/debuglet.js | 9 ++++----- test/standalone/test-debuglet.js | 11 +++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/debuglet.js b/lib/debuglet.js index 2c8556fb..96cb4818 100644 --- a/lib/debuglet.js +++ b/lib/debuglet.js @@ -254,13 +254,13 @@ Debuglet.prototype.updateActiveBreakpoints_ = function(breakpoints) { }); // Remove completed breakpoints that the server no longer cares about. - mapSubtract(this.completedBreakpointMap_, updatedBreakpointMap) + Debuglet.mapSubtract(this.completedBreakpointMap_, updatedBreakpointMap) .forEach(function(breakpoint){ delete this.completedBreakpointMap_[breakpoint.id]; }, this); // Remove active breakpoints that the server no longer care about. - mapSubtract(this.activeBreakpointMap_, updatedBreakpointMap) + Debuglet.mapSubtract(this.activeBreakpointMap_, updatedBreakpointMap) .forEach(this.removeBreakpoint_, this); }; @@ -396,11 +396,10 @@ Debuglet.prototype.stop = function() { /** * Performs a set subtract. Returns A - B given maps A, B. - * TODO(ofrobots): we need unit tests for this * @return {Array.} A array containing elements from A that are not * in B. */ -function mapSubtract(A, B) { +Debuglet.mapSubtract = function mapSubtract(A, B) { var removed = []; for (var key in A) { if (!B[key]) { @@ -408,5 +407,5 @@ function mapSubtract(A, B) { } } return removed; -} +}; diff --git a/test/standalone/test-debuglet.js b/test/standalone/test-debuglet.js index 55c8f196..848abbaf 100644 --- a/test/standalone/test-debuglet.js +++ b/test/standalone/test-debuglet.js @@ -247,5 +247,16 @@ describe(__filename, function(){ debuglet.start(); }); + + describe('map subtract', function() { + it('should be correct', function() { + var a = { a: 1, b: 2 }; + var b = { a: 1 }; + assert.deepEqual(Debuglet.mapSubtract(a, b), [2]); + assert.deepEqual(Debuglet.mapSubtract(b, a), []); + assert.deepEqual(Debuglet.mapSubtract(a, {}), [1, 2]); + assert.deepEqual(Debuglet.mapSubtract({}, b), []); + }); + }); });