Skip to content

Commit ae20cb5

Browse files
committed
Fix Schema::Element required? and array? methods
In 133096b#diff-ff32e4dff2433e31f170b6f43842c940bec1c3581a07a5e3bc44887ce973fcc0L67-L76 the `min_occurs` and `max_occurs` getters were removed, saying they were "invalid". The additional message in [HISTORY](https://github.com/xml4r/libxml-ruby/blob/master/HISTORY#L63C111-L63C111) states: > Remove SchemaElement#minOccurs and SchemaElement#maxOccurs since they actually did not work (Charlie Savage) [Additional history here](https://github.com/search?q=repo%3Axml4r%2Flibxml-ruby+min_occurs&type=commits) I'm not aware of any more context surrounding the change, but those methods were still referenced by the Schema::Element's `array?` and `required?` methods. This PR adds tests for those two methods and adds simple ivar reader methods to replace those removed C methods.
1 parent b0fd435 commit ae20cb5

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)