Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
};
return new Jsonix.XML.Calendar(data);
}
throw new Error('Value [' + value + '] does not match the xs:date pattern.');
throw new Error('Value [' + text + '] does not match the xs:date pattern.');
},
parseDate : function(text, context, input, scope) {
Jsonix.Util.Ensure.ensureString(text);
Expand All @@ -117,7 +117,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
};
return new Jsonix.XML.Calendar(data);
}
throw new Error('Value [' + value + '] does not match the xs:date pattern.');
throw new Error('Value [' + text + '] does not match the xs:date pattern.');
},
parseTime : function(text, context, input, scope) {
Jsonix.Util.Ensure.ensureString(text);
Expand All @@ -133,7 +133,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
};
return new Jsonix.XML.Calendar(data);
}
throw new Error('Value [' + value + '] does not match the xs:time pattern.');
throw new Error('Value [' + text + '] does not match the xs:time pattern.');
},
parseTimezoneString : function(text) {
// (('+' | '-') hh ':' mm) | 'Z'
Expand All @@ -156,7 +156,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
var minute = parseInt(results[5], 10);
return sign * (hour * 60 + minute);
}
throw new Error('Value [' + value + '] does not match the timezone pattern.');
throw new Error('Value [' + text + '] does not match the timezone pattern.');
}
},
print : function(value, context, output, scope) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
function expectError(expectedError, fn) {
try {
fn();
fail('Expected error but none thrown');
} catch (e) {
// throw again the exception thorwned by 'fail' above
if (e instanceof JsUnitException) throw e;

// throwned class and message should be as expected
assertEquals(expectedError.name, e.name);
assertEquals(expectedError.message, e.message)
}
}

function testSchemaXSDString() {
var t = Jsonix.Schema.XSD.String.INSTANCE;
assertEquals('test', t.print('test'));
Expand Down Expand Up @@ -191,6 +205,48 @@ function testSchemaXSDCalendar() {

}

function testSchemaXSDCalendarError() {
expectError(
new Error('Value [nomatch] does not match xs:dateTime, xs:date, xs:time, xs:gYearMonth, xs:gYear, xs:gMonthDay, xs:gMonth or xs:gDay patterns.'),
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parse('nomatch') });

expectError(
new Error('Value [201002] does not match the xs:gYearMonth pattern.'),
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGYearMonth('201002'); });

expectError(
new Error('Value [10] does not match the xs:gYear pattern.'),
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGYear('10'); });

expectError(
new Error('Value [02-10] does not match the xs:gMonthDay pattern.'),
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGMonthDay('02-10'); });

expectError(
new Error('Value [02] does not match the xs:gMonth pattern.'),
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGMonth('02'); });

expectError(
new Error('Value [01] does not match the xs:gDay pattern.'),
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGDay('01'); });

expectError(
new Error('Value [2010-02-01 12:23:0] does not match the xs:date pattern.'),
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseDateTime('2010-02-01 12:23:0'); });

expectError(
new Error('Value [20100201] does not match the xs:date pattern.'),
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseDate('20100201') });

expectError(
new Error('Value [12:23:0] does not match the xs:time pattern.'),
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseTime('12:23:0'); });

expectError(
new Error('Value [PDT] does not match the timezone pattern.'),
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseTimezoneString('PDT'); });
}

function testSchemaXSDTime() {
var t0 = Jsonix.Schema.XSD.TimeAsDate.INSTANCE.parse('10:00:00.5');
var time0 = new Date(1970, 0, 1, 10, 0, 0);
Expand Down