mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
C#: Add file scoped test cases.
This commit is contained in:
25
csharp/ql/test/library-tests/csharp11/FileScoped1.cs
Normal file
25
csharp/ql/test/library-tests/csharp11/FileScoped1.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
file interface I1 { }
|
||||
|
||||
file interface I2 { }
|
||||
|
||||
file class C1 : I1 { }
|
||||
|
||||
public class C2 { }
|
||||
|
||||
public class C3 : I2 { }
|
||||
|
||||
file interface IC { }
|
||||
|
||||
file class C4<T> { }
|
||||
|
||||
file class C5<S> : C4<S> { }
|
||||
|
||||
file struct S1 { }
|
||||
|
||||
file enum E1 { }
|
||||
|
||||
file delegate void D1();
|
||||
|
||||
file record R1 { }
|
||||
|
||||
file record struct RS1 { }
|
||||
23
csharp/ql/test/library-tests/csharp11/FileScoped2.cs
Normal file
23
csharp/ql/test/library-tests/csharp11/FileScoped2.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
file interface I1 { }
|
||||
|
||||
public interface I2 { }
|
||||
|
||||
file class C1 { }
|
||||
|
||||
file class C2 : I2 { }
|
||||
|
||||
file class IC { }
|
||||
|
||||
file class C4<T> { }
|
||||
|
||||
file class C5<S> : C4<S> { }
|
||||
|
||||
file struct S1 { }
|
||||
|
||||
file enum E1 { }
|
||||
|
||||
file delegate void D1();
|
||||
|
||||
file record R1 { }
|
||||
|
||||
file record struct RS1 { }
|
||||
7
csharp/ql/test/library-tests/csharp11/FileScoped3.cs
Normal file
7
csharp/ql/test/library-tests/csharp11/FileScoped3.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace TestFileScoped;
|
||||
|
||||
file interface I10 { }
|
||||
|
||||
file class C10 { }
|
||||
|
||||
public class C11 : I10 { }
|
||||
7
csharp/ql/test/library-tests/csharp11/FileScoped4.cs
Normal file
7
csharp/ql/test/library-tests/csharp11/FileScoped4.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace TestFileScoped;
|
||||
|
||||
public interface I10 { }
|
||||
|
||||
file class C10 { }
|
||||
|
||||
file class C11 : I10 { }
|
||||
@@ -216,6 +216,103 @@ CheckedOperators.cs:
|
||||
# 55| 0: [TypeMention] short
|
||||
# 55| 1: [PropertyCall] access to property Value
|
||||
# 55| -1: [ParameterAccess] access to parameter n
|
||||
FileScoped1.cs:
|
||||
# 1| [Interface] I1
|
||||
# 3| [Interface] I2
|
||||
# 5| [Class] C1
|
||||
#-----| 3: (Base types)
|
||||
# 5| 1: [TypeMention] I1
|
||||
# 7| [Class] C2
|
||||
# 9| [Class] C3
|
||||
#-----| 3: (Base types)
|
||||
# 9| 1: [TypeMention] I2
|
||||
# 11| [Interface] IC
|
||||
# 13| [Class] C4<>
|
||||
#-----| 1: (Type parameters)
|
||||
# 13| 0: [TypeParameter] T
|
||||
# 15| [Class] C5<>
|
||||
#-----| 1: (Type parameters)
|
||||
# 15| 0: [TypeParameter] S
|
||||
#-----| 3: (Base types)
|
||||
# 15| 0: [TypeMention] C4<S>
|
||||
# 15| 1: [TypeMention] S
|
||||
# 17| [Struct] S1
|
||||
# 19| [Enum] E1
|
||||
# 21| [DelegateType] D1
|
||||
# 23| [RecordClass] R1
|
||||
# 23| 12: [NEOperator] !=
|
||||
#-----| 2: (Parameters)
|
||||
# 23| 0: [Parameter] left
|
||||
# 23| 1: [Parameter] right
|
||||
# 23| 13: [EQOperator] ==
|
||||
#-----| 2: (Parameters)
|
||||
# 23| 0: [Parameter] left
|
||||
# 23| 1: [Parameter] right
|
||||
# 23| 14: [Property] EqualityContract
|
||||
# 23| 3: [Getter] get_EqualityContract
|
||||
# 25| [RecordStruct] RS1
|
||||
# 25| 10: [NEOperator] !=
|
||||
#-----| 2: (Parameters)
|
||||
# 25| 0: [Parameter] left
|
||||
# 25| 1: [Parameter] right
|
||||
# 25| 11: [EQOperator] ==
|
||||
#-----| 2: (Parameters)
|
||||
# 25| 0: [Parameter] left
|
||||
# 25| 1: [Parameter] right
|
||||
FileScoped2.cs:
|
||||
# 1| [Interface] I1
|
||||
# 3| [Interface] I2
|
||||
# 5| [Class] C1
|
||||
# 7| [Class] C2
|
||||
#-----| 3: (Base types)
|
||||
# 7| 1: [TypeMention] I2
|
||||
# 9| [Class] IC
|
||||
# 11| [Class] C4<>
|
||||
#-----| 1: (Type parameters)
|
||||
# 11| 0: [TypeParameter] T
|
||||
# 13| [Class] C5<>
|
||||
#-----| 1: (Type parameters)
|
||||
# 13| 0: [TypeParameter] S
|
||||
#-----| 3: (Base types)
|
||||
# 13| 0: [TypeMention] C4<S>
|
||||
# 13| 1: [TypeMention] S
|
||||
# 15| [Struct] S1
|
||||
# 17| [Enum] E1
|
||||
# 19| [DelegateType] D1
|
||||
# 21| [RecordClass] R1
|
||||
# 21| 12: [NEOperator] !=
|
||||
#-----| 2: (Parameters)
|
||||
# 21| 0: [Parameter] left
|
||||
# 21| 1: [Parameter] right
|
||||
# 21| 13: [EQOperator] ==
|
||||
#-----| 2: (Parameters)
|
||||
# 21| 0: [Parameter] left
|
||||
# 21| 1: [Parameter] right
|
||||
# 21| 14: [Property] EqualityContract
|
||||
# 21| 3: [Getter] get_EqualityContract
|
||||
# 23| [RecordStruct] RS1
|
||||
# 23| 10: [NEOperator] !=
|
||||
#-----| 2: (Parameters)
|
||||
# 23| 0: [Parameter] left
|
||||
# 23| 1: [Parameter] right
|
||||
# 23| 11: [EQOperator] ==
|
||||
#-----| 2: (Parameters)
|
||||
# 23| 0: [Parameter] left
|
||||
# 23| 1: [Parameter] right
|
||||
FileScoped3.cs:
|
||||
# 1| [NamespaceDeclaration] namespace ... { ... }
|
||||
# 3| 1: [Interface] I10
|
||||
# 5| 2: [Class] C10
|
||||
# 7| 3: [Class] C11
|
||||
#-----| 3: (Base types)
|
||||
# 7| 1: [TypeMention] I10
|
||||
FileScoped4.cs:
|
||||
# 1| [NamespaceDeclaration] namespace ... { ... }
|
||||
# 3| 1: [Interface] I10
|
||||
# 5| 2: [Class] C10
|
||||
# 7| 3: [Class] C11
|
||||
#-----| 3: (Base types)
|
||||
# 7| 1: [TypeMention] I10
|
||||
GenericAttribute.cs:
|
||||
# 3| [GenericAssemblyAttribute] [assembly: MyGeneric<Int32>(...)]
|
||||
# 3| 0: [TypeMention] MyGenericAttribute<int>
|
||||
|
||||
116
csharp/ql/test/library-tests/csharp11/fileScoped.expected
Normal file
116
csharp/ql/test/library-tests/csharp11/fileScoped.expected
Normal file
@@ -0,0 +1,116 @@
|
||||
typemodifiers
|
||||
| FileScoped1.cs:1:16:1:17 | I1 | file |
|
||||
| FileScoped1.cs:3:16:3:17 | I2 | file |
|
||||
| FileScoped1.cs:5:12:5:13 | C1 | file |
|
||||
| FileScoped1.cs:7:14:7:15 | C2 | public |
|
||||
| FileScoped1.cs:9:14:9:15 | C3 | public |
|
||||
| FileScoped1.cs:11:16:11:17 | IC | file |
|
||||
| FileScoped1.cs:13:12:13:16 | C4<> | file |
|
||||
| FileScoped1.cs:13:12:13:16 | C4<S> | file |
|
||||
| FileScoped1.cs:15:12:15:16 | C5<> | file |
|
||||
| FileScoped1.cs:17:13:17:14 | S1 | file |
|
||||
| FileScoped1.cs:17:13:17:14 | S1 | sealed |
|
||||
| FileScoped1.cs:19:11:19:12 | E1 | file |
|
||||
| FileScoped1.cs:19:11:19:12 | E1 | sealed |
|
||||
| FileScoped1.cs:21:20:21:21 | D1 | file |
|
||||
| FileScoped1.cs:21:20:21:21 | D1 | sealed |
|
||||
| FileScoped1.cs:23:1:23:18 | R1 | file |
|
||||
| FileScoped1.cs:23:1:23:18 | R1 | record |
|
||||
| FileScoped1.cs:25:1:25:26 | RS1 | file |
|
||||
| FileScoped1.cs:25:1:25:26 | RS1 | record |
|
||||
| FileScoped1.cs:25:1:25:26 | RS1 | sealed |
|
||||
| FileScoped2.cs:1:16:1:17 | I1 | file |
|
||||
| FileScoped2.cs:3:18:3:19 | I2 | public |
|
||||
| FileScoped2.cs:5:12:5:13 | C1 | file |
|
||||
| FileScoped2.cs:7:12:7:13 | C2 | file |
|
||||
| FileScoped2.cs:9:12:9:13 | IC | file |
|
||||
| FileScoped2.cs:11:12:11:16 | C4<> | file |
|
||||
| FileScoped2.cs:11:12:11:16 | C4<S> | file |
|
||||
| FileScoped2.cs:13:12:13:16 | C5<> | file |
|
||||
| FileScoped2.cs:15:13:15:14 | S1 | file |
|
||||
| FileScoped2.cs:15:13:15:14 | S1 | sealed |
|
||||
| FileScoped2.cs:17:11:17:12 | E1 | file |
|
||||
| FileScoped2.cs:17:11:17:12 | E1 | sealed |
|
||||
| FileScoped2.cs:19:20:19:21 | D1 | file |
|
||||
| FileScoped2.cs:19:20:19:21 | D1 | sealed |
|
||||
| FileScoped2.cs:21:1:21:18 | R1 | file |
|
||||
| FileScoped2.cs:21:1:21:18 | R1 | record |
|
||||
| FileScoped2.cs:23:1:23:26 | RS1 | file |
|
||||
| FileScoped2.cs:23:1:23:26 | RS1 | record |
|
||||
| FileScoped2.cs:23:1:23:26 | RS1 | sealed |
|
||||
| FileScoped3.cs:3:16:3:18 | I10 | file |
|
||||
| FileScoped3.cs:5:12:5:14 | C10 | file |
|
||||
| FileScoped3.cs:7:14:7:16 | C11 | public |
|
||||
| FileScoped4.cs:3:18:3:20 | I10 | public |
|
||||
| FileScoped4.cs:5:12:5:14 | C10 | file |
|
||||
| FileScoped4.cs:7:12:7:14 | C11 | file |
|
||||
qualifiedtypes
|
||||
| FileScoped1.cs:1:16:1:17 | I1 | I1 |
|
||||
| FileScoped1.cs:3:16:3:17 | I2 | I2 |
|
||||
| FileScoped1.cs:5:12:5:13 | C1 | C1 |
|
||||
| FileScoped1.cs:7:14:7:15 | C2 | C2 |
|
||||
| FileScoped1.cs:9:14:9:15 | C3 | C3 |
|
||||
| FileScoped1.cs:11:16:11:17 | IC | IC |
|
||||
| FileScoped1.cs:13:12:13:16 | C4<> | C4<> |
|
||||
| FileScoped1.cs:13:12:13:16 | C4<S> | C4<S> |
|
||||
| FileScoped1.cs:15:12:15:16 | C5<> | C5<> |
|
||||
| FileScoped1.cs:17:13:17:14 | S1 | S1 |
|
||||
| FileScoped1.cs:19:11:19:12 | E1 | E1 |
|
||||
| FileScoped1.cs:21:20:21:21 | D1 | D1 |
|
||||
| FileScoped1.cs:23:1:23:18 | R1 | R1 |
|
||||
| FileScoped1.cs:25:1:25:26 | RS1 | RS1 |
|
||||
| FileScoped2.cs:1:16:1:17 | I1 | I1 |
|
||||
| FileScoped2.cs:3:18:3:19 | I2 | I2 |
|
||||
| FileScoped2.cs:5:12:5:13 | C1 | C1 |
|
||||
| FileScoped2.cs:7:12:7:13 | C2 | C2 |
|
||||
| FileScoped2.cs:9:12:9:13 | IC | IC |
|
||||
| FileScoped2.cs:11:12:11:16 | C4<> | C4<> |
|
||||
| FileScoped2.cs:11:12:11:16 | C4<S> | C4<S> |
|
||||
| FileScoped2.cs:13:12:13:16 | C5<> | C5<> |
|
||||
| FileScoped2.cs:15:13:15:14 | S1 | S1 |
|
||||
| FileScoped2.cs:17:11:17:12 | E1 | E1 |
|
||||
| FileScoped2.cs:19:20:19:21 | D1 | D1 |
|
||||
| FileScoped2.cs:21:1:21:18 | R1 | R1 |
|
||||
| FileScoped2.cs:23:1:23:26 | RS1 | RS1 |
|
||||
| FileScoped3.cs:3:16:3:18 | I10 | TestFileScoped.I10 |
|
||||
| FileScoped3.cs:5:12:5:14 | C10 | TestFileScoped.C10 |
|
||||
| FileScoped3.cs:7:14:7:16 | C11 | TestFileScoped.C11 |
|
||||
| FileScoped4.cs:3:18:3:20 | I10 | TestFileScoped.I10 |
|
||||
| FileScoped4.cs:5:12:5:14 | C10 | TestFileScoped.C10 |
|
||||
| FileScoped4.cs:7:12:7:14 | C11 | TestFileScoped.C11 |
|
||||
filetypes
|
||||
| FileScoped1.cs:1:16:1:17 | I1 |
|
||||
| FileScoped1.cs:3:16:3:17 | I2 |
|
||||
| FileScoped1.cs:5:12:5:13 | C1 |
|
||||
| FileScoped1.cs:11:16:11:17 | IC |
|
||||
| FileScoped1.cs:13:12:13:16 | C4<> |
|
||||
| FileScoped1.cs:13:12:13:16 | C4<S> |
|
||||
| FileScoped1.cs:15:12:15:16 | C5<> |
|
||||
| FileScoped1.cs:17:13:17:14 | S1 |
|
||||
| FileScoped1.cs:19:11:19:12 | E1 |
|
||||
| FileScoped1.cs:21:20:21:21 | D1 |
|
||||
| FileScoped1.cs:23:1:23:18 | R1 |
|
||||
| FileScoped1.cs:25:1:25:26 | RS1 |
|
||||
| FileScoped2.cs:1:16:1:17 | I1 |
|
||||
| FileScoped2.cs:5:12:5:13 | C1 |
|
||||
| FileScoped2.cs:7:12:7:13 | C2 |
|
||||
| FileScoped2.cs:9:12:9:13 | IC |
|
||||
| FileScoped2.cs:11:12:11:16 | C4<> |
|
||||
| FileScoped2.cs:11:12:11:16 | C4<S> |
|
||||
| FileScoped2.cs:13:12:13:16 | C5<> |
|
||||
| FileScoped2.cs:15:13:15:14 | S1 |
|
||||
| FileScoped2.cs:17:11:17:12 | E1 |
|
||||
| FileScoped2.cs:19:20:19:21 | D1 |
|
||||
| FileScoped2.cs:21:1:21:18 | R1 |
|
||||
| FileScoped2.cs:23:1:23:26 | RS1 |
|
||||
| FileScoped3.cs:3:16:3:18 | I10 |
|
||||
| FileScoped3.cs:5:12:5:14 | C10 |
|
||||
| FileScoped4.cs:5:12:5:14 | C10 |
|
||||
| FileScoped4.cs:7:12:7:14 | C11 |
|
||||
internaltypes
|
||||
publictypes
|
||||
| FileScoped1.cs:7:14:7:15 | C2 |
|
||||
| FileScoped1.cs:9:14:9:15 | C3 |
|
||||
| FileScoped2.cs:3:18:3:19 | I2 |
|
||||
| FileScoped3.cs:7:14:7:16 | C11 |
|
||||
| FileScoped4.cs:3:18:3:20 | I10 |
|
||||
42
csharp/ql/test/library-tests/csharp11/fileScoped.ql
Normal file
42
csharp/ql/test/library-tests/csharp11/fileScoped.ql
Normal file
@@ -0,0 +1,42 @@
|
||||
import csharp
|
||||
private import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
private predicate isInteresting(Type t) {
|
||||
(
|
||||
t instanceof Class or
|
||||
t instanceof Interface or
|
||||
t instanceof Struct or
|
||||
t instanceof Enum or
|
||||
t instanceof DelegateType or
|
||||
t instanceof RecordType
|
||||
) and
|
||||
t.getFile().getStem().matches("FileScoped%")
|
||||
}
|
||||
|
||||
query predicate typemodifiers(Type t, string modifier) {
|
||||
isInteresting(t) and
|
||||
t.(Modifiable).hasModifier(modifier)
|
||||
}
|
||||
|
||||
query predicate qualifiedtypes(Type t, string qualifiedName) {
|
||||
isInteresting(t) and
|
||||
exists(string qualifier, string name |
|
||||
t.hasQualifiedName(qualifier, name) and
|
||||
qualifiedName = getQualifiedName(qualifier, name)
|
||||
)
|
||||
}
|
||||
|
||||
query predicate filetypes(Type t) {
|
||||
isInteresting(t) and
|
||||
t.isFile()
|
||||
}
|
||||
|
||||
query predicate internaltypes(Type t) {
|
||||
isInteresting(t) and
|
||||
t.isInternal()
|
||||
}
|
||||
|
||||
query predicate publictypes(Type t) {
|
||||
isInteresting(t) and
|
||||
t.isPublic()
|
||||
}
|
||||
Reference in New Issue
Block a user