@platform/cell.schema
Version:
URI and database schemas for the `cell.os`.
42 lines (41 loc) • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var test_1 = require("../../test");
var compare_1 = require("./compare");
describe('ManifestFiles: naturalCompare', function () {
it('simple, case-sensitive sorting', function () {
var files = ['z1.doc', 'z10.doc', 'z17.doc', 'z2.doc', 'z23.doc', 'z3.doc'];
files.sort(compare_1.naturalCompare);
(0, test_1.expect)(files).to.eql(['z1.doc', 'z2.doc', 'z3.doc', 'z10.doc', 'z17.doc', 'z23.doc']);
});
it('case-insensitive sorting', function () {
var chars = ['B', 'C', 'a', 'd'];
var compare = function (a, b) { return (0, compare_1.naturalCompare)(a, b, { caseInsensitive: true }); };
chars.sort(compare);
(0, test_1.expect)(chars).to.eql(['a', 'B', 'C', 'd']);
});
it('compare strings containing large numbers', function () {
var res = (0, compare_1.naturalCompare)('1165874568735487968325787328996865', '265812277985321589735871687040841');
(0, test_1.expect)(res).to.eql(1);
});
it('sorting an array of objects', function () {
var rooms = [
{ street: '350 5th Ave', room: 'A-21046-b' },
{ street: '350 5th Ave', room: 'A-1021' },
];
rooms.sort(function (a, b) {
return (0, compare_1.naturalCompare)(a.street, b.street, { caseInsensitive: true }) ||
(0, compare_1.naturalCompare)(a.room, b.room);
});
(0, test_1.expect)(rooms[0].room).to.eql('A-1021');
(0, test_1.expect)(rooms[1].room).to.eql('A-21046-b');
});
it('using a custom alphabet (Russian alphabet)', function () {
var russianOpts = {
alphabet: 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя',
};
var list = ['Ё', 'А', 'б', 'Б'];
list.sort(function (a, b) { return (0, compare_1.naturalCompare)(a, b, russianOpts); });
(0, test_1.expect)(list).to.eql(['А', 'Б', 'Ё', 'б']);
});
});