Skip to content

Commit ad3a9b1

Browse files
committed
Ruby: test files for RBI library
1 parent e03ce8f commit ad3a9b1

File tree

3 files changed

+216
-0
lines changed

3 files changed

+216
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
rbiTypes
2+
| test_types.rb:7:17:7:23 | Integer |
3+
| test_types.rb:10:19:10:25 | Integer |
4+
| test_types.rb:10:31:10:37 | Integer |
5+
| test_types.rb:10:48:10:54 | Integer |
6+
| test_types.rb:13:19:13:25 | Integer |
7+
| test_types.rb:13:36:13:36 | T |
8+
| test_types.rb:13:36:13:45 | Boolean |
9+
| test_types.rb:18:17:18:23 | MyClass |
10+
| test_types.rb:21:17:21:22 | String |
11+
| test_types.rb:24:17:24:23 | Integer |
12+
| test_types.rb:29:10:29:15 | String |
13+
| test_types.rb:30:14:30:14 | T |
14+
| test_types.rb:30:14:30:54 | call to nilable |
15+
| test_types.rb:30:24:30:24 | T |
16+
| test_types.rb:30:24:30:29 | call to proc |
17+
| test_types.rb:30:24:30:48 | call to params |
18+
| test_types.rb:30:24:30:53 | call to void |
19+
| test_types.rb:30:41:30:47 | Integer |
20+
| test_types.rb:37:10:37:15 | String |
21+
| test_types.rb:38:14:38:14 | T |
22+
| test_types.rb:38:14:38:19 | call to proc |
23+
| test_types.rb:38:14:38:38 | call to params |
24+
| test_types.rb:38:14:38:54 | call to returns |
25+
| test_types.rb:38:31:38:37 | Integer |
26+
| test_types.rb:38:48:38:53 | String |
27+
| test_types.rb:43:22:43:22 | T |
28+
| test_types.rb:43:22:43:28 | Hash |
29+
| test_types.rb:43:30:43:30 | T |
30+
| test_types.rb:43:30:43:38 | call to untyped |
31+
| test_types.rb:43:41:43:41 | T |
32+
| test_types.rb:43:41:43:49 | call to untyped |
33+
| test_types.rb:46:21:46:21 | T |
34+
| test_types.rb:46:21:46:28 | Array |
35+
| test_types.rb:46:30:46:35 | Symbol |
36+
| test_types.rb:49:26:49:26 | T |
37+
| test_types.rb:49:26:49:46 | call to any |
38+
| test_types.rb:49:32:49:37 | String |
39+
| test_types.rb:49:40:49:45 | Symbol |
40+
| test_types.rb:49:57:49:62 | String |
41+
unionTypes
42+
| test_types.rb:49:26:49:46 | call to any | test_types.rb:49:32:49:37 | String |
43+
| test_types.rb:49:26:49:46 | call to any | test_types.rb:49:40:49:45 | Symbol |
44+
nilableTypes
45+
| test_types.rb:30:14:30:54 | call to nilable | test_types.rb:30:24:30:53 | call to void |
46+
typeAliases
47+
arrayTypes
48+
| test_types.rb:46:21:46:28 | Array | test_types.rb:46:30:46:35 | Symbol |
49+
hashTypes
50+
| test_types.rb:43:22:43:28 | Hash | test_types.rb:43:30:43:38 | call to untyped | test_types.rb:43:41:43:49 | call to untyped |
51+
signatureCalls
52+
| test_types.rb:4:3:4:14 | call to sig | (void) |
53+
| test_types.rb:7:3:7:26 | call to sig | Integer |
54+
| test_types.rb:10:3:10:57 | call to sig | Integer |
55+
| test_types.rb:13:3:13:48 | call to sig | Boolean |
56+
| test_types.rb:18:3:18:26 | call to sig | MyClass |
57+
| test_types.rb:21:3:21:25 | call to sig | String |
58+
| test_types.rb:24:3:24:26 | call to sig | Integer |
59+
| test_types.rb:27:3:32:5 | call to sig | (void) |
60+
| test_types.rb:30:24:30:29 | call to proc | (void) |
61+
| test_types.rb:38:14:38:19 | call to proc | String |
62+
| test_types.rb:43:3:43:58 | call to sig | (void) |
63+
| test_types.rb:49:3:49:65 | call to sig | String |
64+
paramsCalls
65+
| test_types.rb:10:9:10:38 | call to params |
66+
| test_types.rb:13:9:13:26 | call to params |
67+
| test_types.rb:28:5:31:5 | call to params |
68+
| test_types.rb:30:24:30:48 | call to params |
69+
| test_types.rb:36:5:39:5 | call to params |
70+
| test_types.rb:38:14:38:38 | call to params |
71+
| test_types.rb:43:9:43:51 | call to params |
72+
| test_types.rb:46:9:46:37 | call to params |
73+
| test_types.rb:49:9:49:47 | call to params |
74+
returnsCall
75+
| test_types.rb:7:9:7:24 | call to returns | Integer |
76+
| test_types.rb:10:9:10:55 | call to returns | Integer |
77+
| test_types.rb:13:9:13:46 | call to returns | Boolean |
78+
| test_types.rb:18:9:18:24 | call to returns | MyClass |
79+
| test_types.rb:21:9:21:23 | call to returns | String |
80+
| test_types.rb:24:9:24:24 | call to returns | Integer |
81+
| test_types.rb:38:14:38:54 | call to returns | String |
82+
| test_types.rb:49:9:49:63 | call to returns | String |
83+
voidCall
84+
| test_types.rb:4:9:4:12 | call to void |
85+
| test_types.rb:28:5:31:10 | call to void |
86+
| test_types.rb:30:24:30:53 | call to void |
87+
| test_types.rb:43:9:43:56 | call to void |
88+
parameterTypes
89+
| test_types.rb:10:16:10:25 | Pair | test_types.rb:11:11:11:11 | a | test_types.rb:10:19:10:25 | Integer |
90+
| test_types.rb:10:28:10:37 | Pair | test_types.rb:11:14:11:14 | b | test_types.rb:10:31:10:37 | Integer |
91+
| test_types.rb:13:16:13:25 | Pair | test_types.rb:14:18:14:18 | a | test_types.rb:13:19:13:25 | Integer |
92+
| test_types.rb:29:7:29:15 | Pair | test_types.rb:33:26:33:26 | a | test_types.rb:29:10:29:15 | String |
93+
| test_types.rb:30:7:30:54 | Pair | test_types.rb:33:29:33:34 | &block | test_types.rb:30:14:30:54 | call to nilable |
94+
| test_types.rb:37:7:37:15 | Pair | test_types.rb:41:18:41:18 | a | test_types.rb:37:10:37:15 | String |
95+
| test_types.rb:38:7:38:54 | Pair | test_types.rb:41:21:41:26 | &block | test_types.rb:38:14:38:54 | call to returns |
96+
| test_types.rb:49:16:49:46 | Pair | test_types.rb:50:14:50:21 | new_name | test_types.rb:49:26:49:46 | call to any |
97+
procParameterTypes
98+
| test_types.rb:30:7:30:54 | Pair | test_types.rb:30:24:30:53 | call to void | test_types.rb:30:24:30:29 | call to proc | nilable |
99+
| test_types.rb:38:7:38:54 | Pair | test_types.rb:38:14:38:54 | call to returns | test_types.rb:38:14:38:19 | call to proc | non_nilable |
100+
sigMethods
101+
| test_types.rb:4:3:4:14 | call to sig | test_types.rb:5:3:5:30 | perform_some_action |
102+
| test_types.rb:7:3:7:26 | call to sig | test_types.rb:8:3:8:21 | return_one |
103+
| test_types.rb:10:3:10:57 | call to sig | test_types.rb:11:3:11:20 | add |
104+
| test_types.rb:13:3:13:48 | call to sig | test_types.rb:14:3:14:24 | isPositive |
105+
| test_types.rb:18:3:18:26 | call to sig | test_types.rb:19:3:19:31 | getMyClassInstance |
106+
| test_types.rb:27:3:32:5 | call to sig | test_types.rb:33:3:33:40 | blk_nilable_method |
107+
| test_types.rb:35:3:40:5 | call to sig | test_types.rb:41:3:41:32 | blk_method |
108+
| test_types.rb:43:3:43:58 | call to sig | test_types.rb:44:3:44:28 | read_hash |
109+
| test_types.rb:46:3:46:39 | call to sig | test_types.rb:47:3:47:34 | read_symbol_array |
110+
| test_types.rb:49:3:49:65 | call to sig | test_types.rb:50:3:50:27 | rename |
111+
sigAttrReaders
112+
| test_types.rb:21:3:21:25 | call to sig | test_types.rb:22:3:22:26 | call to attr_reader |
113+
| test_types.rb:24:3:24:26 | call to sig | test_types.rb:25:3:25:24 | call to attr_accessor |
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
private import codeql.ruby.AST
2+
private import codeql.ruby.DataFlow
3+
private import codeql.ruby.controlflow.CfgNodes
4+
private import codeql.ruby.experimental.Rbi::Rbi
5+
6+
query predicate rbiTypes(RbiType t) { any() }
7+
8+
query predicate unionTypes(RbiUnionType t, RbiType u) { u = t.getAType() }
9+
10+
query predicate nilableTypes(RbiNilableType t, RbiType u) { u = t.getUnderlyingType() }
11+
12+
query predicate typeAliases(RbiTypeAlias a, RbiType t) { t = a.getAliasedType() }
13+
14+
query predicate arrayTypes(RbiArrayType at, RbiType et) { et = at.getElementType() }
15+
16+
query predicate hashTypes(RbiHashType ht, RbiType kt, RbiType vt) {
17+
kt = ht.getKeyType() and vt = ht.getValueType()
18+
}
19+
20+
query predicate signatureCalls(SignatureCall c, ReturnType r) { r = c.getReturnType() }
21+
22+
query predicate paramsCalls(ParamsCall c) { any() }
23+
24+
query predicate returnsCall(ReturnsCall c, ReturnType r) { r = c.getReturnType() }
25+
26+
query predicate voidCall(VoidCall c) { any() }
27+
28+
query predicate parameterTypes(ParameterType pt, NamedParameter p, RbiType t) {
29+
p = pt.getParameter() and t = pt.getType()
30+
}
31+
32+
query predicate procParameterTypes(
33+
ParameterType pt, ProcReturnsTypeCall prtc, ProcCall pc, string isNilable
34+
) {
35+
(
36+
exists(RbiNilableType nilable | nilable = pt.getType() |
37+
prtc = nilable.getUnderlyingType() and
38+
isNilable = "nilable"
39+
)
40+
or
41+
pt.getType() = prtc and isNilable = "non_nilable"
42+
) and
43+
pc = prtc.getProcCall()
44+
}
45+
46+
query predicate sigMethods(MethodSignatureCall sig, ExprNodes::MethodBaseCfgNode m) {
47+
m = sig.getAssociatedMethod()
48+
}
49+
50+
query predicate sigAttrReaders(MethodSignatureCall sig, ExprNodes::MethodCallCfgNode attr_reader) {
51+
attr_reader = sig.getAssociatedAttrReaderCall()
52+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# TODO: this should be a .rbi file if we decide to extract them by default
2+
3+
module TestTypes
4+
sig { void }
5+
def perform_some_action; end
6+
7+
sig { returns(Integer) }
8+
def return_one; end
9+
10+
sig { params(a: Integer, b: Integer).returns(Integer) }
11+
def add(a, b); end
12+
13+
sig { params(a: Integer).returns(T::Boolean) }
14+
def isPositive(a); end
15+
16+
class MyClass; end
17+
18+
sig { returns(MyClass) }
19+
def getMyClassInstance(); end
20+
21+
sig { returns(String) }
22+
attr_reader :name, :kind
23+
24+
sig { returns(Integer) }
25+
attr_accessor :version
26+
27+
sig do
28+
params(
29+
a: String,
30+
block: T.nilable(T.proc.params(b: Integer).void)
31+
).void
32+
end
33+
def blk_nilable_method(a, &block); end
34+
35+
sig do
36+
params(
37+
a: String,
38+
block: T.proc.params(b: Integer).returns(String)
39+
)
40+
end
41+
def blk_method(a, &block); end
42+
43+
sig { params(hash: T::Hash[T.untyped, T.untyped]).void }
44+
def read_hash(**hash); end
45+
46+
sig { params(arr: T::Array[Symbol]) }
47+
def read_symbol_array(*arr); end
48+
49+
sig { params(new_name: T.any(String, Symbol)).returns(String) }
50+
def rename(new_name); end
51+
end

0 commit comments

Comments
 (0)