This commit is contained in:
blueloveTH 2025-03-12 19:56:26 +08:00
parent e25cc48463
commit 61e36941a9
2 changed files with 15 additions and 9 deletions

View File

@ -447,7 +447,10 @@ static Error* lex_one_token(Lexer* self, bool* eof, bool is_fstring) {
} }
case ',': add_token(self, TK_COMMA); return NULL; case ',': add_token(self, TK_COMMA); return NULL;
case ':': { case ':': {
if(is_fstring) { return eat_fstring_spec(self, eof); } if(is_fstring) {
// BUG: f"{stack[2:]}"
return eat_fstring_spec(self, eof);
}
add_token(self, TK_COLON); add_token(self, TK_COLON);
return NULL; return NULL;
} }

View File

@ -199,8 +199,6 @@ assert chr(0x1f955) == '🥕'
assert ord('') == 27979 assert ord('') == 27979
assert chr(27979) == '' assert chr(27979) == ''
exit()
# test format() # test format()
assert "Hello, {}!".format("World") == "Hello, World!" assert "Hello, {}!".format("World") == "Hello, World!"
assert "{} {} {}".format("I", "love", "Python") == "I love Python" assert "{} {} {}".format("I", "love", "Python") == "I love Python"
@ -214,14 +212,19 @@ assert "{0}={1}".format('{0}', '{1}') == "{0}={1}"
assert "{{{0}}}".format(1) == "{1}" assert "{{{0}}}".format(1) == "{1}"
assert "{0}{1}{1}".format(1, 2, 3) == "122" assert "{0}{1}{1}".format(1, 2, 3) == "122"
# try: try:
# "{0}={1}}".format(1, 2) "{0}={1}}".format(1, 2)
# exit(1) exit(1)
# except ValueError: except ValueError:
# pass pass
assert "{{{}xxx{}x}}".format(1, 2) == "{1xxx2x}" assert "{{{}xxx{}x}}".format(1, 2) == "{1xxx2x}"
assert "{{abc}}".format() == "{abc}" assert "{{abc}}".format() == "{abc}"
# test f-string # test f-string
# stack=[1,2,3,4]; assert f"{stack[2:]}" == '[3, 4]' assert f"{1+2}" == "3"
# assert f"{1, 2, 3}" == "(1, 2, 3)"
assert f"{(1, 2, 3)}" == "(1, 2, 3)"
# stack=[1,2,3,4]
# assert f"{stack[2:]}" == '[3, 4]'