forked from MapComplete/MapComplete
Chore: formatting
This commit is contained in:
parent
6a0b77eb99
commit
4fe2df61fe
4 changed files with 359 additions and 231 deletions
|
@ -31,7 +31,7 @@ describe("Tag optimalization", () => {
|
|||
const t = new And([
|
||||
new Tag("foo", "bar"),
|
||||
new Or([new Tag("x", "y"), new Tag("a", "b")]),
|
||||
new Or([new Tag("x", "y"), new Tag("c", "d")])
|
||||
new Or([new Tag("x", "y"), new Tag("c", "d")]),
|
||||
])
|
||||
const opt = <TagsFilter>t.optimize()
|
||||
expect(TagUtils.toString(opt)).toBe("foo=bar& (x=y| (a=b&c=d) )")
|
||||
|
@ -42,7 +42,7 @@ describe("Tag optimalization", () => {
|
|||
const t = new And([
|
||||
new Tag("foo", "bar"),
|
||||
new Or([new RegexTag("x", "y"), new RegexTag("a", "b")]),
|
||||
new Or([new RegexTag("x", "y"), new RegexTag("c", "d")])
|
||||
new Or([new RegexTag("x", "y"), new RegexTag("c", "d")]),
|
||||
])
|
||||
const opt = <TagsFilter>t.optimize()
|
||||
expect(TagUtils.toString(opt)).toBe("foo=bar& ( (a=b&c=d) |x=y)")
|
||||
|
@ -53,7 +53,7 @@ describe("Tag optimalization", () => {
|
|||
const t = new And([
|
||||
new Tag("foo", "bar"),
|
||||
new Or([new RegexTag("x", "y"), new RegexTag("a", "b")]),
|
||||
new Or([new RegexTag("x", "y", true), new RegexTag("c", "d")])
|
||||
new Or([new RegexTag("x", "y", true), new RegexTag("c", "d")]),
|
||||
])
|
||||
const opt = <TagsFilter>t.optimize()
|
||||
expect(TagUtils.toString(opt)).toBe("foo=bar& (a=b|x=y) & (c=d|x!=y)")
|
||||
|
@ -86,12 +86,12 @@ describe("Tag optimalization", () => {
|
|||
{
|
||||
and: [
|
||||
{
|
||||
or: ["X=Y", "FOO=BAR"]
|
||||
or: ["X=Y", "FOO=BAR"],
|
||||
},
|
||||
"bicycle=yes"
|
||||
]
|
||||
}
|
||||
]
|
||||
"bicycle=yes",
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
// (X=Y | FOO=BAR | (bicycle=yes & (X=Y | FOO=BAR)) )
|
||||
// This is equivalent to (X=Y | FOO=BAR)
|
||||
|
@ -109,11 +109,11 @@ describe("Tag optimalization", () => {
|
|||
"amenity=charging_station",
|
||||
"disused:amenity=charging_station",
|
||||
"planned:amenity=charging_station",
|
||||
"construction:amenity=charging_station"
|
||||
]
|
||||
"construction:amenity=charging_station",
|
||||
],
|
||||
},
|
||||
"bicycle=yes"
|
||||
]
|
||||
"bicycle=yes",
|
||||
],
|
||||
},
|
||||
{
|
||||
and: [
|
||||
|
@ -122,19 +122,19 @@ describe("Tag optimalization", () => {
|
|||
"amenity=charging_station",
|
||||
"disused:amenity=charging_station",
|
||||
"planned:amenity=charging_station",
|
||||
"construction:amenity=charging_station"
|
||||
]
|
||||
}
|
||||
]
|
||||
"construction:amenity=charging_station",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
"amenity=toilets",
|
||||
"amenity=bench",
|
||||
"leisure=picnic_table",
|
||||
{
|
||||
and: ["tower:type=observation"]
|
||||
and: ["tower:type=observation"],
|
||||
},
|
||||
{
|
||||
and: ["amenity=bicycle_repair_station"]
|
||||
and: ["amenity=bicycle_repair_station"],
|
||||
},
|
||||
{
|
||||
and: [
|
||||
|
@ -143,16 +143,16 @@ describe("Tag optimalization", () => {
|
|||
"amenity=bicycle_rental",
|
||||
"bicycle_rental~*",
|
||||
"service:bicycle:rental=yes",
|
||||
"rental~.*bicycle.*"
|
||||
]
|
||||
"rental~.*bicycle.*",
|
||||
],
|
||||
},
|
||||
"bicycle_rental!=docking_station"
|
||||
]
|
||||
"bicycle_rental!=docking_station",
|
||||
],
|
||||
},
|
||||
{
|
||||
and: ["leisure=playground", "playground!=forest"]
|
||||
}
|
||||
]
|
||||
and: ["leisure=playground", "playground!=forest"],
|
||||
},
|
||||
],
|
||||
})
|
||||
const opt = <TagsFilter>filter.optimize()
|
||||
const expected = [
|
||||
|
@ -166,7 +166,7 @@ describe("Tag optimalization", () => {
|
|||
"planned:amenity=charging_station",
|
||||
"tower:type=observation",
|
||||
"(amenity=bicycle_rental|service:bicycle:rental=yes|bicycle_rental~.+|rental~^(.*bicycle.*)$) &bicycle_rental!=docking_station",
|
||||
"leisure=playground&playground!=forest"
|
||||
"leisure=playground&playground!=forest",
|
||||
]
|
||||
|
||||
expect((<Or>opt).or.map((f) => TagUtils.toString(f))).toEqual(expected)
|
||||
|
@ -184,22 +184,16 @@ describe("Tag optimalization", () => {
|
|||
|
||||
it("should optimize comparing tags", () => {
|
||||
const spec = TagUtils.Tag({
|
||||
and:[
|
||||
"x=5",
|
||||
"x>5"
|
||||
]
|
||||
and: ["x=5", "x>5"],
|
||||
})
|
||||
const opt = spec.optimize()
|
||||
expect(opt).to.eq(false)
|
||||
})
|
||||
it("should optimize regexes in the key", () => {
|
||||
const spec = TagUtils.Tag({
|
||||
and: [
|
||||
"service:bicycle:retail=yes",
|
||||
"service:bicycle:.+~~yes"
|
||||
]
|
||||
and: ["service:bicycle:retail=yes", "service:bicycle:.+~~yes"],
|
||||
})
|
||||
const tag = <TagsFilter> spec.optimize()
|
||||
const tag = <TagsFilter>spec.optimize()
|
||||
expect(tag.asJson()).to.eq("service:bicycle:retail=yes")
|
||||
})
|
||||
})
|
||||
|
@ -208,7 +202,7 @@ describe("Tag optimalization", () => {
|
|||
it("with nested And which has a common property should be dropped", () => {
|
||||
const t = new Or([
|
||||
new Tag("foo", "bar"),
|
||||
new And([new Tag("foo", "bar"), new Tag("x", "y")])
|
||||
new And([new Tag("foo", "bar"), new Tag("x", "y")]),
|
||||
])
|
||||
const opt = <TagsFilter>t.optimize()
|
||||
expect(TagUtils.toString(opt)).toBe("foo=bar")
|
||||
|
@ -233,14 +227,14 @@ describe("Tag optimalization", () => {
|
|||
and: [
|
||||
"sport=climbing",
|
||||
{
|
||||
or: ["office~*", "club~*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
or: ["office~*", "club~*"],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
const gym_tags = TagUtils.Tag({
|
||||
and: ["sport=climbing", "leisure=sports_centre"]
|
||||
and: ["sport=climbing", "leisure=sports_centre"],
|
||||
})
|
||||
const other_climbing = TagUtils.Tag({
|
||||
and: [
|
||||
|
@ -248,8 +242,8 @@ describe("Tag optimalization", () => {
|
|||
"climbing!~route",
|
||||
"leisure!~sports_centre",
|
||||
"climbing!=route_top",
|
||||
"climbing!=route_bottom"
|
||||
]
|
||||
"climbing!=route_bottom",
|
||||
],
|
||||
})
|
||||
const together = new Or([club_tags, gym_tags, other_climbing])
|
||||
const opt = together.optimize()
|
||||
|
@ -291,7 +285,7 @@ describe("Tag optimalization", () => {
|
|||
or: [
|
||||
"club=climbing",
|
||||
{
|
||||
and: ["sport=climbing", { or: ["club~*", "office~*"] }]
|
||||
and: ["sport=climbing", { or: ["club~*", "office~*"] }],
|
||||
},
|
||||
{
|
||||
and: [
|
||||
|
@ -304,63 +298,109 @@ describe("Tag optimalization", () => {
|
|||
"climbing!~route",
|
||||
"climbing!=route_top",
|
||||
"climbing!=route_bottom",
|
||||
"leisure!~sports_centre"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
"leisure!~sports_centre",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should optimize a complicated nested case", () => {
|
||||
const spec = {
|
||||
"and":
|
||||
["service:bicycle:retail=yes",
|
||||
{
|
||||
"or": [
|
||||
{
|
||||
"and": [
|
||||
{ "or": ["shop=outdoor", "shop=sport", "shop=diy", "shop=doityourself"] },
|
||||
{
|
||||
"or": ["service:bicycle:repair=yes", "shop=bicycle",
|
||||
{
|
||||
"and": ["shop=sports",
|
||||
{ "or": ["sport=bicycle", "sport=cycling", "sport="] },
|
||||
"service:bicycle:retail!=no",
|
||||
"service:bicycle:repair!=no"]
|
||||
}]
|
||||
}]
|
||||
}, {
|
||||
"and":
|
||||
[
|
||||
and: [
|
||||
"service:bicycle:retail=yes",
|
||||
{
|
||||
or: [
|
||||
{
|
||||
and: [
|
||||
{
|
||||
or: [
|
||||
"shop=outdoor",
|
||||
"shop=sport",
|
||||
"shop=diy",
|
||||
"shop=doityourself",
|
||||
],
|
||||
},
|
||||
{
|
||||
or: [
|
||||
"service:bicycle:repair=yes",
|
||||
"shop=bicycle",
|
||||
{
|
||||
"or":
|
||||
["shop=outdoor", "shop=sport", "shop=diy", "shop=doityourself"]
|
||||
},
|
||||
{
|
||||
"or": ["service:bicycle:repair=yes", "shop=bicycle",
|
||||
and: [
|
||||
"shop=sports",
|
||||
{
|
||||
"and": ["shop=sports",
|
||||
{ "or": ["sport=bicycle", "sport=cycling", "sport="] },
|
||||
"service:bicycle:retail!=no", "service:bicycle:repair!=no"]
|
||||
}]
|
||||
}]
|
||||
}, {
|
||||
"and":
|
||||
[{
|
||||
"or":
|
||||
["craft=shoe_repair", "craft=key_cutter", "shop~.+"]
|
||||
},
|
||||
{ "or": ["shop=outdoor", "shop=sport", "shop=diy", "shop=doityourself"] },
|
||||
"shop!=mall"]
|
||||
},
|
||||
"service:bicycle:retail~.+",
|
||||
"service:bicycle:retail~.+"]
|
||||
}]
|
||||
or: [
|
||||
"sport=bicycle",
|
||||
"sport=cycling",
|
||||
"sport=",
|
||||
],
|
||||
},
|
||||
"service:bicycle:retail!=no",
|
||||
"service:bicycle:repair!=no",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
and: [
|
||||
{
|
||||
or: [
|
||||
"shop=outdoor",
|
||||
"shop=sport",
|
||||
"shop=diy",
|
||||
"shop=doityourself",
|
||||
],
|
||||
},
|
||||
{
|
||||
or: [
|
||||
"service:bicycle:repair=yes",
|
||||
"shop=bicycle",
|
||||
{
|
||||
and: [
|
||||
"shop=sports",
|
||||
{
|
||||
or: [
|
||||
"sport=bicycle",
|
||||
"sport=cycling",
|
||||
"sport=",
|
||||
],
|
||||
},
|
||||
"service:bicycle:retail!=no",
|
||||
"service:bicycle:repair!=no",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
and: [
|
||||
{
|
||||
or: ["craft=shoe_repair", "craft=key_cutter", "shop~.+"],
|
||||
},
|
||||
{
|
||||
or: [
|
||||
"shop=outdoor",
|
||||
"shop=sport",
|
||||
"shop=diy",
|
||||
"shop=doityourself",
|
||||
],
|
||||
},
|
||||
"shop!=mall",
|
||||
],
|
||||
},
|
||||
"service:bicycle:retail~.+",
|
||||
"service:bicycle:retail~.+",
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const tag = TagUtils.Tag(spec)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue