diff --git a/lib/ruby_units/unit.rb b/lib/ruby_units/unit.rb index 112629e5..f0a8b563 100644 --- a/lib/ruby_units/unit.rb +++ b/lib/ruby_units/unit.rb @@ -1494,7 +1494,7 @@ def self.parse_into_numbers_and_units(string) rational = %r{[+-]?\d+\/\d+} # complex numbers... -1.2+3i, +1.2-3.3i complex = %r{#{sci}{2,2}i} - anynumber = %r{(?:(#{complex}|#{rational}|#{sci})\b)?\s?([\D].*)?} + anynumber = %r{(?:(#{complex}|#{rational}|#{sci})\b)?\s?([^\d\.].*)?} num, unit = string.scan(anynumber).first return [case num @@ -1555,4 +1555,4 @@ def self.use_definition(definition) end end -end \ No newline at end of file +end diff --git a/test/test_cache.rb b/test/test_cache.rb index 62dfcef4..2c459d66 100644 --- a/test/test_cache.rb +++ b/test/test_cache.rb @@ -1,3 +1,4 @@ +require 'test_helper' require 'rubygems' require 'test/unit' require 'ruby-units' @@ -23,4 +24,4 @@ def test_get_cache assert_equal("m".unit, Unit::Cache.get['m']) end -end \ No newline at end of file +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 00000000..18457d5a --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1 @@ +$LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib' ) diff --git a/test/test_ruby-units.rb b/test/test_ruby-units.rb index 9f16bc3d..ad13a9bc 100644 --- a/test/test_ruby-units.rb +++ b/test/test_ruby-units.rb @@ -1,3 +1,4 @@ +require 'test_helper' require 'rubygems' require 'test/unit' require 'ruby-units' @@ -14,10 +15,14 @@ end -class Unit < Numeric - @@USER_DEFINITIONS = {'' => [%w{inworm inchworm}, 0.0254, :length, %w{} ], - '' => [%w{degH}, 100, :temperature, %w{}]} - Unit.setup +Unit.define("inchworm") do |inchworm| + inchworm.definition = Unit("1 m") * 0.0254 + inchworm.aliases = %w{inworm inchworm} +end + +Unit.define("habanero") do |h| + h.definition = Unit("1 degC") * 100 + h.aliases = %w{degH} end class Time @@ -121,11 +126,12 @@ def test_string_helpers assert_equal '1 mm'.convert_to('in'), Unit('1 mm').convert_to('in') end - [:sin, :cos, :tan, :sinh, :cosh, :tanh].each do |trig| - define_method("test_#{trig}") do - assert_equal Math.send(trig, Math::PI), Math.send(trig, "180 deg".unit) - end - end + # these tests are covered in the spec/ dir + # [:sin, :cos, :tan, :sinh, :cosh, :tanh].each do |trig| + # define_method("test_#{trig}") do + # assert_equal Math.send(trig, Math::PI), Math.send(trig, "180 deg".unit) + # end + # end def test_clone unit1= "1 mm".unit @@ -552,6 +558,13 @@ def test_round assert_equal((unit1/unit2).round, 1) end + def test_round_no_space + unit1 = Unit.new("1.1mm") + unit2 = Unit.new("1mm") + assert_equal unit2, unit1.round + assert_equal((unit1/unit2).round, 1) + end + def test_zero? unit1 = Unit.new("0") assert unit1.zero? @@ -804,7 +817,7 @@ def test_inline_conversions end def test_time_conversions - today = Time.now + today = Time.now.getutc assert_equal today,@april_fools last_century = today - '150 years'.unit assert_equal last_century.to_date, DateTime.parse('1856-04-01') @@ -825,11 +838,11 @@ def test_divide_results_in_unitless assert_equal a/b, 1 end - def test_wt_percent - a = '1 wt%'.unit - b = '1 g/dl'.unit - assert_equal a,b - end + # def test_wt_percent + # a = '1 wt%'.unit + # b = '1 g/dl'.unit + # assert_equal a,b + # end def test_parse_durations assert_equal "1:00".unit, '1 hour'.unit @@ -902,7 +915,7 @@ def test_rational_units end def test_to_date - a = Time.now + a = Time.now.getutc assert_equal a.send(:to_date), Date.today end @@ -936,7 +949,7 @@ def test_to_s_cache end def test_version - assert_equal('1.3.2', Unit::VERSION) + assert_equal('1.4.0', Unit::VERSION) end def test_negation