Daniel Werner has uploaded a new change for review.
https://gerrit.wikimedia.org/r/64035
Change subject: [time.js] Added tests for time.Time.parse
......................................................................
[time.js] Added tests for time.Time.parse
Removed "minus" and "bce" fields from parser result since the parser only
requires them for the
field "year". Since the parser result contains "year", this makes them kind of
redundant and
uninteresting for the outside-world.
Change-Id: I49a618f4664b5c2eb5903ca8c4f88012ed29cb5a
---
M DataValues/DataValues.tests.qunit.php
M DataValues/resources/time.js/src/time.Time.parse.js
A DataValues/resources/time.js/tests/time.Time.parse.tests.js
3 files changed, 95 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues
refs/changes/35/64035/1
diff --git a/DataValues/DataValues.tests.qunit.php
b/DataValues/DataValues.tests.qunit.php
index 0eb9761..9f7e9bd 100644
--- a/DataValues/DataValues.tests.qunit.php
+++ b/DataValues/DataValues.tests.qunit.php
@@ -86,6 +86,7 @@
'resources/time.js/tests/time.Time.minPrecision.tests.js',
'resources/time.js/tests/time.Time.maxPrecision.tests.js',
'resources/time.js/tests/time.Time.validate.tests.js',
+
'resources/time.js/tests/time.Time.parse.tests.js',
),
'dependencies' => array(
'time.js',
diff --git a/DataValues/resources/time.js/src/time.Time.parse.js
b/DataValues/resources/time.js/src/time.Time.parse.js
index 3627cc4..5d5736d 100644
--- a/DataValues/resources/time.js/src/time.Time.parse.js
+++ b/DataValues/resources/time.js/src/time.Time.parse.js
@@ -78,6 +78,8 @@
retval.calendarname = 'Gregorian';
}
+ delete( retval.bce ); // nothing we want to expose since this
is redundant with "year"
+ delete( retval.minus );
return retval;
}
diff --git a/DataValues/resources/time.js/tests/time.Time.parse.tests.js
b/DataValues/resources/time.js/tests/time.Time.parse.tests.js
new file mode 100644
index 0000000..cde934e
--- /dev/null
+++ b/DataValues/resources/time.js/tests/time.Time.parse.tests.js
@@ -0,0 +1,92 @@
+/**
+ * @since 0.1
+ * @file
+ * @ingroup Time.js
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Werner
+ */
+( function( QUnit, $, Time ) {
+ 'use strict';
+
+ var PRECISION = Time.PRECISION,
+ G = Time.CALENDAR.GREGORIAN,
+ J = Time.CALENDAR.JULIAN;
+
+ QUnit.module( 'time.js: time.Time.parse()' );
+
+ var times = {
+ '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
+ },
+ 'foo': null, // TODO: in error case, the parser should throw an
error, not just return null!
+ '42 abc': null
+ };
+
+ QUnit.test( 'random parsing', function( assert ) {
+ $.each( times, function( timeInput, exptectedTimeDefinition ) {
+ var parsedTime,
+ timeObject;
+
+ parsedTime = Time.parse( timeInput );
+ assert.deepEqual(
+ parsedTime,
+ exptectedTimeDefinition,
+ '"' + timeInput + '" has been parsed
successfully'
+ );
+
+ // test integration with time.Time:
+ if( parsedTime !== null ) {
+ timeObject = new Time( parsedTime );
+ assert.ok(
+ timeObject.isValid(),
+ '"' + timeInput + '" parser result can
be used to create new valid time.Time instance'
+ );
+ }
+ } );
+ } );
+
+}( QUnit, jQuery, time.Time ) );
--
To view, visit https://gerrit.wikimedia.org/r/64035
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I49a618f4664b5c2eb5903ca8c4f88012ed29cb5a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits