mirror of
https://github.com/zadam/trilium.git
synced 2025-10-29 09:16:45 +01:00
added in-editor help for editing attributes
This commit is contained in:
@@ -1,51 +1,56 @@
|
||||
import attributeParser from '../src/public/app/services/attribute_parser.js';
|
||||
import {describe, it, expect, execute} from './mini_test.js';
|
||||
|
||||
describe("Lexer", () => {
|
||||
describe("Lexing", () => {
|
||||
it("simple label", () => {
|
||||
expect(attributeParser.lexer("#label").map(t => t.text))
|
||||
expect(attributeParser.lex("#label").map(t => t.text))
|
||||
.toEqual(["#label"]);
|
||||
});
|
||||
|
||||
it("simple label with trailing spaces", () => {
|
||||
expect(attributeParser.lex(" #label ").map(t => t.text))
|
||||
.toEqual(["#label"]);
|
||||
});
|
||||
|
||||
it("inherited label", () => {
|
||||
expect(attributeParser.lexer("#label(inheritable)").map(t => t.text))
|
||||
expect(attributeParser.lex("#label(inheritable)").map(t => t.text))
|
||||
.toEqual(["#label", "(", "inheritable", ")"]);
|
||||
|
||||
expect(attributeParser.lexer("#label ( inheritable ) ").map(t => t.text))
|
||||
expect(attributeParser.lex("#label ( inheritable ) ").map(t => t.text))
|
||||
.toEqual(["#label", "(", "inheritable", ")"]);
|
||||
});
|
||||
|
||||
it("label with value", () => {
|
||||
expect(attributeParser.lexer("#label=Hallo").map(t => t.text))
|
||||
expect(attributeParser.lex("#label=Hallo").map(t => t.text))
|
||||
.toEqual(["#label", "=", "Hallo"]);
|
||||
});
|
||||
|
||||
it("label with value", () => {
|
||||
const tokens = attributeParser.lexer("#label=Hallo");
|
||||
const tokens = attributeParser.lex("#label=Hallo");
|
||||
expect(tokens[0].startIndex).toEqual(0);
|
||||
expect(tokens[0].endIndex).toEqual(5);
|
||||
});
|
||||
|
||||
it("relation with value", () => {
|
||||
expect(attributeParser.lexer('~relation=#root/RclIpMauTOKS/NFi2gL4xtPxM').map(t => t.text))
|
||||
expect(attributeParser.lex('~relation=#root/RclIpMauTOKS/NFi2gL4xtPxM').map(t => t.text))
|
||||
.toEqual(["~relation", "=", "#root/RclIpMauTOKS/NFi2gL4xtPxM"]);
|
||||
});
|
||||
|
||||
it("use quotes to define value", () => {
|
||||
expect(attributeParser.lexer("#'label a'='hello\"` world'").map(t => t.text))
|
||||
expect(attributeParser.lex("#'label a'='hello\"` world'").map(t => t.text))
|
||||
.toEqual(["#label a", "=", 'hello"` world']);
|
||||
|
||||
expect(attributeParser.lexer('#"label a" = "hello\'` world"').map(t => t.text))
|
||||
expect(attributeParser.lex('#"label a" = "hello\'` world"').map(t => t.text))
|
||||
.toEqual(["#label a", "=", "hello'` world"]);
|
||||
|
||||
expect(attributeParser.lexer('#`label a` = `hello\'" world`').map(t => t.text))
|
||||
expect(attributeParser.lex('#`label a` = `hello\'" world`').map(t => t.text))
|
||||
.toEqual(["#label a", "=", "hello'\" world"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Parser", () => {
|
||||
it("simple label", () => {
|
||||
const attrs = attributeParser.parser(["#token"].map(t => ({text: t})));
|
||||
const attrs = attributeParser.parse(["#token"].map(t => ({text: t})));
|
||||
|
||||
expect(attrs.length).toEqual(1);
|
||||
expect(attrs[0].type).toEqual('label');
|
||||
@@ -55,7 +60,7 @@ describe("Parser", () => {
|
||||
});
|
||||
|
||||
it("inherited label", () => {
|
||||
const attrs = attributeParser.parser(["#token", "(", "inheritable", ")"].map(t => ({text: t})));
|
||||
const attrs = attributeParser.parse(["#token", "(", "inheritable", ")"].map(t => ({text: t})));
|
||||
|
||||
expect(attrs.length).toEqual(1);
|
||||
expect(attrs[0].type).toEqual('label');
|
||||
@@ -65,7 +70,7 @@ describe("Parser", () => {
|
||||
});
|
||||
|
||||
it("label with value", () => {
|
||||
const attrs = attributeParser.parser(["#token", "=", "val"].map(t => ({text: t})));
|
||||
const attrs = attributeParser.parse(["#token", "=", "val"].map(t => ({text: t})));
|
||||
|
||||
expect(attrs.length).toEqual(1);
|
||||
expect(attrs[0].type).toEqual('label');
|
||||
@@ -74,14 +79,14 @@ describe("Parser", () => {
|
||||
});
|
||||
|
||||
it("relation", () => {
|
||||
let attrs = attributeParser.parser(["~token", "=", "#root/RclIpMauTOKS/NFi2gL4xtPxM"].map(t => ({text: t})));
|
||||
let attrs = attributeParser.parse(["~token", "=", "#root/RclIpMauTOKS/NFi2gL4xtPxM"].map(t => ({text: t})));
|
||||
|
||||
expect(attrs.length).toEqual(1);
|
||||
expect(attrs[0].type).toEqual('relation');
|
||||
expect(attrs[0].name).toEqual("token");
|
||||
expect(attrs[0].value).toEqual('NFi2gL4xtPxM');
|
||||
|
||||
attrs = attributeParser.parser(["~token", "=", "#NFi2gL4xtPxM"].map(t => ({text: t})));
|
||||
attrs = attributeParser.parse(["~token", "=", "#NFi2gL4xtPxM"].map(t => ({text: t})));
|
||||
|
||||
expect(attrs.length).toEqual(1);
|
||||
expect(attrs[0].type).toEqual('relation');
|
||||
@@ -97,6 +102,9 @@ describe("error cases", () => {
|
||||
|
||||
expect(() => attributeParser.lexAndParse("#a&b/s"))
|
||||
.toThrow(`Attribute name "a&b/s" contains disallowed characters, only alphanumeric characters, colon and underscore are allowed.`);
|
||||
|
||||
expect(() => attributeParser.lexAndParse("#"))
|
||||
.toThrow(`Attribute name is empty, please fill the name.`);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user