Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪲 Fix color command error #5603

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion hedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,9 @@ def process_variable_for_fstring(self, name):
if self.is_quoted(name):
name = name[1:-1]
return name.replace("'", "\\'")
name = name if self.is_bool(name) else escape_var(name.replace("'", "\\'"))
if not ConvertToPython.is_int(name) and not ConvertToPython.is_float(name):
name = name if self.is_bool(name) else escape_var(name.replace("'", "\\'"))
name = '"' + name + '"'
return f'{{convert_numerals("{self.numerals_language}", {name})}}'

def var_access(self, meta, args):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_level/test_level_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ def test_undefined_list_access(self):
@parameterized.expand(hedy.english_colors)
def test_all_colors(self, color):
code = f'color {color}'
expected = HedyTester.turtle_color_command_transpiled(f'{{convert_numerals("Latin", {color})}}')
expected = HedyTester.turtle_color_command_transpiled(f'{{convert_numerals("Latin", "{color}")}}')

self.multi_level_tester(
code=code,
Expand All @@ -1054,7 +1054,7 @@ def test_all_colors(self, color):

def test_color_red(self):
code = "color red"
expected = HedyTester.turtle_color_command_transpiled('{convert_numerals("Latin", red)}')
expected = HedyTester.turtle_color_command_transpiled('{convert_numerals("Latin", "red")}')

self.multi_level_tester(
code=code,
Expand All @@ -1066,7 +1066,7 @@ def test_color_red(self):
def test_color_translated(self):
lang = 'nl'
code = "kleur blauw"
expected = HedyTester.turtle_color_command_transpiled('{convert_numerals("Latin", blue)}', lang)
expected = HedyTester.turtle_color_command_transpiled('{convert_numerals("Latin", "blue")}', lang)

self.multi_level_tester(
code=code,
Expand All @@ -1082,7 +1082,7 @@ def test_color_basic(self):
forward 10""")

expected = HedyTester.dedent(
HedyTester.turtle_color_command_transpiled('{convert_numerals("Latin", red)}', 'en'),
HedyTester.turtle_color_command_transpiled('{convert_numerals("Latin", "red")}', 'en'),
HedyTester.forward_transpiled('10', self.level))

self.multi_level_tester(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_level/test_level_15.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def test_assign_list_var_boolean(self):
)

@parameterized.expand(HedyTester.booleans)
def test_print_boolean(self, value, expected):
def test_print_boolean(self, value, exp):
code = f"print 'variable is ' {value}"
expected = f"print(f'''variable is {{convert_numerals(\"Latin\", {expected})}}''')"
expected = f"print(f'''variable is {{convert_numerals(\"Latin\", \"{exp}\")}}''')"

self.multi_level_tester(
code=code,
Expand All @@ -50,7 +50,7 @@ def test_print_boolean(self, value, expected):
@parameterized.expand([('вярно', True), ('Вярно', True), ('невярно', False), ('Невярно', False)])
def test_print_boolean_bulgarian(self, value, exp):
code = f"принтирай 'Това е ' {value}"
expected = f"print(f'''Това е {{convert_numerals(\"Latin\", {exp})}}''')"
expected = f"print(f'''Това е {{convert_numerals(\"Latin\", \"{exp}\")}}''')"

self.multi_level_tester(
code=code,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_level/test_level_17.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def test_if_pressed_with_turtlecolor(self):
if_pressed_mapping = {{"else": "if_pressed_default_else"}}
if_pressed_mapping['x'] = 'if_pressed_x_'
def if_pressed_x_():
__trtl = f'{{convert_numerals("Latin", red)}}'
__trtl = f'{{convert_numerals("Latin", "red")}}'
color_dict = {color_dict}
if __trtl not in ['black', 'blue', 'brown', 'gray', 'green', 'orange', 'pink', 'purple', 'red', 'white', 'yellow']:
raise Exception(f{self.value_exception_transpiled()})
Expand Down
Loading