better_struct 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/better_struct.rb +1 -1
- data/lib/better_struct/methodize.rb +3 -1
- data/lib/better_struct/version.rb +1 -1
- data/test/better_struct_test.rb +33 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3274ecdeb9fbdf35c3cd30b64eb069d16d854ca
|
4
|
+
data.tar.gz: 25e17ddafdb1ebb12860da133b79195143eda353
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3272eaba0944b3ff497d043b1b69b66f8df28f2bce438e85144b3fa27107b1563ee057ec2c5e18d3d89515564fa1e4e6d0629cab4b50e7e8fa1cf818401561b
|
7
|
+
data.tar.gz: ccfa4f37aac90379c96218952cb8c9ca57063f2894530791206f81f8387d7d69fb2ddcff32c18f6f32cda0c26ba07ee73d70c9fff58181ae5b0f4f36733d0fc0
|
data/lib/better_struct.rb
CHANGED
@@ -29,7 +29,9 @@ private
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def __methodized?(string)
|
32
|
-
|
32
|
+
return false if string =~ BEFORE_FIRST_DIGIT_OR_NON_UNDERSCORED_REGEXP
|
33
|
+
return false if string =~ UNDERSCORE_DUPLICATES_REGEXP
|
34
|
+
true
|
33
35
|
end
|
34
36
|
|
35
37
|
def __transliterate!(string)
|
data/test/better_struct_test.rb
CHANGED
@@ -78,6 +78,39 @@ module BetterStructTest
|
|
78
78
|
assert better_struct.map { |i| i * i * 2 }.value == [2, 8, 18]
|
79
79
|
end
|
80
80
|
|
81
|
+
def test_new_assignment
|
82
|
+
better_struct = BetterStruct.new
|
83
|
+
|
84
|
+
better_struct.head = [1, 2, 3]
|
85
|
+
|
86
|
+
assert better_struct.head == BetterStruct.new([1, 2, 3])
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_input_args_immutability
|
90
|
+
better_struct = BetterStruct.new(head: [1, 2, 3])
|
91
|
+
tail = [4, 5, 6]
|
92
|
+
|
93
|
+
better_struct.head.concat(tail)
|
94
|
+
|
95
|
+
assert better_struct.head == BetterStruct.new([1, 2, 3, 4, 5, 6])
|
96
|
+
assert tail == [4, 5, 6]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class Methodize < Minitest::Test
|
101
|
+
def test_methodize_checking
|
102
|
+
better_struct = BetterStruct.new(not__undescore: 1)
|
103
|
+
|
104
|
+
assert better_struct.not__undescore.value == nil
|
105
|
+
assert better_struct.not_undescore.value == 1
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_methodizing
|
109
|
+
better_struct = BetterStruct.new("FooBar foo_bar": 1)
|
110
|
+
|
111
|
+
assert better_struct.foo_bar_foo_bar.value == 1
|
112
|
+
end
|
113
|
+
|
81
114
|
def test_methods_underscoring
|
82
115
|
better_struct = BetterStruct.new({ "! CHAMPION !" => 1 })
|
83
116
|
|
@@ -101,23 +134,5 @@ module BetterStructTest
|
|
101
134
|
|
102
135
|
assert better_struct.titulo.value == 1
|
103
136
|
end
|
104
|
-
|
105
|
-
def test_new_assignment
|
106
|
-
better_struct = BetterStruct.new
|
107
|
-
|
108
|
-
better_struct.head = [1, 2, 3]
|
109
|
-
|
110
|
-
assert better_struct.head == BetterStruct.new([1, 2, 3])
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_input_args_immutability
|
114
|
-
better_struct = BetterStruct.new(head: [1, 2, 3])
|
115
|
-
tail = [4, 5, 6]
|
116
|
-
|
117
|
-
better_struct.head.concat(tail)
|
118
|
-
|
119
|
-
assert better_struct.head == BetterStruct.new([1, 2, 3, 4, 5, 6])
|
120
|
-
assert tail == [4, 5, 6]
|
121
|
-
end
|
122
137
|
end
|
123
138
|
end
|