micropython: add micropython component

This commit is contained in:
KY-zhang-X
2022-09-29 12:10:37 +08:00
parent 1514f1cb9b
commit dd76146324
2679 changed files with 354110 additions and 0 deletions

View File

@@ -0,0 +1 @@
Привет

View File

@@ -0,0 +1,2 @@
aαbβcγ
ぁ🙐

View File

@@ -0,0 +1,4 @@
f = open("unicode/data/utf-8_1.txt", encoding="utf-8")
l = f.readline()
print(l)
print(len(l))

View File

@@ -0,0 +1,28 @@
# test reading a given number of characters
def do(mode):
if mode == "rb":
enc = None
else:
enc = "utf-8"
f = open("unicode/data/utf-8_2.txt", mode=mode, encoding=enc)
print(f.read(1))
print(f.read(1))
print(f.read(2))
print(f.read(4))
# skip to end of line
f.readline()
# check 3-byte utf-8 char
print(f.read(1 if mode == "rt" else 3))
# check 4-byte utf-8 char
print(f.read(1 if mode == "rt" else 4))
f.close()
do("rb")
do("rt")

View File

@@ -0,0 +1,53 @@
# Test a UTF-8 encoded literal
s = "asdf©qwer"
for i in range(len(s)):
print("s[%d]: %s %X" % (i, s[i], ord(s[i])))
# Test all three forms of Unicode escape, and
# all blocks of UTF-8 byte patterns
s = "a\xA9\xFF\u0123\u0800\uFFEE\U0001F44C"
for i in range(-len(s), len(s)):
print("s[%d]: %s %X" % (i, s[i], ord(s[i])))
print("s[:%d]: %d chars, '%s'" % (i, len(s[:i]), s[:i]))
for j in range(i, len(s)):
print("s[%d:%d]: %d chars, '%s'" % (i, j, len(s[i:j]), s[i:j]))
print("s[%d:]: %d chars, '%s'" % (i, len(s[i:]), s[i:]))
# Test UTF-8 encode and decode
enc = s.encode()
print(enc, enc.decode() == s)
# printing of unicode chars using repr
# NOTE: for some characters (eg \u10ff) we differ to CPython
print(repr("a\uffff"))
print(repr("a\U0001ffff"))
# test invalid escape code
try:
eval('"\\U00110000"')
except SyntaxError:
print("SyntaxError")
# test unicode string given to int
try:
int("\u0200")
except ValueError:
print("ValueError")
# test invalid UTF-8 string
try:
str(b"ab\xa1", "utf8")
except UnicodeError:
print("UnicodeError")
try:
str(b"ab\xf8", "utf8")
except UnicodeError:
print("UnicodeError")
try:
str(bytearray(b"ab\xc0a"), "utf8")
except UnicodeError:
print("UnicodeError")
try:
str(b"\xf0\xe0\xed\xe8", "utf8")
except UnicodeError:
print("UnicodeError")

View File

@@ -0,0 +1,5 @@
# test builtin chr with unicode characters
print(chr(945))
print(chr(0x800))
print(chr(0x10000))

View File

@@ -0,0 +1,32 @@
# test unicode in identifiers
# comment
# αβγδϵφζ
# global identifiers
α = 1
αβγ = 2
= 3
βb = 4
print(α, αβγ, , βb)
# function, argument, local identifiers
def α(β, γ):
δ = β + γ
print(β, γ, δ)
α(1, 2)
# class, method identifiers
class φ:
def __init__(self):
pass
def δ(self, ϵ):
print(ϵ)
zζzζz = φ()
if hasattr(zζzζz, "δ"):
zζzζz.δ(ϵ=123)

View File

@@ -0,0 +1,6 @@
print("Привет".find("т"))
print("Привет".find("П"))
print("Привет".rfind("т"))
print("Привет".rfind("П"))
print("Привет".index("т"))
print("Привет".index("П"))

View File

@@ -0,0 +1,4 @@
for c in "Hello":
print(c)
for c in "Привет":
print(c)

View File

@@ -0,0 +1,3 @@
# test builtin ord with unicode characters
print(ord("α"))

View File

@@ -0,0 +1,5 @@
# str methods with explicit start/end pos
print("Привет".startswith("П"))
print("Привет".startswith("р", 1))
print("абвба".find("а", 1))
print("абвба".find("а", 1, -1))

View File

@@ -0,0 +1,12 @@
# Test slicing of Unicode strings
s = "Привет"
print(s[:])
print(s[2:])
print(s[:5])
print(s[2:5])
print(s[2:5:1])
print(s[2:10])
print(s[-3:10])
print(s[-4:10])

View File

@@ -0,0 +1,4 @@
# test handling of unicode chars in format strings
print("α".format())
print("{α}".format(α=1))

View File

@@ -0,0 +1,3 @@
# test handling of unicode chars in string % formatting
print("α" % ())

View File

@@ -0,0 +1,23 @@
a = "¢пр"
print(a[0], a[0:1])
print(a[1], a[1:2])
print(a[2], a[2:3])
try:
print(a[3])
except IndexError:
print("IndexError")
print(a[3:4])
print(a[-1])
print(a[-2], a[-2:-1])
print(a[-3], a[-3:-2])
try:
print(a[-4])
except IndexError:
print("IndexError")
print(a[-4:-3])
print(a[0:2])
print(a[1:3])
print(a[2:4])