-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API: split out MLIR-independent printing into BasePrinter and use in …
…STIM [NFC] (#3613) I'd also like to use the indentation logic in ASL, WGSL, and the assembly dialects, PRs incoming.
- Loading branch information
1 parent
056f76e
commit 414bcb0
Showing
5 changed files
with
187 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.