#!/usr/bin/env node
"use strict";
const assert = require("assert");
const { analyzeOsmPreflight, parseOsm } = require("./lib/area-diagnostics");
function osm({ bounds = '', nodes, ways, relations = "" }) {
return `${bounds}${nodes}${ways}${relations}`;
}
function nodes(ids) {
return ids.map((id) => ``).join("");
}
function way(id, refs, tags = '') {
return `${refs.map((ref) => ``).join("")}${tags}`;
}
function preflight(input) {
return analyzeOsmPreflight(parseOsm(input));
}
assert.equal(preflight(osm({ nodes: nodes([1, 2, 3]), ways: way(10, [1, 2, 3, 1]) })).errors.length, 0);
assert.match(preflight(osm({ bounds: "", nodes: nodes([1, 2, 3]), ways: way(10, [1, 2, 3, 1]) })).errors.join("\n"), /bounds/);
assert.match(preflight(osm({ bounds: '', nodes: nodes([1, 2, 3]), ways: way(10, [1, 2, 3, 1]) })).errors.join("\n"), /bounds/);
assert.match(preflight(osm({ nodes: nodes([1, 2, 3]), ways: way(10, [1, 2, 9, 1]) })).errors.join("\n"), /missing node/);
assert.match(preflight(osm({ nodes: nodes([1, 2, 3]), ways: way(10, [1, 2, 3, 2]) })).errors.join("\n"), /not closed/);
assert.match(preflight(osm({ nodes: nodes([1, 2, 3]), ways: way(10, [1, 2, 3, 1], '') })).errors.join("\n"), /height/);
assert.equal(preflight(osm({ nodes: nodes([1, 2, 3]), ways: '' })).errors.length, 0);
const brokenRelation = '';
assert.match(preflight(osm({ nodes: nodes([1, 2, 3]), ways: "", relations: brokenRelation })).errors.join("\n"), /Building relation 20/);
console.log("OSM preflight tests passed.");