From 8bd2103647e3281d301260a154c3d28ddd1d8027 Mon Sep 17 00:00:00 2001 From: Leigh Dodds Date: Tue, 4 Mar 2014 12:09:11 +0000 Subject: [PATCH] Support xsd:integer --- README.md | 2 +- lib/csvlint/types.rb | 1 + spec/field_spec.rb | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ec6a6b48..b4d0d05b 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ Supported constraints: Supported data types (this is still a work in progress): * String -- `http://www.w3.org/2001/XMLSchema#string` (effectively a no-op) -* Integer -- `http://www.w3.org/2001/XMLSchema#int` +* Integer -- `http://www.w3.org/2001/XMLSchema#integer` or `http://www.w3.org/2001/XMLSchema#int` * Float -- `http://www.w3.org/2001/XMLSchema#float` * Double -- `http://www.w3.org/2001/XMLSchema#double` * URI -- `http://www.w3.org/2001/XMLSchema#anyURI` diff --git a/lib/csvlint/types.rb b/lib/csvlint/types.rb index cb8494e6..751e3f48 100644 --- a/lib/csvlint/types.rb +++ b/lib/csvlint/types.rb @@ -48,6 +48,7 @@ def self.included(base) TYPE_VALIDATIONS = { 'http://www.w3.org/2001/XMLSchema#string' => SIMPLE_FORMATS['string'], 'http://www.w3.org/2001/XMLSchema#int' => lambda { |value, constraints| Integer value }, + 'http://www.w3.org/2001/XMLSchema#integer' => lambda { |value, constraints| Integer value }, 'http://www.w3.org/2001/XMLSchema#float' => lambda { |value, constraints| Float value }, 'http://www.w3.org/2001/XMLSchema#double' => lambda { |value, constraints| Float value }, 'http://www.w3.org/2001/XMLSchema#anyURI' => SIMPLE_FORMATS['uri'], diff --git a/spec/field_spec.rb b/spec/field_spec.rb index 1cfd490a..a52f9803 100644 --- a/spec/field_spec.rb +++ b/spec/field_spec.rb @@ -78,6 +78,12 @@ expect( field.validate_column("forty-two")).to be(false) end + it "validates integers" do + field = Csvlint::Field.new("test", { "type" => "http://www.w3.org/2001/XMLSchema#integer" }) + expect( field.validate_column("42")).to be(true) + expect( field.validate_column("forty-two")).to be(false) + end + it "validates floats" do field = Csvlint::Field.new("test", { "type" => "http://www.w3.org/2001/XMLSchema#float" }) expect(field.validate_column("42.0")).to be(true)