Commit c8334d54 authored by Romain Courteaud's avatar Romain Courteaud

Test Query: drop require usage

parent 4b8bddba
......@@ -17,29 +17,20 @@
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*jslint indent: 2, maxlen: 120, nomen: true, vars: true */
/*global define, exports, require, module, jIO, jiodate, window, test,
ok, equal, deepEqual, sinon, start, stop, RSVP */
// define([module_name], [dependencies], module);
(function (dependencies, module) {
/*global jiodate*/
(function (jIO, jiodate) {
"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";
module('Custom Key Queries with JIODate');
var noop = function () {
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');
test('Stock comparison operators with year precision', function () {
var docList = function () {
return [
......@@ -172,7 +163,8 @@
jIO.QueryFactory.create(qs, key_schema).
exec(docList()).
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 @@
exec(docList()).
then(function (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 @@
RSVP.all(promise).then(noop).always(start);
});
}));
}(jIO, jiodate));
......@@ -17,38 +17,29 @@
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*jslint indent: 2, maxlen: 100, nomen: true, vars: true */
/*global define, exports, require, module, jIO, window, test, ok,
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) {
/*global jiodate*/
(function (jIO, jiodate) {
"use strict";
module('Custom Key Queries with Schema');
var noop = function () {
var test = QUnit.test,
stop = QUnit.stop,
start = QUnit.start,
deepEqual = QUnit.deepEqual,
module = QUnit.module,
noop = function () {
return; // use with RSVP.all
};
var translationEqualityMatcher = function (data) {
},
translationEqualityMatcher = function (data) {
return function (object_value, value) {
value = data[value];
return (object_value === value);
};
};
},
key_schema;
module('Custom Key Queries with Schema');
/*jslint unparam: true*/
var key_schema = {
key_schema = {
cast_lookup: {
dateType: function (obj) {
return new jiodate.JIODate(obj);
......@@ -330,7 +321,8 @@
then(function (dl) {
deepEqual(dl, [
{'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 @@
then(function (dl) {
deepEqual(dl, [
{'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 @@
// }).exec(doc_list);
// deepEqual(doc_list, [
// {'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);
});
}));
}(jIO, jiodate));
......@@ -17,22 +17,12 @@
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*jslint indent: 2, maxlen: 90, nomen: true */
/*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) {
(function (jIO) {
"use strict";
var test = QUnit.test,
equal = QUnit.equal,
ok = QUnit.ok,
module = QUnit.module;
module('Key and key_schema objects validation');
......@@ -53,7 +43,8 @@
} catch (e) {
equal(e.name, 'TypeError', 'wrong exception type');
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');
}
......@@ -139,4 +130,4 @@
}
});
}));
}(jIO));
......@@ -17,29 +17,59 @@
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*jslint indent: 2, maxlen: 120, nomen: true, vars: true */
/*global define, exports, require, module, jIO, window, test, ok,
equal, deepEqual, sinon, stop, start, RSVP, jiodate */
// define([module_name], [dependencies], module);
(function (dependencies, module) {
/*global jiodate*/
(function (jIO, jiodate) {
"use strict";
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
if (typeof exports === 'object') {
return module(require('jio'), require('jiodate'));
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']
];
map.forEach(function (o) {
var rep = function (match) {
if (match.toUpperCase() === match) {
return o[1].toUpperCase();
}
module(jIO, jiodate);
}(['jio', 'jiodate', 'qunit'], function (jIO, jiodate) {
"use strict";
return o[1];
};
s = s.replace(o[0], rep);
});
return s;
};
module('Custom Key Queries');
var noop = function () {
return; // use with RSVP.all
};
test('Simple Key with read_from', function () {
var docList = function () {
return [
......@@ -86,19 +116,14 @@
deepEqual(dl, [
{'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);
});
var dateCast = function (obj) {
return new jiodate.JIODate(obj);
};
test('Simple Key with date casting', function () {
var docList = function () {
return [
......@@ -109,28 +134,25 @@
{'identifier': 'c', 'date': '2013-03-03'},
{'identifier': 'd', 'date': '2013-04-04'}
];
}, promise = [];
var sameDay = function (a, b) {
},
promise = [],
sameDay = function (a, b) {
return (
(a.mom.year() === b.mom.year()) &&
(a.mom.month() === b.mom.month()) &&
(a.mom.date() === b.mom.date())
);
};
var sameMonth = function (a, b) {
},
sameMonth = function (a, b) {
return (
(a.mom.year() === b.mom.year()) &&
(a.mom.month() === b.mom.month())
);
};
var sameYear = function (a, b) {
},
sameYear = function (a, b) {
return (a.mom.year() === b.mom.year());
};
var keys = {
},
keys = {
day: {
read_from: 'date',
cast_to: dateCast,
......@@ -206,7 +228,8 @@
exec(docList()).
then(function (dl) {
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 @@
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 () {
var docList = function () {
return [
......@@ -518,7 +532,8 @@
then(function (dl) {
deepEqual(dl, [
{'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 @@
then(function (dl) {
deepEqual(dl, [
{'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 @@
// }).exec(doc_list);
// deepEqual(doc_list, [
// {'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);
});
// 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 () {
equal(accentFold('àéîöùç'), 'aeiouc');
equal(accentFold('ÀÉÎÖÙÇ'), 'AEIOUC');
......@@ -629,4 +616,4 @@
RSVP.all(promise).then(noop).always(start);
});
}));
}(jIO, jiodate));
......@@ -17,22 +17,16 @@
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define, exports, require, module, jIO, window, test, ok,
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) {
/*global jiodate*/
(function (jIO, jiodate) {
"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');
......@@ -572,7 +566,7 @@
},
cast_lookup: {
dateType: function (str) {
return window.jiodate.JIODate(new Date(str).toISOString());
return jiodate.JIODate(new Date(str).toISOString());
}
}
};
......@@ -655,4 +649,4 @@
}).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