|
| 1 | +using Robust.Shared.Prototypes; |
| 2 | +using Robust.Shared.Localization; |
| 3 | +using Content.Shared.Traits; |
| 4 | +using System.Linq; |
| 5 | +using System.Collections.Generic; |
| 6 | + |
| 7 | +namespace Content.IntegrationTests.Tests.Traits; |
| 8 | + |
| 9 | +/// <summary> |
| 10 | +/// Checks if every trait has a valid desc and name localization string. |
| 11 | +/// </summary> |
| 12 | +[TestFixture] |
| 13 | +[TestOf(typeof(TraitPrototype))] |
| 14 | +public sealed class TraitLocalizationTest |
| 15 | +{ |
| 16 | + |
| 17 | + [Test] |
| 18 | + public async Task TestTraitLocalization() |
| 19 | + { |
| 20 | + await using var pair = await PoolManager.GetServerClient(); |
| 21 | + var server = pair.Server; |
| 22 | + |
| 23 | + var locale = server.ResolveDependency<ILocalizationManager>(); |
| 24 | + var proto = server.ResolveDependency<IPrototypeManager>(); |
| 25 | + |
| 26 | + await server.WaitAssertion(() => |
| 27 | + { |
| 28 | + var passed = true; |
| 29 | + var missingStrings = new List<string>(); |
| 30 | + |
| 31 | + foreach (var traitProto in proto.EnumeratePrototypes<TraitPrototype>().OrderBy(a => a.ID)) |
| 32 | + { |
| 33 | + var name = "trait-name-" + traitProto.ID; |
| 34 | + var desc = "trait-description-" + traitProto.ID; |
| 35 | + |
| 36 | + if (!locale.HasString(name)) |
| 37 | + { |
| 38 | + missingStrings.Add($"\"{traitProto.ID}\", \"{name}\""); |
| 39 | + passed = false; |
| 40 | + } |
| 41 | + if (!locale.HasString(desc)) |
| 42 | + { |
| 43 | + missingStrings.Add($"\"{traitProto.ID}\", \"{desc}\""); |
| 44 | + passed = false; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + Assert.That(passed, Is.True, $"The following traits are missing localization strings:\n {string.Join("\n ", missingStrings)}"); |
| 49 | + }); |
| 50 | + |
| 51 | + await pair.CleanReturnAsync(); |
| 52 | + } |
| 53 | +} |
| 54 | + |
0 commit comments