Skip to content

Commit

Permalink
Fixed unit test execution.
Browse files Browse the repository at this point in the history
There was a subtle bug in the testParsing function that was causing the same unit test
to be run for every expected pair. The key and pairs variables were declared in the wrong
scope so they were being set to the last pair in the set and that last pair was being
tested multiple times.

Fixing this bug also uncovered two failing test cases, which were also fixed.
  • Loading branch information
khamasaki committed Oct 21, 2014
1 parent f3640c3 commit 4492681
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions test/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ define(function (require) {
},
'complex grouping': {
'a&(b|c)': { name: 'and', args: [ 'a', { name: 'or', args: [ 'b', 'c' ]}]},
'a|(b&c)': { name: 'and', args: [{ name: 'or', args: [ 'a', { name: 'and', args: [ 'b', 'c' ]}]}]},
'a(b(c<d,e(f=g)))': {}
'(a|(b&c))': { name: 'and', args: [{ name: 'or', args: [ 'a', { name: 'and', args: [ 'b', 'c' ]}]}]},
'a(b(c<d,e(f=g)))': { 'name': 'and', 'args': [{ 'name': 'a', 'args': [{ 'name': 'b', 'args': [{ 'name': 'lt', 'args': ['c', 'd']}, {'name':'e', 'args': [{ 'name': 'eq', 'args': [ 'f', 'g' ]}]}]}]}]}
},
'complex comparisons': {

Expand Down Expand Up @@ -130,29 +130,34 @@ define(function (require) {
tests[ group ] = test = {};
pairs = queryPairs [ group ];
for (key in pairs) {
test[ key ] = function () {
var actual = parseQuery(key),
expected = pairs[ key ];

if (!hasKeys(actual.cache)) {
delete actual.cache;
}

if (typeof expected === 'string') {
expected = parseQuery(expected);
}

if (!hasKeys(expected.cache)) {
delete expected.cache;
}


// someone decided that matching constructors is necessary for deep equality
// see https://github.com/theintern/intern/issues/284
// the deepEqual assertion also fails due to properties like toString so this assertion seems to
// be the most suitable.
assert.strictEqual(JSON.stringify(actual), JSON.stringify(expected));
// Wrap the test function in another function call so
// that the keys and pairs objects are correctly bound
var f = function (k, p) {
return function () {
var actual = parseQuery(k),
expected = p[ k ];

if (!hasKeys(actual.cache)) {
delete actual.cache;
}

if (typeof expected === 'string') {
expected = parseQuery(expected);
}

if (!hasKeys(expected.cache)) {
delete expected.cache;
}


// someone decided that matching constructors is necessary for deep equality
// see https://github.com/theintern/intern/issues/284
// the deepEqual assertion also fails due to properties like toString so this assertion seems to
// be the most suitable.
assert.strictEqual(JSON.stringify(actual), JSON.stringify(expected));
};
};
test[ key ] = f(key, pairs);
}
}

Expand Down

0 comments on commit 4492681

Please sign in to comment.