forked from MapComplete/MapComplete
Fix Tag.matchesProperties and RegexTag.matchesProperties, they do match on definedProperties now (and are faster)
This commit is contained in:
parent
30bc620827
commit
15ff38a098
3 changed files with 51 additions and 21 deletions
|
@ -47,6 +47,11 @@ export class RegexTag extends TagsFilter {
|
|||
}
|
||||
|
||||
matchesProperties(tags: any): boolean {
|
||||
if(typeof this.key === "string"){
|
||||
const value = tags[this.key] ?? ""
|
||||
return RegexTag.doesMatch(value, this.value) != this.invert;
|
||||
}
|
||||
|
||||
for (const key in tags) {
|
||||
if (key === undefined) {
|
||||
continue;
|
||||
|
|
|
@ -23,26 +23,14 @@ export class Tag extends TagsFilter {
|
|||
|
||||
|
||||
matchesProperties(properties: any): boolean {
|
||||
for (const propertiesKey in properties) {
|
||||
if (!properties.hasOwnProperty(propertiesKey)) {
|
||||
continue
|
||||
}
|
||||
if (this.key === propertiesKey) {
|
||||
const value = properties[propertiesKey];
|
||||
if (value === undefined) {
|
||||
continue
|
||||
}
|
||||
return value === this.value;
|
||||
}
|
||||
}
|
||||
// The tag was not found
|
||||
|
||||
if (this.value === "") {
|
||||
const foundValue = properties[this.key]
|
||||
if (foundValue === undefined && (this.value === "" || this.value === undefined)) {
|
||||
// The tag was not found
|
||||
// and it shouldn't be found!
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return foundValue === this.value;
|
||||
}
|
||||
|
||||
asOverpass(): string[] {
|
||||
|
|
|
@ -9,6 +9,7 @@ import {Tag} from "../Logic/Tags/Tag";
|
|||
import {And} from "../Logic/Tags/And";
|
||||
import {TagUtils} from "../Logic/Tags/TagUtils";
|
||||
import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig";
|
||||
import {RegexTag} from "../Logic/Tags/RegexTag";
|
||||
|
||||
|
||||
Utils.runningFromConsole = true;
|
||||
|
@ -173,7 +174,6 @@ export default class TagSpec extends T {
|
|||
equal(undefined, tr.GetRenderValue({"foo": "bar"}));
|
||||
|
||||
})],
|
||||
|
||||
[
|
||||
"Empty match test",
|
||||
() => {
|
||||
|
@ -214,7 +214,8 @@ export default class TagSpec extends T {
|
|||
const overpassOrInor = TagUtils.Tag(orInOr).asOverpass()
|
||||
equal(3, overpassOrInor.length)
|
||||
}
|
||||
], [
|
||||
],
|
||||
[
|
||||
"Merge touching opening hours",
|
||||
() => {
|
||||
const oh1: OpeningHour = {
|
||||
|
@ -239,7 +240,8 @@ export default class TagSpec extends T {
|
|||
equal(r.endHour, 12)
|
||||
|
||||
}
|
||||
], [
|
||||
],
|
||||
[
|
||||
"Merge overlapping opening hours",
|
||||
() => {
|
||||
const oh1: OpeningHour = {
|
||||
|
@ -394,7 +396,8 @@ export default class TagSpec extends T {
|
|||
|
||||
]));
|
||||
equal(rules, "Tu 23:00-00:00");
|
||||
}], ["JOIN OH with overflowed hours", () => {
|
||||
}],
|
||||
["JOIN OH with overflowed hours", () => {
|
||||
const rules = OH.ToString(
|
||||
OH.MergeTimes([
|
||||
|
||||
|
@ -483,7 +486,41 @@ export default class TagSpec extends T {
|
|||
const tagRendering = new TagRenderingConfig(config, null, "test");
|
||||
equal(true, tagRendering.IsKnown({bottle: "yes"}))
|
||||
equal(false, tagRendering.IsKnown({}))
|
||||
}]]);
|
||||
}],
|
||||
[
|
||||
"Tag matches a lazy property",
|
||||
() => {
|
||||
const properties = {}
|
||||
const key = "_key"
|
||||
Object.defineProperty(properties, key, {
|
||||
configurable: true,
|
||||
get: function () {
|
||||
delete properties[key]
|
||||
properties[key] = "yes"
|
||||
return "yes"
|
||||
}
|
||||
})
|
||||
const filter = new Tag("_key", "yes")
|
||||
T.isTrue(filter.matchesProperties(properties), "Lazy value not matched")
|
||||
}
|
||||
],
|
||||
[
|
||||
"RegextTag matches a lazy property",
|
||||
() => {
|
||||
const properties = {}
|
||||
const key = "_key"
|
||||
Object.defineProperty(properties, key, {
|
||||
configurable: true,
|
||||
get: function () {
|
||||
delete properties[key]
|
||||
properties[key] = "yes"
|
||||
return "yes"
|
||||
}
|
||||
})
|
||||
const filter = TagUtils.Tag("_key~*")
|
||||
T.isTrue(filter.matchesProperties(properties), "Lazy value not matched")
|
||||
}
|
||||
]]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue