Sample validation script and test file apropos an internal excel validation project.
Last active
August 29, 2015 14:06
-
-
Save joyrexus/7992b1c6527894074a74 to your computer and use it in GitHub Desktop.
sample validation script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var valid = require('valid'); | |
var assert = require('assert'); | |
var testLRB = function() { | |
assert(valid.LRB('') === true, "permit empty strings"); | |
assert(valid.LRB('X') === false, "only permit valid code chars"); | |
assert(valid.LRB('L') === true); | |
assert(valid.LRB(' L') === false, "check for spacing"); | |
assert(valid.LRB('LL') === false, "require prefix operators"); | |
assert(valid.LRB('L+L') === true, "permit multiple code chars"); | |
assert(valid.LRB('L+R') === true); | |
assert(valid.LRB('L+R+B') === true); | |
assert(valid.LRB('L+X') === false, "only permit valid code chars"); | |
assert(valid.LRB('X+L') === false, "only permit valid code chars"); | |
assert(valid.LRB('L + R') === false, "do not permit inline spacing"); | |
}; | |
// modify this for testing the next validation function | |
var testNextColumn = function() { | |
assert(valid.nextColumn('') === true); | |
}; | |
// run all tests here | |
var runTests = function() { | |
testLRB(); | |
testNextColumn(); | |
}; | |
runTests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.LRB = function(v) { | |
if (v) | |
return /^[LRB](?:\+[LRB])*$/.test(v); | |
else | |
return v === ''; | |
}; | |
module.exports.nextColumn = function(v) { | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment