Skip to content

Commit 503f5bd

Browse files
authored
[mypyc] Add tests for string equality (#19401)
This is in preparation for adding a faster str equality primitive.
1 parent d503edf commit 503f5bd

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

mypyc/test-data/run-strings.test

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,64 @@ assert remove_prefix_suffix('', '') == ('', '')
9292
assert remove_prefix_suffix('abc', 'a') == ('bc', 'abc')
9393
assert remove_prefix_suffix('abc', 'c') == ('abc', 'ab')
9494

95+
[case testStringEquality]
96+
def eq(a: str, b: str) -> bool:
97+
return a == b
98+
def ne(a: str, b: str) -> bool:
99+
return a != b
100+
101+
def test_basic() -> None:
102+
xy = "xy"
103+
xy2 = str().join(["x", "y"])
104+
xx = "xx"
105+
yy = "yy"
106+
xxx = "xxx"
107+
108+
assert eq("", str())
109+
assert not ne("", str())
110+
111+
assert eq("x", "x" + str())
112+
assert ne("x", "y")
113+
114+
assert eq(xy, xy)
115+
assert eq(xy, xy2)
116+
assert not eq(xy, yy)
117+
assert ne(xy, xx)
118+
assert not ne(xy, xy)
119+
assert not ne(xy, xy2)
120+
121+
assert ne(xx, xxx)
122+
assert ne(xxx, xx)
123+
assert ne("x", "")
124+
assert ne("", "x")
125+
126+
assert ne("XX", xx)
127+
assert ne(yy, xy)
128+
129+
def test_unicode() -> None:
130+
assert eq(chr(200), chr(200) + str())
131+
assert ne(chr(200), chr(201))
132+
133+
assert eq(chr(1234), chr(1234) + str())
134+
assert ne(chr(1234), chr(1235))
135+
136+
assert eq("\U0001f4a9", "\U0001f4a9" + str())
137+
assert eq("\U0001f4a9", "\U0001F4A9" + str())
138+
assert ne("\U0001f4a9", "\U0002f4a9" + str())
139+
assert ne("\U0001f4a9", "\U0001f5a9" + str())
140+
assert ne("\U0001f4a9", "\U0001f4a8" + str())
141+
142+
assert eq("foobar\u1234", "foobar\u1234" + str())
143+
assert eq("\u1234foobar", "\u1234foobar" + str())
144+
assert ne("foobar\uf234", "foobar\uf235")
145+
assert ne("foobar\uf234", "foobar\uf334")
146+
assert ne("foobar\u1234", "Foobar\u1234" + str())
147+
148+
assert eq("foo\U0001f4a9", "foo\U0001f4a9" + str())
149+
assert eq("\U0001f4a9foo", "\U0001f4a9foo" + str())
150+
assert ne("foo\U0001f4a9", "foo\U0001f4a8" + str())
151+
assert ne("\U0001f4a9foo", "\U0001f4a8foo" + str())
152+
95153
[case testStringOps]
96154
from typing import List, Optional, Tuple
97155
from testutil import assertRaises

0 commit comments

Comments
 (0)