Skip to content

Commit

Permalink
[BUG] Fix broken tests (#4882)
Browse files Browse the repository at this point in the history
Fixes #4863.

After #4838, the processing of the string was done after setting the input string on the source map.
This led to 2 tests failing.

This PR first uses process_input_string before setting the input on the source map. Fixing the failing tests.
  • Loading branch information
ToniSkulj authored Dec 11, 2023
1 parent d71cf62 commit b6d8d15
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ logs.txt
.local
node_modules

# Ignore things that start with underscores
# Ignore things that start with underscores (except __init__.py)
_*
!__init__.py
# Ignore pickled versions of YAML files
*.yaml.pickle
dev_database.json
Expand Down
2 changes: 1 addition & 1 deletion hedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3347,7 +3347,6 @@ def create_lookup_table(abstract_syntax_tree, level, lang, input_string):


def create_AST(input_string, level, lang="en"):
input_string = process_input_string(input_string, level, lang)
program_root = parse_input(input_string, level, lang)

try:
Expand Down Expand Up @@ -3377,6 +3376,7 @@ def create_AST(input_string, level, lang="en"):

def transpile_inner(input_string, level, lang="en", populate_source_map=False, is_debug=False):
check_program_size_is_valid(input_string)
input_string = process_input_string(input_string, level, lang)

level = int(level)
if level > HEDY_MAX_LEVEL:
Expand Down
Empty file added tests/__init__.py
Empty file.
49 changes: 24 additions & 25 deletions tests/test_level/test_level_05.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,31 +186,30 @@ def test_if_equality_unquoted_rhs_with_space_print_gives_error(self):
max_level=7
)

# Disabled in 4838
# def test_if_equality_unquoted_rhs_with_space_and_following_command_print_gives_error(self):
# code = textwrap.dedent("""\
# naam is James
# if naam is James Bond print 'shaken'
# print naam
# prind skipping""")
#
# expected = textwrap.dedent("""\
# naam = 'James'
# pass
# print(f'{naam}')
# pass""")
#
# skipped_mappings = [
# SkippedMapping(SourceRange(2, 1, 2, 59), hedy.exceptions.UnquotedEqualityCheckException),
# SkippedMapping(SourceRange(4, 1, 4, 15), hedy.exceptions.InvalidCommandException)
# ]
#
# self.multi_level_tester(
# code=code,
# expected=expected,
# skipped_mappings=skipped_mappings,
# max_level=7
# )
def test_if_equality_unquoted_rhs_with_space_and_following_command_print_gives_error(self):
code = textwrap.dedent("""\
naam is James
if naam is James Bond print 'shaken'
print naam
prind skipping""")

expected = textwrap.dedent("""\
naam = 'James'
pass
print(f'{naam}')
pass""")

skipped_mappings = [
SkippedMapping(SourceRange(2, 1, 2, 58), hedy.exceptions.UnquotedEqualityCheckException),
SkippedMapping(SourceRange(4, 1, 4, 15), hedy.exceptions.InvalidCommandException)
]

self.multi_level_tester(
code=code,
expected=expected,
skipped_mappings=skipped_mappings,
max_level=7
)

def test_if_equality_unquoted_rhs_with_space_assign_gives_error(self):
code = textwrap.dedent("""\
Expand Down
37 changes: 18 additions & 19 deletions tests/test_level/test_level_07.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,25 +170,24 @@ def test_repeat_with_missing_print_gives_error(self):
exception=hedy.exceptions.IncompleteRepeatException
)

# Disabled in 4838
# def test_repeat_with_missing_times_gives_error_skip(self):
# code = textwrap.dedent("""\
# x is 3
# repeat 3 print 'x'""")
#
# expected = textwrap.dedent("""\
# x = '3'
# pass""")
#
# skipped_mappings = [
# SkippedMapping(SourceRange(2, 1, 2, 17), hedy.exceptions.IncompleteRepeatException),
# ]
#
# self.single_level_tester(
# code=code,
# expected=expected,
# skipped_mappings=skipped_mappings,
# )
def test_repeat_with_missing_times_gives_error_skip(self):
code = textwrap.dedent("""\
x is 3
repeat 3 print 'x'""")

expected = textwrap.dedent("""\
x = '3'
pass""")

skipped_mappings = [
SkippedMapping(SourceRange(2, 1, 2, 19), hedy.exceptions.IncompleteRepeatException),
]

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

def test_repeat_with_missing_print_gives_lonely_text_exc(self):
code = textwrap.dedent("""\
Expand Down

0 comments on commit b6d8d15

Please sign in to comment.