diff --git a/RLBotCS/ManagerTools/ConfigParser.cs b/RLBotCS/ManagerTools/ConfigParser.cs index fd38c97..73c51a3 100644 --- a/RLBotCS/ManagerTools/ConfigParser.cs +++ b/RLBotCS/ManagerTools/ConfigParser.cs @@ -184,8 +184,12 @@ private T GetEnum(TomlTable table, string key, T fallback) { if (raw is string val) { - if (Enum.TryParse((string)val, true, out T res)) - return res; + string trimmed = val.Trim(); + foreach (string name in Enum.GetNames()) + { + if (string.Equals(name, trimmed, StringComparison.OrdinalIgnoreCase)) + return Enum.Parse(name); + } throw new InvalidCastException( $"{_context.ToStringWithEnd(key)} has invalid value \"{raw}\". " + $"Find valid values on https://wiki.rlbot.org." diff --git a/RLBotCSTests/ConfigParserTest.cs b/RLBotCSTests/ConfigParserTest.cs index 5d2a624..fc26ab9 100644 --- a/RLBotCSTests/ConfigParserTest.cs +++ b/RLBotCSTests/ConfigParserTest.cs @@ -415,6 +415,32 @@ public void InvalidTomlConfig() ); } + [TestMethod] + [DataRow("\" hOoPs \"", true)] + [DataRow("\"1\"", false)] + [DataRow("\"255\"", false)] + [DataRow("\"Hoops, Dropshot\"", false)] + [DataRow("1", false)] + public void GameModeRequiresOneEnumName(string value, bool valid) + { + string path = Path.GetTempFileName(); + try + { + File.WriteAllText(path, $"[match]\ngame_mode = {value}\n"); + ConfigParser parser = new(); + if (valid) + Assert.AreEqual(GameMode.Hoops, parser.LoadMatchConfig(path).GameMode); + else + AssertThrowsInnerException(() => + parser.LoadMatchConfig(path) + ); + } + finally + { + File.Delete(path); + } + } + [TestMethod] public void BadValues() {