Skip to content

Commit 9461ab0

Browse files
committed
Moved tests to nodeunit. #210
1 parent 5468396 commit 9461ab0

File tree

2 files changed

+40
-56
lines changed

2 files changed

+40
-56
lines changed

nodejs/scripts/tests/xsd.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,46 @@ module.exports =
222222
test.equal(-733, gd.timezone);
223223
test.equal('---06-12:13', Jsonix.Schema.XSD.Calendar.INSTANCE.print(gd));
224224

225+
test.throws(
226+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parse('nomatch'); },
227+
/Value \[nomatch\] does not match xs:dateTime, xs:date, xs:time, xs:gYearMonth, xs:gYear, xs:gMonthDay, xs:gMonth or xs:gDay patterns\./);
228+
229+
test.throws(
230+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGYearMonth('201002'); },
231+
/Value \[201002\] does not match the xs:gYearMonth pattern\./);
232+
233+
test.throws(
234+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGYear('10'); },
235+
/Value \[10\] does not match the xs:gYear pattern\./);
236+
237+
test.throws(
238+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGMonthDay('02-10'); },
239+
/Value \[02-10\] does not match the xs:gMonthDay pattern\./);
240+
241+
test.throws(
242+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGMonth('02'); },
243+
/Value \[02\] does not match the xs:gMonth pattern\./);
244+
245+
test.throws(
246+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseGDay('01'); },
247+
/Value \[01\] does not match the xs:gDay pattern\./);
248+
249+
test.throws(
250+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseDateTime('2010-02-01 12:23:0'); },
251+
/Value \[2010-02-01 12:23:0\] does not match the xs:date pattern\./);
252+
253+
test.throws(
254+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseDate('20100201'); },
255+
/Value \[20100201\] does not match the xs:date pattern\./);
256+
257+
test.throws(
258+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseTime('12:23:0'); },
259+
/Value \[12:23:0\] does not match the xs:time pattern\./);
260+
261+
test.throws(
262+
function() { Jsonix.Schema.XSD.Calendar.INSTANCE.parseTimezoneString('PDT'); },
263+
/Value \[PDT\] does not match the timezone pattern\./);
264+
225265
test.done();
226266
},
227267

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

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
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-
151
function testSchemaXSDString() {
162
var t = Jsonix.Schema.XSD.String.INSTANCE;
173
assertEquals('test', t.print('test'));
@@ -205,48 +191,6 @@ function testSchemaXSDCalendar() {
205191

206192
}
207193

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-
250194
function testSchemaXSDTime() {
251195
var t0 = Jsonix.Schema.XSD.TimeAsDate.INSTANCE.parse('10:00:00.5');
252196
var time0 = new Date(1970, 0, 1, 10, 0, 0);

0 commit comments

Comments
 (0)