Skip to content

Commit

Permalink
increasing test coverage
Browse files Browse the repository at this point in the history
caught an error!
  • Loading branch information
Jeni Tennison committed Oct 3, 2015
1 parent 9bc2e2a commit baf6fba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/csvlint/csvw/number_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def initialize(pattern=nil, grouping_separator=nil, decimal_separator=".")
fractional_regexp += "(#{Regexp.escape(@grouping_separator)}[0-9]{1,#{max_fraction_digits % @fractional_grouping_size}})?" if max_fraction_digits % @fractional_grouping_size > 0
else
fractional_regexp += "([0-9]{#{@fractional_grouping_size}}#{Regexp.escape(@grouping_separator)}){0,#{(max_fraction_digits / @fractional_grouping_size) - 1}}" if max_fraction_digits > @fractional_grouping_size
fractional_regexp += "[0-9]{#{@fractional_grouping_size}}"
fractional_regexp += "[0-9]{1,#{@fractional_grouping_size}}"
end
fractional_regexp = "#{Regexp.escape(@decimal_separator)}#{fractional_regexp}"
fractional_regexp = "(#{fractional_regexp})?" if min_fraction_digits == 0
Expand Down
14 changes: 14 additions & 0 deletions spec/csvw/number_format_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,20 @@
expect(format.parse("12.345,67,8")).to eql(nil)
end

it "should parse numbers that match 0.###,### correctly" do
format = Csvlint::Csvw::NumberFormat.new("0.###,###")
expect(format.parse("1")).to eq(1)
expect(format.parse("12.3")).to eql(12.3)
expect(format.parse("12.34")).to eql(12.34)
expect(format.parse("12.345")).to eq(12.345)
expect(format.parse("12.3456")).to eql(nil)
expect(format.parse("12.345,6")).to eql(12.3456)
expect(format.parse("12.34,56")).to eql(nil)
expect(format.parse("12.345,67")).to eq(12.34567)
expect(format.parse("12.345,678")).to eql(12.345678)
expect(format.parse("12.345,67,8")).to eql(nil)
end

it "should parse numbers that match 0.000,### correctly" do
format = Csvlint::Csvw::NumberFormat.new("0.000,###")
expect(format.parse("1")).to eq(nil)
Expand Down

0 comments on commit baf6fba

Please sign in to comment.