Skip to content

Commit 151204b

Browse files
committed
test: - Add tests of 'explain' output of query.file.property use
This is mainly to show the error message when using multi-line properties in placeholders.
1 parent 06ad6f8 commit 151204b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/Query/Query.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,16 @@ Problem statement:
786786
expect(query.error).toBeUndefined();
787787
expect(query.grouping.length).toEqual(1);
788788
expect(query.grouping[0].instruction).toEqual('group by filename');
789+
790+
expect(query.explainQuery()).toMatchInlineSnapshot(`
791+
"No filters supplied. All tasks will match the query.
792+
793+
{{query.file.property('task_instruction')}} =>
794+
group by filename
795+
796+
No sorting instructions supplied.
797+
"
798+
`);
789799
});
790800

791801
it('cannot yet access multi-line property with query.file.property via placeholder', () => {
@@ -812,6 +822,19 @@ group by filename
812822
group by folder
813823
group by filename
814824
825+
"
826+
`);
827+
828+
expect(query.explainQuery()).toMatchInlineSnapshot(`
829+
"Query has an error:
830+
do not understand query
831+
Problem statement:
832+
{{query.file.property("task_instructions")}} =>
833+
group by root
834+
group by folder
835+
group by filename
836+
837+
815838
"
816839
`);
817840
});
@@ -836,6 +859,22 @@ filter by function \\
836859
expect(query.error).toBeUndefined();
837860
expect(query.filters.length).toEqual(1);
838861

862+
expect(query.explainQuery()).toMatchInlineSnapshot(`
863+
"filter by function \\
864+
if (!query.file.hasProperty('root_dirs_to_search')) { \\
865+
throw Error('Please set the "root_dirs_to_search" list property, with each value ending in a backslash...'); \\
866+
} \\
867+
const roots = query.file.property('root_dirs_to_search'); \\
868+
return roots.includes(task.file.root);
869+
=>
870+
filter by function if (!query.file.hasProperty('root_dirs_to_search')) { throw Error('Please set the "root_dirs_to_search" list property, with each value ending in a backslash...'); } const roots = query.file.property('root_dirs_to_search'); return roots.includes(task.file.root);
871+
872+
No grouping instructions supplied.
873+
874+
No sorting instructions supplied.
875+
"
876+
`);
877+
839878
function checkNumberOfMatches(expectedNumberOfMatches: number, path: string) {
840879
const queryResult = query.applyQueryToTasks([new TaskBuilder().path(path).build()]);
841880
expect(queryResult.totalTasksCount).toEqual(expectedNumberOfMatches);

0 commit comments

Comments
 (0)