def test_template_failed_unbalanced_brackets(): template = r"""```tested > integer x = \ data(1, 2, "alpha beta" ```""" with pytest.raises(ValueError): create_description_instance(template, programming_language="java", is_html=False)
def test_template_natural_type_name(lang: str, tested_type: Any, expected: str): template = f"""${{datatype_common({tested_type})}}""" instance = create_description_instance(template, programming_language=lang, is_html=False) assert instance == f"{expected}"
def test_template_statement_expression(lang: str, expected: str): template = """${statement('random = new Random()')} ${statement('random.new_sequence(10, 10)')} ${expression('[10, 5, 2, 8, 7, 1, 3, 4, 9, 6]')}""" instance = create_description_instance(template, programming_language=lang, is_html=False) assert instance == f"{expected}"
def test_template_escaped_string_code_block_markdown(lang: str, prompt: str): template = r"""```tested "alpha\"beta\tname" ```""" instance = create_description_instance(template, programming_language=lang, is_html=False) expected_str = "'alpha\"beta\\tname'" if lang == "python" else r'"alpha\"beta\tname"' expected = f"""```console?lang={lang}&prompt={prompt} {expected_str} ```""" assert instance == expected
def test_template_multi_line_code_block_markdown(lang: str, prompt: str, expected: str): template = r"""```tested > integer x = \ data(1, 2, "alpha") ```""" instance = create_description_instance(template, programming_language=lang, is_html=False) expected = f"""```console?lang={lang}&prompt={prompt} {prompt} {expected} ```""" assert instance == expected
def test_template_code_block_html(lang: str, prompt: str, expected_stmt: str, expected_expr: str): template = """<code class="tested"> > random() 5 </code>""" instance = create_description_instance(template, programming_language=lang, is_html=True) expected = f"""<code class="tested"> {html.escape(prompt)} {expected_stmt} {expected_expr} </code>""" assert instance == expected
def test_template_code_block_markdown(lang: str, prompt: str): template = """```tested > random() 5 ```""" expected_stmt = "random" if lang == "haskell" else "Submission.random()" if lang == "java" else "random()" expected_expr = "5 :: Int" if lang == "haskell" else "5" instance = create_description_instance(template, programming_language=lang, is_html=False) expected = f"""```console?lang={lang}&prompt={prompt} {prompt} {expected_stmt} {expected_expr} ```""" assert instance == expected
def test_template_function_name(lang: str, expected: str): template = '${function("this_is_a_function_name")}' instance = create_description_instance(template, programming_language=lang, is_html=False) assert instance == f"{expected}"
def test_template_type_name_override(): template = """${datatype("integer", {"java": {"integer": "long"}})}""" instance = create_description_instance(template, programming_language="java", is_html=False) assert instance == "long"