From 4d6e9b14dcfaaee046bd567ae456636e53a1bc15 Mon Sep 17 00:00:00 2001 From: Sasha Lopoukhine Date: Tue, 10 Dec 2024 10:28:08 +0000 Subject: [PATCH] move test --- tests/test_printer.py | 40 ----------------------------- tests/utils/test_base_printer.py | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 tests/utils/test_base_printer.py diff --git a/tests/test_printer.py b/tests/test_printer.py index 843e2d72e7..6645c8c489 100644 --- a/tests/test_printer.py +++ b/tests/test_printer.py @@ -952,43 +952,3 @@ def test_get_printed_name(): printed = StringIO() picked_name = Printer(printed).print_ssa_value(val) assert f"%{picked_name}" == printed.getvalue() - - -def test_indented(): - output = StringIO() - printer = Printer(stream=output) - printer.print("\n{") - with printer.indented(): - printer.print("\nhello\nhow are you?") - printer.print("\n(") - with printer.indented(): - printer.print("\nfoo,") - printer.print("\nbar,") - printer.print("\n") - printer.print_string("test\nraw print!", indent=0) - printer.print_string("\ndifferent indent level", indent=4) - printer.print("\n)") - printer.print("\n}") - printer.print("\n[") - with printer.indented(amount=3): - printer.print("\nbaz") - printer.print("\n]\n") - - EXPECTED = """ -{ - hello - how are you? - ( - foo, - bar, - test -raw print! - different indent level - ) -} -[ - baz -] -""" - - assert output.getvalue() == EXPECTED diff --git a/tests/utils/test_base_printer.py b/tests/utils/test_base_printer.py new file mode 100644 index 0000000000..5d5882f440 --- /dev/null +++ b/tests/utils/test_base_printer.py @@ -0,0 +1,43 @@ +from io import StringIO + +from xdsl.utils.base_printer import BasePrinter + + +def test_indented(): + output = StringIO() + printer = BasePrinter(stream=output) + printer.print_string("\n{") + with printer.indented(): + printer.print_string("\nhello\nhow are you?") + printer.print_string("\n(") + with printer.indented(): + printer.print_string("\nfoo,") + printer.print_string("\nbar,") + printer.print_string("\n") + printer.print_string("test\nraw print!", indent=0) + printer.print_string("\ndifferent indent level", indent=4) + printer.print_string("\n)") + printer.print_string("\n}") + printer.print_string("\n[") + with printer.indented(amount=3): + printer.print_string("\nbaz") + printer.print_string("\n]\n") + + EXPECTED = """ +{ + hello + how are you? + ( + foo, + bar, + test +raw print! + different indent level + ) +} +[ + baz +] +""" + + assert output.getvalue() == EXPECTED