From 53e50941793474a23dcf91e9e92497926b18ffbf Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sat, 17 Jul 2010 23:52:29 -0700 Subject: [PATCH] Fix #502, handle implicitly unsigned chars. --- tests/run/c_int_types_T255.pyx | 102 +++++++++++++++++---------------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/tests/run/c_int_types_T255.pyx b/tests/run/c_int_types_T255.pyx index 1468aa13..23220d5a 100644 --- a/tests/run/c_int_types_T255.pyx +++ b/tests/run/c_int_types_T255.pyx @@ -2,55 +2,6 @@ __doc__ = u"" # ------------------------------------------------------------------- -CHAR_MAX = ((-1)>>1) -CHAR_MIN = (-CHAR_MAX-1) - -def test_char(char x): - u""" - >>> test_char(CHAR_MIN-1) #doctest: +ELLIPSIS - Traceback (most recent call last): - ... - OverflowError: ... - >>> test_char(CHAR_MIN) == CHAR_MIN - True - >>> test_char(-1) - -1 - >>> test_char(0) - 0 - >>> test_char(1) - 1 - >>> test_char(CHAR_MAX) == CHAR_MAX - True - >>> test_char(CHAR_MAX+1) #doctest: +ELLIPSIS - Traceback (most recent call last): - ... - OverflowError: ... - """ - return x - -def test_add_char(x, y): - u""" - >>> test_add_char(CHAR_MIN, -1) #doctest: +ELLIPSIS - Traceback (most recent call last): - ... - OverflowError: ... - >>> test_add_char(CHAR_MIN, 0) == CHAR_MIN - True - >>> test_add_char(CHAR_MIN, 1) == CHAR_MIN+1 - True - >>> test_add_char(CHAR_MAX, -1) == CHAR_MAX-1 - True - >>> test_add_char(CHAR_MAX, 0) == CHAR_MAX - True - >>> test_add_char(CHAR_MAX, 1) #doctest: +ELLIPSIS - Traceback (most recent call last): - ... - OverflowError: ... - """ - cdef char r = x + y - return r - - SCHAR_MAX = ((-1)>>1) SCHAR_MIN = (-SCHAR_MAX-1) @@ -128,6 +79,59 @@ def test_add_uchar(x, y): cdef unsigned char r = x + y return r +# chars may be signed or unsigned +if (-1) < 0: + CHAR_MAX = SCHAR_MAX + CHAR_MIN = SCHAR_MIN +else: + CHAR_MAX = UCHAR_MAX + CHAR_MIN = 0 + +def test_char(char x): + u""" + >>> test_char(CHAR_MIN-1) #doctest: +ELLIPSIS + Traceback (most recent call last): + ... + OverflowError: ... + >>> test_char(CHAR_MIN) == CHAR_MIN + True + >>> test_char(-1) + -1 + >>> test_char(0) + 0 + >>> test_char(1) + 1 + >>> test_char(CHAR_MAX) == CHAR_MAX + True + >>> test_char(CHAR_MAX+1) #doctest: +ELLIPSIS + Traceback (most recent call last): + ... + OverflowError: ... + """ + return x + +def test_add_char(x, y): + u""" + >>> test_add_char(CHAR_MIN, -1) #doctest: +ELLIPSIS + Traceback (most recent call last): + ... + OverflowError: ... + >>> test_add_char(CHAR_MIN, 0) == CHAR_MIN + True + >>> test_add_char(CHAR_MIN, 1) == CHAR_MIN+1 + True + >>> test_add_char(CHAR_MAX, -1) == CHAR_MAX-1 + True + >>> test_add_char(CHAR_MAX, 0) == CHAR_MAX + True + >>> test_add_char(CHAR_MAX, 1) #doctest: +ELLIPSIS + Traceback (most recent call last): + ... + OverflowError: ... + """ + cdef char r = x + y + return r + # ------------------------------------------------------------------- SHORT_MAX = ((-1)>>1) -- 2.26.2