speckle 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/matchers/equality_matcher.riml +66 -3
- data/lib/speckle/version.rb +1 -1
- data/spec/matchers/equality_matcher_spec.riml +30 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmEwMDlhYjVmMzYyMmI3NThhNGU3NzRiYjA5ZDM3ZmE2NDU5ZTIwYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjQ4OTFjNDU1MGI3OWU0N2I1NGI4ODc3NDBmZmZkMTYyYmM3OGNiNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjU3NWJjZjE3NmY5MWMzNGYwYTJjNGEzOTU0ZDgzNWM3OGZiZjEzYjY3MGU0
|
10
|
+
MjBmYjFmMTgyOWM1YjQxNTIzNDM5ZTE0MjU0N2I2ZWEwMjUwYTdhNjk4MzQz
|
11
|
+
ZGY1MDY1ZGJlOTJiMTNjMWQ5M2FkOTlkZTBkNDA2ZjM3MmNkNTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTMzYzdkNmJhZjNjNjdjN2I0NmZlMWVkNjY3NGU3MzgxNmYxMTkwNzg3MjFk
|
14
|
+
YWM0ZDk5NmEzNjBkMjg0MmEwNWZkOGI1MWIzMTkyODg1MWI4ODA5YTI3YTFi
|
15
|
+
YTg0ZDI0N2FkODlkZmRiNzk0ZWJhMmVjMGIyMzVkZmVlYTk0NzQ=
|
@@ -1,13 +1,76 @@
|
|
1
1
|
class EqualityMatcher
|
2
|
+
def initialize
|
3
|
+
types = []
|
4
|
+
add(types, 'Number')
|
5
|
+
add(types, 'String')
|
6
|
+
add(types, 'Funcref')
|
7
|
+
add(types, 'List')
|
8
|
+
add(types, 'Dictionary')
|
9
|
+
add(types, 'Float')
|
10
|
+
|
11
|
+
self.types = types
|
12
|
+
end
|
13
|
+
|
2
14
|
defm match(expected, actual)
|
3
|
-
|
15
|
+
self.type_mismatch = false
|
16
|
+
|
17
|
+
type_expected = type(expected)
|
18
|
+
type_actual = type(actual)
|
19
|
+
|
20
|
+
if type_expected != type_actual
|
21
|
+
self.type_mismatch = true
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
|
25
|
+
return expected == actual
|
4
26
|
end
|
5
27
|
|
6
28
|
defm failure_message_for_match(expected, actual)
|
7
|
-
|
29
|
+
if self.type_mismatch
|
30
|
+
return self.type_mismatch_message(expected, actual)
|
31
|
+
end
|
32
|
+
|
33
|
+
expected_str = self.stringify(expected)
|
34
|
+
actual_str = self.stringify(actual)
|
35
|
+
|
36
|
+
return "expected “#{actual_str}” to equal “#{expected_str}”"
|
8
37
|
end
|
9
38
|
|
10
39
|
defm failure_message_for_mismatch(expected, actual)
|
11
|
-
|
40
|
+
if self.type_mismatch
|
41
|
+
return self.type_mismatch_message(expected, actual)
|
42
|
+
end
|
43
|
+
|
44
|
+
expected_str = self.stringify(expected)
|
45
|
+
actual_str = self.stringify(actual)
|
46
|
+
|
47
|
+
return "expected “#{actual_str}” to not equal “#{expected_str}”"
|
12
48
|
end
|
49
|
+
|
50
|
+
defm type_mismatch_message(expected, actual)
|
51
|
+
actual_type = self.typeof(actual)
|
52
|
+
expected_type = self.typeof(expected)
|
53
|
+
|
54
|
+
return "type mismatch, actual(#{string(actual)}) is “#{actual_type}”, expected(#{string(expected)}) is “#{expected_type}”"
|
55
|
+
end
|
56
|
+
|
57
|
+
" helpers "
|
58
|
+
defm typeof(variable)
|
59
|
+
return self.type_to_str(type(variable))
|
60
|
+
end
|
61
|
+
|
62
|
+
defm type_to_str(num)
|
63
|
+
return self.types[num]
|
64
|
+
end
|
65
|
+
|
66
|
+
defm stringify(value)
|
67
|
+
value_type = type(value)
|
68
|
+
|
69
|
+
if value_type == type('') || value_type == type(1)
|
70
|
+
return value
|
71
|
+
else
|
72
|
+
return string(value)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
13
76
|
end
|
data/lib/speckle/version.rb
CHANGED
@@ -28,4 +28,34 @@ class EqualityMatcherSpec
|
|
28
28
|
defm it_can_check_inequality_with_alias_neq
|
29
29
|
expect('foo').to_neq('bar')
|
30
30
|
end
|
31
|
+
|
32
|
+
defm verify_type_mismatch(a, b)
|
33
|
+
try
|
34
|
+
expect(a).to_equal(b)
|
35
|
+
caught_error = false
|
36
|
+
catch /type mismatch/
|
37
|
+
""get_logger().info(v:exception)
|
38
|
+
caught_error = true
|
39
|
+
end
|
40
|
+
|
41
|
+
expect(caught_error).to_be_true()
|
42
|
+
end
|
43
|
+
|
44
|
+
defm it_can_report_type_mismatch
|
45
|
+
self.verify_type_mismatch(100, 'one hundred')
|
46
|
+
self.verify_type_mismatch(1, '1')
|
47
|
+
self.verify_type_mismatch(0, '0')
|
48
|
+
self.verify_type_mismatch({}, [])
|
49
|
+
self.verify_type_mismatch({}, 'foo')
|
50
|
+
end
|
51
|
+
|
52
|
+
defm it_can_check_equality_of_lists
|
53
|
+
expect(['a', 'b']).to_not_equal(['a', 'b', 'c'])
|
54
|
+
expect(['a', 'b']).to_equal(['a', 'b'])
|
55
|
+
end
|
56
|
+
|
57
|
+
defm it_can_check_equality_of_dicts
|
58
|
+
expect({'foo': 10}).to_not_equal({'bar': 20})
|
59
|
+
expect({'foo': { 'bar': 10 }}).to_equal({'foo': { 'bar': 10 }})
|
60
|
+
end
|
31
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: speckle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darshan Sawardekar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: riml
|