Skip to content
This repository has been archived by the owner on Jul 31, 2020. It is now read-only.

Commit

Permalink
tests can now run in both browser spec runner and gulp test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Elliott committed Nov 30, 2015
1 parent b48b8b8 commit 2ac316c
Show file tree
Hide file tree
Showing 33 changed files with 235 additions and 148 deletions.
9 changes: 9 additions & 0 deletions gulpfile.js
@@ -0,0 +1,9 @@
var gulp = require('gulp');
var jasmine = require('gulp-jasmine');
var Specification = require('./test/scripts/specification-converter.js');


gulp.task('default', function () {
gulp.src(['src/globalization/en-US.js','src/core.js','src/sugarpak.js','src/parser.js','src/time.js','test/core/index.js'])
.pipe(jasmine());
});
3 changes: 3 additions & 0 deletions test/core/index.html
Expand Up @@ -23,6 +23,9 @@

<!-- Test Cases -->
<script type='text/javascript' src='index.js'></script>
<script type='text/javascript'>
$(document).ready(function() { Date.Specification.validate().show() });
</script>
</head>

<body>
Expand Down
12 changes: 8 additions & 4 deletions test/core/index.js
@@ -1,4 +1,10 @@
Date.Specification = new Specification({

if(typeof require !== 'undefined') {
var Specification = require('../scripts/specification-converter.js');
}


new Specification({
'Exception Handling': {
setup: function() {},
'Date.parse() : No params': {
Expand Down Expand Up @@ -1371,6 +1377,4 @@

}

});

$(document).ready(function() { Date.Specification.validate().show() });
});
3 changes: 3 additions & 0 deletions test/culture_info/index.html
Expand Up @@ -22,6 +22,9 @@

<!-- Test Cases -->
<script type='text/javascript' src='index.js'></script>
<script type='text/javascript'>
$(document).ready(function() { Date.Specification.validate().show() });
</script>
</head>

<body>
Expand Down
1 change: 0 additions & 1 deletion test/culture_info/index.js
Expand Up @@ -8,4 +8,3 @@
}
});

$(document).ready( function() { Date.Specification.validate().show() } );
4 changes: 4 additions & 0 deletions test/date/index.html
Expand Up @@ -22,6 +22,10 @@

<!-- Test Cases -->
<script type='text/javascript' src='index.js'></script>

<script type='text/javascript'>
$(document).ready(function() { Date.Specification.validate().show() });
</script>
</head>

<body>
Expand Down
30 changes: 19 additions & 11 deletions test/date/index.js
Expand Up @@ -383,14 +383,7 @@
run: function() { this.date = Date.parse('07012004') },
assert: function() { return this.baseline.equals( this.date ) }
},
'712004': {
run: function() { this.date = Date.parse('712004') },
assert: function() { return this.baseline.equals( this.date ) }
},
'7104': {
run: function() { this.date = Date.parse('7104', { format : "Mdyy" } ) },
assert: function() { return this.baseline.equals( this.date ) }
},


'07152004': {
run: function() { this.date = Date.parse('07152004') },
Expand All @@ -400,11 +393,26 @@
run: function() { this.date = Date.parse('7152004') },
assert: function() { return this.baseline2.equals( this.date ) }
},
},

'Fail' : {
setup: function() {
this.baseline = new Date(2004,6,1);
this.baseline2 = new Date(2004,6,15);
},
'712004': {
run: function() { this.date = Date.parse('712004') },
assert: function() { return this.baseline.equals( this.date ) }
},
'7104': {
run: function() { this.date = Date.parse('7104', { format : "Mdyy" } ) },
assert: function() { return this.baseline.equals( this.date ) }
},

'71504': {
run: function() { this.date = Date.parse('71504', { format : "Mdyy" } ) },
assert: function() { return this.baseline2.equals( this.date ) }
}
}
},
}
});

$(document).ready( function() { Date.Specification.validate().show() } );
1 change: 0 additions & 1 deletion test/date2/index.html
Expand Up @@ -9,7 +9,6 @@
<!-- Datejs -->
<script type='text/javascript' src='date2.js'></script>
<script type='text/javascript' src='../../src/globalization/en-US.js'></script>

</head>
<body>
<h1>Date2 Experiment</h1>
Expand Down
4 changes: 4 additions & 0 deletions test/date_and_time/index.html
Expand Up @@ -22,6 +22,10 @@

