Skip to content

Commit 79a3b13

Browse files
mcbunkuswindelbouwman
authored andcommitted
Implement most of the string methods. (RustPython#239)
* implemented more functions * backup * Improve demo site * Formatting; move the `+ '\n'` hack to eval(). * Rename run_code() to run_from_textbox() * Switch to using json.dumps for py_to_js() * Clarify names of wasm builtins * Remove dependency on num_bigint * Allow injecting JS variables into python with eval_py() eval_py(`return js_vars["a"]`, { a: 9 }) == 9 * dict() now should work properly e.g. ``` dict(a=2, b=3) == {"a": 2, "b": 3} ``` * Add documentation for eval_py() and update error message handling Also, switch from iterating over the values of js_injections and serializing each of them individually to asserting it's an object and then just stringifying the whole thing. * Finish revamping `dict_new()` * Add 'from x import *' syntax. This is a separate opcode in CPython so I added it as such here. * Add test for dicts * added functions * ran rustfmt and fixed isidentifier * fixed zfill and make_title * python3.6 doesn't contain isascii()
1 parent f325ef1 commit 79a3b13

File tree

4 files changed

+562
-29
lines changed

4 files changed

+562
-29
lines changed

Cargo.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/snippets/strings.py

+25
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
assert not a.startswith('f')
3333
assert a.endswith('llo')
3434
assert not a.endswith('on')
35+
assert a.zfill(8) == '000Hallo'
36+
assert a.isalnum()
37+
assert not a.isdigit()
38+
assert not a.isnumeric()
39+
assert a.istitle()
40+
assert a.isalpha()
41+
42+
3543

3644
b = ' hallo '
3745
assert b.strip() == 'hallo'
@@ -40,6 +48,23 @@
4048

4149
c = 'hallo'
4250
assert c.capitalize() == 'Hallo'
51+
assert c.center(11, '-') == '---hallo---'
52+
# assert c.isascii()
53+
assert c.index('a') == 1
54+
assert c.rindex('l') == 3
55+
assert c.find('h') == 0
56+
assert c.rfind('x') == -1
57+
assert c.islower()
58+
assert c.title() == 'Hallo'
59+
assert c.count('l') == 2
60+
61+
assert ' '.isspace()
62+
assert 'hello\nhallo\nHallo'.splitlines() == ['hello', 'hallo', 'Hallo']
63+
assert 'abc\t12345\txyz'.expandtabs() == 'abc 12345 xyz'
64+
assert '-'.join(['1', '2', '3']) == '1-2-3'
65+
assert 'HALLO'.isupper()
66+
assert "hello, my name is".partition("my ") == ('hello, ', 'my ', 'name is')
67+
assert "hello, my name is".rpartition("is") == ('hello, my name ', 'is', '')
4368

4469
# String Formatting
4570
assert "{} {}".format(1,2) == "1 2"

vm/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ serde_json = "1.0.26"
1717
byteorder = "1.2.6"
1818
regex = "1"
1919
statrs = "0.10.0"
20+
caseless = "0.2.1"

0 commit comments

Comments
 (0)