Esempio n. 1
0
    def test_string(self):
        obj = jclass("com.chaquo.python.TestOverload$TestString")()
        Character = jclass("java.lang.Character")

        self.assertEqual("char x", obj.resolve_C_Character("x"))
        self.assertEqual("char x", obj.resolve_C_Character(jchar("x")))
        self.assertEqual("Character x",
                         obj.resolve_C_Character(Character("x")))
        with self.assertRaisesRegexp(
            (TypeError, ValueError),
                r"(expected a character|only single character).*length 2"):
            obj.resolve_C_Character("xy")

        self.assertEqual("String x", obj.resolve_C_String("x"))
        self.assertEqual("char x", obj.resolve_C_String(jchar("x")))
        self.assertEqual("String xy", obj.resolve_C_String("xy"))

        self.assertEqual("Object x", obj.resolve_C_Object("x"))
        self.assertEqual("char x", obj.resolve_C_Object(jchar("x")))
        self.assertEqual("Object xy", obj.resolve_C_Object("xy"))

        self.assertEqual("String x", obj.resolve_Character_String("x"))
        self.assertEqual("Character x",
                         obj.resolve_Character_String(jchar("x")))
        self.assertEqual("String xy", obj.resolve_Character_String("xy"))

        self.assertEqual("Object x", obj.resolve_Character_Object("x"))
        self.assertEqual("Character x",
                         obj.resolve_Character_Object(jchar("x")))
        self.assertEqual("Object xy", obj.resolve_Character_Object("xy"))
Esempio n. 2
0
    def test_char(self):
        self.assertEquals("jchar('x')", str(jchar("x")))

        zhong_j = jchar("中")
        zhong_j_u = "jchar('中')"
        self.assertEqual(zhong_j_u, str(zhong_j))

        with self.assertRaisesRegexp(
            (TypeError, ValueError),
                r"(expected a character|only single character).*length 2"):
            jchar("ab")
        with self.assertRaisesRegexp(TypeError, "non-BMP"):
            jchar("\U00010000")
Esempio n. 3
0
    def test_char(self):
        self.assertEquals("jchar('x')", str(jchar("x")))
        self.assertEquals("jchar('x')", str(jchar(u"x")))

        zhong_j = jchar(u"中")
        zhong_j_u = u"jchar('中')"
        if sys.version_info[0] < 3:
            self.assertEqual(zhong_j_u.encode("utf-8"), str(zhong_j))
        else:
            self.assertEqual(zhong_j_u, str(zhong_j))

        with self.assertRaisesRegexp(
            (TypeError, ValueError),
                r"(expected a character|only single character).*length 2"):
            jchar("ab")
        with self.assertRaisesRegexp(TypeError, "non-BMP"):
            jchar(u"\U00010000")