jenkins-bot has submitted this change and it was merged.

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, 100 insertions(+), 0 deletions(-)

Approvals:
  Henning Snater: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/DataValues/DataValues.tests.qunit.php 
b/DataValues/DataValues.tests.qunit.php
index c574dd4..98ae480 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..4b86965 100644
--- a/DataValues/resources/time.js/src/time.Time.parse.js
+++ b/DataValues/resources/time.js/src/time.Time.parse.js
@@ -14,6 +14,11 @@
 
        var settings = time.settings;
 
+       // TODO: this should probably already return a time.Time instance and 
time.Time constructor
+       //  should not take a string (perhaps just for convenience?).
+       // TODO: have a parser per calendar model and one for time.Time itself 
which is delegating the
+       //  parsing to the different calendar model parsers. This will allow to 
add new calendar models
+       //  without touching existing code. Parser code for similiar models can 
still be shared.
        function parse( text ) {
                var tokens = tokenize( text ),
                        retval = {},
@@ -78,6 +83,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: merged
Gerrit-Change-Id: I49a618f4664b5c2eb5903ca8c4f88012ed29cb5a
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

Reply via email to