Skip to content

Commit c7b46b0

Browse files
authored
Merge pull request #206 from jxa/schema-element-fixes
Fix Schema::Element required? and array? methods
2 parents b0fd435 + ae20cb5 commit c7b46b0

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/libxml/schema/element.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
module LibXML
44
module XML
55
class Schema::Element
6+
def min_occurs
7+
@min
8+
end
9+
10+
def max_occurs
11+
@max
12+
end
13+
614
def required?
715
!min_occurs.zero?
816
end

test/test_schema.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,19 @@ def test_schema_element
198198
assert_equal('orderperson', element.name)
199199
assert_nil(element.namespace)
200200
assert_equal("orderperson element documentation", element.annotation)
201+
assert_equal(false, element.array?)
202+
assert_equal(true, element.required?)
201203

202204
element = @schema.types['shiporderType'].elements['item']
203205
assert_equal('item', element.name)
206+
assert_equal(true, element.array?)
207+
assert_equal(true, element.required?)
204208

205209
element = @schema.types['shiporderType'].elements['item'].type.elements['note']
206210
assert_equal('note', element.name)
207211
assert_equal('string', element.type.name)
212+
assert_equal(false, element.array?)
213+
assert_equal(false, element.required?)
208214
end
209215

210216
def test_schema_attributes

0 commit comments

Comments
 (0)