Skip to content

Commit

Permalink
SchemaSet #inspect #pretty_print
Browse files Browse the repository at this point in the history
  • Loading branch information
notEthan committed Feb 27, 2021
1 parent bbf57ac commit b7b3899
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/jsi/schema_set.rb
Expand Up @@ -54,5 +54,24 @@ def initialize(enum, &block)

freeze
end

def inspect
"#{self.class}[#{map(&:inspect).join(", ")}]"
end

def pretty_print(q)
q.text self.class.to_s
q.text '['
q.group_sub {
q.nest(2) {
q.breakable('')
q.seplist(self, nil, :each) { |e|
q.pp e
}
}
}
q.breakable ''
q.text ']'
end
end
end
12 changes: 12 additions & 0 deletions test/schema_set_test.rb
Expand Up @@ -44,4 +44,16 @@
assert_raises(ArgumentError) { JSI::SchemaSet.ensure_schema_set(3) }
end
end
describe '#inspect' do
it 'inspects' do
schema_set = JSI::SchemaSet[schema_a]
assert_equal(%q(JSI::SchemaSet[#{<JSI (JSI::JSONSchemaOrgDraft06) Schema> "title" => "A"}]), schema_set.inspect)
end
end
describe '#pretty_print' do
it 'pretty prints' do
schema_set = JSI::SchemaSet[schema_a]
assert_equal(%q(JSI::SchemaSet[#{<JSI (JSI::JSONSchemaOrgDraft06) Schema> "title" => "A"}]), schema_set.pretty_inspect.chomp)
end
end
end

0 comments on commit b7b3899

Please sign in to comment.