<!-- Test Cases -->
<script type='text/javascript' src='index.js'></script>

<script type='text/javascript'>
$(document).ready(function() { Date.Specification.validate().show() });
</script>
</head>

<body>
Expand Down
188 changes: 96 additions & 92 deletions test/date_and_time/index.js
Expand Up @@ -23,95 +23,95 @@
}
},

'Standard Patterns': {
setup: function() {
this.today = new Date().clearTime();
this.baseline = new Date(2004,6,1,22,30,0);
this.baseline2 = new Date(2004,6,15,6,45,0);
},

'2004, July 01, 10:30:00 PM : FullDateTimePattern [dddd, MMMM dd, yyyy h:mm:ss tt]': {
run: function() { this.date = Date.parse('2004, July 01, 10:30:00 PM') },
assert: function() { return this.baseline.equals( this.date ) }
},
'2004, July 15, 6:45:00 AM : FullDateTimePattern [dddd, MMMM dd, yyyy h:mm:ss tt]': {
run: function() { this.date = Date.parse('2004, July 15, 6:45:00 AM') },
assert: function() { return this.baseline2.equals( this.date ) }
},


'Thursday, July 01, 2004 : LongDatePattern [dddd, MMMM dd, yyyy]': {
run: function() { this.date = Date.parse('Thursday, July 01, 2004') },
assert: function() { return this.baseline.clearTime().equals( this.date ) }
},
'Thursday, July 15, 2004 : LongDatePattern [dddd, MMMM dd, yyyy]': {
run: function() { this.date = Date.parse('Thursday, July 15, 2004') },
assert: function() { return this.baseline2.clearTime().equals( this.date ) }
},


'10:30:00 PM : LongTimePattern [h:mm:ss tt]': {
run: function() { this.date = Date.parse('10:30:00 PM') },
assert: function() { return this.today.clone().set( { hour: 22, minute: 30 } ).equals( this.date ) }
},
'6:45:00 AM : LongTimePattern [h:mm:ss tt]': {
run: function() { this.date = Date.parse('6:45:00 AM') },
assert: function() { return this.today.clone().set( { hour: 6, minute: 45 } ).equals( this.date ) }
},


'July 01 : MonthDayPattern [MMMM dd]': {
run: function() { this.date = Date.parse('July 01') },
assert: function() { return this.today.clone().set( { month: 6, day: 1 } ).equals( this.date ) }
},
'July 15 : MonthDayPattern [MMMM dd]': {
run: function() { this.date = Date.parse('July 15') },
assert: function() { return Date.today().set( { month: 6, day: 15 } ).equals( this.date ) }
},
'July 2004 : YearMonthPattern [MMMM, yyyy]': {
run: function() { this.date = Date.parse('July 2004') },
assert: function() { return new Date(2004,6,1).equals( this.date ) }
},
'7/1/2004 : ShortDatePattern [M/d/yyyy]': {
run: function() { this.date = Date.parse('7/1/2004') },
assert: function() { return this.baseline.clearTime().equals( this.date ) }
},
'7/15/2004 : ShortDatePattern [M/d/yyyy]': {
run: function() { this.date = Date.parse('7/15/2004') },
assert: function() { return this.baseline2.clearTime().equals( this.date ) }
},
'10:30 PM : ShortTimePattern [h:mm tt]': {
run: function() { this.date = Date.parse('10:30 PM') },
assert: function() { return this.today.clone().set( { hour: 22, minute: 30 } ).equals( this.date ) }
},
'6:45 AM : ShortTimePattern [h:mm tt]': {
run: function() { this.date = Date.parse('6:45 AM') },
assert: function() { return this.today.clone().set( { hour: 6, minute: 45 } ).equals( this.date ) }
},

'2004-07-01T22:30:00 : SortableDateTimePattern [yyyy-MM-ddTHH:mm:ss]': {
run: function() { this.date = Date.parse('2004-07-01T22:30:00') },
assert: function() { return this.baseline.equals( this.date ) }
},
'2004-07-15T06:45:00 : SortableDateTimePattern [yyyy-MM-ddTHH:mm:ss]': {
run: function() { this.date = Date.parse('2004-07-15T06:45:00') },
assert: function() { return this.baseline2.equals( this.date ) }
},
'11 Aug 2007 7:15:00 am EDT': {
run: function() { this.date = Date.parse('11 Aug 2007 7:15:00 am EDT') },
assert: function() { return new Date(2007,7,11,7,15,0).add(-2).hours().equals( this.date ) }
},
'Tue Nov 20 2007 08:00:00 UTC': {
run: function() { this.date = Date.parse("Tue Nov 20 2007 08:00:00 UTC") },
assert: function() { return new Date(2007,10,20,8,0,0).setTimezone("UTC").equals( this.date ) }
},
'24 Apr 2008 17:00': {
run: function() { this.date = Date.parse("24 Apr 2008 17:00") },
assert: function() { return new Date(2008,3,24,17,0,0).equals( this.date ) }
},
'24 April 2008 17:00': {
run: function() { this.date = Date.parse("24 April 2008 17:00") },
assert: function() { return new Date(2008,3,24,17,0,0).equals( this.date ) }
'Standard Patterns': {
setup: function() {
this.today = new Date().clearTime();
this.baseline = new Date(2004,6,1,22,30,0);
this.baseline2 = new Date(2004,6,15,6,45,0);
},

'2004, July 01, 10:30:00 PM : FullDateTimePattern [dddd, MMMM dd, yyyy h:mm:ss tt]': {
run: function() { this.date = Date.parse('2004, July 01, 10:30:00 PM') },
assert: function() { return this.baseline.equals( this.date ) }
},
'2004, July 15, 6:45:00 AM : FullDateTimePattern [dddd, MMMM dd, yyyy h:mm:ss tt]': {
run: function() { this.date = Date.parse('2004, July 15, 6:45:00 AM') },
assert: function() { return this.baseline2.equals( this.date ) }
},


'Thursday, July 01, 2004 : LongDatePattern [dddd, MMMM dd, yyyy]': {
run: function() { this.date = Date.parse('Thursday, July 01, 2004') },
assert: function() { return this.baseline.clearTime().equals( this.date ) }
},
'Thursday, July 15, 2004 : LongDatePattern [dddd, MMMM dd, yyyy]': {
run: function() { this.date = Date.parse('Thursday, July 15, 2004') },
assert: function() { return this.baseline2.clearTime().equals( this.date ) }
},


'10:30:00 PM : LongTimePattern [h:mm:ss tt]': {
run: function() { this.date = Date.parse('10:30:00 PM') },
assert: function() { return this.today.clone().set( { hour: 22, minute: 30 } ).equals( this.date ) }
},
'6:45:00 AM : LongTimePattern [h:mm:ss tt]': {
run: function() { this.date = Date.parse('6:45:00 AM') },
assert: function() { return this.today.clone().set( { hour: 6, minute: 45 } ).equals( this.date ) }
},


'July 01 : MonthDayPattern [MMMM dd]': {
run: function() { this.date = Date.parse('July 01') },
assert: function() { return this.today.clone().set( { month: 6, day: 1 } ).equals( this.date ) }
},
'July 15 : MonthDayPattern [MMMM dd]': {
run: function() { this.date = Date.parse('July 15') },
assert: function() { return Date.today().set( { month: 6, day: 15 } ).equals( this.date ) }
},
'July 2004 : YearMonthPattern [MMMM, yyyy]': {
run: function() { this.date = Date.parse('July 2004') },
assert: function() { return new Date(2004,6,1).equals( this.date ) }
},
'7/1/2004 : ShortDatePattern [M/d/yyyy]': {
run: function() { this.date = Date.parse('7/1/2004') },
assert: function() { return this.baseline.clearTime().equals( this.date ) }
},
'7/15/2004 : ShortDatePattern [M/d/yyyy]': {
run: function() { this.date = Date.parse('7/15/2004') },
assert: function() { return this.baseline2.clearTime().equals( this.date ) }
},
'10:30 PM : ShortTimePattern [h:mm tt]': {
run: function() { this.date = Date.parse('10:30 PM') },
assert: function() { return this.today.clone().set( { hour: 22, minute: 30 } ).equals( this.date ) }
},
'6:45 AM : ShortTimePattern [h:mm tt]': {
run: function() { this.date = Date.parse('6:45 AM') },
assert: function() { return this.today.clone().set( { hour: 6, minute: 45 } ).equals( this.date ) }
},

'2004-07-01T22:30:00 : SortableDateTimePattern [yyyy-MM-ddTHH:mm:ss]': {
run: function() { this.date = Date.parse('2004-07-01T22:30:00') },
assert: function() { return this.baseline.equals( this.date ) }
},
'2004-07-15T06:45:00 : SortableDateTimePattern [yyyy-MM-ddTHH:mm:ss]': {
run: function() { this.date = Date.parse('2004-07-15T06:45:00') },
assert: function() { return this.baseline2.equals( this.date ) }
},
'11 Aug 2007 7:15:00 am EDT': {
run: function() { this.date = Date.parse('11 Aug 2007 7:15:00 am EDT') },
assert: function() { return new Date(2007,7,11,7,15,0).setTimezone('EDT').equals( this.date ) }
},
'Tue Nov 20 2007 08:00:00 UTC': {
run: function() { this.date = Date.parse("Tue Nov 20 2007 08:00:00 UTC") },
assert: function() { return new Date(2007,10,20,8,0,0).setTimezone("UTC").equals( this.date ) }
},
'24 Apr 2008 17:00': {
run: function() { this.date = Date.parse("24 Apr 2008 17:00") },
assert: function() { return new Date(2008,3,24,17,0,0).equals( this.date ) }
},
'24 April 2008 17:00': {
run: function() { this.date = Date.parse("24 April 2008 17:00") },
assert: function() { return new Date(2008,3,24,17,0,0).equals( this.date ) }
}
},

Expand Down Expand Up @@ -701,11 +701,16 @@
run: function() { },
assert: function() { return new Date(1997,6,16,19,20,30).setTimezoneOffset('+0100').equals( Date.parseExact('1997-07-16T19:20:30+01:00', "yyyy-MM-ddTHH:mm:ssz") ) }
},
},

