Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/7992b1c6527894074a74 to your computer and use it in GitHub Desktop.
Save joyrexus/7992b1c6527894074a74 to your computer and use it in GitHub Desktop.
sample validation script
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()
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