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"; "use strict";
if (typeof define === 'function' && define.amd) { var test = QUnit.test,
return define(dependencies, module); stop = QUnit.stop,
} start = QUnit.start,
if (typeof exports === 'object') { deepEqual = QUnit.deepEqual,
return module(require('jio'), require('jiodate')); module = QUnit.module,
} noop = function () {
module(jIO, jiodate);
}(['jio', 'jiodate', 'qunit'], function (jIO, jiodate) {
"use strict";
module('Custom Key Queries with JIODate');
var noop = function () {
return; // use with RSVP.all return; // use with RSVP.all
}; };
module('Custom Key Queries with JIODate');
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,
module('Custom Key Queries with Schema'); stop = QUnit.stop,
start = QUnit.start,
var noop = function () { deepEqual = QUnit.deepEqual,
module = QUnit.module,
noop = function () {
return; // use with RSVP.all return; // use with RSVP.all
}; },
translationEqualityMatcher = function (data) {
var translationEqualityMatcher = function (data) {
return function (object_value, value) { return function (object_value, value) {
value = data[value]; value = data[value];
return (object_value === value); return (object_value === value);
}; };
}; },
key_schema;
module('Custom Key Queries with Schema');
/*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,29 +17,59 @@ ...@@ -17,29 +17,59 @@
* 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"; "use strict";
if (typeof define === 'function' && define.amd) { var test = QUnit.test,
return define(dependencies, module); stop = QUnit.stop,
} start = QUnit.start,
if (typeof exports === 'object') { equal = QUnit.equal,
return module(require('jio'), require('jiodate')); 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']
];
map.forEach(function (o) {
var rep = function (match) {
if (match.toUpperCase() === match) {
return o[1].toUpperCase();
} }
module(jIO, jiodate); return o[1];
}(['jio', 'jiodate', 'qunit'], function (jIO, jiodate) { };
"use strict"; s = s.replace(o[0], rep);
});
return s;
};
module('Custom Key Queries'); module('Custom Key Queries');
var noop = function () {
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 () {
return [ return [
...@@ -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,28 +134,25 @@ ...@@ -109,28 +134,25 @@
{'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())
); );
}; },
sameMonth = function (a, b) {
var sameMonth = 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())
); );
}; },
sameYear = function (a, b) {
var sameYear = function (a, b) {
return (a.mom.year() === b.mom.year()); return (a.mom.year() === b.mom.year());
}; },
keys = {
var keys = {
day: { day: {
read_from: 'date', read_from: 'date',
cast_to: dateCast, cast_to: dateCast,
...@@ -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