Skip to content

Commit

Permalink
added support for YCP::Term in size() builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Jan 22, 2013
1 parent dcb4636 commit 4aa7386
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ruby/ycp/builtins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def self.size object
return nil if object.nil?

case object
when String, Array, Hash then return object.size
when String, Array, Hash, YCP::Term then return object.size
else
raise "Invalid object for size() builtin"
end
Expand Down
5 changes: 4 additions & 1 deletion src/ruby/ycp/term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def != second
def [] index
params[index]
end


def size
params.size
end
end
end
6 changes: 6 additions & 0 deletions tests/ruby/builtins_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

require "ycp/builtins"
require "ycp/path"
require "ycp/term"

class BuiltinsPathTest < YCP::TestCase
def test_add_list
Expand Down Expand Up @@ -77,5 +78,10 @@ def test_size
assert_equal 0, YCP::Builtins.size([])
assert_equal 0, YCP::Builtins.size({})
assert_equal 0, YCP::Builtins.size("")

assert_equal 0, YCP::Builtins.size(YCP::Term.new(:HBox))
assert_equal 1, YCP::Builtins.size(YCP::Term.new(:HBox, "test"))
assert_equal 2, YCP::Builtins.size(YCP::Term.new(:HBox, "test", "test"))
assert_equal 1, YCP::Builtins.size(YCP::Term.new(:HBox, YCP::Term.new(:VBox, "test", "test")))
end
end
7 changes: 7 additions & 0 deletions tests/ruby/term_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ def test_equal
assert_not_equal YCP::Term.new(:HBox), YCP::Term.new(:HBox, "test")
end

def test_size
assert_equal 0, YCP::Term.new(:HBox).size
assert_equal 1, YCP::Term.new(:HBox, "test").size
assert_equal 1, YCP::Term.new(:HBox, "test").size
assert_equal 1, YCP::Term.new(:HBox, YCP::Term.new(:VBox, "test", "test")).size
end

end

0 comments on commit 4aa7386

Please sign in to comment.