Commit c8334d54 authored by Romain Courteaud's avatar Romain Courteaud

Test Query: drop require usage

parent 4b8bddba
...@@ -17,29 +17,20 @@ ...@@ -17,29 +17,20 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint indent: 2, maxlen: 120, nomen: true, vars: true */ /*global jiodate*/
/*global define, exports, require, module, jIO, jiodate, window, test, (function (jIO, jiodate) {
ok, equal, deepEqual, sinon, start, stop, RSVP */
// define([module_name], [dependencies], module);
(function (dependencies, module) {
"use strict";
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
if (typeof exports === 'object') {
return module(require('jio'), require('jiodate'));
}
module(jIO, jiodate);
}(['jio', 'jiodate', 'qunit'], function (jIO, jiodate) {
"use strict"; "use strict";
var test = QUnit.test,
stop = QUnit.stop,
start = QUnit.start,
deepEqual = QUnit.deepEqual,
module = QUnit.module,
noop = function () {
return; // use with RSVP.all
};
module('Custom Key Queries with JIODate'); module('Custom Key Queries with JIODate');
var noop = function () {
return; // use with RSVP.all
};
test('Stock comparison operators with year precision', function () { test('Stock comparison operators with year precision', function () {
var docList = function () { var docList = function () {
return [ return [
...@@ -172,7 +163,8 @@ ...@@ -172,7 +163,8 @@
jIO.QueryFactory.create(qs, key_schema). jIO.QueryFactory.create(qs, key_schema).
exec(docList()). exec(docList()).
then(function (dl) { then(function (dl) {
deepEqual(dl, expected, "Match with '" + qs + "' (parsed query string)"); deepEqual(dl, expected, "Match with '" + qs +
"' (parsed query string)");
}) })
); );
}); });
...@@ -190,7 +182,8 @@ ...@@ -190,7 +182,8 @@
exec(docList()). exec(docList()).
then(function (dl) { then(function (dl) {
deepEqual(dl, [ deepEqual(dl, [
], "Match with an invalid parsed string " + qs + " should return empty list but not raise errors"); ], "Match with an invalid parsed string " + qs +
" should return empty list but not raise errors");
}) })
); );
}); });
...@@ -198,4 +191,4 @@ ...@@ -198,4 +191,4 @@
RSVP.all(promise).then(noop).always(start); RSVP.all(promise).then(noop).always(start);
}); });
})); }(jIO, jiodate));
...@@ -17,38 +17,29 @@ ...@@ -17,38 +17,29 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint indent: 2, maxlen: 100, nomen: true, vars: true */ /*global jiodate*/
/*global define, exports, require, module, jIO, window, test, ok, (function (jIO, jiodate) {
deepEqual, sinon, start, stop, RSVP, jiodate */
// define([module_name], [dependencies], module);
(function (dependencies, module) {
"use strict";
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
if (typeof exports === 'object') {
return module(require('jio'), require('jiodate'));
}
module(jIO, jiodate);
}(['jio', 'jiodate', 'qunit'], function (jIO, jiodate) {
"use strict"; "use strict";
var test = QUnit.test,
stop = QUnit.stop,
start = QUnit.start,
deepEqual = QUnit.deepEqual,
module = QUnit.module,
noop = function () {
return; // use with RSVP.all
},
translationEqualityMatcher = function (data) {
return function (object_value, value) {
value = data[value];
return (object_value === value);
};
},
key_schema;
module('Custom Key Queries with Schema'); module('Custom Key Queries with Schema');
var noop = function () {
return; // use with RSVP.all
};
var translationEqualityMatcher = function (data) {
return function (object_value, value) {
value = data[value];
return (object_value === value);
};
};
/*jslint unparam: true*/ /*jslint unparam: true*/
var key_schema = { key_schema = {
cast_lookup: { cast_lookup: {
dateType: function (obj) { dateType: function (obj) {
return new jiodate.JIODate(obj); return new jiodate.JIODate(obj);
...@@ -330,7 +321,8 @@ ...@@ -330,7 +321,8 @@
then(function (dl) { then(function (dl) {
deepEqual(dl, [ deepEqual(dl, [
{'identifier': '1', 'state': 'open'} {'identifier': '1', 'state': 'open'}
], 'Key Schema: It should be possible to look for a translated string'); ], 'Key Schema: It should be possible to look for a translated ' +
'string');
}) })
); );
...@@ -345,7 +337,8 @@ ...@@ -345,7 +337,8 @@
then(function (dl) { then(function (dl) {
deepEqual(dl, [ deepEqual(dl, [
{'identifier': '1', 'state': 'open'} {'identifier': '1', 'state': 'open'}
], 'Key Schema: It should be possible to look for a translated string with operator ='); ], 'Key Schema: It should be possible to look for a translated ' +
'string with operator =');
}) })
); );
...@@ -360,9 +353,10 @@ ...@@ -360,9 +353,10 @@
// }).exec(doc_list); // }).exec(doc_list);
// deepEqual(doc_list, [ // deepEqual(doc_list, [
// {'identifier': '2', 'state': 'closed'} // {'identifier': '2', 'state': 'closed'}
// ], 'Key Schema: It should be possible to look for a translated string with operator !='); // ], 'Key Schema: It should be possible to look for a translated ' +
// 'string with operator !=');
RSVP.all(promise).then(noop).always(start); RSVP.all(promise).then(noop).always(start);
}); });
})); }(jIO, jiodate));
...@@ -17,22 +17,12 @@ ...@@ -17,22 +17,12 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint indent: 2, maxlen: 90, nomen: true */ (function (jIO) {
/*global define, exports, require, module, jIO, window, test,
raises, ok, equal, deepEqual, sinon */
// define([module_name], [dependencies], module);
(function (dependencies, module) {
"use strict";
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
if (typeof exports === 'object') {
return module(require('jio'));
}
module(jIO);
}(['jio', 'qunit'], function (jIO) {
"use strict"; "use strict";
var test = QUnit.test,
equal = QUnit.equal,
ok = QUnit.ok,
module = QUnit.module;
module('Key and key_schema objects validation'); module('Key and key_schema objects validation');
...@@ -53,7 +43,8 @@ ...@@ -53,7 +43,8 @@
} catch (e) { } catch (e) {
equal(e.name, 'TypeError', 'wrong exception type'); equal(e.name, 'TypeError', 'wrong exception type');
equal(e.message, equal(e.message,
"QueryFactory.create(): Argument 1 is not a search text or a parsable object", "QueryFactory.create(): Argument 1 is not a search text or a " +
"parsable object",
'wrong exception message'); 'wrong exception message');
} }
...@@ -139,4 +130,4 @@ ...@@ -139,4 +130,4 @@
} }
}); });
})); }(jIO));
...@@ -17,28 +17,58 @@ ...@@ -17,28 +17,58 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint indent: 2, maxlen: 120, nomen: true, vars: true */ /*global jiodate*/
/*global define, exports, require, module, jIO, window, test, ok, (function (jIO, jiodate) {
equal, deepEqual, sinon, stop, start, RSVP, jiodate */
// define([module_name], [dependencies], module);
(function (dependencies, module) {
"use strict";
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
if (typeof exports === 'object') {
return module(require('jio'), require('jiodate'));
}
module(jIO, jiodate);
}(['jio', 'jiodate', 'qunit'], function (jIO, jiodate) {
"use strict"; "use strict";
var test = QUnit.test,
stop = QUnit.stop,
start = QUnit.start,
equal = QUnit.equal,
deepEqual = QUnit.deepEqual,
module = QUnit.module,
noop = function () {
return; // use with RSVP.all
},
dateCast = function (obj) {
return new jiodate.JIODate(obj);
},
translationEqualityMatcher = function (data) {
return function (object_value, value) {
value = data[value];
return (object_value === value);
};
},
// This method is provided as an example.
// A more robust solution to manage diacritics is recommended for production
// environments, with unicode normalization, like (untested):
// https://github.com/walling/unorm/
accentFold = function (s) {
var map = [
[new RegExp('[àáâãäå]', 'gi'), 'a'],
[new RegExp('æ', 'gi'), 'ae'],
[new RegExp('ç', 'gi'), 'c'],
[new RegExp('[èéêë]', 'gi'), 'e'],
[new RegExp('[ìíîï]', 'gi'), 'i'],
[new RegExp('ñ', 'gi'), 'n'],
[new RegExp('[òóôõö]', 'gi'), 'o'],
[new RegExp('œ', 'gi'), 'oe'],
[new RegExp('[ùúûü]', 'gi'), 'u'],
[new RegExp('[ýÿ]', 'gi'), 'y']
];
module('Custom Key Queries'); map.forEach(function (o) {
var rep = function (match) {
if (match.toUpperCase() === match) {
return o[1].toUpperCase();
}
return o[1];
};
s = s.replace(o[0], rep);
});
return s;
};
var noop = function () { module('Custom Key Queries');
return; // use with RSVP.all
};
test('Simple Key with read_from', function () { test('Simple Key with read_from', function () {
var docList = function () { var docList = function () {
...@@ -86,19 +116,14 @@ ...@@ -86,19 +116,14 @@
deepEqual(dl, [ deepEqual(dl, [
{'identifier': 'a'}, {'identifier': 'a'},
{'identifier': 'A'} {'identifier': 'A'}
], 'It should be possible to query with a case-insensitive alias key'); ], 'It should be possible to query with a case-insensitive alias ' +
'key');
}) })
); );
RSVP.all(promise).then(noop).always(start); RSVP.all(promise).then(noop).always(start);
}); });
var dateCast = function (obj) {
return new jiodate.JIODate(obj);
};
test('Simple Key with date casting', function () { test('Simple Key with date casting', function () {
var docList = function () { var docList = function () {
return [ return [
...@@ -109,48 +134,45 @@ ...@@ -109,48 +134,45 @@
{'identifier': 'c', 'date': '2013-03-03'}, {'identifier': 'c', 'date': '2013-03-03'},
{'identifier': 'd', 'date': '2013-04-04'} {'identifier': 'd', 'date': '2013-04-04'}
]; ];
}, promise = []; },
promise = [],
var sameDay = function (a, b) { sameDay = function (a, b) {
return ( return (
(a.mom.year() === b.mom.year()) && (a.mom.year() === b.mom.year()) &&
(a.mom.month() === b.mom.month()) && (a.mom.month() === b.mom.month()) &&
(a.mom.date() === b.mom.date()) (a.mom.date() === b.mom.date())
); );
};
var sameMonth = function (a, b) {
return (
(a.mom.year() === b.mom.year()) &&
(a.mom.month() === b.mom.month())
);
};
var sameYear = function (a, b) {
return (a.mom.year() === b.mom.year());
};
var keys = {
day: {
read_from: 'date',
cast_to: dateCast,
equal_match: sameDay
}, },
month: { sameMonth = function (a, b) {
read_from: 'date', return (
cast_to: dateCast, (a.mom.year() === b.mom.year()) &&
equal_match: sameMonth (a.mom.month() === b.mom.month())
);
}, },
year: { sameYear = function (a, b) {
read_from: 'date', return (a.mom.year() === b.mom.year());
cast_to: dateCast,
equal_match: sameYear
}, },
broken: { keys = {
read_from: 'date', day: {
cast_to: function () { throw new Error('Broken!'); } read_from: 'date',
} cast_to: dateCast,
}; equal_match: sameDay
},
month: {
read_from: 'date',
cast_to: dateCast,
equal_match: sameMonth
},
year: {
read_from: 'date',
cast_to: dateCast,
equal_match: sameYear
},
broken: {
read_from: 'date',
cast_to: function () { throw new Error('Broken!'); }
}
};
stop(); stop();
...@@ -206,7 +228,8 @@ ...@@ -206,7 +228,8 @@
exec(docList()). exec(docList()).
then(function (dl) { then(function (dl) {
deepEqual(dl.length, 0, deepEqual(dl.length, 0,
'Constructors that throw exceptions should not break a query, but silently fail comparisons'); 'Constructors that throw exceptions should not break a ' +
'query, but silently fail comparisons');
}) })
); );
...@@ -482,15 +505,6 @@ ...@@ -482,15 +505,6 @@
RSVP.all(promise).then(noop).always(start); RSVP.all(promise).then(noop).always(start);
}); });
var translationEqualityMatcher = function (data) {
return function (object_value, value) {
value = data[value];
return (object_value === value);
};
};
test('Simple Key with translation lookup', function () { test('Simple Key with translation lookup', function () {
var docList = function () { var docList = function () {
return [ return [
...@@ -518,7 +532,8 @@ ...@@ -518,7 +532,8 @@
then(function (dl) { then(function (dl) {
deepEqual(dl, [ deepEqual(dl, [
{'identifier': '1', 'state': 'open'} {'identifier': '1', 'state': 'open'}
], 'It should be possible to look for a translated string with a custom match function'); ], 'It should be possible to look for a translated string with a ' +
'custom match function');
}) })
); );
...@@ -534,7 +549,8 @@ ...@@ -534,7 +549,8 @@
then(function (dl) { then(function (dl) {
deepEqual(dl, [ deepEqual(dl, [
{'identifier': '1', 'state': 'open'} {'identifier': '1', 'state': 'open'}
], 'It should be possible to look for a translated string with operator ='); ], 'It should be possible to look for a translated string with ' +
'operator =');
}) })
); );
...@@ -548,42 +564,13 @@ ...@@ -548,42 +564,13 @@
// }).exec(doc_list); // }).exec(doc_list);
// deepEqual(doc_list, [ // deepEqual(doc_list, [
// {'identifier': '2', 'state': 'closed'} // {'identifier': '2', 'state': 'closed'}
// ], 'It should be possible to look for a translated string with operator !='); // ], 'It should be possible to look for a translated string with ' +
// 'operator !=');
RSVP.all(promise).then(noop).always(start); RSVP.all(promise).then(noop).always(start);
}); });
// This method is provided as an example.
// A more robust solution to manage diacritics is recommended for production
// environments, with unicode normalization, like (untested):
// https://github.com/walling/unorm/
var accentFold = function (s) {
var map = [
[new RegExp('[àáâãäå]', 'gi'), 'a'],
[new RegExp('æ', 'gi'), 'ae'],
[new RegExp('ç', 'gi'), 'c'],
[new RegExp('[èéêë]', 'gi'), 'e'],
[new RegExp('[ìíîï]', 'gi'), 'i'],
[new RegExp('ñ', 'gi'), 'n'],
[new RegExp('[òóôõö]', 'gi'), 'o'],
[new RegExp('œ', 'gi'), 'oe'],
[new RegExp('[ùúûü]', 'gi'), 'u'],
[new RegExp('[ýÿ]', 'gi'), 'y']
];
map.forEach(function (o) {
var rep = function (match) {
if (match.toUpperCase() === match) {
return o[1].toUpperCase();
}
return o[1];
};
s = s.replace(o[0], rep);
});
return s;
};
test('Accent folding', function () { test('Accent folding', function () {
equal(accentFold('àéîöùç'), 'aeiouc'); equal(accentFold('àéîöùç'), 'aeiouc');
equal(accentFold('ÀÉÎÖÙÇ'), 'AEIOUC'); equal(accentFold('ÀÉÎÖÙÇ'), 'AEIOUC');
...@@ -629,4 +616,4 @@ ...@@ -629,4 +616,4 @@
RSVP.all(promise).then(noop).always(start); RSVP.all(promise).then(noop).always(start);
}); });
})); }(jIO, jiodate));
...@@ -17,22 +17,16 @@ ...@@ -17,22 +17,16 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*jslint indent: 2, maxlen: 80, nomen: true */ /*global jiodate*/
/*global define, exports, require, module, jIO, window, test, ok, (function (jIO, jiodate) {
deepEqual, stop, start, expect */
// define([module_name], [dependencies], module);
(function (dependencies, module) {
"use strict";
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
if (typeof exports === 'object') {
return module(require('jio'));
}
module(jIO);
}(['jio', 'qunit'], function (jIO) {
"use strict"; "use strict";
var test = QUnit.test,
stop = QUnit.stop,
start = QUnit.start,
deepEqual = QUnit.deepEqual,
expect = QUnit.expect,
ok = QUnit.ok,
module = QUnit.module;
module('Query'); module('Query');
...@@ -572,7 +566,7 @@ ...@@ -572,7 +566,7 @@
}, },
cast_lookup: { cast_lookup: {
dateType: function (str) { dateType: function (str) {
return window.jiodate.JIODate(new Date(str).toISOString()); return jiodate.JIODate(new Date(str).toISOString());
} }
} }
}; };
...@@ -655,4 +649,4 @@ ...@@ -655,4 +649,4 @@
}).always(start); }).always(start);
}); });
})); }(jIO, jiodate));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment