Skip to content

Commit cb088a4

Browse files
committed
Fix mispelled methods and add tests.
1 parent ba9ac99 commit cb088a4

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

lib/libxml/schema/type.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ def kind_name
55
Schema::Types.constants.find { |k| Schema::Types.const_get(k) == kind }
66
end
77

8-
def annonymus_subtypes
8+
def anonymous_subtypes
99
elements.select { |_, e| e.type.name.nil? }
1010
end
1111

12-
def annonymus_subtypes_recursively(parent=nil)
13-
annonymus_subtypes.map do |element_name, e|
12+
def anonymous_subtypes_recursively(parent=nil)
13+
anonymous_subtypes.map do |element_name, e|
1414
[{[parent, element_name].compact.join('::') => e.type},
15-
e.type.annonymus_subtypes_recursively(element_name)]
15+
e.type.anonymous_subtypes_recursively(element_name)]
1616
end.flatten
1717
end
1818

test/test_schema.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,31 @@ def test_schema_attribute
235235
assert_equal('1', attribute.default)
236236
assert_equal('integer', attribute.type.name)
237237
end
238+
239+
def test_anonymous_subtypes
240+
type = @schema.types['shiporderType']
241+
anon = type.anonymous_subtypes
242+
243+
assert_instance_of(Hash, anon)
244+
assert_equal(2, anon.length)
245+
assert_includes(anon.keys, 'shipto')
246+
assert_includes(anon.keys, 'item')
247+
248+
anon.each_value do |element|
249+
assert_instance_of(LibXML::XML::Schema::Element, element)
250+
assert_nil(element.type.name)
251+
end
252+
end
253+
254+
def test_anonymous_subtypes_recursively
255+
type = @schema.types['shiporderType']
256+
result = type.anonymous_subtypes_recursively
257+
258+
assert_instance_of(Array, result)
259+
assert_operator(result.length, :>=, 2)
260+
261+
keys = result.select { |r| r.is_a?(Hash) }.flat_map(&:keys)
262+
assert_includes(keys, 'shipto')
263+
assert_includes(keys, 'item')
264+
end
238265
end

0 commit comments

Comments
 (0)