Sha256: c687bf13d0a6b4b8e9e5036aa70fb8a5a4263a8505d7616112cba87f4a1e85fa

Contents?: true

Size: 1.97 KB

Versions: 3

Compression:

Stored size: 1.97 KB

Contents

require File.join(File.dirname(__FILE__), 'test_helper')

module Hirb
  class UtilTest < Test::Unit::TestCase
    test "camelize converts underscore lowercase to camelcase" do
      Util.camelize('hirb/util').should == "Hirb::Util"
      Util.camelize('hirb_hash').should == "HirbHash"
    end

    test "any_const_get returns nested class" do
      Util.any_const_get("Test::Unit").should == ::Test::Unit
    end
    
    test "any_const_get returns nil for invalid class" do
      Util.any_const_get("Basdfr").should == nil
    end
    
    test "any_const_get returns class when given class" do
      Util.any_const_get(String).should == String
    end
    
    test "recursive_hash_merge merges" do
      expected_hash = {:output=>{:fields=>["f1", "f2"], :method=>"blah"}, :key1=>"hash1", :key2=>"hash2"}
      Util.recursive_hash_merge({:output=>{:fields=>%w{f1 f2}}, :key1=>'hash1'},
        {:output=>{:method=>'blah'}, :key2=>'hash2'}).should == expected_hash
    end

    test "choose_from_array specifies range with -" do
      Util.choose_from_array([1,2,3,4], '1-2,4').should == [1,2,4]
    end

    test "choose_from_array specifies range with .." do
      Util.choose_from_array([1,2,3,4], '1 .. 2,4').should == [1,2,4]
    end

    test "choose_from_array chooses all with *" do
      Util.choose_from_array([1,2,3,4], '*').should == [1,2,3,4]
    end

    test "choose_from_array ignores non-numerical input" do
      Util.choose_from_array([1,2,3,4], 'a,2').should == [2]
    end

    test "choose_from_array ignores 0" do
      Util.choose_from_array([1,2,3,4], '0,2').should == [2]
    end

    test "choose_from_array returns empty when empty input" do
      Util.choose_from_array([1,2,3,4], "\n").should == []
    end

    test "choose_from_array returns empty with an invalid range" do
      Util.choose_from_array([1,2,3,4], "5").should == []
    end

    test "capture_stdout" do
      string = "sweetness man"
      Util.capture_stdout { puts string }.should == string + "\n"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hirb-0.3.1 test/util_test.rb
hirb-0.3.0 test/util_test.rb
hirb-0.2.10 test/util_test.rb