|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -test "basic" do |
| 3 | +test "no return type, no args leaves as is" do |
4 | 4 | processed = Literally::Processor.call(<<~RUBY) |
5 | | - def foo(a: Integer, b: String) = Numeric do |
| 5 | + def foo |
| 6 | + "a" |
| 7 | + end |
| 8 | + RUBY |
| 9 | + |
| 10 | + assert_equal_ruby processed, <<~RUBY |
| 11 | + def foo |
| 12 | + "a" |
| 13 | + end |
| 14 | + RUBY |
| 15 | +end |
| 16 | + |
| 17 | +test "no return type, required keyword arg leaves as is" do |
| 18 | + processed = Literally::Processor.call(<<~RUBY) |
| 19 | + def foo(a:) |
6 | 20 | a |
7 | 21 | end |
8 | 22 | RUBY |
9 | 23 |
|
10 | 24 | assert_equal_ruby processed, <<~RUBY |
11 | | - def foo(a: nil, b: nil);binding.assert(a: Integer, b: String);__literally_returns__ = (; |
| 25 | + def foo(a:) |
12 | 26 | a |
13 | | - ;);binding.assert(__literally_returns__: Numeric);__literally_returns__;end |
| 27 | + end |
14 | 28 | RUBY |
15 | 29 | end |
16 | 30 |
|
17 | | -test "no args" do |
| 31 | +test "no return type, optional keyword arg leaves as is" do |
18 | 32 | processed = Literally::Processor.call(<<~RUBY) |
19 | | - def foo = Numeric do |
| 33 | + def foo(a: nil) |
| 34 | + a |
| 35 | + end |
| 36 | + RUBY |
| 37 | + |
| 38 | + assert_equal_ruby processed, <<~RUBY |
| 39 | + def foo(a: nil) |
| 40 | + a |
| 41 | + end |
| 42 | + RUBY |
| 43 | +end |
| 44 | + |
| 45 | +test "no return type, required positional arg leaves as is" do |
| 46 | + processed = Literally::Processor.call(<<~RUBY) |
| 47 | + def foo(a) |
| 48 | + a |
| 49 | + end |
| 50 | + RUBY |
| 51 | + |
| 52 | + assert_equal_ruby processed, <<~RUBY |
| 53 | + def foo(a) |
| 54 | + a |
| 55 | + end |
| 56 | + RUBY |
| 57 | +end |
| 58 | + |
| 59 | +test "no return type, optional positional arg leaves as is" do |
| 60 | + processed = Literally::Processor.call(<<~RUBY) |
| 61 | + def foo(a = nil) |
| 62 | + a |
| 63 | + end |
| 64 | + RUBY |
| 65 | + |
| 66 | + assert_equal_ruby processed, <<~RUBY |
| 67 | + def foo(a = nil) |
| 68 | + a |
| 69 | + end |
| 70 | + RUBY |
| 71 | +end |
| 72 | + |
| 73 | +test "no return type, mixed args leaves as is" do |
| 74 | + processed = Literally::Processor.call(<<~RUBY) |
| 75 | + def foo(a, b = nil, c:, d: nil) |
| 76 | + a |
| 77 | + end |
| 78 | + RUBY |
| 79 | + |
| 80 | + assert_equal_ruby processed, <<~RUBY |
| 81 | + def foo(a, b = nil, c:, d: nil) |
| 82 | + a |
| 83 | + end |
| 84 | + RUBY |
| 85 | +end |
| 86 | + |
| 87 | +test "return type, no args processes" do |
| 88 | + processed = Literally::Processor.call(<<~RUBY) |
| 89 | + def say_hello = String do |
| 90 | + "Hello World!" |
| 91 | + end |
| 92 | + RUBY |
| 93 | + |
| 94 | + assert_equal_ruby processed, <<~RUBY |
| 95 | + def say_hello;__literally_returns__ = (; |
| 96 | + "Hello World!" |
| 97 | + ;);binding.assert(__literally_returns__: String);__literally_returns__;end |
| 98 | + RUBY |
| 99 | +end |
| 100 | + |
| 101 | +test "_Void return type, no args processes" do |
| 102 | + processed = Literally::Processor.call(<<~RUBY) |
| 103 | + def return_nothing = _Void do |
| 104 | + background_work |
| 105 | + end |
| 106 | + RUBY |
| 107 | + |
| 108 | + assert_equal_ruby processed, <<~RUBY |
| 109 | + def return_nothing;__literally_returns__ = (; |
| 110 | + background_work |
| 111 | + ;);binding.assert(__literally_returns__: _Void);__literally_returns__;end |
| 112 | + RUBY |
| 113 | +end |
| 114 | + |
| 115 | +test "_Any? return type, no args processes" do |
| 116 | + processed = Literally::Processor.call(<<~RUBY) |
| 117 | + def foo = _Any? do |
20 | 118 | a |
21 | 119 | end |
22 | 120 | RUBY |
23 | 121 |
|
24 | 122 | assert_equal_ruby processed, <<~RUBY |
25 | 123 | def foo;__literally_returns__ = (; |
26 | 124 | a |
| 125 | + ;);binding.assert(__literally_returns__: _Any?);__literally_returns__;end |
| 126 | + RUBY |
| 127 | +end |
| 128 | + |
| 129 | +test "return type, positional arg processes" do |
| 130 | + processed = Literally::Processor.call(<<~'RUBY') |
| 131 | + def say_hello(name = String) = String do |
| 132 | + "Hello #{name}!" |
| 133 | + end |
| 134 | + RUBY |
| 135 | + |
| 136 | + assert_equal_ruby(processed, <<~'RUBY') |
| 137 | + def say_hello(name = nil);binding.assert(name: String);__literally_returns__ = (; |
| 138 | + "Hello #{name}!" |
| 139 | + ;);binding.assert(__literally_returns__: String);__literally_returns__;end |
| 140 | + RUBY |
| 141 | +end |
| 142 | + |
| 143 | +test "return type, positional arg with default processes" do |
| 144 | + processed = Literally::Processor.call(<<~'RUBY') |
| 145 | + def say_hello(name = String {"World"}) = String do |
| 146 | + "Hello #{name}!" |
| 147 | + end |
| 148 | + RUBY |
| 149 | + |
| 150 | + assert_equal_ruby(processed, <<~'RUBY') |
| 151 | + def say_hello(name = "World");binding.assert(name: String);__literally_returns__ = (; |
| 152 | + "Hello #{name}!" |
| 153 | + ;);binding.assert(__literally_returns__: String);__literally_returns__;end |
| 154 | + RUBY |
| 155 | +end |
| 156 | + |
| 157 | +test "return type, keyword arg processes" do |
| 158 | + processed = Literally::Processor.call(<<~'RUBY') |
| 159 | + def say_hello(name: String) = String do |
| 160 | + "Hello #{name}!" |
| 161 | + end |
| 162 | + RUBY |
| 163 | + |
| 164 | + assert_equal_ruby(processed, <<~'RUBY') |
| 165 | + def say_hello(name: nil);binding.assert(name: String);__literally_returns__ = (; |
| 166 | + "Hello #{name}!" |
| 167 | + ;);binding.assert(__literally_returns__: String);__literally_returns__;end |
| 168 | + RUBY |
| 169 | +end |
| 170 | + |
| 171 | +test "return type, keyword arg with default processes" do |
| 172 | + processed = Literally::Processor.call(<<~'RUBY') |
| 173 | + def say_hello(name: String {"World"}) = String do |
| 174 | + "Hello #{name}!" |
| 175 | + end |
| 176 | + RUBY |
| 177 | + |
| 178 | + assert_equal_ruby(processed, <<~'RUBY') |
| 179 | + def say_hello(name: "World");binding.assert(name: String);__literally_returns__ = (; |
| 180 | + "Hello #{name}!" |
| 181 | + ;);binding.assert(__literally_returns__: String);__literally_returns__;end |
| 182 | + RUBY |
| 183 | +end |
| 184 | + |
| 185 | + |
| 186 | + |
| 187 | + |
| 188 | +test "basic" do |
| 189 | + processed = Literally::Processor.call(<<~RUBY) |
| 190 | + def foo(a: Integer, b: String) = Numeric do |
| 191 | + a |
| 192 | + end |
| 193 | + RUBY |
| 194 | + |
| 195 | + assert_equal_ruby processed, <<~RUBY |
| 196 | + def foo(a: nil, b: nil);binding.assert(a: Integer, b: String);__literally_returns__ = (; |
| 197 | + a |
27 | 198 | ;);binding.assert(__literally_returns__: Numeric);__literally_returns__;end |
28 | 199 | RUBY |
29 | 200 | end |
@@ -85,16 +256,3 @@ def foo(a: nil, b: nil);binding.assert(a: Integer, b: String);__literally_return |
85 | 256 | RUBY |
86 | 257 | end |
87 | 258 |
|
88 | | -test "positionals" do |
89 | | - processed = Literally::Processor.call(<<~RUBY) |
90 | | - def foo(a = Integer, b = String) = Numeric do |
91 | | - a |
92 | | - end |
93 | | - RUBY |
94 | | - |
95 | | - assert_equal_ruby processed, <<~RUBY |
96 | | - def foo(a = nil, b = nil);binding.assert(a: Integer, b: String);__literally_returns__ = (; |
97 | | - a |
98 | | - ;);binding.assert(__literally_returns__: Numeric);__literally_returns__;end |
99 | | - RUBY |
100 | | -end |
|
0 commit comments