Skip to content

Commit 8380d71

Browse files
committed
Go: Add test for AliasType extraction
1 parent 1a9608a commit 8380d71

11 files changed

+90
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
entities
2+
| aliases.go | aliases.go:3:6:3:13 | aliasesX | 1 | file://:0:0:0:0 | int |
3+
| aliases.go | aliases.go:4:6:4:13 | aliasesY | 1 | file://:0:0:0:0 | int |
4+
| aliases.go | aliases.go:6:6:6:14 | aliasesS1 | 1 | file://:0:0:0:0 | struct type |
5+
| aliases.go | aliases.go:6:26:6:26 | x | 3 | file://:0:0:0:0 | int |
6+
| aliases.go | aliases.go:8:6:8:14 | aliasesS2 | 1 | file://:0:0:0:0 | struct type |
7+
| aliases.go | aliases.go:8:26:8:26 | x | 3 | file://:0:0:0:0 | int |
8+
| aliases.go | aliases.go:10:6:10:6 | F | 1 | file://:0:0:0:0 | signature type |
9+
| aliases.go | aliases.go:10:8:10:11 | Afs1 | 1 | file://:0:0:0:0 | struct type |
10+
| aliases.go | aliases.go:14:6:14:6 | G | 1 | file://:0:0:0:0 | signature type |
11+
| aliases.go | aliases.go:14:8:14:11 | Afs2 | 1 | file://:0:0:0:0 | struct type |
12+
| aliases.go | aliases.go:19:6:19:7 | S3 | 1 | aliases.go:19:6:19:7 | S3 |
13+
| aliases.go | aliases.go:19:17:19:17 | x | 3 | file://:0:0:0:0 | int |
14+
| aliases.go | aliases.go:22:6:22:6 | T | 1 | aliases.go:19:6:19:7 | S3 |
15+
| aliases.go | aliases.go:25:6:25:6 | H | 1 | file://:0:0:0:0 | signature type |
16+
| aliases.go | aliases.go:25:8:25:11 | Afs3 | 1 | aliases.go:19:6:19:7 | S3 |
17+
#select
18+
| F | func(struct { x int }) int |
19+
| G | func(struct { x int }) int |
20+
| H | func(S3) int |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import go
2+
3+
int countDecls(Entity e) {
4+
result = count(Ident decl | decl = e.getDeclaration())
5+
}
6+
7+
query predicate entities(string fp, Entity e, int c, Type ty) {
8+
c = countDecls(e) and
9+
ty = e.getType() and
10+
exists(DbLocation loc |
11+
loc = e.getDeclaration().getLocation() and
12+
fp = loc.getFile().getBaseName() and
13+
fp = "aliases.go"
14+
)
15+
}
16+
17+
from string fp, FuncDecl decl, SignatureType sig
18+
where
19+
decl.hasLocationInfo(fp, _, _, _, _) and
20+
decl.getName() = ["F", "G", "H"] and
21+
sig = decl.getType() and
22+
fp.matches("%aliases.go%")
23+
select decl.getName(), sig.pp()

go/ql/test/library-tests/semmle/go/Types/Field_getPackage.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
| aliases.go:6:26:6:26 | x | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types |
2+
| aliases.go:8:26:8:26 | x | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types |
3+
| aliases.go:19:17:19:17 | x | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types |
14
| cyclic.go:4:3:4:3 | s | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types |
25
| cyclic.go:8:3:8:3 | u | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types |
36
| cyclic.go:9:2:9:2 | f | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types |

go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName2.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
| aliases.go:6:26:6:26 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.S3 | x |
2+
| aliases.go:8:26:8:26 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.S3 | x |
3+
| aliases.go:19:17:19:17 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.S3 | x |
14
| cyclic.go:4:3:4:3 | s | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.s | s |
25
| cyclic.go:8:3:8:3 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.t | u |
36
| cyclic.go:8:3:8:3 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.u | u |

go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName3.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
| aliases.go:6:26:6:26 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | S3 | x |
2+
| aliases.go:8:26:8:26 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | S3 | x |
3+
| aliases.go:19:17:19:17 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | S3 | x |
14
| cyclic.go:4:3:4:3 | s | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | s | s |
25
| cyclic.go:8:3:8:3 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | t | u |
36
| cyclic.go:8:3:8:3 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | u | u |

go/ql/test/library-tests/semmle/go/Types/QualifiedNames.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| aliases.go:19:6:19:7 | S3 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.S3 |
12
| cyclic.go:3:6:3:6 | s | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.s |
23
| cyclic.go:7:6:7:6 | t | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.t |
34
| cyclic.go:12:6:12:6 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.u |

go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumParameter.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
| aliases.go:10:1:12:1 | function declaration | 1 |
2+
| aliases.go:14:1:16:1 | function declaration | 1 |
3+
| aliases.go:25:1:27:1 | function declaration | 1 |
14
| depth.go:22:1:25:1 | function declaration | 0 |
25
| generic.go:70:1:72:1 | function declaration | 1 |
36
| generic.go:74:1:80:1 | function declaration | 1 |

go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumResult.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
| aliases.go:10:1:12:1 | function declaration | 1 |
2+
| aliases.go:14:1:16:1 | function declaration | 1 |
3+
| aliases.go:25:1:27:1 | function declaration | 1 |
14
| depth.go:22:1:25:1 | function declaration | 0 |
25
| generic.go:70:1:72:1 | function declaration | 1 |
36
| generic.go:74:1:80:1 | function declaration | 0 |

go/ql/test/library-tests/semmle/go/Types/StructFields.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
| aliases.go:19:6:19:7 | S3 | aliases.go:6:18:6:37 | struct type | x | int |
2+
| aliases.go:19:6:19:7 | S3 | aliases.go:8:18:8:37 | struct type | x | int |
3+
| aliases.go:19:6:19:7 | S3 | aliases.go:19:9:19:23 | struct type | x | int |
14
| cyclic.go:3:6:3:6 | s | cyclic.go:3:8:5:1 | struct type | s | * s |
25
| cyclic.go:7:6:7:6 | t | cyclic.go:7:8:10:1 | struct type | f | int |
36
| cyclic.go:7:6:7:6 | t | cyclic.go:7:8:10:1 | struct type | t | t |

go/ql/test/library-tests/semmle/go/Types/Types.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| aliases.go:19:6:19:7 | S3 | S3 |
12
| cyclic.go:3:6:3:6 | s | s |
23
| cyclic.go:7:6:7:6 | t | t |
34
| cyclic.go:12:6:12:6 | u | u |

0 commit comments

Comments
 (0)