emery 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/type_test.rb CHANGED
@@ -1,220 +1,218 @@
1
1
  require "test/unit/runner/junitxml"
2
2
  require "date"
3
3
 
4
- require 'emery/type'
4
+ require 'emery'
5
5
 
6
- module Emery
7
- class TypeEquality < Test::Unit::TestCase
8
- def test_plain_equals
9
- assert_true Integer == Integer
10
- end
6
+ class TypeEquality < Test::Unit::TestCase
7
+ def test_plain_equals
8
+ assert_true Integer == Integer
9
+ end
11
10
 
12
- def test_plain_not_equals
13
- assert_false Integer == String
14
- end
11
+ def test_plain_not_equals
12
+ assert_false Integer == String
13
+ end
15
14
 
16
- def test_uuid_equals
17
- assert_true UUID == UUID
18
- end
15
+ def test_uuid_equals
16
+ assert_true UUID == UUID
17
+ end
19
18
 
20
- def test_boolean_equals
21
- assert_true Boolean == Boolean
22
- end
19
+ def test_boolean_equals
20
+ assert_true Boolean == Boolean
21
+ end
23
22
 
24
- def test_untyped_equals
25
- assert_true Untyped == Untyped
26
- end
23
+ def test_untyped_equals
24
+ assert_true Untyped == Untyped
25
+ end
27
26
 
28
- def test_nilable_equals
29
- assert_true T.nilable(Integer) == T.nilable(Integer)
30
- end
27
+ def test_nilable_equals
28
+ assert_true T.nilable(Integer) == T.nilable(Integer)
29
+ end
31
30
 
32
- def test_nilable_not_equals
33
- assert_false T.nilable(Integer) == T.nilable(String)
34
- end
31
+ def test_nilable_not_equals
32
+ assert_false T.nilable(Integer) == T.nilable(String)
33
+ end
35
34
 
36
- def test_array_equals
37
- assert_true T.array(Integer) == T.array(Integer)
38
- end
35
+ def test_array_equals
36
+ assert_true T.array(Integer) == T.array(Integer)
37
+ end
39
38
 
40
- def test_array_not_equals
41
- assert_false T.array(Integer) == Integer
42
- end
39
+ def test_array_not_equals
40
+ assert_false T.array(Integer) == Integer
41
+ end
43
42
 
44
- def test_array_other_item_type
45
- assert_false T.array(Integer) == T.array(String)
46
- end
43
+ def test_array_other_item_type
44
+ assert_false T.array(Integer) == T.array(String)
45
+ end
47
46
 
48
- def test_hash_equals
49
- assert_true T.hash(String, Integer) == T.hash(String, Integer)
50
- end
47
+ def test_hash_equals
48
+ assert_true T.hash(String, Integer) == T.hash(String, Integer)
49
+ end
51
50
 
52
- def test_hash_not_equals
53
- assert_false T.hash(String, Integer) == String
54
- end
51
+ def test_hash_not_equals
52
+ assert_false T.hash(String, Integer) == String
53
+ end
55
54
 
56
- def test_hash_other_value_type
57
- assert_false T.hash(String, Integer) == T.hash(String, String)
58
- end
55
+ def test_hash_other_value_type
56
+ assert_false T.hash(String, Integer) == T.hash(String, String)
57
+ end
59
58
 
60
- def test_any_equals
61
- assert_true T.any(String, Integer) == T.any(String, Integer)
62
- end
59
+ def test_any_equals
60
+ assert_true T.any(String, Integer) == T.any(String, Integer)
61
+ end
63
62
 
64
- def test_any_equals_other_order
65
- assert_true T.any(String, Integer) == T.any(Integer, String)
66
- end
63
+ def test_any_equals_other_order
64
+ assert_true T.any(String, Integer) == T.any(Integer, String)
65
+ end
67
66
 
68
- def test_any_of_other_type
69
- assert_false T.any(String, Integer) == T.any(Integer, Float)
70
- end
67
+ def test_any_of_other_type
68
+ assert_false T.any(String, Integer) == T.any(Integer, Float)
71
69
  end
70
+ end
72
71
 
73
- class TypeToString < Test::Unit::TestCase
74
- def test_nilable
75
- assert_equal "Nilable[Integer]", T.nilable(Integer).to_s
76
- end
72
+ class TypeToString < Test::Unit::TestCase
73
+ def test_nilable
74
+ assert_equal "Nilable[Integer]", T.nilable(Integer).to_s
75
+ end
77
76
 
78
- def test_array
79
- assert_equal "Array[Integer]", T.array(Integer).to_s
80
- end
77
+ def test_array
78
+ assert_equal "Array[Integer]", T.array(Integer).to_s
79
+ end
81
80
 
