From c9198eba43f33f65ac3eb63296055d4a8e84ed0b Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Sat, 24 Dec 2022 12:36:53 +0100 Subject: [PATCH] eslint: fix tests --- tests/test.autorepair.josm.js | 66 ++++----- tests/test.autorepair.recurse.js | 34 ++--- tests/test.ffs.js | 173 +++++++++++----------- tests/test.mapcss.eval.js | 246 +++++++++++++++---------------- tests/test.permalink.js | 28 ++-- tests/test.query.js | 41 +++--- tests/test.urlParameters.js | 46 +++--- 7 files changed, 315 insertions(+), 319 deletions(-) diff --git a/tests/test.autorepair.josm.js b/tests/test.autorepair.josm.js index 6dd24a7d..fa80b102 100644 --- a/tests/test.autorepair.josm.js +++ b/tests/test.autorepair.josm.js @@ -1,13 +1,13 @@ import {afterEach, describe, expect, it, vi} from "vitest"; import ide from "../js/ide"; -describe("ide.autorepair.josm", function () { +describe("ide.autorepair.josm", () => { afterEach(() => { vi.restoreAllMocks(); }); // repair non-xml output data format: xml query - it("repair non-xml output data format (xml query)", function () { - var examples = [ + it("repair non-xml output data format (xml query)", () => { + const examples = [ { // basic case inp: '', @@ -29,8 +29,8 @@ describe("ide.autorepair.josm", function () { } ]; vi.spyOn(ide, "getQueryLang").mockImplementation(() => "xml"); - for (var i = 0; i < examples.length; i++) { - var setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); + for (let i = 0; i < examples.length; i++) { + const setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); vi.spyOn(ide, "getRawQuery").mockImplementation(() => examples[i].inp); ide.repairQuery("xml+metadata"); expect(setQuery).toHaveBeenCalledWith(examples[i].outp); @@ -38,8 +38,8 @@ describe("ide.autorepair.josm", function () { }); // repair non-xml output data format: ql query - it("repair non-xml output data format (OverpassQL query)", function () { - var examples = [ + it("repair non-xml output data format (OverpassQL query)", () => { + const examples = [ { // basic case inp: "[out:json];", @@ -64,8 +64,8 @@ describe("ide.autorepair.josm", function () { } ]; vi.spyOn(ide, "getQueryLang").mockImplementation(() => "OverpassQL"); - for (var i = 0; i < examples.length; i++) { - var setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); + for (let i = 0; i < examples.length; i++) { + const setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); vi.spyOn(ide, "getRawQuery").mockImplementation(() => examples[i].inp); ide.repairQuery("xml+metadata"); expect(setQuery).toHaveBeenCalledWith(examples[i].outp); @@ -73,8 +73,8 @@ describe("ide.autorepair.josm", function () { }); // repair missing xml+meta infomation: xml query - it("repair missing meta information (xml query)", function () { - var examples = [ + it("repair missing meta information (xml query)", () => { + const examples = [ { // trivial case inp: "", @@ -95,8 +95,8 @@ describe("ide.autorepair.josm", function () { } ]; vi.spyOn(ide, "getQueryLang").mockImplementation(() => "xml"); - for (var i = 0; i < examples.length; i++) { - var setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); + for (let i = 0; i < examples.length; i++) { + const setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); vi.spyOn(ide, "getRawQuery").mockImplementation(() => examples[i].inp); ide.repairQuery("xml+metadata"); expect(setQuery).toHaveBeenCalledWith(examples[i].outp); @@ -104,8 +104,8 @@ describe("ide.autorepair.josm", function () { }); // repair missing xml+meta infomation: ql query - it("repair missing meta information (OverpassQL query)", function () { - var examples = [ + it("repair missing meta information (OverpassQL query)", () => { + const examples = [ { // trivial case inp: "out;", @@ -136,8 +136,8 @@ describe("ide.autorepair.josm", function () { } ]; vi.spyOn(ide, "getQueryLang").mockImplementation(() => "OverpassQL"); - for (var i = 0; i < examples.length; i++) { - var setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); + for (let i = 0; i < examples.length; i++) { + const setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); vi.spyOn(ide, "getRawQuery").mockImplementation(() => examples[i].inp); ide.repairQuery("xml+metadata"); expect(setQuery).toHaveBeenCalledWith(examples[i].outp); @@ -145,8 +145,8 @@ describe("ide.autorepair.josm", function () { }); // overpass complex geometries - it("repair overpass geometry options (xml query)", function () { - var examples = [ + it("repair overpass geometry options (xml query)", () => { + const examples = [ { // center geometry inp: '', @@ -179,8 +179,8 @@ describe("ide.autorepair.josm", function () { } ]; vi.spyOn(ide, "getQueryLang").mockImplementation(() => "xml"); - for (var i = 0; i < examples.length; i++) { - var setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); + for (let i = 0; i < examples.length; i++) { + const setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); vi.spyOn(ide, "getRawQuery").mockImplementation(() => examples[i].inp); ide.repairQuery("xml+metadata"); expect(setQuery).toHaveBeenCalledWith(examples[i].outp); @@ -188,8 +188,8 @@ describe("ide.autorepair.josm", function () { }); // overpass complex geometries - it("repair overpass geometry options (OverpassQL query)", function () { - var examples = [ + it("repair overpass geometry options (OverpassQL query)", () => { + const examples = [ { // center geometry inp: "out meta center;", @@ -222,8 +222,8 @@ describe("ide.autorepair.josm", function () { } ]; vi.spyOn(ide, "getQueryLang").mockImplementation(() => "OverpassQL"); - for (var i = 0; i < examples.length; i++) { - var setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); + for (let i = 0; i < examples.length; i++) { + const setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); vi.spyOn(ide, "getRawQuery").mockImplementation(() => examples[i].inp); ide.repairQuery("xml+metadata"); expect(setQuery).toHaveBeenCalledWith(examples[i].outp); @@ -231,8 +231,8 @@ describe("ide.autorepair.josm", function () { }); // do not repair statements in comments - it("do not repair statements in comments (xml query)", function () { - var examples = [ + it("do not repair statements in comments (xml query)", () => { + const examples = [ { // in xml comment inp: "", @@ -245,8 +245,8 @@ describe("ide.autorepair.josm", function () { } ]; vi.spyOn(ide, "getQueryLang").mockImplementation(() => "xml"); - for (var i = 0; i < examples.length; i++) { - var setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); + for (let i = 0; i < examples.length; i++) { + const setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); vi.spyOn(ide, "getRawQuery").mockImplementation(() => examples[i].inp); ide.repairQuery("xml+metadata"); expect(setQuery).toHaveBeenCalledWith(examples[i].outp); @@ -254,8 +254,8 @@ describe("ide.autorepair.josm", function () { }); // do not repair statements in comments - it("do not repair statements in comments (overpassQL query)", function () { - var examples = [ + it("do not repair statements in comments (overpassQL query)", () => { + const examples = [ { // multiline comment inp: "/*out;*/", @@ -268,8 +268,8 @@ describe("ide.autorepair.josm", function () { } ]; vi.spyOn(ide, "getQueryLang").mockImplementation(() => "OverpassQL"); - for (var i = 0; i < examples.length; i++) { - var setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); + for (let i = 0; i < examples.length; i++) { + const setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); vi.spyOn(ide, "getRawQuery").mockImplementation(() => examples[i].inp); ide.repairQuery("xml+metadata"); expect(setQuery).toHaveBeenCalledWith(examples[i].outp); diff --git a/tests/test.autorepair.recurse.js b/tests/test.autorepair.recurse.js index b13b0bd7..e4410f82 100644 --- a/tests/test.autorepair.recurse.js +++ b/tests/test.autorepair.recurse.js @@ -1,13 +1,13 @@ import {afterEach, describe, expect, it, vi} from "vitest"; import ide from "../js/ide"; -describe("ide.autorepair.recurse", function () { +describe("ide.autorepair.recurse", () => { afterEach(() => { vi.restoreAllMocks(); }); // autocomplete missing recurse statements: xml query - it("autocomplete xml query", function () { - var examples = [ + it("autocomplete xml query", () => { + const examples = [ { // trivial case inp: "", @@ -30,8 +30,8 @@ describe("ide.autorepair.recurse", function () { } ]; vi.spyOn(ide, "getQueryLang").mockImplementation(() => "xml"); - for (var i = 0; i < examples.length; i++) { - var setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); + for (let i = 0; i < examples.length; i++) { + const setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); vi.spyOn(ide, "getRawQuery").mockImplementation(() => examples[i].inp); ide.repairQuery("no visible data"); expect(setQuery).toHaveBeenCalledWith(examples[i].outp); @@ -39,8 +39,8 @@ describe("ide.autorepair.recurse", function () { }); // autocomplete missing recurse statements: OverpassQL query - it("autocomplete OverpassQL query", function () { - var examples = [ + it("autocomplete OverpassQL query", () => { + const examples = [ { // trivial case inp: "out;", @@ -75,8 +75,8 @@ describe("ide.autorepair.recurse", function () { } ]; vi.spyOn(ide, "getQueryLang").mockImplementation(() => "OverpassQL"); - for (var i = 0; i < examples.length; i++) { - var setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); + for (let i = 0; i < examples.length; i++) { + const setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); vi.spyOn(ide, "getRawQuery").mockImplementation(() => examples[i].inp); ide.repairQuery("no visible data"); expect(setQuery).toHaveBeenCalledWith(examples[i].outp); @@ -84,16 +84,16 @@ describe("ide.autorepair.recurse", function () { }); // do not autocomplete in comments (xml query) - it("do not autocomplete in comments (xml query)", function () { - var examples = [ + it("do not autocomplete in comments (xml query)", () => { + const examples = [ { inp: "", outp: "" } ]; vi.spyOn(ide, "getQueryLang").mockImplementation(() => "xml"); - for (var i = 0; i < examples.length; i++) { - var setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); + for (let i = 0; i < examples.length; i++) { + const setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); vi.spyOn(ide, "getRawQuery").mockImplementation(() => examples[i].inp); ide.repairQuery("no visible data"); expect(setQuery).toHaveBeenCalledWith(examples[i].outp); @@ -101,8 +101,8 @@ describe("ide.autorepair.recurse", function () { }); // do not autocomplete in comments (OverpassQL query) - it("do not autocomplete in comments (OverpassQL query)", function () { - var examples = [ + it("do not autocomplete in comments (OverpassQL query)", () => { + const examples = [ { // multiline comments inp: "/*out;*/", @@ -115,8 +115,8 @@ describe("ide.autorepair.recurse", function () { } ]; vi.spyOn(ide, "getQueryLang").mockImplementation(() => "xml"); - for (var i = 0; i < examples.length; i++) { - var setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); + for (let i = 0; i < examples.length; i++) { + const setQuery = vi.spyOn(ide, "setQuery").mockImplementation(() => {}); vi.spyOn(ide, "getRawQuery").mockImplementation(() => examples[i].inp); ide.repairQuery("no visible data"); expect(setQuery).toHaveBeenCalledWith(examples[i].outp); diff --git a/tests/test.ffs.js b/tests/test.ffs.js index da60045e..e96d9802 100644 --- a/tests/test.ffs.js +++ b/tests/test.ffs.js @@ -2,10 +2,10 @@ import {beforeEach, describe, expect, it} from "vitest"; import ffs from "../js/ffs"; import {setPresets} from "../js/ffs/free"; -describe("ide.ffs", function () { +describe("ide.ffs", () => { function construct_query(search) { return new Promise((resolve, reject) => { - ffs.construct_query(search, undefined, function (err, result) { + ffs.construct_query(search, undefined, (err, result) => { if (err) { reject(err); } else if (typeof result === "string") { @@ -22,70 +22,70 @@ describe("ide.ffs", function () { q = q.replace(/\/\/.*/g, ""); q = q.replace(/\[out:json\]\[timeout:.*?\];/, ""); q = q.replace(/\(\{\{bbox\}\}\)/g, "(bbox)"); - q = q.replace(/\{\{geocodeArea:([^\}]*)\}\}/g, "area($1)"); - q = q.replace(/\{\{geocodeCoords:([^\}]*)\}\}/g, "coords:$1"); - q = q.replace(/\{\{date:([^\}]*)\}\}/g, "date:$1"); + q = q.replace(/\{\{geocodeArea:([^}]*)\}\}/g, "area($1)"); + q = q.replace(/\{\{geocodeCoords:([^}]*)\}\}/g, "coords:$1"); + q = q.replace(/\{\{date:([^}]*)\}\}/g, "date:$1"); q = q.replace(/\{\{[\s\S]*?\}\}/g, ""); q = q.replace(/ *\n */g, ""); return q; } - var out_str = "out body;>;out skel qt;"; + const out_str = "out body;>;out skel qt;"; // basic conditions - describe("basic conditions", function () { + describe("basic conditions", () => { // key - it("key=*", async function () { - var search = "foo=*"; + it("key=*", async () => { + const search = "foo=*"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"](bbox);' + ");" + out_str ); }); // not key - it("key!=*", async function () { - var search = "foo!=*"; + it("key!=*", async () => { + const search = "foo!=*"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"!~".*"](bbox);' + ");" + out_str ); }); // key-value - it("key=value", async function () { - var search = "foo=bar"; + it("key=value", async () => { + const search = "foo=bar"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"="bar"](bbox);' + ");" + out_str ); }); // not key-value - it("key!=value", async function () { - var search = "foo!=bar"; + it("key!=value", async () => { + const search = "foo!=bar"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"!="bar"](bbox);' + ");" + out_str ); }); // regex key-value - it("key~value", async function () { - var search = "foo~bar"; + it("key~value", async () => { + const search = "foo~bar"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"~"bar"](bbox);' + ");" + out_str ); }); // regex key - it("~key~value", async function () { - var search = "~foo~bar"; + it("~key~value", async () => { + const search = "~foo~bar"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr[~"foo"~"bar"](bbox);' + ");" + out_str ); }); // not regex key-value - it("key!~value", async function () { - var search = "foo!~bar"; + it("key!~value", async () => { + const search = "foo!~bar"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"!~"bar"](bbox);' + ");" + out_str ); }); // susbtring key-value - it("key:value", async function () { + it("key:value", async () => { // normal case: just do a regex search - var search = "foo:bar"; + let search = "foo:bar"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"~"bar"](bbox);' + ");" + out_str ); @@ -98,43 +98,40 @@ describe("ide.ffs", function () { }); // data types - describe("data types", function () { - describe("strings", function () { + describe("data types", () => { + describe("strings", () => { // strings - it("double quoted strings", async function () { - var search, result; + it("double quoted strings", async () => { // double-quoted string - search = '"a key"="a value"'; + const search = '"a key"="a value"'; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["a key"="a value"](bbox);' + ");" + out_str ); }); - it("single-quoted string", async function () { - var search, result; + it("single-quoted string", async () => { // single-quoted string - search = "'foo bar'='asd fasd'"; + const search = "'foo bar'='asd fasd'"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo bar"="asd fasd"](bbox);' + ");" + out_str ); }); - it("quoted unicode string", async function () { - var search = "name='بیجنگ'"; + it("quoted unicode string", async () => { + const search = "name='بیجنگ'"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["name"="بیجنگ"](bbox);' + ");" + out_str ); }); - it("unicode string", async function () { - var search = "name=Béziers"; + it("unicode string", async () => { + const search = "name=Béziers"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["name"="Béziers"](bbox);' + ");" + out_str ); }); }); // regexes - it("regex", async function () { - var search, result; + it("regex", async () => { // simple regex - search = "foo~/bar/"; + let search = "foo~/bar/"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"~"bar"](bbox);' + ");" + out_str ); @@ -147,29 +144,29 @@ describe("ide.ffs", function () { }); // boolean logic - describe("boolean logic", function () { + describe("boolean logic", () => { // logical and - it("logical and", async function () { - var search = "foo=bar and asd=fasd"; + it("logical and", async () => { + const search = "foo=bar and asd=fasd"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"="bar"]["asd"="fasd"](bbox);' + ");" + out_str ); }); - it("logical and (& operator)", async function () { - var search = "foo=bar & asd=fasd"; + it("logical and (& operator)", async () => { + const search = "foo=bar & asd=fasd"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"="bar"]["asd"="fasd"](bbox);' + ");" + out_str ); }); - it("logical and (&& operator)", async function () { - var search = "foo=bar && asd=fasd"; + it("logical and (&& operator)", async () => { + const search = "foo=bar && asd=fasd"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"="bar"]["asd"="fasd"](bbox);' + ");" + out_str ); }); // logical or - it("logical or", async function () { - var search = "foo=bar or asd=fasd"; + it("logical or", async () => { + const search = "foo=bar or asd=fasd"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"="bar"](bbox);' + @@ -178,8 +175,8 @@ describe("ide.ffs", function () { out_str ); }); - it("logical or (| operator)", async function () { - var search = "foo=bar | asd=fasd"; + it("logical or (| operator)", async () => { + const search = "foo=bar | asd=fasd"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"="bar"](bbox);' + @@ -188,8 +185,8 @@ describe("ide.ffs", function () { out_str ); }); - it("logical or (|| operator)", async function () { - var search = "foo=bar || asd=fasd"; + it("logical or (|| operator)", async () => { + const search = "foo=bar || asd=fasd"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"="bar"](bbox);' + @@ -199,8 +196,8 @@ describe("ide.ffs", function () { ); }); // boolean expression - it("boolean expression", async function () { - var search = "(foo=* or bar=*) and (asd=* or fasd=*)"; + it("boolean expression", async () => { + const search = "(foo=* or bar=*) and (asd=* or fasd=*)"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["foo"]["asd"](bbox);' + @@ -214,11 +211,11 @@ describe("ide.ffs", function () { }); // meta conditions - describe("meta conditions", function () { + describe("meta conditions", () => { // type - it("type", async function () { + it("type", async () => { // simple - var search = "foo=bar and type:node"; + let search = "foo=bar and type:node"; await expect(construct_query(search)).resolves.to.equal( "(" + 'node["foo"="bar"](bbox);' + ");" + out_str ); @@ -238,9 +235,9 @@ describe("ide.ffs", function () { ); }); // newer - it("newer", async function () { + it("newer", async () => { // regular - var search = 'newer:"2000-01-01T01:01:01Z" and type:node'; + let search = 'newer:"2000-01-01T01:01:01Z" and type:node'; await expect(construct_query(search)).resolves.to.equal( "(" + 'node(newer:"2000-01-01T01:01:01Z")(bbox);' + ");" + out_str ); @@ -251,9 +248,9 @@ describe("ide.ffs", function () { ); }); // user - it("user", async function () { + it("user", async () => { // user name - var search = "user:foo and type:node"; + let search = "user:foo and type:node"; await expect(construct_query(search)).resolves.to.equal( "(" + 'node(user:"foo")(bbox);' + ");" + out_str ); @@ -264,9 +261,9 @@ describe("ide.ffs", function () { ); }); // id - it("id", async function () { + it("id", async () => { // with type - var search = "id:123 and type:node"; + let search = "id:123 and type:node"; await expect(construct_query(search)).resolves.to.equal( "(" + "node(123)(bbox);" + ");" + out_str ); @@ -279,18 +276,18 @@ describe("ide.ffs", function () { }); // search-regions - describe("regions", function () { + describe("regions", () => { // global - it("global", async function () { - var search = "foo=bar and type:node global"; + it("global", async () => { + const search = "foo=bar and type:node global"; await expect(construct_query(search)).resolves.to.equal( "(" + 'node["foo"="bar"];' + ");" + out_str ); }); // bbox - it("in bbox", async function () { + it("in bbox", async () => { // implicit - var search = "type:node"; + let search = "type:node"; await expect(construct_query(search)).resolves.to.equal( "(" + "node(bbox);" + ");" + out_str ); @@ -301,8 +298,8 @@ describe("ide.ffs", function () { ); }); // area - it("in area", async function () { - var search = "type:node in foobar"; + it("in area", async () => { + const search = "type:node in foobar"; await expect(construct_query(search)).resolves.to.equal( "area(foobar)->.searchArea;" + "(" + @@ -312,8 +309,8 @@ describe("ide.ffs", function () { ); }); // around - it("around", async function () { - var search = "type:node around foobar"; + it("around", async () => { + const search = "type:node around foobar"; await expect(construct_query(search)).resolves.to.equal( "(" + "node(around:,coords:foobar);" + ");" + out_str ); @@ -321,8 +318,8 @@ describe("ide.ffs", function () { }); // free form - describe("free form", function () { - beforeEach(function () { + describe("free form", () => { + beforeEach(() => { setPresets({ "amenity/hospital": { name: "Hospital", @@ -345,26 +342,26 @@ describe("ide.ffs", function () { }); }); - it("preset not found", async function () { - var search = "foo"; + it("preset not found", async () => { + const search = "foo"; await expect(construct_query(search)).rejects.to.throw( "unknown ffs string" ); }); - it("preset (points, key-value)", async function () { - var search = "Shelter"; + it("preset (points, key-value)", async () => { + const search = "Shelter"; await expect(construct_query(search)).resolves.to.equal( "(" + 'node["amenity"="shelter"](bbox);' + ");" + out_str ); }); - it("preset (points, areas, key-value)", async function () { - var search = "Hospital"; + it("preset (points, areas, key-value)", async () => { + const search = "Hospital"; await expect(construct_query(search)).resolves.to.equal( "(" + 'nwr["amenity"="hospital"](bbox);' + ");" + out_str ); }); - it("preset (lines, key=*)", async function () { - var search = "Highway"; + it("preset (lines, key=*)", async () => { + const search = "Highway"; await expect(construct_query(search)).resolves.to.equal( "(" + 'way["highway"](bbox);' + ");" + out_str ); @@ -372,17 +369,17 @@ describe("ide.ffs", function () { }); // sanity conversions for special conditions - describe("special cases", function () { + describe("special cases", () => { // empty value - it("empty value", async function () { - var search = "foo='' and type:way"; + it("empty value", async () => { + const search = "foo='' and type:way"; await expect(construct_query(search)).resolves.to.equal( "(" + 'way["foo"~"^$"](bbox);' + ");" + out_str ); }); // empty key - it("empty key", async function () { - var search = "''=bar and type:way"; + it("empty key", async () => { + let search = "''=bar and type:way"; await expect(construct_query(search)).resolves.to.equal( "(" + 'way[~"^$"~"^bar$"](bbox);' + ");" + out_str ); @@ -402,8 +399,8 @@ describe("ide.ffs", function () { ); }); // newlines, tabs - it("newlines, tabs", async function () { - var search = "(foo='\t' or foo='\n' or asd='\\t') and type:way"; + it("newlines, tabs", async () => { + const search = "(foo='\t' or foo='\n' or asd='\\t') and type:way"; await expect(construct_query(search)).resolves.to.equal( "(" + 'way["foo"="\\t"](bbox);' + diff --git a/tests/test.mapcss.eval.js b/tests/test.mapcss.eval.js index 714eb7d6..c25f08c4 100644 --- a/tests/test.mapcss.eval.js +++ b/tests/test.mapcss.eval.js @@ -1,194 +1,194 @@ import {describe, expect, it} from "vitest"; import evalparser from "../js/jsmapcss/eval.pegjs"; -describe("mapcss.eval", function () { - it("strings", function () { - var q = '"foo"'; - var p = evalparser.parse(q); +let p, q; + +describe("mapcss.eval", () => { + it("strings", () => { + q = '"foo"'; + p = evalparser.parse(q); expect(p).to.equal("foo"); - var q = "'foo'"; - var p = evalparser.parse(q); + q = "'foo'"; + p = evalparser.parse(q); expect(p).to.equal("foo"); }); - it("num()", function () { - var q = 'num("12.3")'; - var p = evalparser.parse(q); + it("num()", () => { + q = 'num("12.3")'; + p = evalparser.parse(q); expect(p).to.equal("12.3"); - var q = 'num("foo")'; - var p = evalparser.parse(q); + q = 'num("foo")'; + p = evalparser.parse(q); expect(p).to.equal(""); - var q = 'num("-12.3E-1")'; - var p = evalparser.parse(q); + q = 'num("-12.3E-1")'; + p = evalparser.parse(q); expect(p).to.equal("-1.23"); }); - it("str()", function () { - var q = "str(12.3)"; - var p = evalparser.parse(q); + it("str()", () => { + const q = "str(12.3)"; + const p = evalparser.parse(q); expect(p).to.equal("12.3"); }); - it("number arithmetic", function () { - var q = "(1+2*3-4/2-1)*2"; - var p = evalparser.parse(q); + it("number arithmetic", () => { + const q = "(1+2*3-4/2-1)*2"; + const p = evalparser.parse(q); expect(p).to.equal("8"); }); - it("int", function () { - var q = "int(3.1)"; - var p = evalparser.parse(q); + it("int", () => { + q = "int(3.1)"; + p = evalparser.parse(q); expect(p).to.equal("3"); - var q = "int(3.9)"; - var p = evalparser.parse(q); + q = "int(3.9)"; + p = evalparser.parse(q); expect(p).to.equal("3"); - var q = "int(-3.1)"; - var p = evalparser.parse(q); + q = "int(-3.1)"; + p = evalparser.parse(q); expect(p).to.equal("-3"); - var q = "int(-3.9)"; - var p = evalparser.parse(q); + q = "int(-3.9)"; + p = evalparser.parse(q); expect(p).to.equal("-3"); }); - it("number EIAS", function () { - var q = '"2" + 4'; - var p = evalparser.parse(q); + it("number EIAS", () => { + q = '"2" + 4'; + p = evalparser.parse(q); expect(p).to.equal("6"); - var q = '"2" == 2'; - var p = evalparser.parse(q); + q = '"2" == 2'; + p = evalparser.parse(q); expect(p).to.equal("true"); }); - it("none", function () { - var q = "none"; - var p = evalparser.parse(q); + it("none", () => { + const q = "none"; + const p = evalparser.parse(q); expect(p).to.equal(""); }); - it("none aithmetic", function () { - var q = "2 + none"; - var p = evalparser.parse(q); + it("none aithmetic", () => { + q = "2 + none"; + p = evalparser.parse(q); expect(p).to.equal("2"); - var q = "2 * none"; - var p = evalparser.parse(q); + q = "2 * none"; + p = evalparser.parse(q); expect(p).to.equal("0"); }); - it("none EIAS", function () { - var q = '2."" == 2'; - var p = evalparser.parse(q); + it("none EIAS", () => { + q = '2."" == 2'; + p = evalparser.parse(q); expect(p).to.equal("true"); - var q = '2+"" == 2'; - var p = evalparser.parse(q); + q = '2+"" == 2'; + p = evalparser.parse(q); expect(p).to.equal("true"); - var q = 'none == ""'; - var p = evalparser.parse(q); + q = 'none == ""'; + p = evalparser.parse(q); expect(p).to.equal("true"); }); - it("boolean", function () { - var q = "boolean(0)"; - var p = evalparser.parse(q); + it("boolean", () => { + q = "boolean(0)"; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = 'boolean("0")'; - var p = evalparser.parse(q); + q = 'boolean("0")'; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = 'boolean("no")'; - var p = evalparser.parse(q); + q = 'boolean("no")'; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = 'boolean("false")'; - var p = evalparser.parse(q); + q = 'boolean("false")'; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = 'boolean("")'; - var p = evalparser.parse(q); + q = 'boolean("")'; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = "boolean(none)"; - var p = evalparser.parse(q); + q = "boolean(none)"; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = 'boolean("foobar")'; - var p = evalparser.parse(q); + q = 'boolean("foobar")'; + p = evalparser.parse(q); expect(p).to.equal("true"); - var q = 'boolean("yes") == boolean("true")'; - var p = evalparser.parse(q); + q = 'boolean("yes") == boolean("true")'; + p = evalparser.parse(q); expect(p).to.equal("true"); }); - it("boolean arithmetic", function () { - var q = '"true" && "false"'; - var p = evalparser.parse(q); + it("boolean arithmetic", () => { + q = '"true" && "false"'; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = '"true" || "false"'; - var p = evalparser.parse(q); + q = '"true" || "false"'; + p = evalparser.parse(q); expect(p).to.equal("true"); - var q = '!"true"'; - var p = evalparser.parse(q); + q = '!"true"'; + p = evalparser.parse(q); expect(p).to.equal("false"); }); - it("comparison operators", function () { - var q = "2.3 > 01.2"; - var p = evalparser.parse(q); + it("comparison operators", () => { + q = "2.3 > 01.2"; + p = evalparser.parse(q); expect(p).to.equal("true"); - var q = "2 >= 2"; - var p = evalparser.parse(q); + q = "2 >= 2"; + p = evalparser.parse(q); expect(p).to.equal("true"); - var q = "2 < 2"; - var p = evalparser.parse(q); + q = "2 < 2"; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = "1 <= 2"; - var p = evalparser.parse(q); + q = "1 <= 2"; + p = evalparser.parse(q); expect(p).to.equal("true"); - var q = '"2" == "2"'; - var p = evalparser.parse(q); + q = '"2" == "2"'; + p = evalparser.parse(q); expect(p).to.equal("true"); - var q = '"2" == "02"'; - var p = evalparser.parse(q); + q = '"2" == "02"'; + p = evalparser.parse(q); expect(p).to.equal("true"); - var q = '"2" == "3"'; - var p = evalparser.parse(q); + q = '"2" == "3"'; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = '"2" eq "2"'; - var p = evalparser.parse(q); + q = '"2" eq "2"'; + p = evalparser.parse(q); expect(p).to.equal("true"); - var q = '"2" eq "02"'; - var p = evalparser.parse(q); + q = '"2" eq "02"'; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = '"2" != "02"'; - var p = evalparser.parse(q); + q = '"2" != "02"'; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = '"2" <> "02"'; - var p = evalparser.parse(q); + q = '"2" <> "02"'; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = '"2" ne "2"'; - var p = evalparser.parse(q); + q = '"2" ne "2"'; + p = evalparser.parse(q); expect(p).to.equal("false"); - var q = '"2" ne "02"'; - var p = evalparser.parse(q); + q = '"2" ne "02"'; + p = evalparser.parse(q); expect(p).to.equal("true"); }); - it("general functions", function () { - var q = 'tag("_")'; - window.osm_tag = function (_) { - return "foo"; - }; - var p = evalparser.parse(q); + it("general functions", () => { + q = 'tag("_")'; + window.osm_tag = () => "foo"; + p = evalparser.parse(q); expect(p).to.equal("foo"); - var q = 'cond("true", "a", "b")'; - var p = evalparser.parse(q); + q = 'cond("true", "a", "b")'; + p = evalparser.parse(q); expect(p).to.equal("a"); - var q = 'cond("false", "a", "b")'; - var p = evalparser.parse(q); + q = 'cond("false", "a", "b")'; + p = evalparser.parse(q); expect(p).to.equal("b"); - var q = 'any(none, "", "foo", "bar")'; - var p = evalparser.parse(q); + q = 'any(none, "", "foo", "bar")'; + p = evalparser.parse(q); expect(p).to.equal("foo"); }); - it("numeric functions", function () { - var q = "max(1,2,3)"; - var p = evalparser.parse(q); + it("numeric functions", () => { + q = "max(1,2,3)"; + p = evalparser.parse(q); expect(p).to.equal("3"); - var q = "min(1,2,-3)"; - var p = evalparser.parse(q); + q = "min(1,2,-3)"; + p = evalparser.parse(q); expect(p).to.equal("-3"); - var q = "sqrt(16)"; - var p = evalparser.parse(q); + q = "sqrt(16)"; + p = evalparser.parse(q); expect(p).to.equal("4"); }); - it("string functions", function () { - var q = 'concat("foo","bar","asd","fasd")'; - var p = evalparser.parse(q); + it("string functions", () => { + q = 'concat("foo","bar","asd","fasd")'; + p = evalparser.parse(q); expect(p).to.equal("foobarasdfasd"); - var q = '"foo" . 123 . "bar"'; - var p = evalparser.parse(q); + q = '"foo" . 123 . "bar"'; + p = evalparser.parse(q); expect(p).to.equal("foo123bar"); }); }); diff --git a/tests/test.permalink.js b/tests/test.permalink.js index 26130d06..7b0e9c7f 100644 --- a/tests/test.permalink.js +++ b/tests/test.permalink.js @@ -1,12 +1,12 @@ import {describe, expect, it} from "vitest"; import ide from "../js/ide"; -describe("ide.permalink", function () { +describe("ide.permalink", () => { // check share links - it("share uncompressed", function () { - var q = + it("share uncompressed", () => { + const q = '\n\n \n \n\n'; - var p = ide.compose_share_link(q, false, false, false); + const p = ide.compose_share_link(q, false, false, false); expect(p).to.eql( "?Q=%3C%21--%0AThis+is+an+example+Overpass+query.%0ATry+it+out+by+pressing+the+Run+button+above%21%0AYou+can+find+more+examples+with+the+Load+tool.%0A--%3E%0A%3Cquery+type%3D%22node%22%3E%0A++%3Chas-kv+k%3D%22amenity%22+v%3D%22drinking_water%22%2F%3E%0A++%3Cbbox-query+%7B%7Bbbox%7D%7D%2F%3E%3C%21--this+is+auto-completed+with+the%0A+++++++++++++++++++current+map+view+coordinates.--%3E%0A%3C%2Fquery%3E%0A%3Cprint%2F%3E" ); @@ -15,10 +15,10 @@ describe("ide.permalink", function () { expect(p).not.to.have.string("&c="); expect(p).not.to.have.string("&R"); }); - it("share compressed", function () { - var q = + it("share compressed", () => { + const q = '\n\n \n \n\n'; - var p = ide.compose_share_link(q, true, false, false); + const p = ide.compose_share_link(q, true, false, false); expect(p).not.to.have.string("?Q="); expect(p).to.eql( "?q=PCEtLQpUaGlzIMSHIGFuIGV4YW1wbGUgT3ZlcnBhc8SIcXXEmXkuxIRyecSJdCBvdcSoYsSmcHJlxJ1pbmcgdGjElVJ1xI1ixKt0b8SNYWJvxJghClnEqiBjxIwgZsSzZCBtb8SwxI7EkMSSxJTEiHdpxLfEtsS4IExvYcWQxL9vbMSjxII-CjzEn8ShxLZ5cGU9Im5vZGUixakgIDxoxJwta3Yga8WyxJFlbsWbeSIgdsWyZHLEs2vEs2dfd2F0xJkiL8W5xbtixYN4LcWsxKUge3vGnW94fX3GmsSAxILEt8SKxIphxKtvLWNvxZdlxpfFkMWaxZzEt2UKxbrHgMeBx4LHgmN1csSwbsSobWFwxotpZXfFim_Fk2TEs8aWxLEuxajFqi_GoXnFqTzEr8SzdMaa" @@ -27,8 +27,8 @@ describe("ide.permalink", function () { expect(p).not.to.have.string("&c="); expect(p).not.to.have.string("&R"); }); - it("share coordinates", function () { - var q = " "; + it("share coordinates", () => { + const q = " "; ide.map = { getCenter: function () { return {lat: 12.3456, lng: -65.4321}; @@ -37,18 +37,16 @@ describe("ide.permalink", function () { return 8; } }; - var p; - p = ide.compose_share_link(q, false, true, false); + let p = ide.compose_share_link(q, false, true, false); expect(p).to.have.string("&C=12.3456%3B-65.4321%3B8"); expect(p).not.to.have.string("&c="); p = ide.compose_share_link(q, true, true, false); expect(p).not.to.have.string("&C="); expect(p).to.have.string("&c=Au47axyXAI"); }); - it("share autorun", function () { - var q = " "; - var p; - p = ide.compose_share_link(q, false, false, true); + it("share autorun", () => { + const q = " "; + const p = ide.compose_share_link(q, false, false, true); expect(p).to.have.string("&R"); }); }); diff --git a/tests/test.query.js b/tests/test.query.js index c7f38549..f4d011f1 100644 --- a/tests/test.query.js +++ b/tests/test.query.js @@ -1,9 +1,10 @@ import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; +import L from "leaflet"; import ide from "../js/ide"; -describe("ide.query", function () { - var orig_codeEditor, orig_map; - beforeEach(function () { +describe("ide.query", () => { + let orig_codeEditor, orig_map; + beforeEach(() => { orig_codeEditor = ide.codeEditor; ide.codeEditor = {}; orig_map = ide.map; @@ -21,16 +22,16 @@ describe("ide.query", function () { } }; }); - afterEach(function () { + afterEach(() => { ide.map = orig_map; ide.codeEditor = orig_codeEditor; vi.restoreAllMocks(); }); // expand {{parameters}} in ql query - it("expand {{parameters}} in ql query", function () { + it("expand {{parameters}} in ql query", () => { vi.spyOn(ide, "setQuery").mockImplementation(() => {}); - var examples = [ + const examples = [ { // simple expansion inp: "{{parameter=foo}};{{parameter}}", @@ -47,8 +48,8 @@ describe("ide.query", function () { outp: ";foofoo" } ]; - var callback = vi.fn(() => 0); - for (var i = 0; i < examples.length; i++) { + const callback = vi.fn(() => 0); + for (let i = 0; i < examples.length; i++) { ide.codeEditor.getValue = function () { return examples[i].inp; }; @@ -58,9 +59,9 @@ describe("ide.query", function () { ide.setQuery.restore(); }); // expand {{parameters}} in xml query - it("expand {{parameters}} in xml", function () { + it("expand {{parameters}} in xml", () => { vi.spyOn(ide, "setQuery").mockImplementation(() => {}); - var examples = [ + const examples = [ { // simple expansion inp: "{{parameter=foo}}{{parameter}}", @@ -77,8 +78,8 @@ describe("ide.query", function () { outp: "foofoo" } ]; - var callback = vi.fn(() => 0); - for (var i = 0; i < examples.length; i++) { + const callback = vi.fn(() => 0); + for (let i = 0; i < examples.length; i++) { ide.codeEditor.getValue = function () { return examples[i].inp; }; @@ -88,9 +89,9 @@ describe("ide.query", function () { ide.setQuery.restore(); }); // expand {{bbox}} - it("expand {{bbox}}", function () { + it("expand {{bbox}}", () => { vi.spyOn(ide, "setQuery").mockImplementation(() => {}); - var examples = [ + const examples = [ { // ql query inp: "({{bbox}})", @@ -107,8 +108,8 @@ describe("ide.query", function () { outp: '' } ]; - var callback = vi.fn(() => 0); - for (var i = 0; i < examples.length; i++) { + const callback = vi.fn(() => 0); + for (let i = 0; i < examples.length; i++) { ide.codeEditor.getValue = function () { return examples[i].inp; }; @@ -118,9 +119,9 @@ describe("ide.query", function () { ide.setQuery.restore(); }); // expand {{center}} - it("expand {{center}}", function () { + it("expand {{center}}", () => { vi.spyOn(ide, "setQuery").mockImplementation(() => {}); - var examples = [ + const examples = [ { // ql query inp: "({{center}})", @@ -132,8 +133,8 @@ describe("ide.query", function () { outp: '' } ]; - var callback = vi.fn(() => 0); - for (var i = 0; i < examples.length; i++) { + const callback = vi.fn(() => 0); + for (let i = 0; i < examples.length; i++) { ide.codeEditor.getValue = function () { return examples[i].inp; }; diff --git a/tests/test.urlParameters.js b/tests/test.urlParameters.js index 094d5f0b..60c217b9 100644 --- a/tests/test.urlParameters.js +++ b/tests/test.urlParameters.js @@ -2,17 +2,17 @@ import {describe, expect, it} from "vitest"; import settings from "../js/settings"; import urlParameters from "../js/urlParameters"; -describe("urlParameters", function () { +describe("urlParameters", () => { // no parameters - it("defaults", function () { - var args = urlParameters(""); + it("defaults", () => { + let args = urlParameters(""); expect(args).toMatchObject({ has_query: false, has_coords: false, has_zoom: false, run_query: false }); - var args = urlParameters("?"); + args = urlParameters("?"); expect(args).toMatchObject({ has_query: false, has_coords: false, @@ -21,8 +21,8 @@ describe("urlParameters", function () { }); }); // query (uncompressed) - it("query", function () { - var args = urlParameters("?Q=foo"); + it("query", () => { + const args = urlParameters("?Q=foo"); expect(args).toMatchObject({ has_query: true, query: "foo", @@ -31,8 +31,8 @@ describe("urlParameters", function () { }); }); // query (compressed) - it("query (compressed)", function () { - var args = urlParameters("?q=Zm9v"); + it("query (compressed)", () => { + const args = urlParameters("?q=Zm9v"); expect(args).toMatchObject({ has_query: true, query: "foo", @@ -41,8 +41,8 @@ describe("urlParameters", function () { }); }); // coords (uncompressed) - it("coords", function () { - var args = urlParameters("?C=0;180;1"); + it("coords", () => { + const args = urlParameters("?C=0;180;1"); expect(args).toMatchObject({ has_query: false, has_coords: true, @@ -52,8 +52,8 @@ describe("urlParameters", function () { }); }); // coords (uncompressed, lat/lon/zoom) - it("coords (lat/lon/zoom)", function () { - var args = urlParameters("?lat=0&lon=180.0&zoom=1"); + it("coords (lat/lon/zoom)", () => { + let args = urlParameters("?lat=0&lon=180.0&zoom=1"); expect(args).toMatchObject({ has_query: false, has_coords: true, @@ -61,14 +61,14 @@ describe("urlParameters", function () { has_zoom: true, zoom: 1 }); - var args = urlParameters("?lat=0&lon=180.0"); + args = urlParameters("?lat=0&lon=180.0"); expect(args).toMatchObject({ has_query: false, has_coords: true, coords: {lat: 0.0, lng: 180.0}, has_zoom: false }); - var args = urlParameters("?zoom=1"); + args = urlParameters("?zoom=1"); expect(args).toMatchObject({ has_query: false, has_coords: false, @@ -77,8 +77,8 @@ describe("urlParameters", function () { }); }); // coords (compressed) - it("coords (compressed)", function () { - var args = urlParameters("?c=CTVpCWdRAB"); + it("coords (compressed)", () => { + const args = urlParameters("?c=CTVpCWdRAB"); expect(args).toMatchObject({ has_coords: true, coords: {lat: 0.0, lng: 180.0}, @@ -87,19 +87,19 @@ describe("urlParameters", function () { }); }); // RUN flag - it("RUN flag", function () { - var args = urlParameters("?Q=foo&R"); + it("RUN flag", () => { + let args = urlParameters("?Q=foo&R"); expect(args).toMatchObject({run_query: true}); - var args = urlParameters("?Q=foo&R=true"); + args = urlParameters("?Q=foo&R=true"); expect(args).toMatchObject({run_query: true}); }); // template - it("template", async function () { - var orig_ss = settings.saves; + it("template", async () => { + const orig_ss = settings.saves; settings.saves = { T: {type: "template", parameters: ["p"], wizard: "name={{p}}"} }; - var args = new Promise((resolve, reject) => + const args = new Promise((resolve, reject) => urlParameters( "?template=T&p=foo", (err, result) => (err && reject(err)) || resolve(result) @@ -117,7 +117,7 @@ The original search was: ( // query part for: “name=foo” // nwr is short for node/way/relation - nwr[\"name\"=\"foo\"]({{bbox}}); + nwr["name"="foo"]({{bbox}}); ); // print results out body;