Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ruby_units/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,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})?\s?([\D].*)?}
num, unit = string.scan(anynumber).first
[case num
when NilClass
Expand Down
30 changes: 30 additions & 0 deletions spec/ruby-units/unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,36 @@
its(:base) {should == Unit("0.001 m")}
end

describe Unit("1g") do
it {should be_a Numeric}
it {should be_an_instance_of Unit}
its(:scalar) {should == 1}
its(:scalar) {should be_an Integer}
its(:units) {should == "g"}
its(:kind) {should == :mass}
it {should_not be_temperature}
it {should_not be_degree}
it {should_not be_base}
it {should_not be_unitless}
it {should_not be_zero}
its(:base) {should == subject}
end

describe Unit("1.4g") do
it {should be_a Numeric}
it {should be_an_instance_of Unit}
its(:scalar) {should === 1.4}
its(:scalar) {should be_a Float}
its(:units) {should == "g"}
its(:kind) {should == :mass}
it {should_not be_temperature}
it {should_not be_degree}
it {should_not be_base}
it {should_not be_unitless}
it {should_not be_zero}
its(:base) {should == subject}
end

describe Unit("10 m/s^2") do
it {should be_an_instance_of Unit}
its(:scalar) {should == 10}
Expand Down