Skip to content

Commit 5468396

Browse files
authored
Merge pull request #210 from hanayuki/master
fix ReferenceError: function parameter name and variable name were different
2 parents 9e23d75 + 1ef32ae commit 5468396

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Schema/XSD/Calendar.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
102102
};
103103
return new Jsonix.XML.Calendar(data);
104104
}
105-
throw new Error('Value [' + value + '] does not match the xs:date pattern.');
105+
throw new Error('Value [' + text + '] does not match the xs:date pattern.');
106106
},
107107
parseDate : function(text, context, input, scope) {
108108
Jsonix.Util.Ensure.ensureString(text);
@@ -117,7 +117,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
117117
};
118118
return new Jsonix.XML.Calendar(data);
119119
}
120-
throw new Error('Value [' + value + '] does not match the xs:date pattern.');
120+
throw new Error('Value [' + text + '] does not match the xs:date pattern.');
121121
},
122122
parseTime : function(text, context, input, scope) {
123123
Jsonix.Util.Ensure.ensureString(text);
@@ -133,7 +133,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
133133
};
134134
return new Jsonix.XML.Calendar(data);
135135
}
136-
throw new Error('Value [' + value + '] does not match the xs:time pattern.');
136+
throw new Error('Value [' + text + '] does not match the xs:time pattern.');
137137
},
138138
parseTimezoneString : function(text) {
139139
// (('+' | '-') hh ':' mm) | 'Z'
@@ -156,7 +156,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
156156
var minute = parseInt(results[5], 10);
157157
return sign * (hour * 60 + minute);
158158
}
159-
throw new Error('Value [' + value + '] does not match the timezone pattern.');
159+
throw new Error('Value [' + text + '] does not match the timezone pattern.');
160160
}
161161
},
162162
print : function(value, context, output, scope) {

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)