Bug fix: when only files outsiders group was present, no catch-all outsiders group was added automatically. Same for folders-only outsiders group.

Cosmetics: wildcard patters for root like '/*' or '/...' produced a non matchable sort spec in the main sorting spec. The sort spec in wildcards tree was ok.
This commit is contained in:
SebastianMC 2022-09-05 10:52:02 +02:00
parent 4bca9735f2
commit d3e11708a4
2 changed files with 87 additions and 4 deletions

View File

@ -436,6 +436,86 @@ describe('SortingSpecProcessor', () => {
})
})
const txtInputSimplistic1: string = `
target-folder: /*
/:files
//folders
`
const expectedSortSpecForSimplistic1: { [key: string]: CustomSortSpec } = {
"/": {
groups: [{
filesOnly: true,
order: CustomSortOrder.alphabetical,
type: CustomSortGroupType.Outsiders
}, {
order: CustomSortOrder.alphabetical,
type: CustomSortGroupType.Outsiders
}],
outsidersFilesGroupIdx: 0,
outsidersGroupIdx: 1,
targetFoldersPaths: ['/*']
}
}
const expectedWildcardMatchingTreeForSimplistic1 = {
"matchAll": {
groups: [{
filesOnly: true,
order: CustomSortOrder.alphabetical,
type: CustomSortGroupType.Outsiders
}, {
order: CustomSortOrder.alphabetical,
type: CustomSortGroupType.Outsiders
}],
outsidersFilesGroupIdx: 0,
outsidersGroupIdx: 1,
targetFoldersPaths: ['/*']
},
"subtree": {}
}
const txtInputSimplistic2: string = `
target-folder: /
/:files
//folders
`
const expectedSortSpecForSimplistic2: { [key: string]: CustomSortSpec } = {
"/": {
groups: [{
filesOnly: true,
order: CustomSortOrder.alphabetical,
type: CustomSortGroupType.Outsiders
}, {
order: CustomSortOrder.alphabetical,
type: CustomSortGroupType.Outsiders
}],
outsidersFilesGroupIdx: 0,
outsidersGroupIdx: 1,
targetFoldersPaths: ['/']
}
}
describe('SortingSpecProcessor', () => {
let processor: SortingSpecProcessor;
beforeEach(() => {
processor = new SortingSpecProcessor();
});
it('should recognize the simplistic sorting spec to put files first (wildcard /* rule)', () => {
const inputTxtArr: Array<string> = txtInputSimplistic1.split('\n')
const result = processor.parseSortSpecFromText(inputTxtArr, 'mock-folder', 'custom-name-note.md')
expect(result?.sortSpecByPath).toEqual(expectedSortSpecForSimplistic1)
expect(result?.sortSpecByWildcard.tree).toEqual(expectedWildcardMatchingTreeForSimplistic1)
})
it('should recognize the simplistic sorting spec to put files first (direct / rule)', () => {
const inputTxtArr: Array<string> = txtInputSimplistic2.split('\n')
const result = processor.parseSortSpecFromText(inputTxtArr, 'mock-folder', 'custom-name-note.md')
expect(result?.sortSpecByPath).toEqual(expectedSortSpecForSimplistic2)
expect(result?.sortSpecByWildcard).toBeUndefined()
})
})
const txtInputItemsToHideWithDupsSortSpec: string = `
target-folder: AAA
/--hide: SomeFileToHide.md

View File

@ -326,20 +326,23 @@ enum WildcardPriority {
const stripWildcardPatternSuffix = (path: string): [path: string, priority: number] => {
if (path.endsWith(MATCH_ALL_SUFFIX)) {
path = path.slice(0, -MATCH_ALL_SUFFIX.length)
return [
path.slice(0, -MATCH_ALL_SUFFIX.length),
path.length > 0 ? path : '/',
WildcardPriority.MATCH_ALL
]
}
if (path.endsWith(MATCH_CHILDREN_1_SUFFIX)) {
path = path.slice(0, -MATCH_CHILDREN_1_SUFFIX.length)
return [
path.slice(0, -MATCH_CHILDREN_1_SUFFIX.length),
path.length > 0 ? path : '/',
WildcardPriority.MATCH_CHILDREN,
]
}
if (path.endsWith(MATCH_CHILDREN_2_SUFFIX)) {
path = path.slice(0, -MATCH_CHILDREN_2_SUFFIX.length)
return [
path.slice(0, -MATCH_CHILDREN_2_SUFFIX.length),
path.length > 0 ? path : '/',
WildcardPriority.MATCH_CHILDREN
]
}
@ -732,7 +735,7 @@ export class SortingSpecProcessor {
console.warn(`Inconsistent Outsiders sorting group definition in sort spec for folder '${last(spec.targetFoldersPaths)}'`)
}
// For consistency and to simplify sorting code later on, implicitly append a single catch-all Outsiders group
if (!outsidersGroupForFiles && !outsidersGroupForFolders) {
if (!(outsidersGroupForFiles && outsidersGroupForFolders)) {
spec.outsidersGroupIdx = spec.groups.length
spec.groups.push({
type: CustomSortGroupType.Outsiders