Skip to content

Commit

Permalink
Expand date validation tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Nov 29, 2023
1 parent bef5376 commit beb9578
Showing 1 changed file with 49 additions and 6 deletions.
55 changes: 49 additions & 6 deletions test/20-dateRegex.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,64 @@ chai.should();
import * as vc from '../lib/index.js';

describe('verifies RFC3339 Dates', function() {
it('verify a valid date', function() {
it('should verify a valid date', function() {
const latest = new Date().toISOString();
vc.dateRegex.test(latest).should.be.true;
});
it('verify a valid date with lowercase t', function() {
const latest = new Date().toISOString().toLowerCase();
vc.dateRegex.test(latest).should.be.true;
it('should verify a date with lowercase time designator', function() {
const valid = '2019-03-26t14:00Z';
vc.dateRegex.test(valid).should.be.true;
});

it('should not verify an invalid date', function() {
it('should verify a date with lowercase UTC designator', function() {
const valid = '2019-03-26T14:00z';
vc.dateRegex.test(valid).should.be.true;
});
it('should not verify a date that uses / as a separator', function() {
const invalid = '2017/09/27';
vc.dateRegex.test(invalid).should.be.false;
});
it('should not verify 2 digit years', function() {
const invalid = '17-09-27T22:07:22.563z';
vc.dateRegex.test(invalid).should.be.false;
});
it('should not verify 1 digit months', function() {
const invalid = '2017-9-27T22:07:22.563z';
vc.dateRegex.test(invalid).should.be.false;
});
it('should verify 2 digit months starting with 0', function() {
const valid = '2017-09-27T22:07:22.563z';
vc.dateRegex.test(valid).should.be.true;
});
it('should not verify 1 digit days', function() {
const invalid = '2017-9-7T22:07:22.563z';
vc.dateRegex.test(invalid).should.be.false;
});
it('should verify 2 digit days starting with 0', function() {
const valid = '2017-12-07T22:07:22.563z';
vc.dateRegex.test(valid).should.be.true;
});
it('should not verify comma separators', function() {
const invalid = '2019-03-26T14:00:00,999Z';
vc.dateRegex.test(invalid).should.be.false;
});
it('should not verify an ISO 8601 date with hours only offset', function() {
const invalid = '2019-03-26T10:00-04';
vc.dateRegex.test(invalid).should.be.false;
});
it('should not verify an ISO 8601 date with fractional minutes', function() {
const invalid = '2019-03-26T14:00.9Z';
vc.dateRegex.test(invalid).should.be.false;
});
it('should verify leap seconds', function() {
const valid = '1972-06-30T23:59:60Z';
vc.dateRegex.test(valid).should.be.true;
});
it('should verify single digit fractional seconds', function() {
const valid = '2019-03-26T14:00:00.9Z';
vc.dateRegex.test(valid).should.be.true;
});
it('should verify multi-digit fractional seconds', function() {
const valid = '2019-03-26T14:00:00.4999Z';
vc.dateRegex.test(valid).should.be.true;
});
});

0 comments on commit beb9578

Please sign in to comment.