Make ini parsing more robust

This commit is contained in:
Jordan Eldredge 2017-11-16 18:17:16 -08:00
parent c065036e87
commit 76cf5612ad
5 changed files with 58 additions and 2 deletions

View file

@ -422,3 +422,32 @@ Object {
],
}
`;
exports[`regionParser parses the iTuned region.txt 1`] = `
Object {
"equalizer": Array [
"5,0 269,0 269,116 5,116",
"3,1 5,1 5,115 3,115",
"2,2 4,2 4,114 2,114",
"1,3 4,3 4,113 1,113",
"0,5 5,5 5,111 0,111",
"267,1 271,1 271,115 267,115",
"267,2 272,2 272,114 267,114",
"267,3 273,3 273,113 267,113",
"267,4 274,4 274,112 267,112",
"267,6 275,6 275,111 267,111",
],
"normal": Array [
"5,0 269,0 269,116 5,116",
"3,1 5,1 5,115 3,115",
"2,2 4,2 4,114 2,114",
"1,3 4,3 4,113 1,113",
"0,5 5,5 5,111 0,111",
"267,1 271,1 271,115 267,115",
"267,2 272,2 272,114 267,114",
"267,3 273,3 273,113 267,113",
"267,4 274,4 274,112 267,112",
"267,6 275,6 275,111 267,111",
],
}
`;

View file

@ -0,0 +1,7 @@
[Normal]
NumPoints = 4,4,4,4,4,4,4,4,4,4
PointList = 5,0, 269,0, 269,116, 5,116, 3,1 5,1, 5,115, 3,115, 2,2, 4,2, 4,114, 2,114, 1,3, 4,3, 4,113, 1,113, 0,5, 5,5, 5,111, 0,111, 267,1, 271,1 271,115, 267,115, 267,2, 272,2, 272,114, 267,114, 267,3, 273,3, 273,113, 267,113, 267,4, 274,4, 274,112, 267,112, 267,6, 275,6, 275,111, 267,111,
[Equalizer]
NumPoints = 4,4,4,4,4,4,4,4,4,4
PointList = 5,0, 269,0, 269,116, 5,116, 3,1 5,1, 5,115, 3,115, 2,2, 4,2, 4,114, 2,114, 1,3, 4,3, 4,113, 1,113, 0,5, 5,5, 5,111, 0,111, 267,1, 271,1 271,115, 267,115, 267,2, 272,2, 272,114, 267,114, 267,3, 273,3, 273,113, 267,113, 267,4, 274,4, 274,112, 267,112, 267,6, 275,6, 275,111, 267,111,

View file

@ -38,4 +38,11 @@ describe("regionParser", () => {
);
expect(regionParser(regionTxt)).toMatchSnapshot();
});
it("parses the iTuned region.txt", () => {
const regionTxt = fs.readFileSync(
"./js/__tests__/fixtures/region_ituned.txt",
"utf8"
);
expect(regionParser(regionTxt)).toMatchSnapshot();
});
});

View file

@ -46,9 +46,9 @@ export const parseIni = text => {
let section, match;
return text.split(/[\r\n]+/g).reduce((data, line) => {
if ((match = line.match(PROPERTY_REGEX)) && section != null) {
data[section][match[1].toLowerCase()] = match[2];
data[section][match[1].trim().toLowerCase()] = match[2];
} else if ((match = line.match(SECTION_REGEX))) {
section = match[1].toLowerCase();
section = match[1].trim().toLowerCase();
data[section] = {};
}
return data;

View file

@ -129,6 +129,19 @@ describe("parseIni", () => {
};
expect(actual).toEqual(expected);
});
it("allows space around =", () => {
const actual = parseIni(`
[foo]
bar = baz
`);
const expected = {
foo: {
bar: "baz"
}
};
expect(actual).toEqual(expected);
});
});
test("normalize", () => {