|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System; |
| 5 | +using Microsoft.Macios.Generator.Availability; |
| 6 | +using Xunit; |
| 7 | + |
| 8 | +namespace Microsoft.Macios.Generator.Tests.Availability; |
| 9 | + |
| 10 | +public class PlatformSupportVersionTests { |
| 11 | + [Fact] |
| 12 | + public void ImplicitDefaultTest () |
| 13 | + { |
| 14 | + var implicitDefault = PlatformSupportVersion.ImplicitDefault; |
| 15 | + Assert.Equal (new Version (0, 0), implicitDefault.Version); |
| 16 | + Assert.Equal (SupportKind.Implicit, implicitDefault.Kind); |
| 17 | + } |
| 18 | + |
| 19 | + [Fact] |
| 20 | + public void ExplicitDefaultTest () |
| 21 | + { |
| 22 | + var explicitDefault = PlatformSupportVersion.ExplicitDefault; |
| 23 | + Assert.Equal (new Version (0, 0), explicitDefault.Version); |
| 24 | + Assert.Equal (SupportKind.Explicit, explicitDefault.Kind); |
| 25 | + } |
| 26 | + |
| 27 | + public static TheoryData<PlatformSupportVersion, PlatformSupportVersion, PlatformSupportVersion> MaxTestData => |
| 28 | + new () { |
| 29 | + // Same kind, v1 > v2 |
| 30 | + { |
| 31 | + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit }, |
| 32 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, |
| 33 | + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit } |
| 34 | + }, |
| 35 | + // Same kind, v2 > v1 |
| 36 | + { |
| 37 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, |
| 38 | + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit }, |
| 39 | + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit } |
| 40 | + }, |
| 41 | + // Same kind, v1 == v2 |
| 42 | + { |
| 43 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, |
| 44 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, |
| 45 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit } |
| 46 | + }, |
| 47 | + // Different kind, v1.Kind > v2.Kind |
| 48 | + { |
| 49 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit }, |
| 50 | + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit }, |
| 51 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit } |
| 52 | + }, |
| 53 | + // Different kind, v2.Kind > v1.Kind |
| 54 | + { |
| 55 | + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit }, |
| 56 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit }, |
| 57 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit } |
| 58 | + }, |
| 59 | + // ExplicitDefault vs ImplicitDefault |
| 60 | + { |
| 61 | + PlatformSupportVersion.ExplicitDefault, |
| 62 | + PlatformSupportVersion.ImplicitDefault, |
| 63 | + PlatformSupportVersion.ExplicitDefault |
| 64 | + }, |
| 65 | + // ExplicitDefault vs other Implicit |
| 66 | + { |
| 67 | + PlatformSupportVersion.ExplicitDefault, |
| 68 | + new PlatformSupportVersion { Version = new Version (10, 0), Kind = SupportKind.Implicit }, |
| 69 | + PlatformSupportVersion.ExplicitDefault |
| 70 | + }, |
| 71 | + // ImplicitDefault vs other Implicit |
| 72 | + { |
| 73 | + PlatformSupportVersion.ImplicitDefault, |
| 74 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, |
| 75 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit } |
| 76 | + }, |
| 77 | + // ExplicitDefault vs other Explicit |
| 78 | + { |
| 79 | + PlatformSupportVersion.ExplicitDefault, |
| 80 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit }, |
| 81 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit } |
| 82 | + }, |
| 83 | + }; |
| 84 | + |
| 85 | + [Theory] |
| 86 | + [MemberData (nameof (MaxTestData))] |
| 87 | + public void MaxTests (PlatformSupportVersion v1, PlatformSupportVersion v2, PlatformSupportVersion expected) |
| 88 | + { |
| 89 | + Assert.Equal (expected, PlatformSupportVersion.Max (v1, v2)); |
| 90 | + // Test commutativity |
| 91 | + Assert.Equal (expected, PlatformSupportVersion.Max (v2, v1)); |
| 92 | + } |
| 93 | + |
| 94 | + public static TheoryData<PlatformSupportVersion, PlatformSupportVersion, PlatformSupportVersion> MinTestData => |
| 95 | + new () { |
| 96 | + // Same kind, v1 < v2 |
| 97 | + { |
| 98 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, |
| 99 | + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit }, |
| 100 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit } |
| 101 | + }, |
| 102 | + // Same kind, v2 < v1 |
| 103 | + { |
| 104 | + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit }, |
| 105 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, |
| 106 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit } |
| 107 | + }, |
| 108 | + // Same kind, v1 == v2 |
| 109 | + { |
| 110 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, |
| 111 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, |
| 112 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit } |
| 113 | + }, |
| 114 | + // Different kind, v1.Kind > v2.Kind |
| 115 | + { |
| 116 | + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Explicit }, |
| 117 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, |
| 118 | + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Explicit } |
| 119 | + }, |
| 120 | + // Different kind, v2.Kind > v1.Kind |
| 121 | + { |
| 122 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, |
| 123 | + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Explicit }, |
| 124 | + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Explicit } |
| 125 | + }, |
| 126 | + // ExplicitDefault vs ImplicitDefault |
| 127 | + { |
| 128 | + PlatformSupportVersion.ExplicitDefault, |
| 129 | + PlatformSupportVersion.ImplicitDefault, |
| 130 | + PlatformSupportVersion.ExplicitDefault |
| 131 | + }, |
| 132 | + // ExplicitDefault vs other Implicit |
| 133 | + { |
| 134 | + PlatformSupportVersion.ExplicitDefault, |
| 135 | + new PlatformSupportVersion { Version = new Version (10, 0), Kind = SupportKind.Implicit }, |
| 136 | + PlatformSupportVersion.ExplicitDefault |
| 137 | + }, |
| 138 | + // ImplicitDefault vs other Implicit |
| 139 | + { |
| 140 | + PlatformSupportVersion.ImplicitDefault, |
| 141 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, |
| 142 | + PlatformSupportVersion.ImplicitDefault |
| 143 | + }, |
| 144 | + // ExplicitDefault vs other Explicit |
| 145 | + { |
| 146 | + PlatformSupportVersion.ExplicitDefault, |
| 147 | + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit }, |
| 148 | + PlatformSupportVersion.ExplicitDefault |
| 149 | + }, |
| 150 | + }; |
| 151 | + |
| 152 | + [Theory] |
| 153 | + [MemberData (nameof (MinTestData))] |
| 154 | + public void MinTests (PlatformSupportVersion v1, PlatformSupportVersion v2, PlatformSupportVersion expected) |
| 155 | + { |
| 156 | + Assert.Equal (expected, PlatformSupportVersion.Min (v1, v2)); |
| 157 | + // Test commutativity |
| 158 | + Assert.Equal (expected, PlatformSupportVersion.Min (v2, v1)); |
| 159 | + } |
| 160 | +} |
0 commit comments