Sha256: f6c5e04768171c659baf7becfbcf96964b48e77fa2b1bab4d235ee0bc6921e13

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

require File.dirname(__FILE__) + "/../test_helper"

require 'adhearsion/voip/dsl/numerical_string'
require 'adhearsion/voip/constants'

context "A NumericalString" do
  test "NumericalString should appear to be behave like a Fixnum in a case statement" do
    assert 123 === numerical_string_for("123")
    assert 987 === numerical_string_for("0987")
  end
  
  test "NumericalString should appear to behave like a String in a case statement" do
    assert "123"  === numerical_string_for("123")
    assert "0987" === numerical_string_for("0987")
  end
  
  test "when compared against a Range that contains the numeric equivalent, the NumericalString is seen as a member" do
    assert((100..200) === numerical_string_for("150"))
    assert((100..200) === numerical_string_for("0150"))
    assert !((100..200) === numerical_string_for("1000000"))
  end
  
  test "comparing against a regular expression works" do
    assert %r|^\d+$| === numerical_string_for("027316287")
  end
  
  test "checking if a string representation of a number starts with a leading zero" do
    with_leading_zeros    = %w(01 01234 01.23 01.2)
    without_leading_zeros = %w(1 1.2 0 0.0)
    
    with_leading_zeros.each do |number|
      assert numerical_string.starts_with_leading_zero?(number), number
    end
    
    without_leading_zeros.each do |number|
      assert !numerical_string.starts_with_leading_zero?(number), number
    end
  end
    
  private
    def numerical_string
      Adhearsion::VoIP::DSL::NumericalString
    end
    
    def numerical_string_for(string)
      numerical_string.new(string)
    end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
eric-adhearsion-0.7.999 spec/voip/test_numerical_string.rb
sevenscale-adhearsion-0.7.1000 spec/voip/test_numerical_string.rb
sevenscale-adhearsion-0.7.1003 spec/voip/test_numerical_string.rb