82
- def test_hash
83
- assert_equal "Hash[String, Integer]", T.hash(String, Integer).to_s
84
- end
81
+ def test_hash
82
+ assert_equal "Hash[String, Integer]", T.hash(String, Integer).to_s
83
+ end
85
84
 
86
- def test_any
87
- assert_equal "Any[String, Integer]", T.any(String, Integer).to_s
88
- end
85
+ def test_any
86
+ assert_equal "Any[String, Integer]", T.any(String, Integer).to_s
87
+ end
89
88
 
90
- def test_union
91
- assert_equal "Union[str: String, int: Integer]", T.union(str: String, int: Integer).to_s
92
- end
89
+ def test_union
90
+ assert_equal "Union[str: String, int: Integer]", T.union(str: String, int: Integer).to_s
93
91
  end
92
+ end
94
93
 
95
- class TypeCheck < Test::Unit::TestCase
96
- def test_nil
97
- assert_equal nil, T.check(NilClass, nil)
98
- end
94
+ class TypeCheck < Test::Unit::TestCase
95
+ def test_nil
96
+ assert_equal nil, T.check(NilClass, nil)
97
+ end
99
98
 
100
- def test_nil_string
101
- assert_raise TypeError do
102
- T.check(String, nil)
103
- end
99
+ def test_nil_string
100
+ assert_raise TypeError do
101
+ T.check(String, nil)
104
102
  end
103
+ end
105
104
 
106
- def test_types_mismatch
107
- assert_raise TypeError do
108
- T.check(String, 123)
109
- end
105
+ def test_types_mismatch
106
+ assert_raise TypeError do
107
+ T.check(String, 123)
110
108
  end
109
+ end
111
110
 
112
- def test_string
113
- assert_equal "the string", T.check(String, "the string"), "Plain String type should allow String value"
114
- end
111
+ def test_string
112
+ assert_equal "the string", T.check(String, "the string"), "Plain String type should allow String value"
113
+ end
115
114
 
116
- def test_string_nil
117
- err = assert_raise TypeError do
118
- T.check(String, nil)
119
- end
120
- assert_match "Type String does not allow nil value", err.message
115
+ def test_string_nil
116
+ err = assert_raise TypeError do
117
+ T.check(String, nil)
121
118
  end
119
+ assert_match "Type String does not allow nil value", err.message
120
+ end
122
121
 
123
- def test_boolean
124
- assert_equal true, T.check(Boolean, true), "Artificial Boolean type should allow true value"
125
- end
122
+ def test_boolean
123
+ assert_equal true, T.check(Boolean, true), "Artificial Boolean type should allow true value"
124
+ end
126
125
 
127
- def test_date
128
- assert_equal Date.new(2020, 5, 24), T.check(Date, Date.new(2020, 5, 24)), "Date type should pass validation"
129
- end
126
+ def test_date
127
+ assert_equal Date.new(2020, 5, 24), T.check(Date, Date.new(2020, 5, 24)), "Date type should pass validation"
128
+ end
130
129
 
131
- def test_datetime
132
- assert_equal DateTime.new(2020, 5, 24, 14, 30, 30), T.check(Date, DateTime.new(2020, 5, 24, 14, 30, 30)), "DateTime type should pass validation"
133
- end
130
+ def test_datetime
131
+ assert_equal DateTime.new(2020, 5, 24, 14, 30, 30), T.check(Date, DateTime.new(2020, 5, 24, 14, 30, 30)), "DateTime type should pass validation"
132
+ end
134
133
 
135
- def test_time
136
- assert_equal Time.new(2007,11,5,13,45,0, "-05:00"), T.check(Time, Time.new(2007, 11, 5, 13, 45, 0, "-05:00")), "Time type should pass validation"
137
- end
134
+ def test_time
135
+ assert_equal Time.new(2007,11,5,13,45,0, "-05:00"), T.check(Time, Time.new(2007, 11, 5, 13, 45, 0, "-05:00")), "Time type should pass validation"
136
+ end
138
137
 
139
- def test_uuid
140
- assert_equal "123e4567-e89b-12d3-a456-426655440000", T.check(UUID, "123e4567-e89b-12d3-a456-426655440000"), "UUID type should pass validation on correctly formatted string"
141
- end
138
+ def test_uuid
139
+ assert_equal "123e4567-e89b-12d3-a456-426655440000", T.check(UUID, "123e4567-e89b-12d3-a456-426655440000"), "UUID type should pass validation on correctly formatted string"
140
+ end
142
141
 
143
- def test_uuid_fail
144
- assert_raise TypeError do
145
- T.check(UUID, "really not the uuid")
146
- end
142
+ def test_uuid_fail
143
+ assert_raise TypeError do
144
+ T.check(UUID, "really not the uuid")
147
145
  end
146
+ end
148
147
 
