A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Tests: read UiText instead of English literals in five EditMode suites (#2356)
Eyal Golan1078c24e9915
diff --git a/unity/Assets/Tests/EditMode/BudgetScreenTests.cs b/unity/Assets/Tests/EditMode/BudgetScreenTests.csindex f020c5253..fd1502d26 100644--- a/unity/Assets/Tests/EditMode/BudgetScreenTests.cs+++ b/unity/Assets/Tests/EditMode/BudgetScreenTests.cs@@ -65,17 +65,17 @@ public class BudgetScreenTestsvar budget = new BudgetPresenter(ui.Root, bridge, Text);Assert.AreEqual("45%", ui.Q<Label>("budget-defense_minister-share").text);Assert.AreEqual("Minister of Defense (David Ben-Gurion)", ui.Q<Label>("budget-defense_minister-name").text);- Assert.AreEqual("spending effect 150%", ui.Q<Label>("budget-defense_minister-factor").text); // capped at 1.5 (playtest 2, P2-6)+ Assert.AreEqual(Text.Format("budget.factor", "150%"), ui.Q<Label>("budget-defense_minister-factor").text); // capped at 1.5 (playtest 2, P2-6)var (seats, size) = PoliticsSystem.CoalitionSeats(C, bridge.State.Date); // the council approves the budget (#3)- Assert.AreEqual(System.FormattableString.Invariant($"The Provisional State Council must approve it: the coalition holds {seats} of {size} seats"), ui.Q<Label>("budget-vote").text);- Assert.AreEqual("Money IL\u00A020.0m · debt IL\u00A00.0m · foreign currency $40.0m", ui.Q<Label>("budget-money").text);+ Assert.AreEqual(Text.Format("budget.vote_needed", "Provisional State Council", seats, size, Text["cabinet.seats_appointed"]), ui.Q<Label>("budget-vote").text);+ Assert.AreEqual(Text.Format("budget.money", "IL\u00A020.0m", "IL\u00A00.0m", "$40.0m"), ui.Q<Label>("budget-money").text);UiTestKit.Press(ui.Q<Button>("budget-education_minister-up"));Assert.AreEqual("11%", ui.Q<Label>("budget-education_minister-share").text);- Assert.AreEqual("Changed: submit to put it to the vote", ui.Q<Label>("budget-status").text);+ Assert.AreEqual(Text["budget.unsaved"], ui.Q<Label>("budget-status").text);ui.Press("budget-submit");var queued = (AllocateBudget)bridge.Queued.Single();Assert.AreEqual(1.0, queued.Shares.Values.Sum(), 1e-9);- Assert.AreEqual("Submitted: takes effect at End turn", ui.Q<Label>("budget-status").text);+ Assert.AreEqual(Text["budget.queued"], ui.Q<Label>("budget-status").text);bridge.EndTurn();Assert.AreEqual(budget.Draft["education_minister"], bridge.State.Budget["education_minister"], 1e-12);Assert.IsEmpty(bridge.Session.Last!.Rejected);@@ -99,11 +99,11 @@ public class BudgetScreenTestsvar bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);var budget = new BudgetPresenter(ui.Root, bridge, Text);foreach (var office in C.Rules.BudgetStart.Keys)- Assert.AreEqual("spending effect " + PlayerText.Percent(EffectsSystem.BudgetFactor(budget.Draft, office)), ui.Q<Label>($"budget-{office}-factor").text, office);+ Assert.AreEqual(Text.Format("budget.factor", PlayerText.Percent(EffectsSystem.BudgetFactor(budget.Draft, office))), ui.Q<Label>($"budget-{office}-factor").text, office);var f = EconomySystem.Flows(C, bridge.State, 1.0);- Assert.AreEqual(System.FormattableString.Invariant($"Taxes IL\u00A0{f.Tax:0.0}m, spending IL\u00A0{f.Spending:0.0}m and reserve call-up IL\u00A0{f.Mobilization:0.0}m a year"), ui.Q<Label>("budget-flow").text);+ Assert.AreEqual(Text.Format("budget.flow", System.FormattableString.Invariant($"IL\u00A0{f.Tax:0.0}m"), System.FormattableString.Invariant($"IL\u00A0{f.Spending:0.0}m"), System.FormattableString.Invariant($"IL\u00A0{f.Mobilization:0.0}m")), ui.Q<Label>("budget-flow").text);UiTestKit.Press(ui.Q<Button>("budget-education_minister-up"));- Assert.AreEqual("spending effect " + PlayerText.Percent(EffectsSystem.BudgetFactor(budget.Draft, "education_minister")), ui.Q<Label>("budget-education_minister-factor").text);+ Assert.AreEqual(Text.Format("budget.factor", PlayerText.Percent(EffectsSystem.BudgetFactor(budget.Draft, "education_minister"))), ui.Q<Label>("budget-education_minister-factor").text);}[Test]@@ -130,7 +130,7 @@ public class BudgetScreenTestsnew BudgetPresenter(ui.Root, bridge, Text);var leg = Offices.Legislature(C, g.State.Date)!;var (seats, size) = PoliticsSystem.CoalitionSeats(C, g.State.Date);- Assert.AreEqual(System.FormattableString.Invariant($"The {leg.Body} must approve it: the coalition holds {seats} of {size} seats"), ui.Q<Label>("budget-vote").text);+ Assert.AreEqual(Text.Format("budget.vote_needed", leg.Body, seats, size, Text["cabinet.seats_appointed"]), ui.Q<Label>("budget-vote").text);}[Test]@@ -180,7 +180,7 @@ public class BudgetScreenTestsbridge.EndTurn();Assert.AreEqual(before, bridge.State.Budget["education_minister"], 1e-12, "never submitted, so never applied");Assert.AreEqual(before + 0.05, budget.Draft["education_minister"], 1e-9, "the draft is kept");- Assert.AreEqual("Changed: submit to put it to the vote", ui.Q<Label>("budget-status").text);+ Assert.AreEqual(Text["budget.unsaved"], ui.Q<Label>("budget-status").text);}}@@ -192,11 +192,11 @@ public class BudgetScreenTests{UiTestKit.Press(ui.Q<Button>("budget-education_minister-up"));ui.Press("budget-submit");- Assert.AreEqual("Submitted: takes effect at End turn", ui.Q<Label>("budget-status").text);+ Assert.AreEqual(Text["budget.queued"], ui.Q<Label>("budget-status").text);UiTestKit.Press(ui.Q<Button>("budget-education_minister-up"));- Assert.AreEqual("Changed: submit to put it to the vote", ui.Q<Label>("budget-status").text);+ Assert.AreEqual(Text["budget.unsaved"], ui.Q<Label>("budget-status").text);ui.Press("budget-submit");- Assert.AreEqual("Submitted: takes effect at End turn", ui.Q<Label>("budget-status").text);+ Assert.AreEqual(Text["budget.queued"], ui.Q<Label>("budget-status").text);var queued = (AllocateBudget)bridge.Queued.Single();foreach (var kv in budget.Draft) Assert.AreEqual(kv.Value, queued.Shares[kv.Key], 1e-12);}@@ -311,13 +311,13 @@ public class BudgetScreenTests{c.Eras[0].Systems.Legislature = EraSystems.Assembly;new BudgetPresenter(ui.Root, new SimBridge(g, Text), Text);- Assert.AreEqual(System.FormattableString.Invariant($"The {leg.Body} votes on it, but its vote does not bind: the coalition holds {seats} of {size} seats"), ui.Q<Label>("budget-vote").text);+ Assert.AreEqual(Text.Format("budget.vote_advisory", leg.Body, seats, size, Text["cabinet.seats_appointed"]), ui.Q<Label>("budget-vote").text);}using (var ui = new UiTestKit()){c.Eras[0].Systems.Legislature = EraSystems.State;new BudgetPresenter(ui.Root, new SimBridge(g, Text), Text);- Assert.AreEqual(System.FormattableString.Invariant($"The {leg.Body} must approve it: the coalition holds {seats} of {size} seats"), ui.Q<Label>("budget-vote").text);+ Assert.AreEqual(Text.Format("budget.vote_needed", leg.Body, seats, size, Text["cabinet.seats_appointed"]), ui.Q<Label>("budget-vote").text);}}}diff --git a/unity/Assets/Tests/EditMode/CabinetScreenTests.cs b/unity/Assets/Tests/EditMode/CabinetScreenTests.csindex 578ea0e33..849bc7fc3 100644--- a/unity/Assets/Tests/EditMode/CabinetScreenTests.cs+++ b/unity/Assets/Tests/EditMode/CabinetScreenTests.cs@@ -276,7 +276,7 @@ public class CabinetScreenTestsvar holder = Cabinet.Holder(C, bridge.State, "finance_minister")!;Assert.AreNotEqual("golda_meir", holder.Id);Assert.AreEqual(holder.Name, ui.Q<Label>("seat-finance_minister-holder").text);- StringAssert.DoesNotContain("(your appointee)", ui.Q<Label>("seat-finance_minister-holder").text);+ StringAssert.DoesNotContain(Text.Format("card.appointed_name", "").Trim(), ui.Q<Label>("seat-finance_minister-holder").text);Assert.IsTrue(bridge.Session.Last!.Why.Any(w => w.System == "cabinet" && w.Target == "appointments"));}diff --git a/unity/Assets/Tests/EditMode/ControlTests.cs b/unity/Assets/Tests/EditMode/ControlTests.csindex 8b3b9a0e0..0a7ced1a0 100644--- a/unity/Assets/Tests/EditMode/ControlTests.cs+++ b/unity/Assets/Tests/EditMode/ControlTests.cs@@ -293,7 +293,7 @@ public class ControlTests// a demilitarized zone hex: the zone's own line, not a second "Demilitarized zone"var dmz = m.Control!.Periods.Count > 0 ? FindHex(m, After, Control1948.Side.Dmz) : default;Assert.AreEqual("Demilitarized zone", InfoPanelPresenter.ControlText(m, En, dmz.q, dmz.r, After));- StringAssert.DoesNotContain("Demilitarized zone", InfoPanelPresenter.RegionText(m, En, dmz.q, dmz.r, After));+ StringAssert.DoesNotContain(En["info.control_dmz"], InfoPanelPresenter.RegionText(m, En, dmz.q, dmz.r, After));// no-man's land from a minimal file too (the data has it only in the opening period, in the Old City's hex)var nml = Control1948.Parse("layer: x\nshown_from: 1948-06-11\nperiods:\n - { id: a, from: 1948-06-11, until: null, legend: held, line_date: '1948-07-09', fronts: [] }\nhexes:\n - [1, 2, 'm']\n");Assert.AreEqual((Control1948.Side.NoMansLand, (string?)null), nml.At(1, 2, Truce1));diff --git a/unity/Assets/Tests/EditMode/HudTests.cs b/unity/Assets/Tests/EditMode/HudTests.csindex 82670969d..dfda628f2 100644--- a/unity/Assets/Tests/EditMode/HudTests.cs+++ b/unity/Assets/Tests/EditMode/HudTests.cs@@ -76,15 +76,15 @@ public class HudTests{var m = HudModel.From(NewBridge(), Text);Assert.AreEqual("1948", m.Year);- Assert.AreEqual("Turn 0", m.Turn);+ Assert.AreEqual(Text.Format("hud.turn", 0), m.Turn);Assert.AreEqual("15 May 1948", m.Date);Assert.AreEqual("IL\u00A020.0m", m.Treasury.Value); // Israeli pounds (playtest 1, item 7)Assert.AreEqual("$40.0m", m.Fx.Value);Assert.AreEqual("30%", m.Security.Value); // the 0-100 scale, with its unit (fix round 1, I2)Assert.AreEqual("50%", m.Standing.Value);StringAssert.EndsWith("%", m.Support.Value);- Assert.AreEqual("Level 5 of 5", m.SecurityLevel);- Assert.AreEqual("Attention 4.0 of 4.0", m.Attention);+ Assert.AreEqual(Text.Format("hud.level", 5), m.SecurityLevel);+ Assert.AreEqual(Text.Format("hud.attention", 4.0, 4.0), m.Attention);Assert.AreEqual("", m.Treasury.Delta); // no previous turn yet}@@ -220,9 +220,9 @@ public class HudTestspublic void TheGddGameShowsItsScore(){var bridge = GddBridge();- Assert.AreEqual("Score 0", HudModel.From(bridge, Text).Score);+ Assert.AreEqual(Text.Format("hud.score", 0), HudModel.From(bridge, Text).Score);bridge.State.Score = 150;- Assert.AreEqual("Score 150", HudModel.From(bridge, Text).Score);+ Assert.AreEqual(Text.Format("hud.score", 150), HudModel.From(bridge, Text).Score);// The value carries left-to-right marks in a Hebrew line (U+200E, #543), as every Hebrew value does.var he = HudModel.From(bridge, He).Score;Assert.AreEqual("ניקוד \u200E150\u200E", he);@@ -236,11 +236,11 @@ public class HudTestsvar bridge = GddBridge();using var hud = new HudPresenter(ui.Root, bridge, Text);var label = ui.Q<Label>("score");- Assert.AreEqual("Score 0", label.text);+ Assert.AreEqual(Text.Format("hud.score", 0), label.text);Assert.AreEqual(DisplayStyle.Flex, label.style.display.value);bridge.State.Score = 150;hud.Render();- Assert.AreEqual("Score 150", label.text);+ Assert.AreEqual(Text.Format("hud.score", 150), label.text);}// ---- The exhausted-turn count (#812, R-END-002): "1 of 3" under the date while Money and Food are both out ----@@ -258,7 +258,7 @@ public class HudTestsvar limit = bridge.Content.RulesAt(bridge.State.Date).Mvp!.DefeatTurns!.Value;bridge.State.ExhaustedTurns = 1;hud.Render();- Assert.AreEqual($"Money and Food ran out: turn 1 of {limit}", label.text);+ Assert.AreEqual(Text.Format("hud.exhausted", 1, limit), label.text);Assert.AreEqual(DisplayStyle.Flex, label.style.display.value);// The value carries left-to-right marks in a Hebrew line (U+200E, #543), as every Hebrew value does.var he = HudModel.From(bridge, He).Exhausted;@@ -278,7 +278,7 @@ public class HudTestsusing var hud = new HudPresenter(ui.Root, bridge, Text);var meter = ui.Q<VisualElement>("meter-cohesion");Assert.AreEqual(DisplayStyle.Flex, meter.style.display.value, "shown in the GDD loop");- Assert.AreEqual("Social cohesion", meter.Q<Label>(className: "meter-name").text);+ Assert.AreEqual(Text["hud.caption.cohesion"], meter.Q<Label>(className: "meter-name").text);Assert.AreEqual("rings", meter.Q<UiIcon>().Glyph);Assert.Greater(bridge.State.Indicators["morale"], 0.0, "precondition: the indicator starts at its base");Assert.AreEqual(PlayerText.Percent(bridge.State.Indicators["morale"]), ui.Q<Label>("cohesion-value").text);@@ -291,12 +291,12 @@ public class HudTestsAssert.AreEqual("63%", ui.Q<Label>("cohesion-value").text);Assert.AreEqual("+5%", ui.Q<Label>("cohesion-delta").text);Assert.IsTrue(ui.Q<Label>("cohesion-delta").ClassListContains("delta-up"));- Assert.AreEqual("Social cohesion: 63%, up 5 points since last turn", meter.tooltip);+ Assert.AreEqual(Text.Format("hud.say_up", Text["hud.caption.cohesion"], "63%", Text.Format("hud.say_points", 5)), meter.tooltip);now.Indicators["morale"] = 0.574; // 58% -> 57%: down 1 pointhud.Render();Assert.AreEqual("-1%", ui.Q<Label>("cohesion-delta").text);Assert.IsTrue(ui.Q<Label>("cohesion-delta").ClassListContains("delta-down"));- Assert.AreEqual("Social cohesion: 57%, down 1 point since last turn", meter.tooltip);+ Assert.AreEqual(Text.Format("hud.say_down", Text["hud.caption.cohesion"], "57%", Text.Format("hud.say_point", 1)), meter.tooltip);using var heUi = new UiTestKit();using var heHud = new HudPresenter(heUi.Root, GddBridge(), He);Assert.AreEqual("לכידות חברתית", heUi.Q<VisualElement>("meter-cohesion").Q<Label>(className: "meter-name").text);@@ -323,7 +323,7 @@ public class HudTestsforeach (var id in bridge.NeedsOrders.ToList()) bridge.Skip(id);ui.Press("end-turn");Assert.AreEqual(1, bridge.State.Turn);- Assert.AreEqual("Turn 1", ui.Q<Label>("turn").text);+ Assert.AreEqual(Text.Format("hud.turn", 1), ui.Q<Label>("turn").text);Assert.AreEqual("15 June 1948", ui.Q<Label>("date").text); // monthly turns since the GDD cutovervar arrivals = bridge.Session.Last!.Why.Where(w => w.System == "population").Sum(w => w.Delta);Assert.AreEqual(arrivals.ToString("N0", System.Globalization.CultureInfo.InvariantCulture), ui.Q<Label>("immigration-value").text);@@ -344,7 +344,7 @@ public class HudTestsAssert.IsNull(bridge.Queue(new SetMobilization(0.9))); // replaces the first: still one orderAssert.AreEqual(1, bridge.Queued.Count);Assert.IsNull(bridge.Queue(new SecurityOrder(-1)));- Assert.AreEqual("Not enough attention (need 2.0, have 0.0)", bridge.Queue(new SetPolicy("rationing", 1)));+ Assert.AreEqual(Text.Format("order.no_attention", 2.0, 0.0), bridge.Queue(new SetPolicy("rationing", 1)));}[Test]@@ -574,7 +574,7 @@ public class HudTestsnew ToastPresenter(ui.Root, bridge, Text);LogAssert.Expect(LogType.Log, new System.Text.RegularExpressions.Regex("unknown policy 'curfew'")); // the id: log only (#622)Assert.IsNotNull(bridge.Queue(new SetPolicy("curfew", 1)));- Assert.AreEqual("Not done: Unknown policy", ui.Q<Label>("toast").text);+ Assert.AreEqual(Text.Format("toast.refused", Text.Format("order.unknown", Text["order.kind.policy"])), ui.Q<Label>("toast").text);Assert.AreEqual(DisplayStyle.Flex, ui.Q<Label>("toast").style.display.value);Assert.IsNull(bridge.Queue(new SecurityOrder(-1)));Assert.AreEqual(DisplayStyle.None, ui.Q<Label>("toast").style.display.value);@@ -692,7 +692,7 @@ public class HudTestsAssert.AreEqual(0, bridge.Queued.Count);Assert.IsNull(bridge.BeforeLast);Assert.AreSame(order, seen![0].Command);- Assert.AreEqual("Not done: The turn could not run. Your orders were cleared. Give them again.", ui.Q<Label>("toast").text); // "boom": the log only (#622)+ Assert.AreEqual(Text.Format("toast.refused", Text["order.failed"]), ui.Q<Label>("toast").text); // "boom": the log only (#622)}/// <summary>#912: the sim and autosave have advanced before End Turn notifies presenters. A broken presenter is@@ -896,7 +896,6 @@ public class HudTests}static readonly string[] MeterIds = { "treasury", "immigration", "security", "support", "cohesion", "standing", "fx" };- static string Inv(System.FormattableString f) => System.FormattableString.Invariant(f);static UiText He => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings.Replace("strings.en.yaml", "strings.he.yaml")).text, "strings.he.yaml");/// <summary>Ends turns until Immigration shows a change (it compares two turns' arrivals), so every meter can show one.@@ -916,8 +915,8 @@ public class HudTestsusing var ui = new UiTestKit();var bridge = NewBridge();var hud = new HudPresenter(ui.Root, bridge, Text);- Assert.AreEqual("Money (net): IL\u00A020.0 million", ui.Q<VisualElement>("meter-treasury").tooltip); // turn 0: no change- Assert.AreEqual("Foreign currency: $40.0 million", ui.Q<VisualElement>("meter-fx").tooltip);+ Assert.AreEqual(Text.Format("hud.say", Text["hud.caption.treasury"], Text.Format("hud.say_million", "IL\u00A0", "20.0")), ui.Q<VisualElement>("meter-treasury").tooltip); // turn 0: no change+ Assert.AreEqual(Text.Format("hud.say", Text["hud.caption.fx"], Text.Format("hud.say_million", "$", "40.0")), ui.Q<VisualElement>("meter-fx").tooltip);Assert.AreEqual("Security: 30%", ui.Q<VisualElement>("meter-security").tooltip);bridge.EndTurn();var prev = bridge.Session.Previous!; var now = bridge.State;@@ -928,8 +927,8 @@ public class HudTestshud.Render();var net = System.Math.Round(now.Treasury - now.Debt, 1, System.MidpointRounding.AwayFromZero);Assert.Greater(net, 0, "the test expects a positive net position after one turn");- Assert.AreEqual(Inv($"Money (net): IL\u00A0{net:0.0} million, down IL\u00A01.4 million since last turn"), ui.Q<VisualElement>("meter-treasury").tooltip);- Assert.AreEqual(Inv($"Foreign currency: ${now.FxReserves:0.0} million, up $2.0 million since last turn"), ui.Q<VisualElement>("meter-fx").tooltip);+ Assert.AreEqual(Text.Format("hud.say_down", Text["hud.caption.treasury"], Text.Format("hud.say_million", "IL\u00A0", net.ToString("0.0", System.Globalization.CultureInfo.InvariantCulture)), Text.Format("hud.say_million", "IL\u00A0", "1.4")), ui.Q<VisualElement>("meter-treasury").tooltip);+ Assert.AreEqual(Text.Format("hud.say_up", Text["hud.caption.fx"], Text.Format("hud.say_million", "$", now.FxReserves.ToString("0.0", System.Globalization.CultureInfo.InvariantCulture)), Text.Format("hud.say_million", "$", "2.0")), ui.Q<VisualElement>("meter-fx").tooltip);Assert.AreEqual($"Security: {ui.Q<Label>("security-value").text}, up 5 points since last turn", ui.Q<VisualElement>("meter-security").tooltip);Assert.AreEqual($"International support: {ui.Q<Label>("standing-value").text}, down 1 point since last turn", ui.Q<VisualElement>("meter-standing").tooltip);// Immigration after one turn has no change yet (it needs two turns of arrivals): the caption and the count only.@@ -982,7 +981,7 @@ public class HudTestsnow.Debt = now.Treasury + 3; // net -3.0prev.Debt = prev.Treasury - 1; // net +1.0 before: down by 4m = HudModel.From(bridge, Text);- Assert.AreEqual("Money: IL\u00A0-3.0 million, down IL\u00A04.0 million since last turn", HudModel.Spoken(Text, "Money", m.Treasury));+ Assert.AreEqual(Text.Format("hud.say_down", "Money", Text.Format("hud.say_million", "IL\u00A0-", "3.0"), Text.Format("hud.say_million", "IL\u00A0", "4.0")), HudModel.Spoken(Text, "Money", m.Treasury));using var ui = new UiTestKit();var he = He;new HudPresenter(ui.Root, bridge, he);diff --git a/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs b/unity/Assets/Tests/EditMode/UnitsInPlayTests.csindex 7e74543d2..392151ba1 100644--- a/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs+++ b/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs@@ -1148,7 +1148,7 @@ public class UnitsInPlayTestsStringAssert.Contains("commissioned 1948", ship.Subtitle);StringAssert.Contains("Wikipedia only", UnitCard.For(Token("golani", start), start, text).Note, "Golani is still Wikipedia only; Kiryati cites the Haganah lexicon (P66)");var hatzor = StateAt(new DateTime(1948, 12, 1), 5, 0.8);- StringAssert.DoesNotContain("Wikipedia only", UnitCard.For(Token("squadron_101", hatzor), hatzor, text).Note,+ StringAssert.DoesNotContain(text["unit.draft_wikipedia"], UnitCard.For(Token("squadron_101", hatzor), hatzor, text).Note,"Hatzor's position cites Eduard (review M8: the note is per position)");var july = StateAt(new DateTime(1948, 7, 1), 5, 0.8);StringAssert.Contains("Wikipedia only", UnitCard.For(Token("squadron_101", july), july, text).Note, "Herzliya's position is Wikipedia only");