Files
h-school/tests/HSchool.Content.Tests/CountryDefTests.cs
T
Leonid PershinandCursor 8e7ab46e79 Sample outdoor weather from the climate preset so people can freeze and the clock can show it.
Protocol v8 adds tenths of a °C and precipitation to the clock frame; warmth drains from insulation versus place temperature.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-20 03:49:40 +03:00

82 lines
3.3 KiB
C#

namespace HSchool.Content.Tests;
public class CountryDefTests
{
private readonly CatalogLoader _loader = new();
[Fact]
public void VanillaCore_LoadsRussiaAndClimatePresets()
{
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
var catalog = _loader.Load([CatalogLoader.CorePackId], PackDocuments.FromDirectory(CatalogLoader.CorePackId, root));
Assert.True(catalog.Countries.ContainsKey("Russia"));
Assert.False(catalog.Countries.ContainsKey("Slavic"));
var russia = catalog.Countries["Russia"];
Assert.Equal(
["RussianLanguage", "BelarusianLanguage", "UkrainianLanguage"],
russia.Names.Spoken);
Assert.Equal(0.6f, russia.Names.RelatedLanguageChance);
Assert.Equal(40, russia.Names.RelatedLanguageMax);
Assert.True(russia.Names.MaleGiven.Count >= 20);
Assert.Equal(["TemperateContinental", "ContinentalCold"], russia.ClimatePresets);
Assert.True(catalog.ClimatePresets.ContainsKey("TemperateContinental"));
Assert.True(catalog.ClimatePresets.ContainsKey("ContinentalCold"));
Assert.Equal("Россия", catalog.Label("ru", russia));
Assert.Equal("Russia", catalog.Label("en", russia));
}
[Fact]
public void CountryWithoutNames_FailsTheCatalog()
{
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
[CatalogLoader.CorePackId],
[
PackDocuments.Def(
CatalogLoader.CorePackId,
"climates",
"temperate",
"""{ "defName": "TemperateContinental", "monthlyNorms": [0,0,0,0,0,0,0,0,0,0,0,0] }"""),
PackDocuments.Def(
CatalogLoader.CorePackId,
"countries",
"ghost",
"""{ "defName": "GhostLand", "climatePresets": ["TemperateContinental"] }"""),
]));
Assert.Contains("GhostLand", ex.Message, StringComparison.Ordinal);
Assert.Contains("names", ex.Message, StringComparison.OrdinalIgnoreCase);
}
[Fact]
public void CountryWithUnknownPreset_FailsTheCatalog()
{
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
[CatalogLoader.CorePackId],
[
PackDocuments.Def(
CatalogLoader.CorePackId,
"climates",
"temperate",
"""{ "defName": "TemperateContinental", "monthlyNorms": [0,0,0,0,0,0,0,0,0,0,0,0] }"""),
PackDocuments.Def(
CatalogLoader.CorePackId,
"countries",
"ghost",
"""
{
"defName": "GhostLand",
"climatePresets": ["NoSuchClimate"],
"names": {
"maleGiven": [{ "form": "Иван" }],
"femaleGiven": [{ "form": "Анна", "declension": "a" }],
"surnames": [{ "male": "Иванов", "female": "Иванова" }]
}
}
"""),
]));
Assert.Contains("NoSuchClimate", ex.Message, StringComparison.Ordinal);
}
}