fix comparator sort && add more tests

This commit is contained in:
cudr
2019-04-28 00:04:06 +03:00
parent 8c7ce2c6bb
commit 54efe7235a
9 changed files with 33 additions and 21 deletions

View File

@@ -249,13 +249,19 @@ type Part = {
spread?: boolean;
};
function is_spead(path: string) {
const spread_pattern = /\[\.{3}/g;
return spread_pattern.test(path)
}
function comparator(
a: { basename: string, parts: Part[], file: string, is_index: boolean },
b: { basename: string, parts: Part[], file: string, is_index: boolean }
) {
if (a.is_index !== b.is_index) {
const spread_pattern = /\[\.{3}/g;
return a.is_index && spread_pattern.test(a.file) ? 1 : -1;
if (a.is_index) return is_spead(a.file) ? 1 : -1;
return is_spead(b.file) ? -1 : 1;
}
const max = Math.max(a.parts.length, b.parts.length);