149
- def test_untyped_success
150
- assert_equal "bla", T.check(Untyped, "bla"), "Untyped should accept strings"
151
- end
148
+ def test_untyped_success
149
+ assert_equal "bla", T.check(Untyped, "bla"), "Untyped should accept strings"
150
+ end
152
151
 
153
- def test_untyped_nil
154
- assert_raise TypeError do
155
- T.check(Untyped, nil)
156
- end
152
+ def test_untyped_nil
153
+ assert_raise TypeError do
154
+ T.check(Untyped, nil)
157
155
  end
156
+ end
158
157
 
159
- def test_nilable_nil
160
- assert_equal nil, T.check(T.nilable(String), nil), "Nilable type should allow nil value"
161
- end
158
+ def test_nilable_nil
159
+ assert_equal nil, T.check(T.nilable(String), nil), "Nilable type should allow nil value"
160
+ end
162
161
 
163
- def test_nilable
164
- assert_equal "the string", T.check(T.nilable(String), "the string"), "Nilable String type should allow String value"
165
- end
162
+ def test_nilable
163
+ assert_equal "the string", T.check(T.nilable(String), "the string"), "Nilable String type should allow String value"
166
164
  end
165
+ end
167
166
 
168
- class TypeCheckArray < Test::Unit::TestCase
169
- def test_array_string
170
- assert_equal ["the string"], T.check(T.array(String), ["the string"]), "Array of String should allow String value"
171
- end
167
+ class TypeCheckArray < Test::Unit::TestCase
168
+ def test_array_string
169
+ assert_equal ["the string"], T.check(T.array(String), ["the string"]), "Array of String should allow String value"
170
+ end
172
171
 
173
- def test_array_fail
174
- assert_raise TypeError do
175
- T.check(T.array(String), "the string")
176
- end
172
+ def test_array_fail
173
+ ex = assert_raise TypeError do
174
+ T.check(T.array(String), "the string")
177
175
  end
176
+ puts ex
177
+ end
178
178
 
179
- def test_array_wrong_item_type
180
- assert_raise TypeError do
181
- T.check(T.array(String), ["the string", 123])
182
- end
179
+ def test_array_wrong_item_type
180
+ assert_raise TypeError do
181
+ T.check(T.array(String), ["the string", 123])
183
182
  end
184
183
  end
184
+ end
185
185
 
186
- class TypeCheckHash < Test::Unit::TestCase
187
- def test_hash_string_to_string
188
- assert_equal({"key" => "the value"}, T.check(T.hash(String, String), {"key" => "the value"}), "Hash of String -> String should allow String -> String value")
189
- end
186
+ class TypeCheckHash < Test::Unit::TestCase
187
+ def test_hash_string_to_string
188
+ assert_equal({"key" => "the value"}, T.check(T.hash(String, String), {"key" => "the value"}), "Hash of String -> String should allow String -> String value")
189
+ end
190
190
 
191
- def test_hash_string_to_untyped
192
- assert_equal({"key" => "the value"}, T.check(T.hash(String, Untyped), {"key" => "the value"}), "Hash of String -> Untyped should allow String -> String value")
193
- end
191
+ def test_hash_string_to_untyped
192
+ assert_equal({"key" => "the value"}, T.check(T.hash(String, Untyped), {"key" => "the value"}), "Hash of String -> Untyped should allow String -> String value")
194
193
  end
194
+ end
195
195
 
196
- class TypeCheckAny < Test::Unit::TestCase
197
- def test_success
198
- assert_equal(123, T.check(T.any(String, Integer), 123), "Any of String, Integer should allow Integer value")
199
- end
196
+ class TypeCheckAny < Test::Unit::TestCase
197
+ def test_success
198
+ assert_equal(123, T.check(T.any(String, Integer), 123), "Any of String, Integer should allow Integer value")
199
+ end
200
200
 
201
- def test_fail
202
- assert_raise TypeError do
203
- T.check(T.any(String, Integer), true)
204
- end
201
+ def test_fail
202
+ assert_raise TypeError do
203
+ T.check(T.any(String, Integer), true)
205
204
  end
206
205
  end
206
+ end
207
207
 
208
- class TypeCheckUnion < Test::Unit::TestCase
209
- def test_success
210
- assert_equal(123, T.check(T.union(str: String, int: Integer), 123))
211
- end
208
+ class TypeCheckUnion < Test::Unit::TestCase
209
+ def test_success
210
+ assert_equal(123, T.check(T.union(str: String, int: Integer), 123))
211
+ end
212
212
 
213
- def test_fail
214
- assert_raise TypeError do
215
- T.check(T.union(str: String, int: Integer), true)
216
- end
213
+ def test_fail
214
+ assert_raise TypeError do
215
+ T.check(T.union(str: String, int: Integer), true)
217
216
  end
218
217
  end
219
-
220
218
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Sapronov