|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Runtime.CompilerServices; |
| 6 | +using nanoFramework.TestFramework; |
| 7 | + |
| 8 | +namespace NFUnitTestSystemLib |
| 9 | +{ |
| 10 | + [TestClass] |
| 11 | + class RuntimeHelpersTests |
| 12 | + { |
| 13 | + [TestMethod] |
| 14 | + public static void IsReferenceOrContainsReferences() |
| 15 | + { |
| 16 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<int>()); |
| 17 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<string>()); |
| 18 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<Guid>()); |
| 19 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<StructWithoutReferences>()); |
| 20 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<StructWithReferences>()); |
| 21 | + Assert.IsFalse(RuntimeHelpers.IsReferenceOrContainsReferences<RefStructWithoutReferences>()); |
| 22 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<RefStructWithReferences>()); |
| 23 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<Span<char>>()); |
| 24 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<ReadOnlySpan<char>>()); |
| 25 | + //Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<RefStructWithRef>()); |
| 26 | + Assert.IsTrue(RuntimeHelpers.IsReferenceOrContainsReferences<RefStructWithNestedRef>()); |
| 27 | + } |
| 28 | + |
| 29 | + private struct StructWithoutReferences |
| 30 | + { |
| 31 | + public int a, b, c; |
| 32 | + } |
| 33 | + |
| 34 | + private struct StructWithReferences |
| 35 | + { |
| 36 | + public int a, b, c; |
| 37 | + public object d; |
| 38 | + } |
| 39 | + |
| 40 | + private ref struct RefStructWithoutReferences |
| 41 | + { |
| 42 | + public int a; |
| 43 | + public long b; |
| 44 | + } |
| 45 | + |
| 46 | + private ref struct RefStructWithReferences |
| 47 | + { |
| 48 | + public int a; |
| 49 | + public object b; |
| 50 | + } |
| 51 | + |
| 52 | + // TODO: add after checking viability of ref fields in ref structs |
| 53 | + //private ref struct RefStructWithRef |
| 54 | + //{ |
| 55 | + // public ref int a; |
| 56 | + |
| 57 | + // internal RefStructWithRef(ref int aVal) |
| 58 | + // { |
| 59 | + // a = ref aVal; |
| 60 | + // } |
| 61 | + //} |
| 62 | + |
| 63 | + private ref struct RefStructWithNestedRef |
| 64 | + { |
| 65 | + public Span<char> a; |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments