Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = class Options {

let parsed = this.parseZoom(str);

let matches = str.match(/(G(PK|PU|BK|GY|BN|[WKEARGBYPCNOI]|~[0-9A-F]{6}|~[0-9A-F]{3}))|[DEFN]|[CHW][0-9]*|[BZ][0-9\.]*|[O][0-9]+:[0-9]+/ig);
let matches = str.match(/(G(PK|PU|BK|GY|BN|[WKEARGBYPCNOI]|~[0-9A-F]{6}|~[0-9A-F]{3}))|[DEFN]|H[0-9]*|C[0-9]{2,3}(\.[0-9])?|[BZ][0-9\.]*|[O][0-9]+:[0-9]+/ig);

if (!matches)
return parsed;
Expand All @@ -52,9 +52,9 @@ module.exports = class Options {
break;

case 'c':
let size = parseInt(match.substring(1), 10);
let size = parseFloat(match.substring(1));
if (size < 20) size = 20;
if (size > 100) size = 100;
if (size > 200) size = 200;
this._cellSize = size;
break;

Expand Down
49 changes: 49 additions & 0 deletions test/unit/parsers/gridsize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,52 @@ test('parsing 3', (t) => {
t.same(options.cellSizePx, 120 );
t.end();
});

test('supports single precision float', (t) => {
const options = new Options();
const result = options.parseOptions('@c60.1');

t.same(result, true);
t.same(options.cellSizePx, 60.1 );
t.end();
});

test('ignores additional precision in float', (t) => {
const options = new Options();
const result = options.parseOptions('@c60.2345');

t.same(result, true);
t.same(options.cellSizePx, 60.2 );
t.end();
});

test('supports sizes up to 200', (t) => {
const options = new Options();
const result = options.parseOptions('@c200');

t.same(result, true);
t.same(options.cellSizePx, 200 );
t.end();
});

test('clips sizes over 200 to 200', (t) => {
const options = new Options();
const result = options.parseOptions('@c201');

t.same(result, true);
t.same(options.cellSizePx, 200 );
t.end();
});

test('handles floats with other settings', (t) => {
const options = new Options();
const result = options.parseOptions('@z2dnc60.9o13:12');

t.same(result, true);
t.same(options.cellSizePx, 121.8 );
t.same(options.zoom, 2 );
t.same(options.darkMode, true );
t.same(options.background.offsetX, 13 );
t.same(options.background.offsetY, 12 );
t.end();
});