-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathAttributesTests.cs
More file actions
430 lines (360 loc) · 13.8 KB
/
AttributesTests.cs
File metadata and controls
430 lines (360 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
namespace System.Runtime.CompilerServices.Tests
{
public static class AttributesTests
{
[Fact]
public static void ModuleInitializerAttributeTests()
{
new ModuleInitializerAttribute();
}
[Fact]
public static void SkipLocalsInitAttributeTests()
{
new SkipLocalsInitAttribute();
}
[Fact]
public static void AccessedThroughPropertyAttributeTests()
{
var attr1 = new AccessedThroughPropertyAttribute(null);
Assert.Null(attr1.PropertyName);
var attr2 = new AccessedThroughPropertyAttribute("MyProperty");
Assert.Equal("MyProperty", attr2.PropertyName);
}
[Fact]
public static void CallerFilePathAttributeTests()
{
new CallerFilePathAttribute();
}
[Fact]
public static void CallerLineNumberAttributeTests()
{
new CallerLineNumberAttribute();
}
[Fact]
public static void CallerMemberNameAttributeTests()
{
new CallerMemberNameAttribute();
}
[Fact]
public static void CollectionBuilderAttributeTests()
{
var attr = new CollectionBuilderAttribute(typeof(AttributesTests), "Create");
Assert.Same(typeof(AttributesTests), attr.BuilderType);
Assert.Equal("Create", attr.MethodName);
}
[Fact]
public static void CompilationRelaxationsAttributeTests()
{
var attr1 = new CompilationRelaxationsAttribute(42);
Assert.Equal(42, attr1.CompilationRelaxations);
var attr2 = new CompilationRelaxationsAttribute(CompilationRelaxations.NoStringInterning);
Assert.Equal((int)CompilationRelaxations.NoStringInterning, attr2.CompilationRelaxations);
}
[Fact]
public static void CompilerGeneratedAttributeTests()
{
new CompilerGeneratedAttribute();
}
[Fact]
public static void CompilerGlobalScopeAttributeTests()
{
new CompilerGlobalScopeAttribute();
}
[Fact]
public static void DateTimeConstantAttributeTests()
{
long ticks = DateTime.Now.Ticks;
var attr = new DateTimeConstantAttribute(ticks);
Assert.Equal(new DateTime(ticks), attr.Value);
Assert.Throws<ArgumentOutOfRangeException>(() => new DateTimeConstantAttribute(-1));
}
[Fact]
public static void DecimalConstantAttributeTests()
{
var attrSigned = new DecimalConstantAttribute(scale: 10, sign: 20, hi: 30, mid: 40, low: 50);
Assert.Equal(-55340232238.3085240370m, attrSigned.Value);
var attrUnsigned = new DecimalConstantAttribute(scale: 0, sign: 0, hi: 12u, mid: 13u, low: 14u);
Assert.Equal(221360928940349194254m, attrUnsigned.Value);
Assert.Throws<ArgumentOutOfRangeException>(() => new DecimalConstantAttribute(scale: 50, sign: 55, hi: 60, mid: 65, low: 70));
Assert.Throws<ArgumentOutOfRangeException>(() => new DecimalConstantAttribute(scale: 100, sign: 101, hi: 102u, mid: 103u, low: 104u));
}
[Fact]
public static void DefaultDependencyAttributeTests()
{
var attr1 = new DefaultDependencyAttribute(LoadHint.Sometimes);
Assert.Equal(LoadHint.Sometimes, attr1.LoadHint);
var attr2 = new DefaultDependencyAttribute((LoadHint)(-1));
Assert.Equal((LoadHint)(-1), attr2.LoadHint);
}
[Fact]
public static void DependencyAttributeTests()
{
var attr1 = new DependencyAttribute("DependentAssembly", LoadHint.Always);
Assert.Equal("DependentAssembly", attr1.DependentAssembly);
Assert.Equal(LoadHint.Always, attr1.LoadHint);
var attr2 = new DependencyAttribute(null, (LoadHint)(-2));
Assert.Null(attr2.DependentAssembly);
Assert.Equal((LoadHint)(-2), attr2.LoadHint);
}
#pragma warning disable SYSLIB0015 // Obsolete: DisablePrivateReflectionAttribute
[Fact]
public static void DisablePrivateReflectionAttributeTests()
{
new DisablePrivateReflectionAttribute();
}
#pragma warning restore SYSLIB0015 // Obsolete: DisablePrivateReflectionAttribute
[Fact]
public static void DiscardableAttributeTests()
{
new DiscardableAttribute();
}
[Fact]
public static void ExtensionAttributeTests()
{
new ExtensionAttribute();
}
[Fact]
public static void FixedAddressValueTypeAttributeTests()
{
new FixedAddressValueTypeAttribute();
}
[Fact]
public static void FixedBufferAttributeTests()
{
var attr1 = new FixedBufferAttribute(typeof(AttributesTests), 5);
Assert.Equal(typeof(AttributesTests), attr1.ElementType);
Assert.Equal(5, attr1.Length);
var attr2 = new FixedBufferAttribute(null, -1);
Assert.Null(attr2.ElementType);
Assert.Equal(-1, attr2.Length);
}
[Fact]
public static void IndexerNameAttributeTests()
{
new IndexerNameAttribute("Indexer");
new IndexerNameAttribute(null);
}
[Fact]
public static void InternalsVisibleToAttributeTests()
{
var attr1 = new InternalsVisibleToAttribute("MyAssembly");
Assert.Equal("MyAssembly", attr1.AssemblyName);
Assert.True(attr1.AllInternalsVisible);
attr1.AllInternalsVisible = false;
Assert.False(attr1.AllInternalsVisible);
var attr2 = new InternalsVisibleToAttribute(null);
Assert.Null(attr2.AssemblyName);
}
[Fact]
public static void IteratorStateMachineAttributeTests()
{
new IteratorStateMachineAttribute(typeof(AttributesTests));
new IteratorStateMachineAttribute(null);
}
[Fact]
public static void MethodImplAttributeTests()
{
var attr1 = new MethodImplAttribute();
Assert.Equal(default(MethodImplOptions), attr1.Value);
var attr2 = new MethodImplAttribute(-1);
Assert.Equal((MethodImplOptions)(-1), attr2.Value);
var attr3 = new MethodImplAttribute(MethodImplOptions.Unmanaged);
Assert.Equal(MethodImplOptions.Unmanaged, attr3.Value);
}
[Fact]
public static void NullableAttributeTests()
{
var attr = new NullableAttribute(42);
Assert.Equal(new byte[] { 42 }, attr.NullableFlags);
attr = new NullableAttribute(new byte[] { 1, 2, 3 });
Assert.Equal(new byte[] { 1, 2, 3 }, attr.NullableFlags);
}
[Fact]
public static void NullableContextAttributeTests()
{
var attr = new NullableContextAttribute(42);
Assert.Equal(42, attr.Flag);
}
[Theory]
[InlineData(false)]
[InlineData(true)]
public static void NullablePublicOnlyAttributeTests(bool includeInternals)
{
var attr = new NullablePublicOnlyAttribute(includeInternals);
Assert.Equal(includeInternals, attr.IncludesInternals);
}
[Theory]
[InlineData(-1)]
[InlineData(42)]
public static void RefSafetyRulesAttributeTests(int version)
{
var attr = new RefSafetyRulesAttribute(version);
Assert.Equal(version, attr.Version);
}
[Theory]
[InlineData(-1)]
[InlineData(0)]
[InlineData(2)]
[InlineData(42)]
public static void MemorySafetyRulesAttributeTests(int version)
{
var attr = new MemorySafetyRulesAttribute(version);
Assert.Equal(version, attr.Version);
}
[Theory]
[InlineData("1")]
[InlineData("2")]
public static void ExtensionMarkerAttributeTests(string name)
{
var attr = new ExtensionMarkerAttribute(name);
Assert.Equal(name, attr.Name);
}
[Fact]
public static void ReferenceAssemblyAttributeTests()
{
var attr1 = new ReferenceAssemblyAttribute(null);
Assert.Null(attr1.Description);
var attr2 = new ReferenceAssemblyAttribute("description");
Assert.Equal("description", attr2.Description);
}
[Fact]
public static void RuntimeCompatibilityAttributeTests()
{
var attr = new RuntimeCompatibilityAttribute();
Assert.False(attr.WrapNonExceptionThrows);
attr.WrapNonExceptionThrows = true;
Assert.True(attr.WrapNonExceptionThrows);
}
[Fact]
public static void SpecialNameAttributeTests()
{
new SpecialNameAttribute();
}
[Fact]
public static void StateMachineAttributeTests()
{
var attr1 = new StateMachineAttribute(null);
Assert.Null(attr1.StateMachineType);
var attr2 = new StateMachineAttribute(typeof(AttributesTests));
Assert.Equal(typeof(AttributesTests), attr2.StateMachineType);
}
[Fact]
public static void StringFreezingAttributeTests()
{
new StringFreezingAttribute();
}
#pragma warning disable SYSLIB0025 // Obsolete: SuppressIldasmAttribute
[Fact]
public static void SuppressIldasmAttributeTests()
{
new SuppressIldasmAttribute();
}
#pragma warning restore SYSLIB0025 // Obsolete: SuppressIldasmAttribute
[Fact]
public static void TypeForwardedFromAttributeTests()
{
string assemblyFullName = "MyAssembly";
var attr = new TypeForwardedFromAttribute(assemblyFullName);
Assert.Equal(assemblyFullName, attr.AssemblyFullName);
AssertExtensions.Throws<ArgumentNullException>("assemblyFullName", () => new TypeForwardedFromAttribute(null));
AssertExtensions.Throws<ArgumentException>("assemblyFullName", () => new TypeForwardedFromAttribute(""));
}
[Fact]
public static void TypeForwardedToAttributeTests()
{
var attr1 = new TypeForwardedToAttribute(null);
Assert.Null(attr1.Destination);
var attr2 = new TypeForwardedToAttribute(typeof(AttributesTests));
Assert.Equal(typeof(AttributesTests), attr2.Destination);
}
[Fact]
public static void UnsafeValueTypeAttributeTests()
{
new UnsafeValueTypeAttribute();
}
[Fact]
public static void AsyncMethodBuilderAttributeTests()
{
var attr1 = new AsyncMethodBuilderAttribute(null);
Assert.Null(attr1.BuilderType);
var attr2 = new AsyncMethodBuilderAttribute(typeof(AttributesTests));
Assert.Equal(typeof(AttributesTests), attr2.BuilderType);
}
[Fact]
public static void IsByRefLikeAttributeTests()
{
new IsByRefLikeAttribute();
}
[Fact]
public static void IsReadOnlyAttributeTests()
{
new IsReadOnlyAttribute();
}
[Fact]
public static void IsUnmanagedAttributeTests()
{
new IsUnmanagedAttribute();
}
[Fact]
public static void EnumeratorCancellationAttributeTests()
{
new EnumeratorCancellationAttribute();
}
[Fact]
public static void InterpolatedStringHandlerAttributeTests()
{
new InterpolatedStringHandlerAttribute();
}
[Theory]
[InlineData("")]
[InlineData("param1")]
public static void InterpolatedStringHandlerArgumentAttributeTests(string firstParameterName)
{
var attr1 = new InterpolatedStringHandlerArgumentAttribute(firstParameterName);
Assert.NotNull(attr1.Arguments);
Assert.Same(attr1.Arguments, attr1.Arguments);
Assert.Equal(1, attr1.Arguments.Length);
Assert.Equal(firstParameterName, attr1.Arguments[0]);
string[] arguments = new[] { firstParameterName, "param2" };
var attr2 = new InterpolatedStringHandlerArgumentAttribute(arguments);
Assert.NotNull(attr2.Arguments);
Assert.Same(arguments, attr2.Arguments);
Assert.Equal(firstParameterName, attr2.Arguments[0]);
Assert.Equal("param2", attr2.Arguments[1]);
}
[Fact]
public static void RequiredMemberAttributeTests()
{
new RequiredMemberAttribute();
}
[Fact]
public static void ScopedRefAttributeTests()
{
new ScopedRefAttribute();
}
[Fact]
public static void CompilerFeatureRequiredTests()
{
var attr1 = new CompilerFeatureRequiredAttribute("feature1");
Assert.Equal("feature1", attr1.FeatureName);
Assert.False(attr1.IsOptional);
var attr2 = new CompilerFeatureRequiredAttribute("feature2") { IsOptional = true };
Assert.Equal("feature2", attr2.FeatureName);
Assert.True(attr2.IsOptional);
}
[Fact]
public static void RequiresLocationAttributeTests()
{
new RequiresLocationAttribute();
}
[Fact]
public static void OverloadResolutionPriorityAttributeTests()
{
var attr = new OverloadResolutionPriorityAttribute(42);
Assert.Equal(42, attr.Priority);
}
}
}