skeleton of first tests

This commit is contained in:
zadam 2020-06-03 17:11:03 +02:00
parent 915b1d1a45
commit 99120be46d
5 changed files with 458 additions and 346 deletions

707
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -38,7 +38,7 @@
"electron-window-state": "5.0.3",
"express": "4.17.1",
"express-session": "1.17.1",
"file-type": "14.5.0",
"file-type": "14.6.0",
"fs-extra": "9.0.0",
"helmet": "3.22.0",
"html": "1.0.0",
@ -49,7 +49,7 @@
"imagemin": "7.0.1",
"imagemin-giflossy": "5.1.10",
"imagemin-mozjpeg": "9.0.0",
"imagemin-pngquant": "8.0.0",
"imagemin-pngquant": "9.0.0",
"ini": "1.3.5",
"is-svg": "4.2.1",
"jimp": "0.12.1",
@ -67,7 +67,7 @@
"serve-favicon": "2.5.0",
"session-file-store": "1.4.0",
"simple-node-logger": "18.12.24",
"sqlite": "4.0.9",
"sqlite": "4.0.10",
"sqlite3": "4.1.1",
"string-similarity": "4.0.1",
"tar-stream": "2.1.2",
@ -80,7 +80,7 @@
},
"devDependencies": {
"cross-env": "^7.0.2",
"electron": "9.0.0",
"electron": "9.0.2",
"electron-builder": "22.7.0",
"electron-packager": "14.2.1",
"electron-rebuild": "1.11.0",
@ -88,7 +88,7 @@
"jasmine": "^3.5.0",
"jsdoc": "3.6.4",
"lorem-ipsum": "2.0.3",
"webpack": "5.0.0-beta.16",
"webpack": "5.0.0-beta.17",
"webpack-cli": "4.0.0-beta.8"
},
"optionalDependencies": {

View file

@ -0,0 +1,47 @@
import attributeParser from '../src/public/app/services/attribute_parser.mjs';
function describe(name, cb) {
console.log(`Running ${name}`);
cb();
}
function it(name, cb) {
console.log(` Running ${name}`);
cb();
}
let errorCount = 0;
function expect(val) {
return {
toEqual: comparedVal => {
const jsonVal = JSON.stringify(val);
const comparedJsonVal = JSON.stringify(comparedVal);
if (jsonVal !== comparedJsonVal) {
console.trace("toEqual check failed.");
console.error(`expected: ${comparedJsonVal}`);
console.error(`got: ${jsonVal}`);
errorCount++;
}
}
}
}
describe("Lexer fulltext", () => {
it("simple label", () => {
expect(attributeParser.lexer("#label")).toEqual(["#labe"]);
});
});
console.log("");
if (errorCount) {
console.log(`!!!${errorCount} tests failed!!!`);
}
else {
console.log("All tests passed!");
}

View file

@ -1,7 +0,0 @@
import attributeParser from '../../src/public/app/services/search/attribute_parser.js';
describe("Lexer fulltext", () => {
it("simple lexing", () => {
console.log("HI!");
});
});

View file

@ -1,11 +1,9 @@
function lexer(str) {
str = str.toLowerCase();
const fulltextTokens = [];
const expressionTokens = [];
let quotes = false;
let fulltextEnded = false;
let currentWord = '';
function isOperatorSymbol(chr) {
@ -26,11 +24,7 @@ function lexer(str) {
return;
}
if (fulltextEnded) {
expressionTokens.push(currentWord);
} else {
fulltextTokens.push(currentWord);
}
expressionTokens.push(currentWord);
currentWord = '';
}
@ -52,18 +46,11 @@ function lexer(str) {
}
else if (['"', "'", '`'].includes(chr)) {
if (!quotes) {
if (currentWord.length === 0 || fulltextEnded) {
if (previousOperatorSymbol()) {
finishWord();
}
if (previousOperatorSymbol()) {
finishWord();
}
quotes = chr;
}
else {
// quote inside a word does not have special meening and does not break word
// e.g. d'Artagnan is kept as a single token
currentWord += chr;
}
quotes = chr;
}
else if (quotes === chr) {
quotes = false;
@ -78,7 +65,6 @@ function lexer(str) {
}
else if (!quotes) {
if (currentWord.length === 0 && (chr === '#' || chr === '~')) {
fulltextEnded = true;
currentWord = chr;
continue;
@ -87,13 +73,13 @@ function lexer(str) {
finishWord();
continue;
}
else if (fulltextEnded && ['(', ')', '.'].includes(chr)) {
else if (['(', ')', '.'].includes(chr)) {
finishWord();
currentWord += chr;
finishWord();
continue;
}
else if (fulltextEnded && previousOperatorSymbol() !== isOperatorSymbol(chr)) {
else if (previousOperatorSymbol() !== isOperatorSymbol(chr)) {
finishWord();
currentWord += chr;
@ -106,10 +92,7 @@ function lexer(str) {
finishWord();
return {
fulltextTokens,
expressionTokens
}
return expressionTokens;
}
export default {