mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	parser tests added
This commit is contained in:
		| @@ -2,9 +2,102 @@ const parser = require('../src/services/search/parser'); | ||||
|  | ||||
| describe("Parser", () => { | ||||
|     it("fulltext parser without content", () => { | ||||
|         const exps = parser(["hello", "hi"], [], false); | ||||
|         const rootExp = parser(["hello", "hi"], [], false); | ||||
|  | ||||
|         expect(exps.constructor.name).toEqual("NoteCacheFulltextExp"); | ||||
|         expect(exps.tokens).toEqual(["hello", "hi"]); | ||||
|         expect(rootExp.constructor.name).toEqual("NoteCacheFulltextExp"); | ||||
|         expect(rootExp.tokens).toEqual(["hello", "hi"]); | ||||
|     }); | ||||
|  | ||||
|     it("fulltext parser with content", () => { | ||||
|         const rootExp = parser(["hello", "hi"], [], true); | ||||
|  | ||||
|         expect(rootExp.constructor.name).toEqual("OrExp"); | ||||
|         const [firstSub, secondSub] = rootExp.subExpressions; | ||||
|  | ||||
|         expect(firstSub.constructor.name).toEqual("NoteCacheFulltextExp"); | ||||
|         expect(firstSub.tokens).toEqual(["hello", "hi"]); | ||||
|  | ||||
|         expect(secondSub.constructor.name).toEqual("NoteContentFulltextExp"); | ||||
|         expect(secondSub.tokens).toEqual(["hello", "hi"]); | ||||
|     }); | ||||
|  | ||||
|     it("simple label comparison", () => { | ||||
|         const rootExp = parser([], ["#mylabel", "=", "text"], true); | ||||
|  | ||||
|         expect(rootExp.constructor.name).toEqual("FieldComparisonExp"); | ||||
|         expect(rootExp.attributeType).toEqual("label"); | ||||
|         expect(rootExp.attributeName).toEqual("mylabel"); | ||||
|         expect(rootExp.comparator).toBeTruthy(); | ||||
|     }); | ||||
|  | ||||
|     it("simple label AND", () => { | ||||
|         const rootExp = parser([], ["#first", "=", "text", "AND", "#second", "=", "text"], true); | ||||
|  | ||||
|         expect(rootExp.constructor.name).toEqual("AndExp"); | ||||
|         const [firstSub, secondSub] = rootExp.subExpressions; | ||||
|  | ||||
|         expect(firstSub.constructor.name).toEqual("FieldComparisonExp"); | ||||
|         expect(firstSub.attributeName).toEqual("first"); | ||||
|  | ||||
|         expect(secondSub.constructor.name).toEqual("FieldComparisonExp"); | ||||
|         expect(secondSub.attributeName).toEqual("second"); | ||||
|     }); | ||||
|  | ||||
|     it("simple label AND without explicit AND", () => { | ||||
|         const rootExp = parser([], ["#first", "=", "text", "#second", "=", "text"], true); | ||||
|  | ||||
|         expect(rootExp.constructor.name).toEqual("AndExp"); | ||||
|         const [firstSub, secondSub] = rootExp.subExpressions; | ||||
|  | ||||
|         expect(firstSub.constructor.name).toEqual("FieldComparisonExp"); | ||||
|         expect(firstSub.attributeName).toEqual("first"); | ||||
|  | ||||
|         expect(secondSub.constructor.name).toEqual("FieldComparisonExp"); | ||||
|         expect(secondSub.attributeName).toEqual("second"); | ||||
|     }); | ||||
|  | ||||
|     it("simple label OR", () => { | ||||
|         const rootExp = parser([], ["#first", "=", "text", "OR", "#second", "=", "text"], true); | ||||
|  | ||||
|         expect(rootExp.constructor.name).toEqual("OrExp"); | ||||
|         const [firstSub, secondSub] = rootExp.subExpressions; | ||||
|  | ||||
|         expect(firstSub.constructor.name).toEqual("FieldComparisonExp"); | ||||
|         expect(firstSub.attributeName).toEqual("first"); | ||||
|  | ||||
|         expect(secondSub.constructor.name).toEqual("FieldComparisonExp"); | ||||
|         expect(secondSub.attributeName).toEqual("second"); | ||||
|     }); | ||||
|  | ||||
|     it("fulltext and simple label", () => { | ||||
|         const rootExp = parser(["hello"], ["#mylabel", "=", "text"], false); | ||||
|  | ||||
|         expect(rootExp.constructor.name).toEqual("AndExp"); | ||||
|         const [firstSub, secondSub] = rootExp.subExpressions; | ||||
|  | ||||
|         expect(firstSub.constructor.name).toEqual("NoteCacheFulltextExp"); | ||||
|         expect(firstSub.tokens).toEqual(["hello"]); | ||||
|  | ||||
|         expect(secondSub.constructor.name).toEqual("FieldComparisonExp"); | ||||
|         expect(secondSub.attributeName).toEqual("mylabel"); | ||||
|     }); | ||||
|  | ||||
|     it("label sub-expression", () => { | ||||
|         const rootExp = parser([], ["#first", "=", "text", "OR", ["#second", "=", "text", "AND", "#third", "=", "text"]], false); | ||||
|  | ||||
|         expect(rootExp.constructor.name).toEqual("OrExp"); | ||||
|         const [firstSub, secondSub] = rootExp.subExpressions; | ||||
|  | ||||
|         expect(firstSub.constructor.name).toEqual("FieldComparisonExp"); | ||||
|         expect(firstSub.attributeName).toEqual("first"); | ||||
|  | ||||
|         expect(secondSub.constructor.name).toEqual("AndExp"); | ||||
|         const [firstSubSub, secondSubSub] = secondSub.subExpressions; | ||||
|  | ||||
|         expect(firstSubSub.constructor.name).toEqual("FieldComparisonExp"); | ||||
|         expect(firstSubSub.attributeName).toEqual("second"); | ||||
|  | ||||
|         expect(secondSubSub.constructor.name).toEqual("FieldComparisonExp"); | ||||
|         expect(secondSubSub.attributeName).toEqual("third"); | ||||
|     }); | ||||
| }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user