Skip to content

Commit 4b2d323

Browse files
committed
C#: Add some more test cases.
1 parent 2c5d85e commit 4b2d323

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

csharp/ql/test/query-tests/Likely Bugs/HashedButNoHash/HashedButNoHash.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,26 @@ public void M()
77
{
88
var h = new Hashtable();
99
h.Add(this, null); // $ Alert
10+
h.Contains(this); // $ Alert
11+
h.ContainsKey(this); // $ Alert
12+
h[this] = null; // $ Alert
13+
h.Remove(this); // $ Alert
14+
15+
var l = new List<Test>();
16+
l.Add(this); // Good
1017

1118
var d = new Dictionary<Test, bool>();
1219
d.Add(this, false); // $ Alert
20+
d.ContainsKey(this); // $ Alert
21+
d[this] = false; // $ Alert
22+
d.Remove(this); // $ Alert
23+
d.TryAdd(this, false); // $ Alert
24+
d.TryGetValue(this, out bool _); // $ Alert
25+
26+
var hs = new HashSet<Test>();
27+
hs.Add(this); // $ Alert
28+
hs.Contains(this); // $ Alert
29+
hs.Remove(this); // $ Alert
1330
}
1431

1532
public override bool Equals(object other)
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1+
#select
12
| HashedButNoHash.cs:9:15:9:18 | this access | This expression is hashed, but type 'Test' only defines Equals(...) not GetHashCode(). |
2-
| HashedButNoHash.cs:12:15:12:18 | this access | This expression is hashed, but type 'Test' only defines Equals(...) not GetHashCode(). |
3+
| HashedButNoHash.cs:11:23:11:26 | this access | This expression is hashed, but type 'Test' only defines Equals(...) not GetHashCode(). |
4+
| HashedButNoHash.cs:19:15:19:18 | this access | This expression is hashed, but type 'Test' only defines Equals(...) not GetHashCode(). |
5+
| HashedButNoHash.cs:20:23:20:26 | this access | This expression is hashed, but type 'Test' only defines Equals(...) not GetHashCode(). |
6+
testFailures
7+
| HashedButNoHash.cs:10:27:10:36 | // ... | Missing result: Alert |
8+
| HashedButNoHash.cs:12:25:12:34 | // ... | Missing result: Alert |
9+
| HashedButNoHash.cs:13:25:13:34 | // ... | Missing result: Alert |
10+
| HashedButNoHash.cs:21:26:21:35 | // ... | Missing result: Alert |
11+
| HashedButNoHash.cs:22:25:22:34 | // ... | Missing result: Alert |
12+
| HashedButNoHash.cs:23:32:23:41 | // ... | Missing result: Alert |
13+
| HashedButNoHash.cs:24:42:24:51 | // ... | Missing result: Alert |
14+
| HashedButNoHash.cs:27:23:27:32 | // ... | Missing result: Alert |
15+
| HashedButNoHash.cs:28:28:28:37 | // ... | Missing result: Alert |
16+
| HashedButNoHash.cs:29:26:29:35 | // ... | Missing result: Alert |

0 commit comments

Comments
 (0)