Skip to content

Commit

Permalink
Positive and Negative RFC2822 testCases streamlined.
Browse files Browse the repository at this point in the history
  • Loading branch information
TracyGJG authored and ichernev committed Mar 12, 2017
1 parent 55583a7 commit e58c42b
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/test/moment/create.js
Expand Up @@ -457,27 +457,34 @@ test('cloning carrying over utc mode', function (assert) {
});

test('parsing RFC 2822', function (assert) {
assert.ok(moment('Tue, 01 Nov 2016 01:23:45 GMT', moment.RFC_2822, true).isValid(),
'clean RFC2822 datetime with all options');
assert.ok(moment('Tue 01 Nov 2016 01:23:45 GMT', moment.RFC_2822, true).isValid(),
'clean RFC2822 datetime without comma');
assert.ok(moment('Tue, 01 Nov 2016 01:23 GMT', moment.RFC_2822, true).isValid(),
'clean RFC2822 datetime without seconds');
assert.ok(moment('Tue, 01 Nov 16 01:23:45 GMT', moment.RFC_2822, true).isValid(),
'clean RFC2822 datetime without century');
assert.ok(moment('01 Nov 2016 01:23:45 GMT', moment.RFC_2822, true).isValid(),
'clean RFC2822 datetime without day');
assert.ok(moment('Tue, 1 Nov 2016 01:23:45 GMT', moment.RFC_2822, true).isValid(),
'clean RFC2822 datetime with single-digit day-of-month');
assert.ok(moment('(Init Comment) Tue,\n 1 Nov 2016 (Split\n Comment) 01:23:45 +0000 (GMT)', moment.RFC_2822, true).isValid(),
'RFC2822 datetime with CFWSs');
var testCases = {
'clean RFC2822 datetime with all options': 'Tue, 01 Nov 2016 01:23:45 GMT',
'clean RFC2822 datetime without comma': 'Tue 01 Nov 2016 01:23:45 GMT',
'clean RFC2822 datetime without seconds': 'Tue, 01 Nov 2016 01:23 GMT',
'clean RFC2822 datetime without century': 'Tue, 01 Nov 16 01:23:45 GMT',
'clean RFC2822 datetime without day': '01 Nov 2016 01:23:45 GMT',
'clean RFC2822 datetime with single-digit day-of-month': 'Tue, 1 Nov 2016 01:23:45 GMT',
'RFC2822 datetime with CFWSs': '(Init Comment) Tue,\n 1 Nov 2016 (Split\n Comment) 01:23:45 +0000 (GMT)'
};
var testCase;

for (testCase in testCases) {
var testResult = moment(testCases[testCase], moment.RFC_2822, true)
assert.ok(testResult.isValid(), testResult);
}
});

test('non RFC 2822 strings', function (assert) {
assert.ok(!moment('Tue. 01 Nov 2016 01:23:45 GMT', moment.RFC_2822, true).isValid(),
'RFC2822 datetime with all options but invalid day delimiter');
assert.ok(!moment('Mon, 01 Nov 2016 01:23:45 GMT', moment.RFC_2822, true).isValid(),
'RFC2822 datetime with mismatching Day (week v date)');
var testCases = {
'RFC2822 datetime with all options but invalid day delimiter': 'Tue. 01 Nov 2016 01:23:45 GMT',
'RFC2822 datetime with mismatching Day (week v date)': 'Mon, 01 Nov 2016 01:23:45 GMT'
};
var testCase;

for (testCase in testCases) {
var testResult = moment(testCases[testCase], moment.RFC_2822, true)
assert.ok(!testResult.isValid(), testResult);
}
});

test('parsing iso', function (assert) {
Expand Down

0 comments on commit e58c42b

Please sign in to comment.