Skip to content

Commit 1ef32ae

Browse files
committed
add tests for the case schema.xsd.calendar.parseXXX throw error
1 parent cc8a09d commit 1ef32ae

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

scripts/src/test/javascript/org/hisrc/jsonix/test/JsonixSchemaXSDTest.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
function expectError(expectedError, fn) {
2+
try {
3+
fn();
4+
fail('Expected error but none thrown');
5+
} catch (e) {
6+
// throw again the exception thorwned by 'fail' above
7+
if (e instanceof JsUnitException) throw e;
8+
9+
// throwned class and message should be as expected
10+
assertEquals(expectedError.name, e.name);
11+
assertEquals(expectedError.message, e.message)
12+
}
13+
}
14+
115
function testSchemaXSDString() {
216
var t = Jsonix.Schema.XSD.String.INSTANCE;
317
assertEquals('test', t.print('test'));
@@ -191,6 +205,48 @@ function testSchemaXSDCalendar() {
191205

192206
}
193207

208+
function testSchemaXSDCalendarError() {
209+
expectError(
210+
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.'),
211+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parse('nomatch') });
212+
213+
expectError(
214+
new Error('Value [201002] does not match the xs:gYearMonth pattern.'),
215+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGYearMonth('201002'); });
216+
217+
expectError(
218+
new Error('Value [10] does not match the xs:gYear pattern.'),
219+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGYear('10'); });
220+
221+
expectError(
222+
new Error('Value [02-10] does not match the xs:gMonthDay pattern.'),
223+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGMonthDay('02-10'); });
224+
225+
expectError(
226+
new Error('Value [02] does not match the xs:gMonth pattern.'),
227+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGMonth('02'); });
228+
229+
expectError(
230+
new Error('Value [01] does not match the xs:gDay pattern.'),
231+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGDay('01'); });
232+
233+
expectError(
234+
new Error('Value [2010-02-01 12:23:0] does not match the xs:date pattern.'),
235+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseDateTime('2010-02-01 12:23:0'); });
236+
237+
expectError(
238+
new Error('Value [20100201] does not match the xs:date pattern.'),
239+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseDate('20100201') });
240+
241+
expectError(
242+
new Error('Value [12:23:0] does not match the xs:time pattern.'),
243+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseTime('12:23:0'); });
244+
245+
expectError(
246+
new Error('Value [PDT] does not match the timezone pattern.'),
247+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseTimezoneString('PDT'); });
248+
}
249+
194250
function testSchemaXSDTime() {
195251
var t0 = Jsonix.Schema.XSD.TimeAsDate.INSTANCE.parse('10:00:00.5');
196252
var time0 = new Date(1970, 0, 1, 10, 0, 0);

0 commit comments

Comments
 (0)