Skip to content

Commit

Permalink
more edgecase checks
Browse files Browse the repository at this point in the history
  • Loading branch information
KoryNunn committed Dec 2, 2013
1 parent f45b978 commit 2b2a940
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
10 changes: 6 additions & 4 deletions paths.js
Expand Up @@ -141,12 +141,14 @@ function createRootPath(){
}

function pathToParts(path){
if(!path && typeof path !== 'string'){
var pathType = typeof path;

if(pathType !== 'string' && pathType !== 'number'){
if(Array.isArray(path)){
return path;
}
return;
}
if(Array.isArray(path)){
return path;
}

// if we haven't been passed a path, then turn the input into a path
if (!isPath(path)) {
Expand Down
28 changes: 25 additions & 3 deletions test/all.js
Expand Up @@ -208,7 +208,7 @@ test('bubble capturing path with bubble capture as only child key', function(t)
);
});

test('to parts', function(t) {
test('to parts valid path', function(t) {
var path = '[a/b/c]'

t.plan(1);
Expand All @@ -219,7 +219,7 @@ test('to parts', function(t) {
);
});

test('to parts', function(t) {
test('to parts valid key', function(t) {
var path = 'a';

t.plan(1);
Expand All @@ -230,7 +230,7 @@ test('to parts', function(t) {
);
});

test('to parts', function(t) {
test('to parts invalid key', function(t) {
var path = 'a[b]';

t.plan(1);
Expand All @@ -239,4 +239,26 @@ test('to parts', function(t) {
paths.toParts(path),
'no valid path'
);
});

test('to parts boolean', function(t) {
var path = true;

t.plan(1);

t.notOk(
paths.toParts(path),
'true is not a path'
);
});

test('to parts boolean', function(t) {
var path = false;

t.plan(1);

t.notOk(
paths.toParts(path),
'false is not a path'
);
});

0 comments on commit 2b2a940

Please sign in to comment.