jenkins-bot has submitted this change and it was merged.
Change subject: [time.js] Constructor tests for time.Time and introduction of
time.validTimeDefinitions
......................................................................
[time.js] Constructor tests for time.Time and introduction of
time.validTimeDefinitions
* making use of time.validTimeDefinitions in new test but also in
time.Time.validate test now.
Change-Id: I8ceda8dd9b5a5340766c64b9b0a1ab4744669003
---
M DataValues/DataValues.resources.php
M DataValues/DataValues.tests.qunit.php
A DataValues/resources/time.js/tests/time.Time.tests.js
M DataValues/resources/time.js/tests/time.Time.validate.tests.js
A DataValues/resources/time.js/tests/time.validTimeDefinitions.js
5 files changed, 147 insertions(+), 50 deletions(-)
Approvals:
Henning Snater: Looks good to me, approved
jenkins-bot: Verified
diff --git a/DataValues/DataValues.resources.php
b/DataValues/DataValues.resources.php
index b4038df..f751c69 100644
--- a/DataValues/DataValues.resources.php
+++ b/DataValues/DataValues.resources.php
@@ -95,7 +95,16 @@
),
'dependencies' => array(
'jquery',
- )
+ ),
+ ),
+
+ 'time.js.validTimeDefinitions' => $moduleTemplate + array(
+ 'scripts' => array(
+ 'time.js/tests/time.validTimeDefinitions.js' //
example times for testing purposes
+ ),
+ 'dependencies' => array(
+ 'time.js',
+ ),
),
// qunit-parameterize from
https://github.com/AStepaniuk/qunit-parameterize
@@ -105,7 +114,7 @@
),
'dependencies' => array(
'jquery.qunit'
- )
+ ),
),
);
diff --git a/DataValues/DataValues.tests.qunit.php
b/DataValues/DataValues.tests.qunit.php
index 98ae480..01a2005 100644
--- a/DataValues/DataValues.tests.qunit.php
+++ b/DataValues/DataValues.tests.qunit.php
@@ -85,11 +85,13 @@
'resources/time.js/tests/time.Time.knowsPrecision.tests.js',
'resources/time.js/tests/time.Time.minPrecision.tests.js',
'resources/time.js/tests/time.Time.maxPrecision.tests.js',
+ 'resources/time.js/tests/time.Time.tests.js',
'resources/time.js/tests/time.Time.validate.tests.js',
'resources/time.js/tests/time.Time.parse.tests.js',
),
'dependencies' => array(
'time.js',
+ 'time.js.validTimeDefinitions',
),
),
diff --git a/DataValues/resources/time.js/tests/time.Time.tests.js
b/DataValues/resources/time.js/tests/time.Time.tests.js
new file mode 100644
index 0000000..cd3dbeb
--- /dev/null
+++ b/DataValues/resources/time.js/tests/time.Time.tests.js
@@ -0,0 +1,59 @@
+/**
+ * @since 0.1
+ * @file
+ * @ingroup Time.js
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Werner
+ */
+( function( QUnit, $, time ) {
+ 'use strict';
+
+ var Time = time.Time,
+ validTimeDefinitions = time.validTimeDefinitions;
+
+ QUnit.module( 'Time.js: time.Time' );
+
+ QUnit.test( 'Construct using time definition object', function( assert
) {
+ $.each( validTimeDefinitions, function( name, definition ) {
+ testConstructByObject( assert, name, definition );
+ } );
+ } );
+
+ function testConstructByObject( assert, definitionName, definition ) {
+ var time,
+ valid = true;
+ try {
+ var time = new Time( definition ); // throws an error
if failure
+ } catch( e ) {
+ valid = false;
+ }
+
+ assert.ok(
+ valid,
+ 'New time.Time object built from "' + definitionName +
'" example definition'
+ );
+ }
+
+ QUnit.test( 'Construct using string to be parsed', function( assert ) {
+ $.each( validTimeDefinitions, function( name, definition ) {
+ testConstructByString( assert, name, definition );
+ } );
+ } );
+
+ function testConstructByString( assert, definitionName, definition ) {
+ var time,
+ valid = true;
+ try {
+ time = new Time( definitionName ); // throws an error
if failure
+ } catch( e ) {
+ valid = false;
+ }
+
+ assert.ok(
+ valid && time.isValid(),
+ 'New valid time.Time object built from "' +
definitionName + '" example definition'
+ );
+ }
+
+}( QUnit, jQuery, time ) );
diff --git a/DataValues/resources/time.js/tests/time.Time.validate.tests.js
b/DataValues/resources/time.js/tests/time.Time.validate.tests.js
index 24d175f..683a205 100644
--- a/DataValues/resources/time.js/tests/time.Time.validate.tests.js
+++ b/DataValues/resources/time.js/tests/time.Time.validate.tests.js
@@ -6,7 +6,7 @@
* @licence GNU GPL v2+
* @author Daniel Werner
*/
-( function( QUnit, $, Time ) {
+( function( QUnit, $, Time, validTimeDefinitions ) {
'use strict';
var PRECISION = Time.PRECISION,
@@ -15,51 +15,8 @@
QUnit.module( 'time.js: time.Time.validate()' );
- var validDefinitions = [
- {
- calendarname: G,
- year: -44,
- precision: PRECISION.YEAR
- }, {
- calendarname: J,
- year: 1492,
- month: 10,
- day: 12,
- precision: PRECISION.DAY
- }, {
- calendarname: G,
- month: 3,
- year: -44,
- precision: PRECISION.MONTH
- }, {
- calendarname: J,
- year: 1616,
- month: 4,
- day: 23,
- precision: PRECISION.DAY
- }, {
- calendarname: G,
- year: 1616,
- month: 4,
- day: 22,
- precision: PRECISION.DAY
- }, {
- calendarname: G,
- year: 2001,
- month: 1,
- day: 1,
- precision: PRECISION.DAY
- }, {
- calendarname: G,
- year: 1989,
- month: 11,
- day: 20,
- precision: PRECISION.DAY
- }
- ];
-
QUnit.test( 'validating valid time definitions', function( assert ) {
- $.each( validDefinitions, function( i, timeDefinition ) {
+ $.each( validTimeDefinitions, function( name, timeDefinition ) {
var valid = true;
try {
Time.validate( timeDefinition ); // throws an
error if failure
@@ -69,7 +26,7 @@
assert.ok(
valid,
- 'valid definition ' + i + ' has been accepted
by validate()'
+ 'valid definition (with key "' + name + '") has
been accepted by validate()'
);
} );
} );
@@ -144,7 +101,7 @@
}, {
reason: 'precision is "DAY" but field "month" not
given',
definition: {
- calendarname: J,
+ calendarname: G,
year: 1492,
day: 1,
precision: PRECISION.DAY
@@ -198,4 +155,4 @@
} );
} );
-}( QUnit, jQuery, time.Time ) );
+}( QUnit, jQuery, time.Time, time.validTimeDefinitions ) );
diff --git a/DataValues/resources/time.js/tests/time.validTimeDefinitions.js
b/DataValues/resources/time.js/tests/time.validTimeDefinitions.js
new file mode 100644
index 0000000..cf7c2b0
--- /dev/null
+++ b/DataValues/resources/time.js/tests/time.validTimeDefinitions.js
@@ -0,0 +1,70 @@
+/**
+ * Object holding example time definitions indexed by a string describing it.
The string describing
+ * it is basically a string that could be fed to the time parser, the parsed
result should be a
+ * time definition equal to the ones given here. This is particularly useful
for testing purposes.
+ *
+ * @since 0.1
+ * @file
+ * @ingroup Time.js
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Werner
+ */
+time.validTimeDefinitions = ( function( time ) {
+ 'use strict';
+
+ var Time = time.Time,
+ PRECISION = Time.PRECISION,
+ G = Time.CALENDAR.GREGORIAN,
+ J = Time.CALENDAR.JULIAN;
+
+ return {
+ '45 BC': {
+ calendarname: G,
+ year: -44,
+ precision: PRECISION.YEAR
+ },
+ '12 October 1492': {
+ calendarname: J,
+ year: 1492,
+ month: 10,
+ day: 12,
+ precision: PRECISION.DAY
+ },
+ 'March 45 BC': {
+ calendarname: G,
+ month: 3,
+ year: -44,
+ precision: PRECISION.MONTH
+ },
+ 'April 23, 1616 Old Style': {
+ calendarname: J,
+ year: 1616,
+ month: 4,
+ day: 23,
+ precision: PRECISION.DAY
+ },
+ '22.4.1616 Gregorian': {
+ calendarname: G,
+ year: 1616,
+ month: 4,
+ day: 22,
+ precision: PRECISION.DAY
+ },
+ '2001-01-01': {
+ calendarname: G,
+ year: 2001,
+ month: 1,
+ day: 1,
+ precision: PRECISION.DAY
+ },
+ 'November 20, 1989': {
+ calendarname: G,
+ year: 1989,
+ month: 11,
+ day: 20,
+ precision: PRECISION.DAY
+ }
+ };
+
+}( time ) );
--
To view, visit https://gerrit.wikimedia.org/r/64042
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8ceda8dd9b5a5340766c64b9b0a1ab4744669003
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits