From 26a9975fba2bbd8875f2671495003b9bdcb8d8b2 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 14 Mar 2015 21:20:58 +0000 Subject: [PATCH] tests: Add some more tests for bytes, bignum, string and ujson. --- tests/basics/bytes.py | 2 ++ tests/basics/int_big_and.py | 2 ++ tests/basics/int_big_or.py | 4 ++++ tests/basics/int_big_rshift.py | 3 +++ tests/basics/int_big_xor.py | 7 +++++++ tests/basics/int_mpz.py | 6 ++++++ tests/basics/string1.py | 2 ++ tests/basics/string_endswith.py | 1 + tests/basics/string_format.py | 2 ++ tests/basics/string_format_modulo.py | 2 ++ tests/basics/string_replace.py | 1 + tests/extmod/ujson_dumps.py | 2 ++ 12 files changed, 34 insertions(+) create mode 100644 tests/basics/int_big_or.py create mode 100644 tests/basics/int_big_rshift.py create mode 100644 tests/basics/int_big_xor.py diff --git a/tests/basics/bytes.py b/tests/basics/bytes.py index ca0594a259..2dafad49b8 100644 --- a/tests/basics/bytes.py +++ b/tests/basics/bytes.py @@ -1,3 +1,5 @@ +print(bytes()) + a = b"123" print(a) print(str(a)) diff --git a/tests/basics/int_big_and.py b/tests/basics/int_big_and.py index a48848dbf0..e0d0935a48 100644 --- a/tests/basics/int_big_and.py +++ b/tests/basics/int_big_and.py @@ -13,6 +13,8 @@ print(a & -1) print(a & -2) print(a & -2345678901234567890123456789) print(a & (-a)) +print(a & (-a - 1)) +print(a & (-a + 1)) # test negative on lhs a = 123456789012345678901234567890 diff --git a/tests/basics/int_big_or.py b/tests/basics/int_big_or.py new file mode 100644 index 0000000000..a279ce742b --- /dev/null +++ b/tests/basics/int_big_or.py @@ -0,0 +1,4 @@ +print(0 | (1 << 80)) + +a = 0xfffffffffffffffffffffffffffff +print(a | (1 << 200)) diff --git a/tests/basics/int_big_rshift.py b/tests/basics/int_big_rshift.py new file mode 100644 index 0000000000..d11f8f63eb --- /dev/null +++ b/tests/basics/int_big_rshift.py @@ -0,0 +1,3 @@ +i = 123456789012345678901234567890 +print(i >> 1) +print(i >> 1000) diff --git a/tests/basics/int_big_xor.py b/tests/basics/int_big_xor.py new file mode 100644 index 0000000000..f755dc8117 --- /dev/null +++ b/tests/basics/int_big_xor.py @@ -0,0 +1,7 @@ +print(0 ^ (1 << 80)) +print((1 << 80) ^ (1 << 80)) +print((1 << 80) ^ 0) + +a = 0xfffffffffffffffffffffffffffff +print(a ^ (1 << 100)) +print(a ^ (1 << 200)) diff --git a/tests/basics/int_mpz.py b/tests/basics/int_mpz.py index ee172edffe..6e4d4c18d0 100644 --- a/tests/basics/int_mpz.py +++ b/tests/basics/int_mpz.py @@ -56,6 +56,12 @@ for i in range(8): print(-10000000000000000000000003 >> i) print(-10000000000000000000000004 >> i) +# conversion from string +print(int("123456789012345678901234567890")) +print(int("-123456789012345678901234567890")) +print(int("123456789012345678901234567890abcdef", 16)) +print(int("123456789012345678901234567890ABCDEF", 16)) + # test constant integer with more than 255 chars x = 0x84ce72aa8699df436059f052ac51b6398d2511e49631bcb7e71f89c499b9ee425dfbc13a5f6d408471b054f2655617cbbaf7937b7c80cd8865cf02c8487d30d2b0fbd8b2c4e102e16d828374bbc47b93852f212d5043c3ea720f086178ff798cc4f63f787b9c2e419efa033e7644ea7936f54462dc21a6c4580725f7f0e7d1aaaaaaa print(x) diff --git a/tests/basics/string1.py b/tests/basics/string1.py index 074b04ef8f..b617cc786d 100644 --- a/tests/basics/string1.py +++ b/tests/basics/string1.py @@ -1,5 +1,7 @@ # basic strings +print(str()) + x = 'abc' print(x) diff --git a/tests/basics/string_endswith.py b/tests/basics/string_endswith.py index 078ee6dba5..3e8fba925d 100644 --- a/tests/basics/string_endswith.py +++ b/tests/basics/string_endswith.py @@ -3,6 +3,7 @@ print("foobar".endswith("baR")) print("foobar".endswith("bar1")) print("foobar".endswith("foobar")) print("foobar".endswith("")) +print("foobar".endswith("foobarbaz")) #print("1foobar".startswith("foo", 1)) #print("1foo".startswith("foo", 1)) diff --git a/tests/basics/string_format.py b/tests/basics/string_format.py index 07071be5ab..5398c6e236 100644 --- a/tests/basics/string_format.py +++ b/tests/basics/string_format.py @@ -6,6 +6,7 @@ full_tests = False def test(fmt, *args): print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') +test("}}{{") test("{}-{}", 1, [4, 5]) test("{0}-{1}", 1, [4, 5]) test("{1}-{0}", 1, [4, 5]) @@ -40,6 +41,7 @@ test("{:#4X}", 0) test("{:<6s}", "ab") test("{:>6s}", "ab") test("{:^6s}", "ab") +test("{:.1s}", "ab") test("{: <6d}", 123) test("{: <6d}", -123) diff --git a/tests/basics/string_format_modulo.py b/tests/basics/string_format_modulo.py index f3f57b45ad..a1c31def90 100644 --- a/tests/basics/string_format_modulo.py +++ b/tests/basics/string_format_modulo.py @@ -1,3 +1,4 @@ +print("%%" % ()) print("=%s=" % 1) print("=%s=%s=" % (1, 2)) print("=%s=" % (1,)) @@ -23,6 +24,7 @@ except TypeError: print("%s" % True) print("%s" % 1) +print("%.1s" % "ab") print("%r" % True) print("%r" % 1) diff --git a/tests/basics/string_replace.py b/tests/basics/string_replace.py index 8c4c171807..95e2ba9bc8 100644 --- a/tests/basics/string_replace.py +++ b/tests/basics/string_replace.py @@ -1,4 +1,5 @@ print("".replace("a", "b")) +print("aaa".replace("b", "c")) print("aaa".replace("a", "b", 0)) print("aaa".replace("a", "b", -5)) print("asdfasdf".replace("a", "b")) diff --git a/tests/extmod/ujson_dumps.py b/tests/extmod/ujson_dumps.py index 0b8d239a06..16a695ab5c 100644 --- a/tests/extmod/ujson_dumps.py +++ b/tests/extmod/ujson_dumps.py @@ -21,3 +21,5 @@ print(json.dumps((1, (2, 3)))) print(json.dumps({})) print(json.dumps({"a":1})) print(json.dumps({"a":(2,[3,None])})) +print(json.dumps('"quoted"')) +print(json.dumps('space\n\r\tspace'))