forked from MapComplete/MapComplete
More tests
This commit is contained in:
parent
50d383279d
commit
074782c1e0
6 changed files with 52 additions and 56 deletions
|
@ -31,6 +31,15 @@ export default class ComparingTag implements TagsFilter {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the properties match
|
||||
*
|
||||
* const t = new ComparingTag("key", (x => Number(x) < 42))
|
||||
* t.matchesProperties({key: 42}) // => false
|
||||
* t.matchesProperties({key: 41}) // => true
|
||||
* t.matchesProperties({key: 0}) // => true
|
||||
* t.matchesProperties({differentKey: 42}) // => false
|
||||
*/
|
||||
matchesProperties(properties: any): boolean {
|
||||
return this._predicate(properties[this._key]);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ export class Tag extends TagsFilter {
|
|||
* isEmpty.matchesProperties({"key": ""}) // => true
|
||||
* isEmpty.matchesProperties({"other_key": ""}) // => true
|
||||
* isEmpty.matchesProperties({"other_key": "value"}) // => true
|
||||
* isEmpty.matchesProperties({"key": undefined}) // => true
|
||||
*
|
||||
*/
|
||||
matchesProperties(properties: any): boolean {
|
||||
const foundValue = properties[this.key]
|
||||
|
|
|
@ -220,6 +220,23 @@ export class OH {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an OH-syntax rule into an object
|
||||
*
|
||||
*
|
||||
* const rules = OH.ParsePHRule("PH 12:00-17:00")
|
||||
* rules.mode // => " "
|
||||
* rules.start // => "12:00"
|
||||
* rules.end // => "17:00"
|
||||
*
|
||||
* OH.ParseRule("PH 12:00-17:00") // => null
|
||||
* OH.ParseRule("Th[-1] off") // => null
|
||||
*
|
||||
* const rules = OH.Parse("24/7");
|
||||
* rules.length // => 7
|
||||
* rules[0].startHour // => 0
|
||||
* OH.ToString(rules) // => "24/7"
|
||||
*/
|
||||
public static ParseRule(rule: string): OpeningHour[] {
|
||||
try {
|
||||
if (rule.trim() == "24/7") {
|
||||
|
|
|
@ -43,6 +43,14 @@ export default class Translations {
|
|||
return new Translation(t, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 'Wrap Translation': given an object containing translations OR a string, returns a translation object
|
||||
*
|
||||
* const json: any = {"en": "English", "nl": "Nederlands"};
|
||||
* const translation = Translations.WT(new Translation(json));
|
||||
* translation.textFor("en") // => "English"
|
||||
* translation.textFor("nl") // => "Nederlands"
|
||||
*/
|
||||
public static WT(s: string | Translation): Translation {
|
||||
if (s === undefined || s === null) {
|
||||
return undefined;
|
||||
|
|
17
Utils.ts
17
Utils.ts
|
@ -109,7 +109,22 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
return "" + i;
|
||||
}
|
||||
|
||||
public static Round(i: number) {
|
||||
/**
|
||||
* Converts a number to a string with one number after the comma
|
||||
*
|
||||
* Utils.Round(15) // => "15.0"
|
||||
* Utils.Round(1) // => "1.0"
|
||||
* Utils.Round(1.5) // => "1.5"
|
||||
* Utils.Round(0.5) // => "0.5"
|
||||
* Utils.Round(1.6) // => "1.6"
|
||||
* Utils.Round(-15) // => "-15.0"
|
||||
* Utils.Round(-1) // => "-1.0"
|
||||
* Utils.Round(-1.5) // => "-1.5"
|
||||
* Utils.Round(-0.5) // => "-0.5"
|
||||
* Utils.Round(-1.6) // => "-1.6"
|
||||
* Utils.Round(-1531.63543) // =>"-1531.6"
|
||||
*/
|
||||
public static Round(i: number): string {
|
||||
if (i < 0) {
|
||||
return "-" + Utils.Round(-i);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import {Utils} from "../Utils";
|
||||
import {equal} from "assert";
|
||||
import T from "./TestHelper";
|
||||
import Locale from "../UI/i18n/Locale";
|
||||
import Translations from "../UI/i18n/Translations";
|
||||
import {Translation} from "../UI/i18n/Translation";
|
||||
import {OH, OpeningHour} from "../UI/OpeningHours/OpeningHours";
|
||||
import {Tag} from "../Logic/Tags/Tag";
|
||||
import {And} from "../Logic/Tags/And";
|
||||
|
@ -97,15 +94,6 @@ export default class TagSpec extends T {
|
|||
equal(false, t2.isEquivalent(t0))
|
||||
equal(false, t2.isEquivalent(t1))
|
||||
})],
|
||||
["Parse translation map", (() => {
|
||||
|
||||
const json: any = {"en": "English", "nl": "Nederlands"};
|
||||
const translation = Translations.WT(new Translation(json));
|
||||
Locale.language.setData("en");
|
||||
equal(translation.txt, "English");
|
||||
Locale.language.setData("nl");
|
||||
equal(translation.txt, "Nederlands");
|
||||
})],
|
||||
["Parse tag rendering", (() => {
|
||||
Locale.language.setData("nl");
|
||||
const tr = new TagRenderingConfig({
|
||||
|
@ -130,13 +118,6 @@ export default class TagSpec extends T {
|
|||
equal(undefined, tr.GetRenderValue({"foo": "bar"}));
|
||||
|
||||
})],
|
||||
[
|
||||
"Empty match test",
|
||||
() => {
|
||||
const t = new Tag("key", "");
|
||||
equal(false, t.matchesProperties({"key": "somevalue"}))
|
||||
}
|
||||
],
|
||||
[
|
||||
"Test not with overpass",
|
||||
() => {
|
||||
|
@ -385,42 +366,6 @@ export default class TagSpec extends T {
|
|||
]));
|
||||
equal(rules, "Tu 23:00-00:00");
|
||||
}],
|
||||
["OH 24/7", () => {
|
||||
const rules = OH.Parse("24/7");
|
||||
equal(rules.length, 7);
|
||||
equal(rules[0].startHour, 0);
|
||||
const asStr = OH.ToString(rules);
|
||||
equal(asStr, "24/7");
|
||||
}],
|
||||
["OH Th[-1] off", () => {
|
||||
const rules = OH.ParseRule("Th[-1] off");
|
||||
equal(rules, null);
|
||||
}],
|
||||
["OHNo parsePH 12:00-17:00", () => {
|
||||
const rules = OH.ParseRule("PH 12:00-17:00");
|
||||
equal(rules, null);
|
||||
}],
|
||||
["OH Parse PH 12:00-17:00", () => {
|
||||
const rules = OH.ParsePHRule("PH 12:00-17:00");
|
||||
equal(rules.mode, " ");
|
||||
equal(rules.start, "12:00")
|
||||
equal(rules.end, "17:00")
|
||||
}],
|
||||
["Round", () => {
|
||||
equal(Utils.Round(15), "15.0")
|
||||
equal(Utils.Round(1), "1.0")
|
||||
equal(Utils.Round(1.5), "1.5")
|
||||
equal(Utils.Round(0.5), "0.5")
|
||||
equal(Utils.Round(1.6), "1.6")
|
||||
|
||||
equal(Utils.Round(-15), "-15.0")
|
||||
equal(Utils.Round(-1), "-1.0")
|
||||
equal(Utils.Round(-1.5), "-1.5")
|
||||
equal(Utils.Round(-0.5), "-0.5")
|
||||
equal(Utils.Round(-1.6), "-1.6")
|
||||
|
||||
}
|
||||
],
|
||||
["Regression", () => {
|
||||
|
||||
const config = {
|
||||
|
|
Loading…
Reference in a new issue