'Fail': {
'1997-07-16T19:20:30.45+01:00 : "YYYY-MM-DDThh:mm:ss.sTZD"': {
run: function() { },
assert: function() { return new Date(1997,6,16,19,20,30,45).setTimezoneOffset('+0100').equals( Date.parse('1997-07-16T19:20:30.45+01:00') ) }
assert: function() {
return new Date(1997,6,16,19,20,30,45).setTimezoneOffset('+0100').equals( Date.parse('1997-07-16T19:20:30.45+01:00') )
}
}
},
},

'RFC 3339 Formats': {
setup: function() {
Expand Down Expand Up @@ -737,4 +742,3 @@
}
});

$(document).ready( function() { Date.Specification.validate().show() });
4 changes: 4 additions & 0 deletions test/date_math/index.html
Expand Up @@ -22,6 +22,10 @@

<!-- Test Cases -->
<script type='text/javascript' src='index.js'></script>

<script type='text/javascript'>
$(document).ready(function() { Date.Specification.validate().show() });
</script>
</head>

<body>
Expand Down
4 changes: 1 addition & 3 deletions test/date_math/index.js
Expand Up @@ -852,7 +852,5 @@
run: function() { },
assert: function() { return this.today.add(-5).weeks().equals( Date.parse('-5 Weeks') ) }
}
}
}
});

$(document).ready( function() { Date.Specification.validate().show() } );
4 changes: 4 additions & 0 deletions test/dst/index.html
Expand Up @@ -23,6 +23,10 @@

<!-- Test Cases -->
<script type='text/javascript' src='index.js'></script>

<script type='text/javascript'>
$(document).ready(function() { Date.Specification.validate().show() });
</script>
</head>

<body>
Expand Down
9 changes: 5 additions & 4 deletions test/dst/index.js
Expand Up @@ -7,14 +7,15 @@ Date.Specification = new Specification({
return new Date(2007,2,11,1,59,59).addSeconds(1).equals(new Date(2007,2,11,3,0,0));
}
},
'11/4/2007 1:59:59 + 1 second = 11/4/2007 1:00:00': {
},
'Fail': {
'11/4/2007 1:59:59 + 1 second = 11/4/2007 1:00:00': {
run: function() { },
assert: function() {
return new Date(2007,10,4,1,59,59).addSeconds(1).equals(new Date(2007,10,4,1,0,0));
}
}
}
},
}

});

$(document).ready( function() { Date.Specification.validate().show() } );

0 comments on commit 2ac316c

Please sign in to comment.