mirror of
https://github.com/zadam/trilium.git
synced 2024-09-20 15:45:58 +08:00
fix inQuotes + tests
This commit is contained in:
parent
35469f6f2d
commit
4e5ddaf7d1
|
@ -49,6 +49,22 @@ describe("Lexer expression", () => {
|
||||||
.toEqual(["#label", "*=*", "text"]);
|
.toEqual(["#label", "*=*", "text"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("simple label operator with in quotes and without", () => {
|
||||||
|
expect(lexer("#label*=*'text'").expressionTokens)
|
||||||
|
.toEqual([
|
||||||
|
{token: "#label", inQuotes: false},
|
||||||
|
{token: "*=*", inQuotes: false},
|
||||||
|
{token: "text", inQuotes: true}
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(lexer("#label*=*text").expressionTokens)
|
||||||
|
.toEqual([
|
||||||
|
{token: "#label", inQuotes: false},
|
||||||
|
{token: "*=*", inQuotes: false},
|
||||||
|
{token: "text", inQuotes: false}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it("complex expressions with and, or and parenthesis", () => {
|
it("complex expressions with and, or and parenthesis", () => {
|
||||||
expect(lexer(`# (#label=text OR #second=text) AND ~relation`).expressionTokens.map(t => t.token))
|
expect(lexer(`# (#label=text OR #second=text) AND ~relation`).expressionTokens.map(t => t.token))
|
||||||
.toEqual(["#", "(", "#label", "=", "text", "or", "#second", "=", "text", ")", "and", "~relation"]);
|
.toEqual(["#", "(", "#label", "=", "text", "or", "#second", "=", "text", ")", "and", "~relation"]);
|
||||||
|
|
|
@ -28,7 +28,7 @@ function lexer(str) {
|
||||||
|
|
||||||
const rec = {
|
const rec = {
|
||||||
token: currentWord,
|
token: currentWord,
|
||||||
inQuotes: quotes
|
inQuotes: !!quotes
|
||||||
};
|
};
|
||||||
|
|
||||||
if (fulltextEnded) {
|
if (fulltextEnded) {
|
||||||
|
@ -71,9 +71,9 @@ function lexer(str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (quotes === chr) {
|
else if (quotes === chr) {
|
||||||
quotes = false;
|
|
||||||
|
|
||||||
finishWord();
|
finishWord();
|
||||||
|
|
||||||
|
quotes = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// it's a quote but within other kind of quotes so it's valid as a literal character
|
// it's a quote but within other kind of quotes so it's valid as a literal character
|
||||||
|
|
Loading…
Reference in a new issue