summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/bytearray_byte_operations.py35
-rw-r--r--tests/basics/bytearray_center.py8
-rw-r--r--tests/basics/bytearray_count.py7
-rw-r--r--tests/basics/bytearray_partition.py8
-rw-r--r--tests/basics/bytes_center.py13
5 files changed, 71 insertions, 0 deletions
diff --git a/tests/basics/bytearray_byte_operations.py b/tests/basics/bytearray_byte_operations.py
new file mode 100644
index 000000000..7ce53cac5
--- /dev/null
+++ b/tests/basics/bytearray_byte_operations.py
@@ -0,0 +1,35 @@
+# test bytearray with its re-use of byte functions
+
+print(bytearray(b"hello world").find(b"ll"))
+print(bytearray(b"hello\x00world").rfind(b"l"))
+
+print(bytearray(b"abc efg ").strip(b"g a"))
+print(bytearray(b" spacious ").lstrip())
+print(bytearray(b"www.example.com").lstrip(b"cmowz."))
+print(bytearray(b" spacious ").rstrip())
+print(bytearray(b"mississippi").rstrip(b"ipz"))
+
+print(bytearray(b"abc").split(b"a"))
+print(bytearray(b"abcabc").rsplit(b"bc"))
+
+print(bytearray(b"asdfasdf").replace(b"a", b"b"))
+
+print("00\x0000".index("0", 0))
+print("00\x0000".index("0", 3))
+print("00\x0000".rindex("0", 0))
+print("00\x0000".rindex("0", 3))
+
+print(bytearray(b"foobar").endswith(b"bar"))
+print(bytearray(b"1foo").startswith(b"foo", 1))
+
+print(bytearray(b" T E \x00 S T").lower())
+print(bytearray(b" te \x00 st").upper())
+
+print(bytearray(b" \t\n\r\v\f").isspace())
+print(bytearray(b"this ").isalpha())
+print(bytearray(b"0123456789").isdigit())
+print(bytearray(b"AB").isupper())
+print(bytearray(b"cheese-cake").islower())
+
+print(bytearray(b",").join((bytearray(b"abc"), bytearray(b"def"))))
+print(type(bytearray(b",").join((b"a", b"b", b"c"))))
diff --git a/tests/basics/bytearray_center.py b/tests/basics/bytearray_center.py
new file mode 100644
index 000000000..c262a8c20
--- /dev/null
+++ b/tests/basics/bytearray_center.py
@@ -0,0 +1,8 @@
+try:
+ bytearray.center
+except AttributeError:
+ print("SKIP")
+ raise SystemExit
+
+print(bytearray(b"foo").center(6))
+print(type(bytearray(b"foo").center(6)))
diff --git a/tests/basics/bytearray_count.py b/tests/basics/bytearray_count.py
new file mode 100644
index 000000000..a151c1e81
--- /dev/null
+++ b/tests/basics/bytearray_count.py
@@ -0,0 +1,7 @@
+try:
+ bytearray.count
+except AttributeError:
+ print("SKIP")
+ raise SystemExit
+
+print(bytearray(b"aaaa").count(b"a"))
diff --git a/tests/basics/bytearray_partition.py b/tests/basics/bytearray_partition.py
new file mode 100644
index 000000000..b48ec4ed9
--- /dev/null
+++ b/tests/basics/bytearray_partition.py
@@ -0,0 +1,8 @@
+try:
+ bytearray.partition
+except AttributeError:
+ print("SKIP")
+ raise SystemExit
+
+print(bytearray(b"asdsf").partition(b"s"))
+print(bytearray(b"asdsf").rpartition(b"s"))
diff --git a/tests/basics/bytes_center.py b/tests/basics/bytes_center.py
new file mode 100644
index 000000000..5d8b41d92
--- /dev/null
+++ b/tests/basics/bytes_center.py
@@ -0,0 +1,13 @@
+try:
+ bytes.center
+except:
+ print("SKIP")
+ raise SystemExit
+
+print(b"foo".center(0))
+print(b"foo".center(1))
+print(b"foo".center(3))
+print(b"foo".center(4))
+print(b"foo".center(5))
+print(b"foo".center(6))
+print(b"foo".center(20))