mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-28 12:36:35 +00:00
Add ini parser and parseviscolor tests
This commit is contained in:
parent
7045fdeb75
commit
cd5f77e44c
5 changed files with 125 additions and 1 deletions
6
js/__tests__/fixtures/PLEDIT.TXT
Normal file
6
js/__tests__/fixtures/PLEDIT.TXT
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[Text]
|
||||
Normal=#00FF00
|
||||
Current=#FFFFFF
|
||||
NormalBG=#000000
|
||||
SelectedBG=#0000FF
|
||||
Font=Arial
|
||||
8
js/__tests__/fixtures/PLEDIT_TOPAZ.TXT
Executable file
8
js/__tests__/fixtures/PLEDIT_TOPAZ.TXT
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
[Text]
|
||||
Normal=#319593
|
||||
Current=#89D8D1
|
||||
NormalBG=#000000
|
||||
SelectedBG=#2B4242
|
||||
Font=Arial
|
||||
mbBG=#000000
|
||||
mbFG=#89D8D1
|
||||
24
js/__tests__/fixtures/VISCOLOR.TXT
Normal file
24
js/__tests__/fixtures/VISCOLOR.TXT
Normal file
|
|
@ -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
|
||||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
14
js/utils.js
14
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
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue