quack 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1830bde6d8a56a3e4c301d835fd92e1256d5eb17
4
- data.tar.gz: 38b60b97814429883b911d500c8ece47ff3f0876
3
+ metadata.gz: 7a304d056868937d1ee1826e161f6c98f0a3689b
4
+ data.tar.gz: 4b3d887a9fd30f017e476d3255d304bc68b65787
5
5
  SHA512:
6
- metadata.gz: a0fcc64f9e0d8bc09b9e9a34e35e09619b22f96b98678fd3b1a1faa2c031585c290c87b02969235db2506c90f5b55e8c32c7077912b9dd41068639c9d29dc9f6
7
- data.tar.gz: 2964091d32eb62b21096c2b8a9791e7b4144bd6232187483b3fcbf91fae44950aeef2dedc7c5348b887068036068c8d9c6a42c0298c36d7804452693b072ec2f
6
+ metadata.gz: 985c6eb97f59ade57f907f62bb34db075496e4d9ada71d228727a7d5b90c77b7379da7a837e961466689fa6bd457fed7d3a2916d7fbbf647630ba0dd77f9e3a2
7
+ data.tar.gz: 46c3e096e6196e130b8d2287ca5fa9efee3f1bec692a86619de0657fdd2e5acb2ea94e315479ce402b5a1c7f7a0fe488a72e3dd9624c6b9fdaaf2919a7b8af69
@@ -1,8 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.0
4
+
5
+ - Support for negative values (#3)
6
+
3
7
  ## 0.0.4
4
8
 
5
9
  Breaking change: Times are now only coereced if there is no surrounding text.
6
10
 
7
11
  I.e. "It was 04-05-2016" is now considered a String rather than a Time
8
-
@@ -3,7 +3,7 @@ require "quack/type"
3
3
  module Quack
4
4
  module Types
5
5
  class Float < Quack::Type
6
- PATTERN = /\A\d+\.\d*\z/
6
+ PATTERN = /\A-?\d+\.\d*\z/
7
7
 
8
8
  class << self
9
9
  def built_in_types
@@ -20,4 +20,4 @@ module Quack
20
20
  end
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -3,7 +3,7 @@ require "quack/type"
3
3
  module Quack
4
4
  module Types
5
5
  class Integer < Quack::Type
6
- PATTERN = /\A\d+\z/
6
+ PATTERN = /\A-?\d+\z/
7
7
 
8
8
  class << self
9
9
  def built_in_types
@@ -21,4 +21,4 @@ module Quack
21
21
  end
22
22
  end
23
23
  end
24
- end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Quack
2
- VERSION = "1.0.0"
2
+ VERSION = '1.1.0'.freeze
3
3
  end
@@ -2,8 +2,8 @@ require "test_helper"
2
2
 
3
3
  describe Quack::Guesser do
4
4
  describe "given a string integer" do
5
- let(:value) { "123" }
6
- let(:subject) { Quack::Guesser.new(value) }
5
+ let(:raw_value) { "123" }
6
+ let(:subject) { Quack::Guesser.new(raw_value) }
7
7
 
8
8
  it "should have Integer type" do
9
9
  subject.guess.class.must_equal(Quack::Types::Integer)
@@ -11,8 +11,8 @@ describe Quack::Guesser do
11
11
  end
12
12
 
13
13
  describe "given a Fixnum integer" do
14
- let(:value) { 123 }
15
- let(:subject) { Quack::Guesser.new(value) }
14
+ let(:raw_value) { 123 }
15
+ let(:subject) { Quack::Guesser.new(raw_value) }
16
16
 
17
17
  it "should have Integer type" do
18
18
  subject.guess.class.must_equal(Quack::Types::Integer)
@@ -20,8 +20,8 @@ describe Quack::Guesser do
20
20
  end
21
21
 
22
22
  describe "given a string float" do
23
- let(:value) { "123.4" }
24
- let(:subject) { Quack::Guesser.new(value) }
23
+ let(:raw_value) { "123.4" }
24
+ let(:subject) { Quack::Guesser.new(raw_value) }
25
25
 
26
26
  it "should have Float type" do
27
27
  subject.guess.class.must_equal(Quack::Types::Float)
@@ -29,8 +29,8 @@ describe Quack::Guesser do
29
29
  end
30
30
 
31
31
  describe "given a Float" do
32
- let(:value) { 123.4 }
33
- let(:subject) { Quack::Guesser.new(value) }
32
+ let(:raw_value) { 123.4 }
33
+ let(:subject) { Quack::Guesser.new(raw_value) }
34
34
 
35
35
  it "should have Float type" do
36
36
  subject.guess.class.must_equal(Quack::Types::Float)
@@ -38,8 +38,8 @@ describe Quack::Guesser do
38
38
  end
39
39
 
40
40
  describe "given a 'true' string" do
41
- let(:value) { "true" }
42
- let(:subject) { Quack::Guesser.new(value) }
41
+ let(:raw_value) { "true" }
42
+ let(:subject) { Quack::Guesser.new(raw_value) }
43
43
 
44
44
  it "should have Boolean type" do
45
45
  subject.guess.class.must_equal(Quack::Types::Boolean)
@@ -47,8 +47,8 @@ describe Quack::Guesser do
47
47
  end
48
48
 
49
49
  describe "given a 'false' string" do
50
- let(:value) { "false" }
51
- let(:subject) { Quack::Guesser.new(value) }
50
+ let(:raw_value) { "false" }
51
+ let(:subject) { Quack::Guesser.new(raw_value) }
52
52
 
53
53
  it "should have Boolean type" do
54
54
  subject.guess.class.must_equal(Quack::Types::Boolean)
@@ -56,8 +56,8 @@ describe Quack::Guesser do
56
56
  end
57
57
 
58
58
  describe "given true" do
59
- let(:value) { true }
60
- let(:subject) { Quack::Guesser.new(value) }
59
+ let(:raw_value) { true }
60
+ let(:subject) { Quack::Guesser.new(raw_value) }
61
61
 
62
62
  it "should have Boolean type" do
63
63
  subject.guess.class.must_equal(Quack::Types::Boolean)
@@ -65,8 +65,8 @@ describe Quack::Guesser do
65
65
  end
66
66
 
67
67
  describe "given false" do
68
- let(:value) { false }
69
- let(:subject) { Quack::Guesser.new(value) }
68
+ let(:raw_value) { false }
69
+ let(:subject) { Quack::Guesser.new(raw_value) }
70
70
 
71
71
  it "should have Boolean type" do
72
72
  subject.guess.class.must_equal(Quack::Types::Boolean)
@@ -74,8 +74,8 @@ describe Quack::Guesser do
74
74
  end
75
75
 
76
76
  describe "given an ISO 8061 UTC date" do
77
- let(:value) { "2014-03-22T03:00:00Z" }
78
- let(:subject) { Quack::Guesser.new(value) }
77
+ let(:raw_value) { "2014-03-22T03:00:00Z" }
78
+ let(:subject) { Quack::Guesser.new(raw_value) }
79
79
 
80
80
  it "should have Time type" do
81
81
  subject.guess.class.must_equal(Quack::Types::Time)
@@ -83,8 +83,8 @@ describe Quack::Guesser do
83
83
  end
84
84
 
85
85
  describe "given a padded ISO 8061 UTC date" do
86
- let(:value) { " 2014-03-22T03:00:00Z " }
87
- let(:subject) { Quack::Guesser.new(value) }
86
+ let(:raw_value) { " 2014-03-22T03:00:00Z " }
87
+ let(:subject) { Quack::Guesser.new(raw_value) }
88
88
 
89
89
  it "should have Time type" do
90
90
  subject.guess.class.must_equal(Quack::Types::Time)
@@ -92,8 +92,8 @@ describe Quack::Guesser do
92
92
  end
93
93
 
94
94
  describe "given an embedded ISO 8061 UTC date" do
95
- let(:value) { "something awesome will happen 2014-03-22T03:00:00Z or thereabouts" }
96
- let(:subject) { Quack::Guesser.new(value) }
95
+ let(:raw_value) { "something awesome will happen 2014-03-22T03:00:00Z or thereabouts" }
96
+ let(:subject) { Quack::Guesser.new(raw_value) }
97
97
 
98
98
  it "should have String type" do
99
99
  subject.guess.class.must_equal(Quack::Types::String)
@@ -101,8 +101,8 @@ describe Quack::Guesser do
101
101
  end
102
102
 
103
103
  describe "given an embedded simple date" do
104
- let(:value) { "something awesome will happen 2014-03-22 or thereabouts" }
105
- let(:subject) { Quack::Guesser.new(value) }
104
+ let(:raw_value) { "something awesome will happen 2014-03-22 or thereabouts" }
105
+ let(:subject) { Quack::Guesser.new(raw_value) }
106
106
 
107
107
  it "should have String type" do
108
108
  subject.guess.class.must_equal(Quack::Types::String)
@@ -110,8 +110,8 @@ describe Quack::Guesser do
110
110
  end
111
111
 
112
112
  describe "given an ISO 8061 non-UTC date" do
113
- let(:value) { "2014-03-22T03:00:00-07:00" }
114
- let(:subject) { Quack::Guesser.new(value) }
113
+ let(:raw_value) { "2014-03-22T03:00:00-07:00" }
114
+ let(:subject) { Quack::Guesser.new(raw_value) }
115
115
 
116
116
  it "should have Time type" do
117
117
  subject.guess.class.must_equal(Quack::Types::Time)
@@ -119,11 +119,11 @@ describe Quack::Guesser do
119
119
  end
120
120
 
121
121
  describe "given an random string" do
122
- let(:value) { "foo123" }
123
- let(:subject) { Quack::Guesser.new(value) }
122
+ let(:raw_value) { "foo123" }
123
+ let(:subject) { Quack::Guesser.new(raw_value) }
124
124
 
125
125
  it "should have String type" do
126
126
  subject.guess.class.must_equal(Quack::Types::String)
127
127
  end
128
128
  end
129
- end
129
+ end
@@ -10,6 +10,14 @@ describe Quack::Types::Float do
10
10
  Quack::Types::Float.matches?(123.4).must_equal(true)
11
11
  end
12
12
 
13
+ it "should be true for negative float strings" do
14
+ Quack::Types::Float.matches?("-123.4").must_equal(true)
15
+ end
16
+
17
+ it "should be true for negative floats" do
18
+ Quack::Types::Float.matches?(-123.4).must_equal(true)
19
+ end
20
+
13
21
  it "should be false for integer strings" do
14
22
  Quack::Types::Float.matches?("123").must_equal(false)
15
23
  end
@@ -17,6 +25,14 @@ describe Quack::Types::Float do
17
25
  it "should be false for integers" do
18
26
  Quack::Types::Float.matches?(123).must_equal(false)
19
27
  end
28
+
29
+ it "should be false for negative integer strings" do
30
+ Quack::Types::Float.matches?("-123").must_equal(false)
31
+ end
32
+
33
+ it "should be false for negative integers" do
34
+ Quack::Types::Float.matches?(-123).must_equal(false)
35
+ end
20
36
  end
21
37
 
22
38
  describe "#to_coerced" do
@@ -31,4 +47,4 @@ describe Quack::Types::Float do
31
47
  type.to_coerced.class.must_equal(Float)
32
48
  end
33
49
  end
34
- end
50
+ end
@@ -10,6 +10,14 @@ describe Quack::Types::Integer do
10
10
  Quack::Types::Integer.matches?(123).must_equal(true)
11
11
  end
12
12
 
13
+ it "should be true for negative integer stings" do
14
+ Quack::Types::Integer.matches?("-123").must_equal(true)
15
+ end
16
+
17
+ it "should be true for negative Integers" do
18
+ Quack::Types::Integer.matches?(-123).must_equal(true)
19
+ end
20
+
13
21
  it "should be true for large Integer" do
14
22
  num = 232305722798259244150093798251441
15
23
  Quack::Types::Integer.matches?(num).must_equal(true)
@@ -22,6 +30,14 @@ describe Quack::Types::Integer do
22
30
  it "should be false for floats" do
23
31
  Quack::Types::Integer.matches?(123.4).must_equal(false)
24
32
  end
33
+
34
+ it "should be false for negative float strings" do
35
+ Quack::Types::Integer.matches?("-123.4").must_equal(false)
36
+ end
37
+
38
+ it "should be false for negative floats" do
39
+ Quack::Types::Integer.matches?(-123.4).must_equal(false)
40
+ end
25
41
  end
26
42
 
27
43
  describe "#to_coerced" do
@@ -42,4 +58,4 @@ describe Quack::Types::Integer do
42
58
  type.to_coerced.class.must_equal(1.class)
43
59
  end
44
60
  end
45
- end
61
+ end
@@ -14,7 +14,7 @@ describe Quack::Types::Null do
14
14
  describe "#to_coerced" do
15
15
  it "should return nil" do
16
16
  type = Quack::Types::Null.new(nil)
17
- type.to_coerced.must_equal(nil)
17
+ type.to_coerced.must_be_nil
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -46,6 +46,11 @@ describe Quack::Types::Time do
46
46
  type.to_coerced.must_equal(expected)
47
47
  end
48
48
 
49
+ it "should raise a ParseError for dates out of range" do
50
+ type = Quack::Types::Time.new("0000-00-00")
51
+ proc { type.to_coerced }.must_raise(Quack::ParseError)
52
+ end
53
+
49
54
  it "should raise a ParseError for invalid dates" do
50
55
  type = Quack::Types::Time.new("foo")
51
56
  proc { type.to_coerced }.must_raise(Quack::ParseError)
@@ -65,4 +70,4 @@ describe Quack::Types::Time do
65
70
  type.to_s.must_equal("2014-03-22T03:10:12-07:00")
66
71
  end
67
72
  end
68
- end
73
+ end
@@ -1,10 +1,10 @@
1
1
  require "test_helper"
2
2
 
3
3
  describe Quack do
4
- let(:value) { "123" }
4
+ let(:raw_value) { "123" }
5
5
  it "should proxy to the guesser" do
6
- type = Quack(value)
6
+ type = Quack(raw_value)
7
7
  type.class.must_equal(Quack::Types::Integer)
8
8
  type.to_coerced.must_equal(123)
9
9
  end
10
- end
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derrick Reimer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-20 00:00:00.000000000 Z
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler