-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor hierarchy printers (#10791)
- Loading branch information
1 parent
4a54929
commit 78b6cfb
Showing
3 changed files
with
167 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require "../../../spec_helper" | ||
|
||
describe Crystal::TextHierarchyPrinter do | ||
it "works" do | ||
program = semantic(%( | ||
class Foo | ||
end | ||
class Bar < Foo | ||
end | ||
), inject_primitives: false).program | ||
|
||
output = String.build { |io| Crystal.print_hierarchy(program, io, "ar$", "text") } | ||
output.should eq(<<-EOS) | ||
- class Object (4 bytes) | ||
| | ||
+- class Reference (4 bytes) | ||
| | ||
+- class Foo (4 bytes) | ||
| | ||
+- class Bar (4 bytes)\n | ||
EOS | ||
end | ||
end | ||
|
||
describe Crystal::JSONHierarchyPrinter do | ||
it "works" do | ||
program = semantic(%( | ||
class Foo | ||
end | ||
class Bar < Foo | ||
end | ||
), inject_primitives: false).program | ||
|
||
output = String.build { |io| Crystal.print_hierarchy(program, io, "ar$", "json") } | ||
JSON.parse(output).should eq(JSON.parse(<<-EOS)) | ||
{ | ||
"name": "Object", | ||
"kind": "class", | ||
"size_in_bytes": 4, | ||
"sub_types": [ | ||
{ | ||
"name": "Reference", | ||
"kind": "class", | ||
"size_in_bytes": 4, | ||
"sub_types": [ | ||
{ | ||
"name": "Foo", | ||
"kind": "class", | ||
"size_in_bytes": 4, | ||
"sub_types": [ | ||
{ | ||
"name": "Bar", | ||
"kind": "class", | ||
"size_in_bytes": 4, | ||
"sub_types": [] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
EOS | ||
end | ||
end |
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.