Fix: correctly optimize 'key=A&key!=B' into 'key=A'

This commit is contained in:
Pieter Vander Vennet 2023-05-16 01:33:58 +02:00
parent 201f5446f8
commit d8a5f3c2be
2 changed files with 36 additions and 10 deletions

View file

@ -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: [