summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics
diff options
context:
space:
mode:
Diffstat (limited to 'tests/basics')
-rw-r--r--tests/basics/for_break.py27
-rw-r--r--tests/basics/for_return.py7
-rw-r--r--tests/basics/int-big-and.py24
-rw-r--r--tests/basics/string_istest.py20
-rw-r--r--tests/basics/string_strip.py15
5 files changed, 89 insertions, 4 deletions
diff --git a/tests/basics/for_break.py b/tests/basics/for_break.py
new file mode 100644
index 0000000000..f8bb0578e2
--- /dev/null
+++ b/tests/basics/for_break.py
@@ -0,0 +1,27 @@
+# Testcase for break in a for [within bunch of other code]
+# https://github.com/micropython/micropython/issues/635
+
+def foo():
+ seq = [1, 2, 3]
+ v = 100
+ i = 5
+ while i > 0:
+ print(i)
+ for a in seq:
+ if a == 2:
+ break
+ i -= 1
+
+foo()
+
+# break from within nested for loop
+def bar():
+ l = [1, 2, 3]
+ for e1 in l:
+ print(e1)
+ for e2 in l:
+ print(e1, e2)
+ if e2 == 2:
+ break
+
+bar()
diff --git a/tests/basics/for_return.py b/tests/basics/for_return.py
new file mode 100644
index 0000000000..0441352ad9
--- /dev/null
+++ b/tests/basics/for_return.py
@@ -0,0 +1,7 @@
+# test returning from within a for loop
+
+def f():
+ for i in [1, 2, 3]:
+ return i
+
+print(f())
diff --git a/tests/basics/int-big-and.py b/tests/basics/int-big-and.py
index 75fbd52884..a48848dbf0 100644
--- a/tests/basics/int-big-and.py
+++ b/tests/basics/int-big-and.py
@@ -2,7 +2,23 @@ print(0 & (1 << 80))
print(0 & (1 << 80) == 0)
print(bool(0 & (1 << 80)))
-#a = 0xfffffffffffffffffffffffffffff
-#print(a & (1 << 80))
-#print((a & (1 << 80)) >> 80)
-#print((a & (1 << 80)) >> 80 == 1)
+a = 0xfffffffffffffffffffffffffffff
+print(a & (1 << 80))
+print((a & (1 << 80)) >> 80)
+print((a & (1 << 80)) >> 80 == 1)
+
+# test negative on rhs
+a = 123456789012345678901234567890
+print(a & -1)
+print(a & -2)
+print(a & -2345678901234567890123456789)
+print(a & (-a))
+
+# test negative on lhs
+a = 123456789012345678901234567890
+print(-1 & a)
+print(-2 & a)
+print(-2345678901234567890123456789 & a)
+print((-a) & a)
+print((-a) & 0xffffffff)
+print((-a) & 0xffffffffffffffffffffffffffffffff)
diff --git a/tests/basics/string_istest.py b/tests/basics/string_istest.py
new file mode 100644
index 0000000000..7ea6c4508f
--- /dev/null
+++ b/tests/basics/string_istest.py
@@ -0,0 +1,20 @@
+print("".isspace())
+print(" \t\n\r\v\f".isspace())
+print("a".isspace())
+print(" \t\n\r\v\fa".isspace())
+print("".isalpha())
+print("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".isalpha())
+print("0abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".isalpha())
+print("this ".isalpha())
+print("".isdigit())
+print("0123456789".isdigit())
+print("0123456789a".isdigit())
+print("0123456789 ".isdigit())
+print("".isupper())
+print("CHEESE-CAKE WITH ... _FROSTING_*99".isupper())
+print("aB".isupper())
+print("".islower())
+print("cheese-cake with ... _frosting_*99".islower())
+print("aB".islower())
+print("123".islower())
+print("123a".islower())
diff --git a/tests/basics/string_strip.py b/tests/basics/string_strip.py
index 4684c2a248..5d99a78e51 100644
--- a/tests/basics/string_strip.py
+++ b/tests/basics/string_strip.py
@@ -20,3 +20,18 @@ try:
print('mississippi'.rstrip(b'ipz'))
except TypeError:
print("TypeError")
+
+# single-char subj string used to give a problem
+print("a".strip())
+print("a".lstrip())
+print("a".rstrip())
+print(" a".strip())
+print(" a".lstrip())
+print(" a".rstrip())
+print("a ".strip())
+print("a ".lstrip())
+print("a ".rstrip())
+
+# Test that stripping unstrippable string returns original object
+s = "abc"
+print(id(s.strip()) == id(s))