Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor hierarchy printers #10791

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions spec/compiler/crystal/tools/hierarchy_spec.cr
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
2 changes: 1 addition & 1 deletion src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Crystal::Command
private def hierarchy
config, result = compile_no_codegen "tool hierarchy", hierarchy: true, top_level: true
@progress_tracker.stage("Tool (hierarchy)") do
Crystal.print_hierarchy result.program, config.hierarchy_exp, config.output_format
Crystal.print_hierarchy result.program, STDOUT, config.hierarchy_exp, config.output_format
end
end

Expand Down
Loading