Skip to content

Commit 94ffade

Browse files
pvcresinmame
authored andcommitted
Add known issues scenarios
1 parent 3c2eebc commit 94ffade

10 files changed

Lines changed: 319 additions & 0 deletions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## update
2+
def foo(arr)
3+
result = []
4+
arr.each {|x| result << x * 2 }
5+
result
6+
end
7+
8+
foo([1, 2, 3])
9+
10+
## assert
11+
class Object
12+
def foo: ([Integer, Integer, Integer]) -> Array[Integer]
13+
end
14+
15+
## update
16+
def collect(arr)
17+
acc = []
18+
arr.each_with_index do |x, i|
19+
acc << [i, x]
20+
end
21+
acc
22+
end
23+
24+
collect(["a", "b"])
25+
26+
## assert
27+
class Object
28+
def collect: ([String, String]) -> Array[[Integer, String]]
29+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## update
2+
class C
3+
def hello = "hi"
4+
alias greet hello
5+
end
6+
7+
C.new.greet
8+
9+
## assert
10+
class C
11+
def hello: -> String
12+
alias greet hello
13+
end
14+
15+
## update
16+
class C
17+
def hello = "hi"
18+
alias_method :greet, :hello
19+
end
20+
21+
C.new.greet
22+
23+
## assert
24+
class C
25+
def hello: -> String
26+
alias greet hello
27+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## update
2+
Foo = Data.define(:x, :y)
3+
Foo.new(x: 1, y: "a")
4+
5+
## assert
6+
class Foo < Data
7+
def initialize: (x: Integer, y: String) -> void
8+
def x: -> Integer
9+
def y: -> String
10+
end
11+
12+
## update
13+
class Bar < Data.define(:name)
14+
def greet = "hi, #{name}"
15+
end
16+
17+
Bar.new(name: "taro").greet
18+
19+
## assert
20+
class Bar < Data
21+
def initialize: (name: String) -> void
22+
def name: -> String
23+
def greet: -> String
24+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## update
2+
class C
3+
define_method(:hello) { "hi" }
4+
define_method(:double) {|x| x * 2 }
5+
end
6+
7+
C.new.hello
8+
C.new.double(1)
9+
10+
## assert
11+
class C
12+
def hello: -> String
13+
def double: (Integer) -> Integer
14+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## update
2+
class C
3+
class << self
4+
attr_accessor :age
5+
end
6+
end
7+
8+
C.age = 1
9+
C.age
10+
11+
## assert
12+
class C
13+
def self.age: -> Integer
14+
def self.age=: (Integer) -> Integer
15+
end
16+
17+
## update
18+
class C
19+
class << self
20+
attr_reader :name
21+
attr_writer :value
22+
end
23+
end
24+
25+
C.value = "value"
26+
27+
## assert
28+
class C
29+
def self.name: -> untyped
30+
def self.value=: (String) -> String
31+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## update
2+
module M
3+
extend self
4+
5+
def hello = "hi"
6+
end
7+
8+
M.hello
9+
10+
## assert
11+
module M
12+
def hello: -> String
13+
def self.hello: -> String
14+
end
15+
16+
## update
17+
module Helpers
18+
def shout(s) = s.upcase
19+
end
20+
21+
module App
22+
extend Helpers
23+
end
24+
25+
App.shout("hi")
26+
27+
## assert
28+
module Helpers
29+
def shout: (String) -> String
30+
end
31+
module App
32+
extend Helpers
33+
end
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## update
2+
module M
3+
def foo = "foo"
4+
def bar = "bar"
5+
module_function :foo
6+
end
7+
8+
C.foo
9+
10+
## assert
11+
module M
12+
def self.foo: -> String
13+
def bar: -> String
14+
private
15+
def foo: -> String
16+
end
17+
18+
## update
19+
module M
20+
def foo = "foo"
21+
def bar = "bar"
22+
module_function :foo, :bar
23+
end
24+
25+
C.foo
26+
C.bar
27+
28+
## assert
29+
module M
30+
def self.foo: -> String
31+
def self.bar: -> String
32+
private
33+
def foo: -> String
34+
def bar: -> String
35+
end
36+
37+
## update
38+
module M
39+
module_function
40+
41+
def foo = "foo"
42+
def bar = "bar"
43+
end
44+
45+
C.foo
46+
C.bar
47+
48+
## assert
49+
module M
50+
def self.foo: -> String
51+
def self.bar: -> String
52+
private
53+
def foo: -> String
54+
def bar: -> String
55+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## update
2+
def check(a)
3+
case a
4+
in Integer => n
5+
n + 1
6+
in String => s
7+
s.upcase
8+
end
9+
end
10+
11+
check(1)
12+
check("foo")
13+
14+
## assert
15+
class Object
16+
def check: (Integer | String) -> (Integer | String)?
17+
end
18+
19+
## update
20+
def check(a)
21+
case a
22+
in [Integer => n, String => s]
23+
[n, s]
24+
end
25+
end
26+
27+
check([42, "foo"])
28+
29+
## assert
30+
class Object
31+
def check: ([Integer, String]) -> [Integer, String]?
32+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## update
2+
class A
3+
def foo(x) = x + 1
4+
end
5+
6+
class B < A
7+
def foo(x)
8+
super
9+
end
10+
end
11+
12+
B.new.foo(1)
13+
14+
## assert
15+
class A
16+
def foo: (Integer) -> Integer
17+
end
18+
class B < A
19+
def foo: (Integer) -> Integer
20+
end
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## update
2+
class Foo
3+
def public_method = "public_method"
4+
5+
private
6+
7+
def private_method = "private_method"
8+
end
9+
10+
## assert
11+
class Foo
12+
def public_method: -> String
13+
private
14+
def private_method: -> String
15+
end
16+
17+
## update
18+
class Foo
19+
private def private_method = "private_method"
20+
public def public_method = "public_method"
21+
end
22+
23+
## assert
24+
class Foo
25+
private def private_method: -> String
26+
public def public_method: -> String
27+
end
28+
29+
## update
30+
class Foo
31+
private def private_method = "private_method"
32+
public def public_method = "public_method"
33+
def other_method = "other_method"
34+
end
35+
36+
## assert
37+
class Foo
38+
private def private_method: -> String
39+
public def public_method: -> String
40+
def other_method: -> String
41+
end
42+
43+
## update
44+
class Foo
45+
def private_method = "private_method"
46+
def public_method = "public_method"
47+
private :private_method
48+
end
49+
50+
## assert
51+
class Foo
52+
private def private_method: -> String
53+
def public_method: -> String
54+
end

0 commit comments

Comments
 (0)