Merge develop
This commit is contained in:
commit
5904142402
13 changed files with 80 additions and 40 deletions
|
@ -7,8 +7,8 @@ import { describe, it } from "vitest"
|
|||
* @param reason
|
||||
* @private
|
||||
*/
|
||||
function detectInCode(forbidden: string, reason: string): (done: () => void) => void {
|
||||
return (done: () => void) => {
|
||||
function detectInCode(forbidden: string, reason: string): Promise<void> {
|
||||
return new Promise<void>((done) => {
|
||||
const excludedDirs = [
|
||||
".git",
|
||||
"node_modules",
|
||||
|
@ -49,14 +49,23 @@ function detectInCode(forbidden: string, reason: string): (done: () => void) =>
|
|||
console.error(found.length, "issues found")
|
||||
throw msg
|
||||
}
|
||||
done()
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function wrap(promise: Promise<void>): ((done: () => void) => void) {
|
||||
return (done => {
|
||||
promise.then(done)
|
||||
})
|
||||
}
|
||||
|
||||
function itAsync(name: string, promise: Promise<void>){
|
||||
it(name, wrap(promise))
|
||||
}
|
||||
|
||||
describe("Code quality", () => {
|
||||
it(
|
||||
itAsync(
|
||||
"should not contain reverse",
|
||||
detectInCode(
|
||||
"reverse()",
|
||||
|
@ -64,12 +73,12 @@ describe("Code quality", () => {
|
|||
)
|
||||
)
|
||||
|
||||
it(
|
||||
itAsync(
|
||||
"should not contain 'constructor.name'",
|
||||
detectInCode("constructor\\.name", "This is not allowed, as minification does erase names.")
|
||||
)
|
||||
|
||||
it(
|
||||
itAsync(
|
||||
"should not contain 'innerText'",
|
||||
detectInCode(
|
||||
"innerText",
|
||||
|
@ -77,7 +86,7 @@ describe("Code quality", () => {
|
|||
)
|
||||
)
|
||||
|
||||
it(
|
||||
itAsync(
|
||||
"should not contain 'import * as name from \"xyz.json\"'",
|
||||
detectInCode(
|
||||
'import \\* as [a-zA-Z0-9_]\\+ from \\"[.-_/a-zA-Z0-9]\\+\\.json\\"',
|
||||
|
@ -85,7 +94,7 @@ describe("Code quality", () => {
|
|||
)
|
||||
)
|
||||
|
||||
it(
|
||||
itAsync(
|
||||
"should not contain '[\"default\"]'",
|
||||
detectInCode('\\[\\"default\\"\\]', "Possible leftover of faulty default import")
|
||||
)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { TagsFilter } from "../../../Logic/Tags/TagsFilter"
|
||||
import { And } from "../../../Logic/Tags/And"
|
||||
import { Tag } from "../../../Logic/Tags/Tag"
|
||||
import { TagUtils } from "../../../Logic/Tags/TagUtils"
|
||||
import { Or } from "../../../Logic/Tags/Or"
|
||||
import { RegexTag } from "../../../Logic/Tags/RegexTag"
|
||||
import { describe, expect, it } from "vitest"
|
||||
import {TagsFilter} from "../../../Logic/Tags/TagsFilter"
|
||||
import {And} from "../../../Logic/Tags/And"
|
||||
import {Tag} from "../../../Logic/Tags/Tag"
|
||||
import {TagUtils} from "../../../Logic/Tags/TagUtils"
|
||||
import {Or} from "../../../Logic/Tags/Or"
|
||||
import {RegexTag} from "../../../Logic/Tags/RegexTag"
|
||||
import {describe, expect, it} from "vitest"
|
||||
|
||||
describe("Tag optimalization", () => {
|
||||
describe("And", () => {
|
||||
|
@ -71,6 +71,14 @@ describe("Tag optimalization", () => {
|
|||
expect(TagUtils.toString(opt)).toBe("amenity=binoculars&bicycle=yes")
|
||||
})
|
||||
|
||||
it("should correctly optimize key=A&key!=B into key=A", () => {
|
||||
const t = new And([new Tag("shop", "sports"), new RegexTag("shop", "mall", true)])
|
||||
const opt = t.optimize()
|
||||
expect(typeof opt !== "boolean").true
|
||||
expect(TagUtils.toString(<TagsFilter>opt)).toBe("shop=sports")
|
||||
|
||||
})
|
||||
|
||||
it("should optimize nested ORs", () => {
|
||||
const filter = TagUtils.Tag({
|
||||
or: [
|
||||
|
@ -263,7 +271,7 @@ describe("Tag optimalization", () => {
|
|||
or: [
|
||||
"club=climbing",
|
||||
{
|
||||
and: ["sport=climbing", { or: ["club~*", "office~*"] }],
|
||||
and: ["sport=climbing", {or: ["club~*", "office~*"]}],
|
||||
},
|
||||
{
|
||||
and: [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue