Allow region.txt to have leading ,s

This commit is contained in:
Jordan Eldredge 2017-11-16 18:36:44 -08:00
parent d86f20705c
commit 445f5c557f
4 changed files with 44 additions and 3 deletions

View file

@ -409,6 +409,23 @@ Object {
}
`;
exports[`regionParser parses a region.txt where the points have leading commas 1`] = `
Object {
"equalizer": Array [
"5,0 3,1 2,2 1,3 0,5 0,116 275,116 275,6 274,3 273,2 272,1 270,0",
],
"equalizerws": Array [
"5,0 3,1 2,2 1,3 0,5 0,14 275,14 275,6 274,3 273,2 272,1 270,0",
],
"normal": Array [
"5,0 3,1 2,2 1,3 0,5 0,116 275,116 275,6 274,3 273,2 272,1 270,0",
],
"windowshade": Array [
"5,0 3,1 2,2 1,3 0,5 0,14 275,14 275,6 274,3 273,2 272,1 270,0",
],
}
`;
exports[`regionParser parses the EVAunit region.txt 1`] = `
Object {
"equalizer": Array [

View file

@ -0,0 +1,15 @@
[Normal]
NumPoints=12
PointList=,5,0, 3,1, 2,2 1,3, 0,5, 0,116, 275,116, 275,6, 274,3, 273,2 272,1, 270,0
[EQUALIZER]
NumPoints=12
PointList=,5,0, 3,1, 2,2 1,3, 0,5, 0,116, 275,116, 275,6, 274,3, 273,2 272,1, 270,0
[WindowShade]
NumPoints=12
PointList=,5,0, 3,1, 2,2 1,3, 0,5, 0,14, 275,14, 275,6, 274,3, 273,2 272,1, 270,0
[EqualizerWS]
NumPoints=12
PointList=,5,0, 3,1, 2,2 1,3, 0,5, 0,14, 275,14, 275,6, 274,3, 273,2 272,1, 270,0

View file

@ -16,9 +16,11 @@ export default function regionParser(regionStr) {
if (!numpoints || !pointlist) {
return;
}
const pointCounts = numpoints.split(/\s*,\s*/);
// points can be separated by spaces, or by commas
const points = pointPairs(pointlist.split(/\s*[, ]\s*/));
const pointCounts = numpoints.split(/\s*,\s*/).filter(val => val !== "");
const points = pointPairs(
// points can be separated by spaces, or by commas
pointlist.split(/\s*[, ]\s*/).filter(val => val !== "")
);
let pointIndex = 0;
const polygons = pointCounts.map(numStr => {
const num = Number(numStr);

View file

@ -45,4 +45,11 @@ describe("regionParser", () => {
);
expect(regionParser(regionTxt)).toMatchSnapshot();
});
it("parses a region.txt where the points have leading commas", () => {
const regionTxt = fs.readFileSync(
"./js/__tests__/fixtures/region_leading_comma.txt",
"utf8"
);
expect(regionParser(regionTxt)).toMatchSnapshot();
});
});