This commit is contained in:
Leonid Pershin
2026-08-18 23:51:10 +03:00
parent d8f8db6a48
commit 65feda3756
50 changed files with 1485 additions and 224 deletions
+2 -9
View File
@@ -43,16 +43,9 @@ public class MapViewTests
var classroom = ru.Single(node => node.Id == "classroom-101");
Assert.Equal("Класс 101", classroom.Name);
Assert.Equal(
[
new MapViewItem("Доска", 1),
new MapViewItem("Стол", 1),
new MapViewItem("Стул", 1),
new MapViewItem("Парта", 16),
],
classroom.Items);
Assert.Equal([new MapViewItem("Парта", 16)], classroom.Items);
Assert.Equal(16, classroom.PupilSlots);
Assert.Equal(["Учитель"], classroom.Positions);
Assert.Empty(classroom.Positions);
Assert.Equal("Classroom 101", en.Single(node => node.Id == "classroom-101").Name);
}
@@ -23,6 +23,9 @@ public class PeopleDefTests
Assert.Equal("Славянский", catalog.Label("ru", catalog.NameSets["Slavic"]));
Assert.Equal("Slavic", catalog.Label("en", catalog.NameSets["Slavic"]));
Assert.Equal("Усидчивый", catalog.Label("ru", catalog.Traits["Diligent"]));
Assert.True(catalog.Subjects.ContainsKey("PrimarySchool"));
Assert.Equal("Начальные классы", catalog.Label("ru", catalog.Subjects["PrimarySchool"]));
Assert.Equal("Primary", catalog.Label("en", catalog.Subjects["PrimarySchool"]));
}
[Fact]
@@ -147,6 +150,30 @@ public class PeopleDefTests
Assert.Contains("Ghost", ex.Message);
}
[Fact]
public void Subject_UnknownSkill_FailsTheCatalog()
{
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
[CatalogLoader.CorePackId],
[
PackDocuments.Def(CatalogLoader.CorePackId, "skills", "math", """{ "defName": "Mathematics" }"""),
PackDocuments.Def(
CatalogLoader.CorePackId,
"subjects",
"ghost",
"""
{
"defName": "GhostSubject",
"grades": { "min": 1, "max": 4 },
"hoursPerWeek": 2,
"skills": [{ "skill": "Missing", "share": 1 }]
}
"""),
]));
Assert.Contains("Missing", ex.Message);
}
[Fact]
public void OneWayIncompatibility_IsMutual()
{
@@ -26,24 +26,80 @@ public class VanillaCoreTests
Assert.True(catalog.Rooms["Classroom"].Homeroom);
Assert.False(catalog.Rooms["ComputerLab"].Homeroom);
Assert.Equal("Класс", catalog.Label("ru", catalog.Rooms["Classroom"]));
Assert.Equal(["Teacher"], catalog.PositionsFor(DefKind.Room, "Classroom"));
Assert.Empty(catalog.PositionsFor(DefKind.Room, "Classroom"));
Assert.Empty(catalog.PositionsFor(DefKind.Room, "ComputerLab"));
Assert.Empty(catalog.PositionsFor(DefKind.Room, "GymHall"));
Assert.False(catalog.Positions.ContainsKey("PETeacher"));
Assert.Equal("StudentDesk", catalog.Rooms["Classroom"].SeatThing);
Assert.Equal(16, catalog.Rooms["Classroom"].DefaultSeats);
Assert.Empty(catalog.Rooms["Classroom"].Slots);
Assert.Equal(1, catalog.Things["StudentDesk"].PupilSlots);
Assert.Equal(1, catalog.Things["Computer"].PupilSlots);
Assert.Equal(0, catalog.Things["Desk"].PupilSlots);
Assert.Equal(0, catalog.Things["Chair"].PupilSlots);
Assert.Contains(catalog.Rooms["Classroom"].Slots, slot => slot.Key == "teacherChair" && slot.Thing == "Chair");
Assert.Equal(16, catalog.Rooms["Classroom"].Slots.Single(slot => slot.Key == "studentDesks").Count);
Assert.True(catalog.Subjects.ContainsKey("PrimarySchool"));
Assert.Equal(1, catalog.Subjects["PrimarySchool"].Grades.Min);
Assert.Equal(4, catalog.Subjects["PrimarySchool"].Grades.Max);
Assert.True(catalog.Subjects.ContainsKey("PhysicalEducation"));
Assert.Equal(2, map.Buildings.Count);
var homerooms = map.Rooms.Where(room => room.Def == "Classroom").ToList();
Assert.Equal(11, homerooms.Count);
Assert.Contains(map.Rooms, room => room.Id == "classroom-101" && room.Label == "101");
Assert.Contains(map.Rooms, room => room.Id == "classroom-207" && room.Label == "207");
Assert.DoesNotContain(map.Rooms, room => room.Label is "1A" or "1B" or "2A" or "2B");
Assert.Equal(
16,
map.Rooms.Single(room => room.Id == "classroom-101").Slots.Single(slot => slot.Key == "studentDesks").Count);
Assert.Contains(
map.Rooms.Single(room => room.Id == "classroom-101").Slots,
slot => slot.Key == "teacherChair" && slot.Thing == "Chair");
Assert.Equal(16, map.Rooms.Single(room => room.Id == "classroom-101").Seats);
Assert.Empty(map.Rooms.Single(room => room.Id == "classroom-101").Slots);
}
/// <summary>
/// Every name a card can print has to exist in both locales. Missing ones do not fail — they
/// fall through to the raw key, which reads as a label in English and as a leak in Russian:
/// the build row showed "Build: Обычное" for exactly this reason.
/// </summary>
[Fact]
public void EveryVanillaLabel_ExistsInBothLocales()
{
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
var catalog = new CatalogLoader().Load(
[CatalogLoader.CorePackId],
PackDocuments.FromDirectory(CatalogLoader.CorePackId, root));
var keys = new List<string>();
keys.AddRange(Names(catalog.Actions.Values));
keys.AddRange(Names(catalog.Things.Values));
keys.AddRange(Names(catalog.Positions.Values));
keys.AddRange(Names(catalog.Works.Values));
keys.AddRange(Names(catalog.Rooms.Values));
keys.AddRange(Names(catalog.Buildings.Values));
keys.AddRange(Names(catalog.Floors.Values));
keys.AddRange(Names(catalog.Territories.Values));
keys.AddRange(Names(catalog.Skills.Values));
keys.AddRange(Names(catalog.Traits.Values));
keys.AddRange(Names(catalog.BodyAttributes.Values));
keys.AddRange(Names(catalog.Needs.Values));
keys.AddRange(Names(catalog.NameSets.Values));
keys.AddRange(Names(catalog.Subjects.Values));
// Derived in code, so no def carries them.
keys.Add(BodyBuilds.Attribute);
keys.AddRange(BodyBuilds.Values);
foreach (var value in catalog.BodyAttributes.Values.SelectMany(def => def.Options))
{
keys.Add(value.Value);
}
var missing = keys
.Distinct(StringComparer.Ordinal)
.SelectMany(key => new[] { ("ru", key), ("en", key) })
.Where(pair => !catalog.HasText(pair.Item1, pair.Item2))
.Select(pair => $"{pair.Item1}:{pair.Item2}")
.Order(StringComparer.Ordinal)
.ToArray();
Assert.Empty(missing);
}
private static IEnumerable<string> Names(IEnumerable<Def> defs) =>
defs.Where(def => !def.Abstract).Select(def => def.DefName);
}