diff --git a/js/__tests__/fixtures/PLEDIT.TXT b/js/__tests__/fixtures/PLEDIT.TXT new file mode 100644 index 00000000..a6120155 --- /dev/null +++ b/js/__tests__/fixtures/PLEDIT.TXT @@ -0,0 +1,6 @@ +[Text] +Normal=#00FF00 +Current=#FFFFFF +NormalBG=#000000 +SelectedBG=#0000FF +Font=Arial diff --git a/js/__tests__/fixtures/PLEDIT_TOPAZ.TXT b/js/__tests__/fixtures/PLEDIT_TOPAZ.TXT new file mode 100755 index 00000000..9046a031 --- /dev/null +++ b/js/__tests__/fixtures/PLEDIT_TOPAZ.TXT @@ -0,0 +1,8 @@ +[Text] +Normal=#319593 +Current=#89D8D1 +NormalBG=#000000 +SelectedBG=#2B4242 +Font=Arial +mbBG=#000000 +mbFG=#89D8D1 diff --git a/js/__tests__/fixtures/VISCOLOR.TXT b/js/__tests__/fixtures/VISCOLOR.TXT new file mode 100644 index 00000000..5871ad89 --- /dev/null +++ b/js/__tests__/fixtures/VISCOLOR.TXT @@ -0,0 +1,24 @@ +0,0,0, // color 0 = black +24,33,41, // color 1 = grey for dots +239,49,16, // color 2 = top of spec +206,41,16, // 3 +214,90,0, // 4 +214,102,0, // 5 +214,115,0, // 6 +198,123,8, // 7 +222,165,24, // 8 +214,181,33, // 9 +189,222,41, // 10 +148,222,33, // 11 +41,206,16, // 12 +50,190,16, // 13 +57,181,16, // 14 +49,156,8, // 15 +41,148,0, // 16 +24,132,8, // 17 = bottom of spec +255,255,255, // 18 = osc 1 +214,214,222, // 19 = osc 2 (slightly dimmer) +181,189,189, // 20 = osc 3 +160,170,175, // 21 = osc 4 +148,156,165, // 22 = osc 4 +150, 150, 150, // 23 = analyzer peak dots diff --git a/js/__tests__/utils-test.js b/js/__tests__/utils-test.js index c80da491..562d5f58 100644 --- a/js/__tests__/utils-test.js +++ b/js/__tests__/utils-test.js @@ -1,11 +1,19 @@ +import fs from 'fs'; + jest.unmock('../utils'); import { getTimeObj, getTimeStr, - clamp + clamp, + parseViscolors, + parseIni } from '../utils'; +const fixture = (filename) => ( + fs.readFileSync(`./js/__tests__/fixtures/${filename}`).toString() +); + describe('getTimeObj', () => { it('expresses seconds as an object', () => { const actual = getTimeObj(1234); @@ -54,3 +62,67 @@ describe('clamp', () => { expect(actual).toEqual(expected); }); }); + +describe('parseViscolors', () => { + it('can parse the default viscolors file', () => { + const viscolors = fixture('VISCOLOR.TXT'); + const actual = parseViscolors(viscolors); + const expected = [ + 'rgb(0,0,0)', + 'rgb(24,33,41)', + 'rgb(239,49,16)', + 'rgb(206,41,16)', + 'rgb(214,90,0)', + 'rgb(214,102,0)', + 'rgb(214,115,0)', + 'rgb(198,123,8)', + 'rgb(222,165,24)', + 'rgb(214,181,33)', + 'rgb(189,222,41)', + 'rgb(148,222,33)', + 'rgb(41,206,16)', + 'rgb(50,190,16)', + 'rgb(57,181,16)', + 'rgb(49,156,8)', + 'rgb(41,148,0)', + 'rgb(24,132,8)', + 'rgb(255,255,255)', + 'rgb(214,214,222)', + 'rgb(181,189,189)', + 'rgb(160,170,175)', + 'rgb(148,156,165)', + 'rgb(150,150,150)' + ]; + expect(actual).toEqual(expected); + }); +}); + +describe('parseIni', () => { + it('can parse the default pledit.txt file', () => { + const pledit = fixture('PLEDIT.TXT'); + const actual = parseIni(pledit); + const expected = { + Normal: '#00FF00', + Current: '#FFFFFF', + NormalBG: '#000000', + SelectedBG: '#0000FF', + Font: 'Arial' + }; + expect(actual).toEqual(expected); + }); + + it("can parse TopazAmp's pledit.txt file", () => { + const pledit = fixture('PLEDIT_TOPAZ.TXT'); + const actual = parseIni(pledit); + const expected = { + Normal: '#319593', + Current: '#89D8D1', + NormalBG: '#000000', + SelectedBG: '#2B4242', + Font: 'Arial', + mbBG: '#000000', + mbFG: '#89D8D1' + }; + expect(actual).toEqual(expected); + }); +}); diff --git a/js/utils.js b/js/utils.js index 92e5429f..020801a9 100644 --- a/js/utils.js +++ b/js/utils.js @@ -39,6 +39,19 @@ const parseViscolors = (text) => { return colors; }; +// Dumb ini parser that just gets all the key/value pairs +const parseIni = (text) => { + const lines = text.split(/[\r\n]+/g); + const data = {}; + lines.forEach((line) => { + if (line.includes('=')) { + const [key, value] = line.split('='); + data[key] = value; + } + }); + return data; +}; + const clamp = (value, min, max) => { return Math.min(Math.max(value, min), max); }; @@ -47,5 +60,6 @@ module.exports = { getTimeObj, getTimeStr, parseViscolors, + parseIni, clamp };