Skip to content

Commit 20a983a

Browse files
committed
start adding more test cases
1 parent e11ba61 commit 20a983a

File tree

1 file changed

+177
-19
lines changed

1 file changed

+177
-19
lines changed

test/processor.test.rb

Lines changed: 177 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,200 @@
11
# frozen_string_literal: true
22

3-
test "basic" do
3+
test "no return type, no args leaves as is" do
44
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:)
620
a
721
end
822
RUBY
923

1024
assert_equal_ruby processed, <<~RUBY
11-
def foo(a: nil, b: nil);binding.assert(a: Integer, b: String);__literally_returns__ = (;
25+
def foo(a:)
1226
a
13-
;);binding.assert(__literally_returns__: Numeric);__literally_returns__;end
27+
end
1428
RUBY
1529
end
1630

17-
test "no args" do
31+
test "no return type, optional keyword arg leaves as is" do
1832
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
20118
a
21119
end
22120
RUBY
23121

24122
assert_equal_ruby processed, <<~RUBY
25123
def foo;__literally_returns__ = (;
26124
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
27198
;);binding.assert(__literally_returns__: Numeric);__literally_returns__;end
28199
RUBY
29200
end
@@ -85,16 +256,3 @@ def foo(a: nil, b: nil);binding.assert(a: Integer, b: String);__literally_return
85256
RUBY
86257
end
87258

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

Comments
 (0)