|
1 | | -;(function(root) { |
| 1 | +(function(root) { |
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | | - /** Use a single `load` function */ |
5 | | - var load = typeof require == 'function' ? require : root.load; |
| 4 | + var noop = Function.prototype; |
| 5 | + |
| 6 | + var load = (typeof require == 'function' && !(root.define && define.amd)) ? |
| 7 | + require : |
| 8 | + (!root.document && root.java && root.load) || noop; |
6 | 9 |
|
7 | | - /** The unit testing framework */ |
8 | 10 | var QUnit = (function() { |
9 | | - var noop = Function.prototype; |
10 | 11 | return root.QUnit || ( |
11 | 12 | root.addEventListener || (root.addEventListener = noop), |
12 | 13 | root.setTimeout || (root.setTimeout = noop), |
13 | 14 | root.QUnit = load('../node_modules/qunitjs/qunit/qunit.js') || root.QUnit, |
14 | | - (load('../node_modules/qunit-clib/qunit-clib.js') || { 'runInContext': noop }).runInContext(root), |
15 | 15 | addEventListener === noop && delete root.addEventListener, |
16 | 16 | root.QUnit |
17 | 17 | ); |
18 | 18 | }()); |
19 | 19 |
|
| 20 | + var qe = load('../node_modules/qunit-extras/qunit-extras.js'); |
| 21 | + if (qe) { |
| 22 | + qe.runInContext(root); |
| 23 | + } |
| 24 | + |
20 | 25 | /** The `utf8` object to test */ |
21 | 26 | var utf8 = root.utf8 || (root.utf8 = ( |
22 | 27 | utf8 = load('../utf8.js') || root.utf8, |
|
96 | 101 | { |
97 | 102 | 'codePoint': 0xD800, |
98 | 103 | 'decoded': '\uD800', |
99 | | - 'encoded': '\xED\xA0\x80' |
| 104 | + 'encoded': '\xED\xA0\x80', |
| 105 | + 'error': true |
100 | 106 | }, |
101 | 107 | { |
102 | 108 | 'description': 'High surrogate followed by another high surrogate', |
103 | 109 | 'decoded': '\uD800\uD800', |
104 | | - 'encoded': '\xED\xA0\x80\xED\xA0\x80' |
| 110 | + 'encoded': '\xED\xA0\x80\xED\xA0\x80', |
| 111 | + 'error': true |
105 | 112 | }, |
106 | 113 | { |
107 | 114 | 'description': 'High surrogate followed by a symbol that is not a surrogate', |
108 | 115 | 'decoded': '\uD800A', |
109 | | - 'encoded': '\xED\xA0\x80A' |
| 116 | + 'encoded': '\xED\xA0\x80A', |
| 117 | + 'error': true |
110 | 118 | }, |
111 | 119 | { |
112 | 120 | 'description': 'Unmatched high surrogate, followed by a surrogate pair, followed by an unmatched high surrogate', |
113 | 121 | 'decoded': '\uD800\uD834\uDF06\uD800', |
114 | | - 'encoded': '\xED\xA0\x80\xF0\x9D\x8C\x86\xED\xA0\x80' |
| 122 | + 'encoded': '\xED\xA0\x80\xF0\x9D\x8C\x86\xED\xA0\x80', |
| 123 | + 'error': true |
115 | 124 | }, |
116 | 125 | { |
117 | 126 | 'codePoint': 0xD9AF, |
118 | 127 | 'decoded': '\uD9AF', |
119 | | - 'encoded': '\xED\xA6\xAF' |
| 128 | + 'encoded': '\xED\xA6\xAF', |
| 129 | + 'error': true |
120 | 130 | }, |
121 | 131 | { |
122 | 132 | 'codePoint': 0xDBFF, |
123 | 133 | 'decoded': '\uDBFF', |
124 | | - 'encoded': '\xED\xAF\xBF' |
| 134 | + 'encoded': '\xED\xAF\xBF', |
| 135 | + 'error': true |
125 | 136 | }, |
126 | 137 | // low surrogates: 0xDC00 to 0xDFFF |
127 | 138 | { |
128 | 139 | 'codePoint': 0xDC00, |
129 | 140 | 'decoded': '\uDC00', |
130 | | - 'encoded': '\xED\xB0\x80' |
| 141 | + 'encoded': '\xED\xB0\x80', |
| 142 | + 'error': true |
131 | 143 | }, |
132 | 144 | { |
133 | 145 | 'description': 'Low surrogate followed by another low surrogate', |
134 | 146 | 'decoded': '\uDC00\uDC00', |
135 | | - 'encoded': '\xED\xB0\x80\xED\xB0\x80' |
| 147 | + 'encoded': '\xED\xB0\x80\xED\xB0\x80', |
| 148 | + 'error': true |
136 | 149 | }, |
137 | 150 | { |
138 | 151 | 'description': 'Low surrogate followed by a symbol that is not a surrogate', |
139 | 152 | 'decoded': '\uDC00A', |
140 | | - 'encoded': '\xED\xB0\x80A' |
| 153 | + 'encoded': '\xED\xB0\x80A', |
| 154 | + 'error': true |
141 | 155 | }, |
142 | 156 | { |
143 | 157 | 'description': 'Unmatched low surrogate, followed by a surrogate pair, followed by an unmatched low surrogate', |
144 | 158 | 'decoded': '\uDC00\uD834\uDF06\uDC00', |
145 | | - 'encoded': '\xED\xB0\x80\xF0\x9D\x8C\x86\xED\xB0\x80' |
| 159 | + 'encoded': '\xED\xB0\x80\xF0\x9D\x8C\x86\xED\xB0\x80', |
| 160 | + 'error': true |
146 | 161 | }, |
147 | 162 | { |
148 | 163 | 'codePoint': 0xDEEE, |
149 | 164 | 'decoded': '\uDEEE', |
150 | | - 'encoded': '\xED\xBB\xAE' |
| 165 | + 'encoded': '\xED\xBB\xAE', |
| 166 | + 'error': true |
151 | 167 | }, |
152 | 168 | { |
153 | 169 | 'codePoint': 0xDFFF, |
154 | 170 | 'decoded': '\uDFFF', |
155 | | - 'encoded': '\xED\xBF\xBF' |
| 171 | + 'encoded': '\xED\xBF\xBF', |
| 172 | + 'error': true |
156 | 173 | }, |
157 | 174 |
|
158 | 175 | // 4-byte |
|
188 | 205 | forEach(data, function(object) { |
189 | 206 | var description = object.description || 'U+' + object.codePoint.toString(16).toUpperCase(); |
190 | 207 | ; |
191 | | - equal( |
192 | | - object.encoded, |
193 | | - utf8.encode(object.decoded), |
194 | | - 'Encoding: ' + description |
195 | | - ); |
196 | | - equal( |
197 | | - object.decoded, |
198 | | - utf8.decode(object.encoded), |
199 | | - 'Decoding: ' + description |
200 | | - ); |
| 208 | + if (object.error) { |
| 209 | + raises( |
| 210 | + function() { |
| 211 | + utf8.decode(object.encoded); |
| 212 | + }, |
| 213 | + Error, |
| 214 | + 'Error: non-scalar value detected' |
| 215 | + ); |
| 216 | + raises( |
| 217 | + function() { |
| 218 | + utf8.encode(object.decoded); |
| 219 | + }, |
| 220 | + Error, |
| 221 | + 'Error: non-scalar value detected' |
| 222 | + ); |
| 223 | + } else { |
| 224 | + equal( |
| 225 | + object.encoded, |
| 226 | + utf8.encode(object.decoded), |
| 227 | + 'Encoding: ' + description |
| 228 | + ); |
| 229 | + equal( |
| 230 | + object.decoded, |
| 231 | + utf8.decode(object.encoded), |
| 232 | + 'Decoding: ' + description |
| 233 | + ); |
| 234 | + } |
201 | 235 | }); |
202 | 236 |
|
203 | 237 | // Error handling |
|
0 commit comments