test/jini_test.rb in jini-0.0.4 vs test/jini_test.rb in jini-0.0.5
- old
+ new
@@ -29,21 +29,34 @@
# Jini test.
# Author:: Ivan Ivanchuk (clicker.heroes.acg@gmail.com)
# Copyright:: Copyright (c) 2022-2022 Ivan Ivanchuck
# License:: MIT
class JiniTest < Minitest::Test
+ PARENT = 'parent'
+ CHILD = 'child'
def test_add_path_and_at_success
assert_equal(
'/parent/child[1]',
Jini.new
- .add_path('parent')
- .add_path('child')
+ .add_path(PARENT)
+ .add_path(CHILD)
.at(1)
.to_s
)
end
+ def test_remove_path
+ assert_equal(
+ 'parent/toy',
+ Jini.new(PARENT)
+ .add_path(CHILD)
+ .add_path('toy')
+ .remove_path(CHILD)
+ .to_s
+ )
+ end
+
def test_add_attr_success
assert_equal(
'/node[@key="value"]',
Jini.new
.add_path('node')
@@ -54,21 +67,21 @@
def test_all_success
assert_equal(
'/parent/child/*',
Jini.new
- .add_path('parent')
- .add_path('child')
+ .add_path(PARENT)
+ .add_path(CHILD)
.all
.to_s
)
end
def test_all_fail
assert_raises do
Jini.new
- .add_path('parent')
+ .add_path(PARENT)
.add_attr('key', 'value')
.all
end
end
@@ -87,15 +100,53 @@
def test_remove_attr_many
assert_equal(
'/parent/child/toy',
Jini
.new
- .add_path('parent')
- .add_path('child')
+ .add_path(PARENT)
+ .add_path(CHILD)
.add_attr('age', 'teen')
.add_path('toy')
.add_attr('age', 'old')
.remove_attr('age')
.to_s
+ )
+ end
+
+ def test_add_all
+ assert_equal(
+ 'parent//children',
+ Jini.new(PARENT).add_all('children').to_s
+ )
+ end
+
+ def test_selection_success
+ assert_equal(
+ 'parent::child',
+ Jini.new(PARENT)
+ .add_path(CHILD)
+ .selection
+ .to_s
+ )
+ end
+
+ def test_selection_fail
+ assert_raises do
+ Jini.new
+ .add_path(PARENT)
+ .add_path(CHILD)
+ .add_attr('k', 'v')
+ .selection
+ .to_s
+ end
+ end
+
+ def test_or
+ assert_equal(
+ 'parent/child|animal',
+ Jini.new(PARENT)
+ .add_path(CHILD)
+ .or('animal')
+ .to_s
)
end
end