Skip to content

Commit

Permalink
Merge branch 'main' into fix-race-condish
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Sep 26, 2023
2 parents 11051e1 + 145f7e4 commit 75c1153
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ def translate_error(code, arguments, keyword_lang):
'allowed_types',
'invalid_type',
'invalid_type_2',
'offending_keyword',
'character_found',
'concept',
'tip',
Expand All @@ -762,6 +763,7 @@ def translate_error(code, arguments, keyword_lang):
'guessed_command',
'invalid_argument',
'invalid_argument_2',
'offending_keyword',
'variable',
'invalid_value',
'print',
Expand Down
17 changes: 14 additions & 3 deletions hedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3007,12 +3007,23 @@ def contains_any_of(commands, line):
return True
return False

def next_non_empty_line(lines, start_line_number):
if start_line_number > len(lines):
return '' # end of code, return empty so that starts_with doesnt find anything
else:
for i in range(start_line_number + 1, len(lines)):
if lines[i] == '':
continue
else:
return lines[i]

return '' # nothing found? return empty so that starts_with doesnt find anything

for i in range(len(lines) - 1):
line = lines[i]
next_line = lines[i + 1]

# if this line starts with if but does not contain an else, and the next line too is not an else.
if (starts_with('if', line) or starts_with_after_repeat('if', line)) and (not starts_with('else', next_line)) and (not contains('else', line)):
# if this line starts with if but does not contain an else, and the next non-empty line too is not an else.
if (starts_with('if', line) or starts_with_after_repeat('if', line)) and (not starts_with('else', next_non_empty_line(lines, i))) and (not contains('else', line)):
# is this line just a condition and no other keyword (because that is no problem)
commands = ["print", "ask", "forward", "turn"]
excluded_commands = ["pressed"]
Expand Down
16 changes: 16 additions & 0 deletions tests/test_level/test_level_05.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,22 @@ def test_if_equality_print_linebreak_else_print(self):

self.single_level_tester(code=code, expected=expected)

def test_if_equality_print_linebreaks_else_print(self):
# line break before else is allowed
code = textwrap.dedent("""\
naam is Hedy
if naam is Hedy print 'leuk'\n\n
else print 'minder leuk'""")

expected = textwrap.dedent("""\
naam = 'Hedy'
if naam == 'Hedy':
print(f'leuk')
else:
print(f'minder leuk')""")

self.single_level_tester(code=code, expected=expected)

def test_if_equality_linebreak_print_else_print(self):
# line break after if-condition is allowed
code = textwrap.dedent("""\
Expand Down
2 changes: 1 addition & 1 deletion translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ msgstr "Are you sure? You cannot revert this action."
msgid "ask_needs_var"
msgstr ""
"Starting in level 2, {ask} needs to be used with a variable. Example: "
"name {is} {ask} What are you called?"
"name {is} {ask} What is your name?"

msgid "back_to_class"
msgstr "Go back to class"
Expand Down
2 changes: 1 addition & 1 deletion translations/nl/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ msgstr "Weet je het zeker? Je kunt dit niet meer ongedaan maken."

msgid "ask_needs_var"
msgstr ""
"Vanaf level 2 hoort {ask} met een variabele ervoor. Bijv: naam is {ask} "
"Vanaf level 2 hoort {ask} met een variabele ervoor. Bijv: naam {is} {ask} "
"Hoe heet jij?"

msgid "back_to_class"
Expand Down

0 comments on commit 75c1153

Please sign in to comment.