0.2.0-dev Download ZIP
209 lines ·8.8 KB Raw
| 1 | using EvilEngine.Api; |
| 2 | |
| 3 | namespace EvilEngine.Host.Tests; |
| 4 | |
| 5 | public sealed class ManifestTests |
| 6 | { |
| 7 | [Fact] |
| 8 | public void ReadsANativePortManifest() |
| 9 | { |
| 10 | var manifest = PluginManifest.Parse(""" |
| 11 | id = "evil.fungus" |
| 12 | name = "Evil Fungus" |
| 13 | version = "2.0.0" |
| 14 | api = 1 |
| 15 | |
| 16 | [needs] |
| 17 | "evil.claims" = "^1" |
| 18 | |
| 19 | [wants] |
| 20 | "evil.crawlers" = "^1" |
| 21 | |
| 22 | [exports."evil.fungus"] |
| 23 | version = "1.0.0" |
| 24 | realm = "server" |
| 25 | functions = ["Nearest", "Feed"] |
| 26 | """, "plugin.toml"); |
| 27 | |
| 28 | Assert.Equal("evil.fungus", manifest.Id); |
| 29 | Assert.Equal(new SemanticVersion(2, 0, 0), manifest.Version); |
| 30 | Assert.True(manifest.Needs["evil.claims"].Contains(new SemanticVersion(1, 4, 0))); |
| 31 | Assert.False(manifest.Needs["evil.claims"].Contains(new SemanticVersion(2, 0, 0))); |
| 32 | var export = Assert.Single(manifest.Exports); |
| 33 | Assert.Equal(Realm.Server, export.Realm); |
| 34 | Assert.Equal(["Nearest", "Feed"], export.Functions); |
| 35 | } |
| 36 | |
| 37 | [Fact] |
| 38 | public void ReadsAGameSystemsManifest() |
| 39 | { |
| 40 | var manifest = PluginManifest.Parse(""" |
| 41 | id = "skate3.skating" |
| 42 | name = "Skate 3 skating" |
| 43 | version = "0.1.0" |
| 44 | api = 1 |
| 45 | code = "Code/skate3.skating.dll" |
| 46 | phases = ["skate3.skating:input", "skate3.skating:solve", "skate3.skating:pose"] |
| 47 | |
| 48 | [[mounts]] |
| 49 | game = "skate3" |
| 50 | parts = ["gameplay"] |
| 51 | |
| 52 | [exports."skate3.boards"] |
| 53 | version = "0.1.0" |
| 54 | functions = ["Board", "Unboard"] |
| 55 | """, "plugin.toml"); |
| 56 | |
| 57 | var mount = Assert.Single(manifest.Mounts); |
| 58 | Assert.Equal("skate3", mount.Game); |
| 59 | Assert.Equal(["gameplay"], mount.Parts); |
| 60 | Assert.Equal("Code/skate3.skating.dll", manifest.Code); |
| 61 | Assert.Equal(3, manifest.Phases.Count); |
| 62 | } |
| 63 | |
| 64 | [Fact] |
| 65 | public void ReadsAnAdapterManifest() |
| 66 | { |
| 67 | var manifest = AdapterManifest.Parse(""" |
| 68 | id = "skate3" |
| 69 | name = "Skate 3" |
| 70 | version = "0.1.0" |
| 71 | api = 1 |
| 72 | code = "Code/skate3.dll" |
| 73 | games = ["skate3"] |
| 74 | platforms = ["ps3", "x360"] |
| 75 | |
| 76 | [titles] |
| 77 | skate3 = "Skate 3" |
| 78 | |
| 79 | [needs] |
| 80 | "ea.pegasus" = "^1" |
| 81 | "iso9660" = "^1" |
| 82 | """, "adapter.toml"); |
| 83 | |
| 84 | Assert.True(manifest.IsGameAdapter); |
| 85 | Assert.Equal(["ps3", "x360"], manifest.Platforms); |
| 86 | Assert.Equal(2, manifest.Needs.Count); |
| 87 | Assert.Equal("Skate 3", manifest.Title("skate3")); |
| 88 | Assert.Null(manifest.Engine); |
| 89 | Assert.Empty(manifest.Products("skate3")); |
| 90 | } |
| 91 | |
| 92 | [Fact] |
| 93 | public void ReadsEachGamesEngineAndStoreProducts() |
| 94 | { |
| 95 | var manifest = AdapterManifest.Parse(""" |
| 96 | id = "sourcegames" |
| 97 | name = "Source games" |
| 98 | version = "0.1.0" |
| 99 | api = 1 |
| 100 | code = "Code/sourcegames.dll" |
| 101 | games = ["hl2", "lostcoast"] |
| 102 | engine = "Source" |
| 103 | |
| 104 | [titles] |
| 105 | hl2 = "Half-Life 2" |
| 106 | lostcoast = "Half-Life 2: Lost Coast" |
| 107 | |
| 108 | [stores] |
| 109 | hl2 = { steam = 220 } |
| 110 | lostcoast = { steam = "340" } |
| 111 | """, "adapter.toml"); |
| 112 | |
| 113 | Assert.Equal("Source", manifest.Engine); |
| 114 | Assert.Equal("220", manifest.Products("hl2")["steam"]); |
| 115 | Assert.Equal("340", manifest.Products("lostcoast")["steam"]); |
| 116 | } |
| 117 | |
| 118 | [Fact] |
| 119 | public void ReadsWhichGamesAreSwitchedOn() |
| 120 | { |
| 121 | var flags = FeatureFlags.Parse("[games]\ngmod = true\nquake = false\n", "features.toml"); |
| 122 | |
| 123 | Assert.True(flags.Game("gmod")); |
| 124 | Assert.False(flags.Game("quake")); |
| 125 | Assert.False(flags.Game("skate3")); |
| 126 | Assert.True(FeatureFlags.All.Game("skate3")); |
| 127 | Assert.Contains("'games.gmod' must be true or false.", |
| 128 | Assert.Throws<ManifestException>(() => FeatureFlags.Parse("[games]\ngmod = 1", "features.toml")).Message); |
| 129 | Assert.Contains("'mounts'", |
| 130 | Assert.Throws<ManifestException>(() => FeatureFlags.Parse("mounts = []", "features.toml")).Message); |
| 131 | } |
| 132 | |
| 133 | [Theory] |
| 134 | [InlineData("[stores]\nep2 = { steam = 420 }", "stores 'ep2', which isn't in 'games'.")] |
| 135 | [InlineData("[stores]\nhl2 = { steam = true }", "'stores.hl2.steam' must be a string or an integer.")] |
| 136 | [InlineData("[stores]\nhl2 = { steam = \" \" }", "'stores.hl2.steam' is empty.")] |
| 137 | [InlineData("engine = \"\"", "'engine' is empty.")] |
| 138 | public void RefusesStoresItCantRead(string extra, string named) |
| 139 | { |
| 140 | var error = Assert.Throws<ManifestException>(() => AdapterManifest.Parse($""" |
| 141 | id = "sourcegames" |
| 142 | name = "Source games" |
| 143 | version = "0.1.0" |
| 144 | api = 1 |
| 145 | code = "Code/sourcegames.dll" |
| 146 | games = ["hl2"] |
| 147 | {extra} |
| 148 | |
| 149 | [titles] |
| 150 | hl2 = "Half-Life 2" |
| 151 | """, "adapter.toml")); |
| 152 | Assert.Contains(named, error.Message); |
| 153 | } |
| 154 | |
| 155 | [Theory] |
| 156 | [InlineData("", "needs 'titles.hl2'.")] |
| 157 | [InlineData("hl2 = \"Half-Life 2\"", "needs 'titles.episodic'.")] |
| 158 | [InlineData("hl2 = \"Half-Life 2\"\nepisodic = \"half-life 2\"", "titles 'hl2' and 'episodic' alike, 'Half-Life 2'.")] |
| 159 | [InlineData("hl2 = \"Half-Life 2\"\nepisodic = \" \"", "'titles.episodic' is empty.")] |
| 160 | [InlineData("hl2 = \"Half-Life 2\"\nepisodic = \"Episode One\"\nep2 = \"Episode Two\"", "titles 'ep2', which isn't in 'games'.")] |
| 161 | public void TitlesEveryGameItReadsApart(string titles, string named) |
| 162 | { |
| 163 | var error = Assert.Throws<ManifestException>(() => AdapterManifest.Parse($""" |
| 164 | id = "sourcegames" |
| 165 | name = "Source games" |
| 166 | version = "0.1.0" |
| 167 | api = 1 |
| 168 | code = "Code/sourcegames.dll" |
| 169 | games = ["hl2", "episodic"] |
| 170 | |
| 171 | [titles] |
| 172 | {titles} |
| 173 | """, "adapter.toml")); |
| 174 | Assert.Contains(named, error.Message); |
| 175 | } |
| 176 | |
| 177 | [Theory] |
| 178 | [InlineData("mount = []", "'mount'")] |
| 179 | [InlineData("side = \"sideways\"", "'side'")] |
| 180 | [InlineData("phases = [\"other:solve\"]", "other:solve")] |
| 181 | [InlineData("code = \"../escape.dll\"", "../escape.dll")] |
| 182 | [InlineData("[[mounts]]\ngame = \"gmod\"\npart = [\"content\"]", "'mounts[0].part'")] |
| 183 | public void RefusesWhatItDoesntKnowByName(string extra, string named) |
| 184 | { |
| 185 | var error = Assert.Throws<ManifestException>(() => PluginManifest.Parse($""" |
| 186 | id = "evil.test" |
| 187 | name = "Test" |
| 188 | version = "1.0.0" |
| 189 | api = 1 |
| 190 | {extra} |
| 191 | """, "plugin.toml")); |
| 192 | Assert.Contains(named, error.Message); |
| 193 | } |
| 194 | |
| 195 | [Theory] |
| 196 | [InlineData("^1", "1.0.0", true)] |
| 197 | [InlineData("^1", "1.9.3", true)] |
| 198 | [InlineData("^1", "2.0.0", false)] |
| 199 | [InlineData("^1.2", "1.1.9", false)] |
| 200 | [InlineData("^0.2", "0.2.5", true)] |
| 201 | [InlineData("^0.2", "0.3.0", false)] |
| 202 | [InlineData("1.2.3", "1.2.3", true)] |
| 203 | [InlineData("1.2.3", "1.2.4", false)] |
| 204 | [InlineData("*", "7.0.0", true)] |
| 205 | public void MatchesVersionRanges(string range, string version, bool expected) |
| 206 | { |
| 207 | Assert.Equal(expected, VersionRange.Parse(range).Contains(SemanticVersion.Parse(version))); |
| 208 | } |
| 209 | } |