Permalink
Browse files

tests for am/pm

  • Loading branch information...
1 parent c112560 commit dca14224efd328e82952349c7dbe7917eb833b83 @zackdever committed Sep 18, 2012
Showing with 32 additions and 0 deletions.
  1. +32 −0 test/time.test.js
View
@@ -5,6 +5,19 @@ var hours=[], minutes=[], periods=[];
for (var i = 1; i < 13; i++) hours.push(i.toString());
for (var i = 0; i < 60; i++) minutes.push(('0' + i).slice(-2));
+var seed = ['pm', 'p', 'p.m.', 'pm.', 'p.m'];
+for (var i=0; i<seed.length; i++) {
+ var s = seed[i];
+ periods.push(s);
+ periods.push(s.toUpperCase());
+ periods.push(s.replace('m', 'M'));
+ periods.push(s.replace('p', 'P'));
+ periods.push(s.replace('p', 'a'));
+ periods.push(s.toUpperCase());
+ periods.push(s.toUpperCase().replace('M', 'm'));
+ periods.push(s.replace('a', 'A'));
+}
+
describe('Time', function() {
describe('constructor', function() {
it('should work without using `new`', function() {
@@ -61,6 +74,25 @@ describe('Time', function() {
}
};
});
+
+ it('should pass with lower and upper case period', function() {
+ time('8 PM').isValid().should.be.ok;
+ time('8:20PM').isValid().should.be.ok;
+ time('8:20pM').isValid().should.be.ok;
+ time('8:20 pm').isValid().should.be.ok;
+ time('8:20 p.m.').isValid().should.be.ok;
+
+ for (var i = 0; i < periods.lengh; i++) {
+ time('1:23 ' + period[i]).isValid().should.be.ok;
+ time.isValid('1:23 ' + period[i]).should.be.ok;
+ }
+ });
+
+ it('should fail if just given a period with no time', function() {
+ time('PM').isValid().should.not.be.ok;
+ time('a.m.').isValid().should.not.be.ok;
+ time.isValid(' a.m.').should.not.be.ok;
+ });
});
describe('#isValid', function() {

0 comments on commit dca1422

Please sign in to comment.