Skip to content

Commit

Permalink
tiny fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
bronson committed Sep 20, 2011
1 parent 49aa734 commit ec2d87d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -7,6 +7,10 @@
- Good test coverage.


# TODO

- test? valid? check? Could these names be more generic?

### Declarative

var inRange = Valid.number().min(4).max(9)
Expand Down
15 changes: 8 additions & 7 deletions lib/valid-engine.js
Expand Up @@ -41,6 +41,7 @@ Valid.SimpleTest = function SimpleTest(fn) {
};
};

// Run all the tests in the given queue
Valid.ValidateQueue = function ValidateQueue(queue, value) {
if(!queue || queue.length < 1) return "no tests!";
for(var i=0; i<queue.length; i++) {
Expand All @@ -50,14 +51,13 @@ Valid.ValidateQueue = function ValidateQueue(queue, value) {
};

Valid.Escape = function Escape(value) {
// todo: escape \n, \t, \\, \' and \" in the printed strings?
if(typeof value == 'string') return "'" + value.substring(0,20) + "'";
// todo: escape \n, \t, \\, \' and \" in the printed strings
if(typeof value === 'string') return "'" + value.substring(0,20) + "'";
return value;
}
};


// core api
// TODO: test? check? verify? these names suck.

// returns null if valid, the error string if invalid
Valid.test = function test(value) {
Expand All @@ -76,10 +76,11 @@ Valid.verify = function assert(value) {
if(message) throw value + " " + message;
};

// Allows you to reuse a chain as as a chainable test. If you get the error
// Allows you to reuse a chain as as a chainable test:
// Valid.isFour = Valid.equal(4).define(); // define the isFour test
// Valid.isFour().test(4); // success!
// If you get this error then you forgot to call define() on your chain:
// Property 'myfunc' of object function Valid() { } is not a function
// then you forgot to call define().
//
// It's really shameful that this function needs to exist.
// In an ideal world you could just do this: Valid.null() = Valid.equal(null);
// In our world, that only works if you don't call it: Valid.null.verify(1); Ugh.
Expand Down

0 comments on commit ec2d87d

Please sign in to comment.