decoor 0.0.1 → 0.1.1

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/test_decoor.rb DELETED
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2024 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
-
23
- require 'minitest/autorun'
24
- require_relative '../lib/decoor'
25
-
26
- # Decoor main module test.
27
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
- # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
- # License:: MIT
30
- class TestDecoor < Minitest::Test
31
- def test_object_decoration
32
- cy = Class.new do
33
- def booo
34
- yield 55
35
- end
36
-
37
- def zero
38
- 0
39
- end
40
- end
41
- x = decoor(cy.new, bar: 42) do
42
- def foo
43
- @bar
44
- end
45
-
46
- def sum
47
- @origin.zero + 10
48
- end
49
- end
50
- assert_equal(42, x.foo)
51
- assert_equal(10, x.sum)
52
- assert_equal(56, x.booo { |v| v + 1 })
53
- end
54
-
55
- def test_class_decoration
56
- cy = Class.new do
57
- def booo
58
- yield 44
59
- end
60
- end
61
- cz = Class.new do
62
- decoor(:origin)
63
-
64
- def initialize(origin, bar: nil)
65
- @origin = origin
66
- @bar = bar
67
- end
68
-
69
- def foo
70
- @bar
71
- end
72
- end
73
- z = cz.new(cy.new, bar: 42)
74
- assert_equal(42, z.foo)
75
- assert_equal(45, z.booo { |v| v + 1 })
76
- end
77
- end