mirror of
https://github.com/koloml/philomena-tagging-assistant.git
synced 2026-06-23 18:22:20 +00:00
Covering quoted term decoding/encoding behavior
This commit is contained in:
31
tests/lib/philomena/search/QueryLexer.spec.ts
Normal file
31
tests/lib/philomena/search/QueryLexer.spec.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { QueryLexer, QuotedTermToken, Token } from "$lib/philomena/search/QueryLexer";
|
||||
|
||||
describe('QueryLexer', () => {
|
||||
function parseQuery(query: string): Token[] {
|
||||
return new QueryLexer(query).parse();
|
||||
}
|
||||
|
||||
describe('QuotedTermToken', () => {
|
||||
it('should decode and encode quotes and backslash', () => {
|
||||
const encodedQuote = `"term with \\\" inside of it"`;
|
||||
const decodedQuote = 'term with " inside of it';
|
||||
|
||||
expect(QuotedTermToken.decode(encodedQuote)).toBe(decodedQuote);
|
||||
expect(QuotedTermToken.encode(decodedQuote)).toBe(encodedQuote);
|
||||
|
||||
const encodedBackslash = `"term with \\\\ inside of it"`;
|
||||
const decodedBackslash = 'term with \\ inside of it';
|
||||
|
||||
expect(QuotedTermToken.decode(encodedBackslash)).toBe(decodedBackslash);
|
||||
expect(QuotedTermToken.encode(decodedBackslash)).toBe(encodedBackslash);
|
||||
});
|
||||
|
||||
it('should not care for anything else', () => {
|
||||
const encodedTerm = '"operators: , && || AND OR NOT ! ^ ? *"';
|
||||
const decodedTerm = 'operators: , && || AND OR NOT ! ^ ? *';
|
||||
|
||||
expect(QuotedTermToken.decode(encodedTerm)).toBe(decodedTerm);
|
||||
expect(QuotedTermToken.encode(decodedTerm)).toBe(encodedTerm);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user