Skip to content

Commit d95fcae

Browse files
authored
Change sys.maxunicode to 0xffff (#1196)
* Change sys.maxunicode to 0xffff * Fix test failures * Use char.MaxValue
1 parent 21f522c commit d95fcae

5 files changed

Lines changed: 18 additions & 28 deletions

File tree

Src/IronPython/Modules/sys.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ public override string __repr__(CodeContext context) {
241241

242242
// hex_version is set by PythonContext
243243

244-
public const int maxsize = Int32.MaxValue;
245-
public const int maxunicode = 0x10ffff;
244+
public const int maxsize = int.MaxValue;
245+
public const int maxunicode = char.MaxValue;
246246

247247
// modules is set by PythonContext and only on the initial load
248248

Src/StdLib/Lib/test/test_builtin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def test_chr(self):
283283
self.assertEqual(chr(0xff), '\xff')
284284
self.assertRaises(ValueError, chr, 1<<24)
285285
self.assertEqual(chr(sys.maxunicode),
286-
str('\\U0010ffff'.encode("ascii"), 'unicode-escape'))
286+
str(('\\U%08x' % (sys.maxunicode)).encode("ascii"), 'unicode-escape')) # ironpython: sys.maxunicode is still 0xffff
287287
self.assertRaises(TypeError, chr)
288288
self.assertEqual(chr(0x0000FFFF), "\U0000FFFF")
289289
self.assertEqual(chr(0x00010000), "\U00010000")

Src/StdLib/Lib/test/test_codecs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,7 @@ def test_decode_with_int2int_map(self):
22232223

22242224
self.assertRaises(TypeError,
22252225
codecs.charmap_decode, b"\x00\x01\x02", "strict",
2226-
{0: sys.maxunicode + 1, 1: b, 2: c}
2226+
{0: 0x110000, 1: b, 2: c} # ironpython: 0x110000 instead of sys.maxunicode + 1
22272227
)
22282228

22292229
self.assertRaises(UnicodeDecodeError,

Tests/test_builtinfunc.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -307,28 +307,19 @@ def sumtest(values, expected):
307307
sumtest([1.7976931348623157e+308, long(1.7976931348623157e+308)], inf)
308308
self.assertRaises(OverflowError, sum, [1.0, 100000000<<2000])
309309

310-
def test_unichr(self):
311-
312-
#Added the following to resolve Codeplex WorkItem #3220.
313-
max_uni = sys.maxunicode
314-
self.assertTrue(max_uni==0xFFFF or max_uni==0x10FFFF)
315-
max_uni_plus_one = max_uni + 1
316-
317-
huger_than_max = 100000
318-
max_ok_value = u'\uffff'
319-
320-
#special case for WorkItem #3220
321-
if max_uni==0x10FFFF:
322-
huger_than_max = 10000000
323-
max_ok_value = u'\U0010FFFF'
324-
325-
unichr = chr
326-
327-
self.assertRaises(ValueError, unichr, -1) # arg must be in the range [0...65535] or [0...1114111] inclusive
328-
self.assertRaises(ValueError, unichr, max_uni_plus_one)
329-
self.assertRaises(ValueError, unichr, huger_than_max)
330-
self.assertTrue(unichr(0) == '\x00')
331-
self.assertTrue(unichr(max_uni) == max_ok_value)
310+
def test_chr(self):
311+
self.assertEqual(sys.maxunicode, 0xFFFF if is_cli else 0x10FFFF)
312+
313+
max_chr = 0x10FFFF
314+
max_chr_plus_one = max_chr + 1
315+
overflow_chr = 1<<64
316+
317+
# chr() arg must be in range(0x110000)
318+
self.assertRaises(ValueError, chr, -1)
319+
self.assertRaises(ValueError, chr, max_chr_plus_one)
320+
self.assertRaises(OverflowError, chr, overflow_chr)
321+
self.assertTrue(chr(0) == '\x00')
322+
self.assertTrue(chr(max_chr) == u'\U0010FFFF')
332323

333324
def test_max(self):
334325
self.assertEqual(max('123123'), '3')

Tests/test_nonlocal.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from iptest import IronPythonTestCase, run_test, is_cli, is_cpython
99

10-
1110
class SyntaxTests(IronPythonTestCase):
1211

1312
def check_compile_error(self, code, msg, lineno):
@@ -319,7 +318,7 @@ def foo():
319318
from sys import maxunicode
320319
from sys import maxsize as some_number
321320
foo()
322-
self.assertEqual(maxunicode, 1114111)
321+
self.assertEqual(maxunicode, 0xFFFF if is_cli else 0x10FFFF)
323322
self.assertGreaterEqual(some_number, 0x7FFFFFFF)
324323

325324
run_test(__name__)

0 commit comments

Comments
 (0)