Skip to content

Commit 877077b

Browse files
committed
add validate function for 'subplotid' val types
1 parent d304864 commit 877077b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/lib/coerce.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ exports.valObjects = {
177177
return;
178178
}
179179
propOut.set(dflt);
180+
},
181+
validateFunction: function(v, opts) {
182+
var dflt = opts.dflt,
183+
dlen = dflt.length;
184+
185+
if(v === dflt) return true;
186+
if(typeof v !== 'string') return false;
187+
if(v.substr(0, dlen) === dflt && idRegex.test(v.substr(dlen))) {
188+
return true;
189+
}
190+
191+
return false;
180192
}
181193
},
182194
flaglist: {

test/jasmine/tests/lib_test.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -938,14 +938,8 @@ describe('Test lib.js:', function() {
938938
});
939939

940940
it('should work for valType \'subplotid\' where', function() {
941-
var shouldPass = ['sp', 'sp1', 'sp4'],
942-
shouldFail = [{}, [], 'sp0', 'spee1', null, undefined];
943-
944-
// This fails because coerceFunction depends on dflt
945-
// having a length.
946-
//
947-
// Solution: don't use dflt as base string ->
948-
// add other options to valObject
941+
var shouldPass = ['sp', 'sp4', 'sp10'],
942+
shouldFail = [{}, [], 'sp1', 'sp0', 'spee1', null, undefined, true];
949943

950944
assert(shouldPass, shouldFail, {
951945
valType: 'subplotid',

0 commit comments

Comments
 (0)