fixed references to stings, fixed tests

This commit is contained in:
Toastie 2025-01-29 23:28:04 +13:00
parent 3dcf08baf5
commit 12bcae137a
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7
7 changed files with 19 additions and 14 deletions
src
EllieBot.Generators
EllieBot.Tests
EllieBot

View file

@ -11,7 +11,7 @@ Project which contains source generators required for EllieBot project
-- How it works -- -- How it works --
Creates a file "strs.cs" containing a class called "strs" in "EllieBot" namespace. Creates a file "strs.cs" containing a class called "strs" in "EllieBot" namespace.
Loads "data/strings/responses.en-US.json" and creates a property or a function for each key in the responses json file based on whether the value has string format placeholders or not. Loads "strings/responses.en-US.json" and creates a property or a function for each key in the responses json file based on whether the value has string format placeholders or not.
- If a value has no placeholders, it creates a property in the strs class which returns an instance of a LocStr struct containing only the key and no replacement parameters - If a value has no placeholders, it creates a property in the strs class which returns an instance of a LocStr struct containing only the key and no replacement parameters

View file

@ -11,9 +11,9 @@ namespace EllieBot.Tests
{ {
public class CommandStringsTests public class CommandStringsTests
{ {
private const string responsesPath = "../../../../EllieBot/data/strings/responses"; private const string responsesPath = "../../../../EllieBot/strings/responses";
private const string commandsPath = "../../../../EllieBot/data/strings/commands"; private const string commandsPath = "../../../../EllieBot/strings/commands";
private const string aliasesPath = "../../../../EllieBot/data/aliases.yml"; private const string aliasesPath = "../../../../EllieBot/aliases.yml";
[Test] [Test]
public void AllCommandNamesHaveStrings() public void AllCommandNamesHaveStrings()
@ -96,7 +96,7 @@ namespace EllieBot.Tests
if (isSuccess) if (isSuccess)
Assert.Pass(); Assert.Pass();
else else
Assert.Warn("There are some unused entries in data/aliases.yml"); Assert.Warn("There are some unused entries in aliases.yml");
} }
[Test] [Test]
@ -123,7 +123,7 @@ namespace EllieBot.Tests
} }
} }
Assert.That(isSuccess, Is.True, "There are some unused command strings in data/strings/commands.en-US.yml"); Assert.That(isSuccess, Is.True, "There are some unused command strings in strings/commands.en-US.yml");
} }
} }
} }

View file

@ -109,7 +109,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<AdditionalFiles Include="data\strings\responses\responses.en-US.json" /> <AdditionalFiles Include="strings\responses\responses.en-US.json" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -133,6 +133,11 @@
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
<None Update="strings\aliases.yml">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -10,14 +10,14 @@ public static class CommandNameLoadHelper
private static readonly Lazy<Dictionary<string, string[]>> _lazyCommandAliases private static readonly Lazy<Dictionary<string, string[]>> _lazyCommandAliases
= new(() => LoadAliases()); = new(() => LoadAliases());
public static Dictionary<string, string[]> LoadAliases(string aliasesFilePath = "data/aliases.yml") public static Dictionary<string, string[]> LoadAliases(string aliasesFilePath = "strings/aliases.yml")
{ {
var text = File.ReadAllText(aliasesFilePath); var text = File.ReadAllText(aliasesFilePath);
return _deserializer.Deserialize<Dictionary<string, string[]>>(text); return _deserializer.Deserialize<Dictionary<string, string[]>>(text);
} }
public static Dictionary<string, CommandStrings> LoadCommandStrings( public static Dictionary<string, CommandStrings> LoadCommandStrings(
string commandsFilePath = "data/strings/commands.yml") string commandsFilePath = "strings/commands.yml")
{ {
var text = File.ReadAllText(commandsFilePath); var text = File.ReadAllText(commandsFilePath);

View file

@ -11,7 +11,7 @@ public class Localization : ILocalization, IReadyExecutor
{ {
private static readonly Dictionary<string, CommandData> _commandData = private static readonly Dictionary<string, CommandData> _commandData =
JsonConvert.DeserializeObject<Dictionary<string, CommandData>>( JsonConvert.DeserializeObject<Dictionary<string, CommandData>>(
File.ReadAllText("./data/strings/commands/commands.en-US.json")); File.ReadAllText("./strings/commands/commands.en-US.json"));
private ConcurrentDictionary<ulong, CultureInfo> _guildCultureInfos; private ConcurrentDictionary<ulong, CultureInfo> _guildCultureInfos;

View file

@ -9,12 +9,12 @@ namespace EllieBot.Services;
/// </summary> /// </summary>
public class LocalFileStringsSource : IStringsSource public class LocalFileStringsSource : IStringsSource
{ {
private readonly string _responsesPath = "data/strings/responses"; private readonly string _responsesPath = "strings/responses";
private readonly string _commandsPath = "data/strings/commands"; private readonly string _commandsPath = "strings/commands";
public LocalFileStringsSource( public LocalFileStringsSource(
string responsesPath = "data/strings/responses", string responsesPath = "strings/responses",
string commandsPath = "data/strings/commands") string commandsPath = "strings/commands")
{ {
_responsesPath = responsesPath; _responsesPath = responsesPath;
_commandsPath = commandsPath; _commandsPath = commandsPath;