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 ':': {
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);
return NULL;
}

View File

@ -199,8 +199,6 @@ assert chr(0x1f955) == '🥕'
assert ord('') == 27979
assert chr(27979) == ''
exit()
# test format()
assert "Hello, {}!".format("World") == "Hello, World!"
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}{1}{1}".format(1, 2, 3) == "122"
# try:
# "{0}={1}}".format(1, 2)
# exit(1)
# except ValueError:
# pass
try:
"{0}={1}}".format(1, 2)
exit(1)
except ValueError:
pass
assert "{{{}xxx{}x}}".format(1, 2) == "{1xxx2x}"
assert "{{abc}}".format() == "{abc}"
# 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]'