Skip to content

Commit

Permalink
fix wizard-related test
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrasd committed Sep 30, 2023
1 parent 8e77228 commit 8011da9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 57 deletions.
2 changes: 1 addition & 1 deletion js/ffs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export function ffs_construct_query(
}

if (query_parts.indexOf("(") === query_parts.length - 2) {
var idx = query_parts.indexOf("(");
const idx = query_parts.indexOf("(");
query_parts.splice(idx, 1);
query_parts[idx] = query_parts[idx].substr(2);
} else {
Expand Down
77 changes: 37 additions & 40 deletions tests/test.ffs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,70 +29,70 @@ describe("ide.ffs", () => {
q = q.replace(/ *\n */g, "");
return q;
}
const out_str = "out body;>;out skel qt;";
const out_str = "out geom;";

// basic conditions
describe("basic conditions", () => {
// key
it("key=*", async () => {
const search = "foo=*";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["foo"](bbox);` + `);${out_str}`
`nwr["foo"](bbox);${out_str}`
);
});
// not key
it("key!=*", async () => {
const search = "foo!=*";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["foo"!~".*"](bbox);` + `);${out_str}`
`nwr["foo"!~".*"](bbox);${out_str}`
);
});
// key-value
it("key=value", async () => {
const search = "foo=bar";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["foo"="bar"](bbox);` + `);${out_str}`
`nwr["foo"="bar"](bbox);${out_str}`
);
});
// not key-value
it("key!=value", async () => {
const search = "foo!=bar";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["foo"!="bar"](bbox);` + `);${out_str}`
`nwr["foo"!="bar"](bbox);${out_str}`
);
});
// regex key-value
it("key~value", async () => {
const search = "foo~bar";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["foo"~"bar"](bbox);` + `);${out_str}`
`nwr["foo"~"bar"](bbox);${out_str}`
);
});
// regex key
it("~key~value", async () => {
const search = "~foo~bar";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr[~"foo"~"bar"](bbox);` + `);${out_str}`
`nwr[~"foo"~"bar"](bbox);${out_str}`
);
});
// not regex key-value
it("key!~value", async () => {
const search = "foo!~bar";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["foo"!~"bar"](bbox);` + `);${out_str}`
`nwr["foo"!~"bar"](bbox);${out_str}`
);
});
// susbtring key-value
it("key:value", async () => {
// normal case: just do a regex search
let search = "foo:bar";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["foo"~"bar"](bbox);` + `);${out_str}`
`nwr["foo"~"bar"](bbox);${out_str}`
);
// but also escape special characters
search = "foo:'*'";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["foo"~"\\\\*"](bbox);` + `);${out_str}`
`nwr["foo"~"\\\\*"](bbox);${out_str}`
);
});
});
Expand All @@ -105,26 +105,26 @@ describe("ide.ffs", () => {
// double-quoted string
const search = '"a key"="a value"';
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["a key"="a value"](bbox);` + `);${out_str}`
`nwr["a key"="a value"](bbox);${out_str}`
);
});
it("single-quoted string", async () => {
// single-quoted string
const search = "'foo bar'='asd fasd'";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["foo bar"="asd fasd"](bbox);` + `);${out_str}`
`nwr["foo bar"="asd fasd"](bbox);${out_str}`
);
});
it("quoted unicode string", async () => {
const search = "name='بیجنگ'";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["name"="بیجنگ"](bbox);` + `);${out_str}`
`nwr["name"="بیجنگ"](bbox);${out_str}`
);
});
it("unicode string", async () => {
const search = "name=Béziers";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["name"="Béziers"](bbox);` + `);${out_str}`
`nwr["name"="Béziers"](bbox);${out_str}`
);
});
});
Expand All @@ -133,12 +133,12 @@ describe("ide.ffs", () => {
// simple regex
let search = "foo~/bar/";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["foo"~"bar"](bbox);` + `);${out_str}`
`nwr["foo"~"bar"](bbox);${out_str}`
);
// simple regex with modifier
search = "foo~/bar/i";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["foo"~"bar",i](bbox);` + `);${out_str}`
`nwr["foo"~"bar",i](bbox);${out_str}`
);
});
});
Expand All @@ -149,19 +149,19 @@ describe("ide.ffs", () => {
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}`
`nwr["foo"="bar"]["asd"="fasd"](bbox);${out_str}`
);
});
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}`
`nwr["foo"="bar"]["asd"="fasd"](bbox);${out_str}`
);
});
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}`
`nwr["foo"="bar"]["asd"="fasd"](bbox);${out_str}`
);
});
// logical or
Expand Down Expand Up @@ -213,7 +213,7 @@ describe("ide.ffs", () => {
// simple
let search = "foo=bar and type:node";
await expect(construct_query(search)).resolves.to.equal(
`(` + `node["foo"="bar"](bbox);` + `);${out_str}`
`node["foo"="bar"](bbox);${out_str}`
);
// multiple types
search = "foo=bar and (type:node or type:way)";
Expand All @@ -234,38 +234,38 @@ describe("ide.ffs", () => {
// regular
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}`
`node(newer:"2000-01-01T01:01:01Z")(bbox);${out_str}`
);
// relative
search = "newer:1day and type:node";
await expect(construct_query(search)).resolves.to.equal(
`(` + `node(newer:"date:1day")(bbox);` + `);${out_str}`
`node(newer:"date:1day")(bbox);${out_str}`
);
});
// user
it("user", async () => {
// user name
let search = "user:foo and type:node";
await expect(construct_query(search)).resolves.to.equal(
`(` + `node(user:"foo")(bbox);` + `);${out_str}`
`node(user:"foo")(bbox);${out_str}`
);
// uid
search = "uid:123 and type:node";
await expect(construct_query(search)).resolves.to.equal(
`(` + `node(uid:123)(bbox);` + `);${out_str}`
`node(uid:123)(bbox);${out_str}`
);
});
// id
it("id", async () => {
// with type
let search = "id:123 and type:node";
await expect(construct_query(search)).resolves.to.equal(
`(` + `node(123)(bbox);` + `);${out_str}`
`node(123)(bbox);${out_str}`
);
// without type
search = "id:123";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr(123)(bbox);` + `);${out_str}`
`nwr(123)(bbox);${out_str}`
);
});
});
Expand All @@ -276,37 +276,34 @@ describe("ide.ffs", () => {
it("global", async () => {
const search = "foo=bar and type:node global";
await expect(construct_query(search)).resolves.to.equal(
`(` + `node["foo"="bar"];` + `);${out_str}`
`node["foo"="bar"];${out_str}`
);
});
// bbox
it("in bbox", async () => {
// implicit
let search = "type:node";
await expect(construct_query(search)).resolves.to.equal(
`(` + `node(bbox);` + `);${out_str}`
`node(bbox);${out_str}`
);
// explicit
search = "type:node in bbox";
await expect(construct_query(search)).resolves.to.equal(
`(` + `node(bbox);` + `);${out_str}`
`node(bbox);${out_str}`
);
});
// area
it("in area", async () => {
const search = "type:node in foobar";
await expect(construct_query(search)).resolves.to.equal(
`area(foobar)->.searchArea;` +
`(` +
`node(area.searchArea);` +
`);${out_str}`
`area(foobar)->.searchArea;` + `node(area.searchArea);` + `${out_str}`
);
});
// around
it("around", async () => {
const search = "type:node around foobar";
await expect(construct_query(search)).resolves.to.equal(
`(` + `node(around:,coords:foobar);` + `);${out_str}`
`node(around:,coords:foobar);${out_str}`
);
});
});
Expand Down Expand Up @@ -345,19 +342,19 @@ describe("ide.ffs", () => {
it("preset (points, key-value)", async () => {
const search = "Shelter";
await expect(construct_query(search)).resolves.to.equal(
`(` + `node["amenity"="shelter"](bbox);` + `);${out_str}`
`node["amenity"="shelter"](bbox);${out_str}`
);
});
it("preset (points, areas, key-value)", async () => {
const search = "Hospital";
await expect(construct_query(search)).resolves.to.equal(
`(` + `nwr["amenity"="hospital"](bbox);` + `);${out_str}`
`nwr["amenity"="hospital"](bbox);${out_str}`
);
});
it("preset (lines, key=*)", async () => {
const search = "Highway";
await expect(construct_query(search)).resolves.to.equal(
`(` + `way["highway"](bbox);` + `);${out_str}`
`way["highway"](bbox);${out_str}`
);
});
});
Expand All @@ -368,19 +365,19 @@ describe("ide.ffs", () => {
it("empty value", async () => {
const search = "foo='' and type:way";
await expect(construct_query(search)).resolves.to.equal(
`(` + `way["foo"~"^$"](bbox);` + `);${out_str}`
`way["foo"~"^$"](bbox);${out_str}`
);
});
// empty key
it("empty key", async () => {
let search = "''=bar and type:way";
await expect(construct_query(search)).resolves.to.equal(
`(` + `way[~"^$"~"^bar$"](bbox);` + `);${out_str}`
`way[~"^$"~"^bar$"](bbox);${out_str}`
);
// make sure stuff in the value section gets escaped properly
search = "''='*' and type:way";
await expect(construct_query(search)).resolves.to.equal(
`(` + `way[~"^$"~"^\\\\*$"](bbox);` + `);${out_str}`
`way[~"^$"~"^\\\\*$"](bbox);${out_str}`
);
// does also work for =*, ~ and : searches
search = "(''=* or ''~/.../) and type:way";
Expand Down
20 changes: 4 additions & 16 deletions tests/test.urlParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,9 @@ describe("urlParameters", () => {
// fetch area “Riga” to search in
{{geocodeArea:Riga}}->.searchArea;
// gather results
(
// query part for: “"addr:street"="Tālivalža iela"”
// nwr is short for node/way/relation
nwr["addr:street"="Tālivalža iela"](area.searchArea);
);
nwr["addr:street"="Tālivalža iela"](area.searchArea);
// print results
out body;
>;
out skel qt;`,
out geom;`,
has_coords: false,
has_zoom: false
});
Expand All @@ -141,15 +135,9 @@ The original search was:
*/
[out:json][timeout:25];
// gather results
(
// query part for: “name=foo”
// nwr is short for node/way/relation
nwr["name"="foo"]({{bbox}});
);
nwr["name"="foo"]({{bbox}});
// print results
out body;
>;
out skel qt;`
out geom;`
});
settings.saves = orig_ss;
});
Expand Down

0 comments on commit 8011da9

Please sign in to comment.