Skip to content

Commit

Permalink
fix arguments error handling message. fixes benjamminf#17
Browse files Browse the repository at this point in the history
  • Loading branch information
bgmort committed Oct 23, 2020
1 parent 54d982c commit 7c542c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/path/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function parser(pathString)

let segmentMatch
segmentExpr.lastIndex = 0

while( (segmentMatch = segmentExpr.exec(pathString)) )
{
const type = segmentMatch[1].toLowerCase()
Expand All @@ -20,7 +20,7 @@ export default function parser(pathString)

if(numbers.length < schema.length)
{
throw new Error(`Malformed path data: type "${type}" has ${numbers.length} arguments, expected ${scheme.length}`)
throw new Error(`Malformed path data: type "${type}" has ${numbers.length} arguments, expected ${schema.length}`)
}

if(schema.length > 0)
Expand Down
16 changes: 15 additions & 1 deletion test/path/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('parser()', function()
{
assert.deepEqual([], parser(' '))
})

it('should parse space separated path string', function()
{
assert.deepEqual([
Expand Down Expand Up @@ -66,4 +66,18 @@ describe('parser()', function()
{ type: 'z', relative: false },
], parser('M 0,1 L 2,3 Z'))
})

it('should detect too few arguments', function()
{
assert.throws(() => {
parser('A 110 110 0 0')
}, {message: /Malformed path data/})
})

it('should detect too many arguments', function()
{
assert.throws(() => {
parser('a 110 110 0 0 1 55 -7 42')
}, {message: /Malformed path data/})
})
})

0 comments on commit 7c542c1

Please sign in to comment.