ReviewOS

also looking at this

stacks/ts-punycode

Fix the failing tests

#47
Merged case wants to merge tests-fix into main
1 file +22 -16
test/punycode.test.tsmodified+22-16
Changes to test/punycode.test.ts
@@ -237,7 +237,7 @@ describe('punycode', () => {
237237 })
238238
239239 it('should throw on invalid input', () => {
240 expect(() => punycode.decode('xyz-')).toThrow('Invalid input')
240 expect(() => punycode.decode('abc-!')).toThrow('Invalid input')
241241 })
242242 })
243243
@@ -286,18 +286,6 @@ describe('punycode.ucs2.decode', () => {
286286 expect(punycode.ucs2.decode(object.encoded)).toEqual(object.decoded)
287287 })
288288 }
289
290 it('throws RangeError: Illegal input >= 0x80 (not a basic code point)', () => {
291 expect(() => {
292 punycode.decode('\x81-')
293 }).toThrow('Illegal input >= 0x80 (not a basic code point)')
294 })
295
296 it('throws RangeError: Overflow: input needs wider integers to process', () => {
297 expect(() => {
298 punycode.decode('\x81')
299 }).toThrow('Overflow: input needs wider integers to process')
300 })
301289})
302290
303291describe('punycode.ucs2.encode', () => {
@@ -331,6 +319,24 @@ describe('punycode.decode', () => {
331319 punycode.decode('ls8h=')
332320 }).toThrow('Invalid input')
333321 })
322
323 it('throws RangeError: Illegal input >= 0x80 (not a basic code point)', () => {
324 expect(() => {
325 punycode.decode('\x81-')
326 }).toThrow('Illegal input >= 0x80 (not a basic code point)')
327 })
328
329 it('throws RangeError: Invalid input for non-basic code point without delimiter', () => {
330 expect(() => {
331 punycode.decode('\x81')
332 }).toThrow('Invalid input')
333 })
334
335 it('throws RangeError: Overflow for input needing wider integers', () => {
336 expect(() => {
337 punycode.decode('bb000000')
338 }).toThrow('Overflow: input needs wider integers to process')
339 })
334340})
335341
336342describe('punycode.encode', () => {
@@ -349,7 +355,7 @@ describe('punycode.toUnicode', () => {
349355 }
350356
351357 for (const object of testData.strings) {
352 it('does not convert names (or other strings) that don\'t start with `xn--`', () => {
358 it(`does not convert non-xn-- strings: ${object.description || object.encoded}`, () => {
353359 expect(punycode.toUnicode(object.encoded)).toBe(object.encoded)
354360 expect(punycode.toUnicode(object.decoded)).toBe(object.decoded)
355361 })
@@ -364,13 +370,13 @@ describe('punycode.toASCII', () => {
364370 }
365371
366372 for (const object of testData.strings) {
367 it('does not convert domain names (or other strings) that are already in ASCII', () => {
373 it(`does not convert ASCII-only strings: ${object.description || object.encoded}`, () => {
368374 expect(punycode.toASCII(object.encoded)).toBe(object.encoded)
369375 })
370376 }
371377
372378 for (const object of testData.separators) {
373 it('supports IDNA2003 separators for backwards compatibility', () => {
379 it(`supports IDNA2003 separators: ${object.description}`, () => {
374380 expect(punycode.toASCII(object.decoded)).toBe(object.encoded)
375381 })
376382 }