using System; using System.Globalization; using System.Threading; using Azimuth; using Prism; using UnitTestSharp; namespace Konis.Testbed.UnitTests { public class DefTextTests : TestFixture { private static StandardEmitterDef Def( Variation? rate = null, Variation? lifetime = null, Variation? gravity = null, Axis up = Axis.Z, bool sortDescending = false, int capacity = 10, double clipSoftness = 0, IScalarFunction sizeOverLife = null, IScalarFunction alphaOverLife = null, SpriteDef sprite = null, Slab[] slabs = null) { return new StandardEmitterDef { Sprite = sprite, ClipSlabs = slabs, SizeOverLife = sizeOverLife, AlphaOverLife = alphaOverLife, Capacity = capacity, ClipSoftness = clipSoftness, Rate = rate ?? 1, Lifetime = lifetime ?? 1, Gravity = gravity ?? default(Variation), Up = up, SortDescending = sortDescending, TintOverLife = new GradientDef { Gradient = Gradient.Constant(Colors.White) }, }; } private static TunableProperty Find(EmitterDef def, string name) { foreach (TunableProperty property in Tunables.Of(def)) { if (property.Name == name) { return property; } } throw new InvalidOperationException("No tunable property is called " + name + "."); } private static string Line(string source) { return DefText.Indent + source + "," + Environment.NewLine; } public class ValueTextTests : TestFixture { public void AWholeNumber_IsItsDigits() { StandardEmitterDef def = Def(capacity: 500); CheckEqual("500", DefText.ValueText(Find(def, "Capacity"), def)); } public void ANumber_IsItsDigits() { StandardEmitterDef def = Def(clipSoftness: 0.25); CheckEqual("0.25", DefText.ValueText(Find(def, "ClipSoftness"), def)); } public void AFixedRange_IsOneNumber() { StandardEmitterDef def = Def(rate: 140); CheckEqual("140", DefText.ValueText(Find(def, "Rate"), def)); } public void ARealRange_IsANewVariation() { StandardEmitterDef def = Def(lifetime: new Variation(0.6, 1)); CheckEqual("new Variation(0.6, 1)", DefText.ValueText(Find(def, "Lifetime"), def)); } public void ANegativeNumber_KeepsItsSign() { StandardEmitterDef def = Def(gravity: -30); CheckEqual("-30", DefText.ValueText(Find(def, "Gravity"), def)); } public void ARangeAcrossZero_KeepsBothSigns() { StandardEmitterDef def = Def(gravity: new Variation(-0.5, 0.5)); CheckEqual("new Variation(-0.5, 0.5)", DefText.ValueText(Find(def, "Gravity"), def)); } public void ZeroIsZero() { StandardEmitterDef def = Def(); CheckEqual("0", DefText.ValueText(Find(def, "Gravity"), def)); } public void AFraction_IsWrittenWithAPointWhateverTheCulture() { StandardEmitterDef def = Def(lifetime: 0.6); CultureInfo before = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); try { CheckEqual("0.6", DefText.ValueText(Find(def, "Lifetime"), def)); } finally { Thread.CurrentThread.CurrentCulture = before; } } public void AChoice_IsItsTypeAndName() { StandardEmitterDef def = Def(up: Axis.Y); CheckEqual("Axis.Y", DefText.ValueText(Find(def, "Up"), def)); CheckEqual("ClockBase.Game", DefText.ValueText(Find(def, "Clock"), def)); } public void AToggle_IsTrueOrFalse() { StandardEmitterDef off = Def(); StandardEmitterDef on = Def(sortDescending: true); CheckEqual("false", DefText.ValueText(Find(off, "SortDescending"), off)); CheckEqual("true", DefText.ValueText(Find(on, "SortDescending"), on)); } public void AComputedProperty_Throws() { StandardEmitterDef def = Def(); var computed = new TunableProperty( typeof(EmitterDef).GetProperty(nameof(EmitterDef.ClipSlabs)), TunableKind.Computed, TuneEffect.None); CheckThrow(typeof(InvalidOperationException)); DefText.ValueText(computed, def); } public void ADefWithNoSlabs_IsNull() { StandardEmitterDef def = Def(); CheckEqual("null", DefText.ValueText(Find(def, "ClipSlabs"), def)); } public void AnEmptySetOfSlabs_IsNull() { StandardEmitterDef def = Def(slabs: new Slab[0]); CheckEqual("null", DefText.ValueText(Find(def, "ClipSlabs"), def)); } public void ASlabWithOnlyAMinimumOnAnAxis_IsAbove() { StandardEmitterDef def = Def(slabs: new[] { Slab.Above(Axis.Z, 0) }); CheckEqual("new[] { Slab.Above(Axis.Z, 0) }", DefText.ValueText(Find(def, "ClipSlabs"), def)); } public void ASlabWithOnlyAMaximumOnAnAxis_IsBelow() { StandardEmitterDef def = Def(slabs: new[] { Slab.Below(Axis.X, 4.5) }); CheckEqual("new[] { Slab.Below(Axis.X, 4.5) }", DefText.ValueText(Find(def, "ClipSlabs"), def)); } public void ASlabWithBothEndsOnAnAxis_IsBetween() { StandardEmitterDef def = Def(slabs: new[] { Slab.Between(Axis.Y, 1, 5) }); CheckEqual("new[] { Slab.Between(Axis.Y, 1, 5) }", DefText.ValueText(Find(def, "ClipSlabs"), def)); } public void ASlabWithNeitherEndOnAnAxis_NamesBothInfinities() { StandardEmitterDef def = Def( slabs: new[] { Slab.Between(Axis.Z, double.NegativeInfinity, double.PositiveInfinity) }); CheckEqual( "new[] { Slab.Between(Axis.Z, double.NegativeInfinity, double.PositiveInfinity) }", DefText.ValueText(Find(def, "ClipSlabs"), def)); } public void ASlabOffTheAxes_IsBetweenItsNormalizedDirection() { StandardEmitterDef def = Def(slabs: new[] { Slab.Between(new Vector3(0, 3, 4), 1, 2) }); CheckEqual( "new[] { Slab.Between(new Vector3(0, 0.6, 0.8), 1, 2) }", DefText.ValueText(Find(def, "ClipSlabs"), def)); } public void ASlabOffTheAxesWithAnOpenEnd_NamesTheInfinity() { StandardEmitterDef def = Def( slabs: new[] { Slab.Between(new Vector3(0, 3, 4), double.NegativeInfinity, 2) }); CheckEqual( "new[] { Slab.Between(new Vector3(0, 0.6, 0.8), double.NegativeInfinity, 2) }", DefText.ValueText(Find(def, "ClipSlabs"), def)); } public void SeveralSlabsThatFitOnALine_ShareIt() { StandardEmitterDef def = Def(slabs: new[] { Slab.Above(Axis.Z, 0), Slab.Below(Axis.X, 10) }); CheckEqual( "new[] { Slab.Above(Axis.Z, 0), Slab.Below(Axis.X, 10) }", DefText.ValueText(Find(def, "ClipSlabs"), def)); } public void SlabsTooLongForALine_PutEachOnItsOwn() { Slab skewed = Slab.Between(new Vector3(0, 3, 4), 1, 2); StandardEmitterDef def = Def(slabs: new[] { skewed, skewed, skewed }); string expected = "new[]" + Environment.NewLine + DefText.Indent + "{" + Environment.NewLine + DefText.Indent + " Slab.Between(new Vector3(0, 0.6, 0.8), 1, 2)," + Environment.NewLine + DefText.Indent + " Slab.Between(new Vector3(0, 0.6, 0.8), 1, 2)," + Environment.NewLine + DefText.Indent + " Slab.Between(new Vector3(0, 0.6, 0.8), 1, 2)," + Environment.NewLine + DefText.Indent + "}"; CheckEqual(expected, DefText.ValueText(Find(def, "ClipSlabs"), def)); } public void ASprite_IsTheStaticFieldThatHoldsIt() { StandardEmitterDef def = Def(sprite: TestbedSprites.Diamond); CheckEqual("TestbedSprites.Diamond", DefText.ValueText(Find(def, "Sprite"), def)); } public void ASpriteNoStaticFieldHolds_Throws() { StandardEmitterDef def = Def(sprite: Effects.Flicker.Def.Sprite); CheckThrow(typeof(InvalidOperationException)); DefText.ValueText(Find(def, "Sprite"), def); } public void ADefWithNoSprite_Throws() { StandardEmitterDef def = Def(); CheckThrow(typeof(InvalidOperationException)); DefText.ValueText(Find(def, "Sprite"), def); } public void AFunctionMadeOfPoints_IsANewOfItsTypeWithAPairForEachPoint() { StandardEmitterDef def = Def(sizeOverLife: new PiecewiseLinear((0, 1), (0.5, 0.25), (1, 0))); CheckEqual( "new PiecewiseLinear((0, 1), (0.5, 0.25), (1, 0))", DefText.ValueText(Find(def, "SizeOverLife"), def)); } public void AStepFunctionAndASplineAreNamedForTheirTypes() { StandardEmitterDef def = Def( sizeOverLife: new PiecewiseStep((0, 1), (0.5, 2)), alphaOverLife: new MonotoneSpline((0, 0), (1, 1))); CheckEqual( "new PiecewiseStep((0, 1), (0.5, 2))", DefText.ValueText(Find(def, "SizeOverLife"), def)); CheckEqual( "new MonotoneSpline((0, 0), (1, 1))", DefText.ValueText(Find(def, "AlphaOverLife"), def)); } public void AFunctionWithTooManyPointsForALine_PutsEachPointOnItsOwn() { StandardEmitterDef def = Def(alphaOverLife: new MonotoneSpline( (0, 1), (0.125, 0.984375), (0.25, 0.9375), (0.375, 0.859375), (0.5, 0.75), (0.625, 0.609375), (0.75, 0.4375), (0.875, 0.234375), (1, 0))); string expected = "new MonotoneSpline(" + Environment.NewLine + DefText.Indent + " (0, 1)," + Environment.NewLine + DefText.Indent + " (0.125, 0.984375)," + Environment.NewLine + DefText.Indent + " (0.25, 0.9375)," + Environment.NewLine + DefText.Indent + " (0.375, 0.859375)," + Environment.NewLine + DefText.Indent + " (0.5, 0.75)," + Environment.NewLine + DefText.Indent + " (0.625, 0.609375)," + Environment.NewLine + DefText.Indent + " (0.75, 0.4375)," + Environment.NewLine + DefText.Indent + " (0.875, 0.234375)," + Environment.NewLine + DefText.Indent + " (1, 0))"; CheckEqual(expected, DefText.ValueText(Find(def, "AlphaOverLife"), def)); } public void AFunctionWhoseLineJustFits_StaysOnOneLine() { var function = new PiecewiseLinear( (0, 1), (0.1, 0.5), (0.2, 0.25), (0.3, 0.75), (0.4, 0.125), (0.5, 0.5)); StandardEmitterDef def = Def(alphaOverLife: function); string text = DefText.ValueText(Find(def, "AlphaOverLife"), def); CheckEqual(120, DefText.Indent.Length + "AlphaOverLife = ".Length + text.Length + 1); CheckFalse(text.Contains(Environment.NewLine)); } public void AFunctionWhoseLineIsOneColumnTooLong_Wraps() { var function = new PiecewiseLinear( (0, 1), (0.1, 0.5), (0.2, 0.25), (0.3, 0.75), (0.4, 0.125), (0.5, 0.55)); StandardEmitterDef def = Def(alphaOverLife: function); CheckTrue(DefText.ValueText(Find(def, "AlphaOverLife"), def).Contains(Environment.NewLine)); } public void AFunctionMadeOfCode_Throws() { StandardEmitterDef def = Def(sizeOverLife: new CallbackFunction(x => x)); CheckThrow(typeof(InvalidOperationException)); DefText.ValueText(Find(def, "SizeOverLife"), def); } public void AFunctionTheDefLacks_Throws() { StandardEmitterDef def = Def(); CheckThrow(typeof(InvalidOperationException)); DefText.ValueText(Find(def, "SizeOverLife"), def); } public void AGradient_IsATintWrapAroundItsSpaceAndStopsOnALineEach() { StandardEmitterDef def = Def(); def.TintOverLife.Gradient = new Gradient( GradientSpace.Oklab, new GradientStop(0, Color.FromArgb(255, 255, 240, 150)), new GradientStop(0.4, Color.FromArgb(255, 255, 140, 30)), new GradientStop(1, Color.FromArgb(255, 150, 20, 10))); string expected = "Tint(new Gradient(" + Environment.NewLine + DefText.Indent + " GradientSpace.Oklab," + Environment.NewLine + DefText.Indent + " new GradientStop(0, Rgb(255, 240, 150))," + Environment.NewLine + DefText.Indent + " new GradientStop(0.4, Rgb(255, 140, 30))," + Environment.NewLine + DefText.Indent + " new GradientStop(1, Rgb(150, 20, 10))))"; CheckEqual(expected, DefText.ValueText(Find(def, "TintOverLife"), def)); } public void AGradientGoingRoundTheHueCircleALongWay_NamesItsDirection() { StandardEmitterDef def = Def(); def.TintOverLife.Gradient = new Gradient( GradientSpace.Hsv, HueDirection.Longest, new GradientStop(0, Colors.Red), new GradientStop(1, Colors.Blue)); string text = DefText.ValueText(Find(def, "TintOverLife"), def); CheckTrue(text.Contains( "GradientSpace.Hsv," + Environment.NewLine + DefText.Indent + " HueDirection.Longest,")); } public void AGradientOnADefWithNoGradientDef_Throws() { var def = new StandardEmitterDef(); CheckThrow(typeof(InvalidOperationException)); DefText.ValueText(Find(def, "TintOverLife"), def); } public void AGradientWithTheDefaultDirection_LeavesTheDirectionOut() { StandardEmitterDef def = Def(); CheckFalse(DefText.ValueText(Find(def, "TintOverLife"), def).Contains("HueDirection")); } public void AStopThatIsNotOpaque_IsWrittenWithItsAlpha() { StandardEmitterDef def = Def(); def.TintOverLife.Gradient = Gradient.Constant(Color.FromArgb(128, 10, 20, 30)); CheckTrue(DefText.ValueText(Find(def, "TintOverLife"), def).Contains( "new GradientStop(0, Color.FromArgb(128, 10, 20, 30))")); } [IgnoreTest] private static string TextOf(Gradient gradient) { StandardEmitterDef def = Def(); def.TintOverLife.Gradient = gradient; return DefText.ValueText(Find(def, "TintOverLife"), def); } [IgnoreTest] private static string ExactTail(string stop) { return "Tint(new Gradient(" + Environment.NewLine + DefText.Indent + " GradientSpace.Hsv," + Environment.NewLine + DefText.Indent + " " + stop; } public void AStopThatIsNotMadeOfBytes_IsWrittenInTheSpacesOwnNumbers_AndTheOthersInBytes() { string text = TextOf(new Gradient( GradientSpace.Hsv, new ExactStop(0, StopColor.FromHsv(new Hsv(0.3, 0.004, 0.5))), new ExactStop(1, StopColor.FromHsv(Hsv.FromColor(Colors.Red))))); string expected = ExactTail( "new ExactStop(0, StopColor.FromHsv(new Hsv(0.3, 0.004, 0.5)))," + Environment.NewLine + DefText.Indent + " new ExactStop(1, StopColor.FromColor(" + "GradientSpace.Hsv, Rgb(255, 0, 0)))))"); CheckEqual(expected, text); } public void AnExactStopInLinearLight_IsWrittenAsLinearComponents() { string text = TextOf(new Gradient( GradientSpace.LinearLight, new ExactStop(0.5, StopColor.FromLinear(new LinearSpaceColor(0.1, 0.2, 0.3))))); CheckTrue(text.Contains( "new ExactStop(0.5, StopColor.FromLinear(new LinearSpaceColor(0.1, 0.2, 0.3)))))")); } public void AnExactStopInOklab_IsWrittenAsOklabComponents() { string text = TextOf(new Gradient( GradientSpace.Oklab, new ExactStop(0, StopColor.FromOklab(new Oklab(0.5, 0.1, -0.1))))); CheckTrue(text.Contains("new ExactStop(0, StopColor.FromOklab(new Oklab(0.5, 0.1, -0.1)))))")); } public void AnExactStopInOklch_IsWrittenAsOklchComponents() { string text = TextOf(new Gradient( GradientSpace.Oklch, new ExactStop(0, StopColor.FromOklch(new Oklch(0.5, 0.1, 0.25))))); CheckTrue(text.Contains("new ExactStop(0, StopColor.FromOklch(new Oklch(0.5, 0.1, 0.25)))))")); } public void AnExactStopInHsl_IsWrittenAsHslComponents() { string text = TextOf(new Gradient( GradientSpace.Hsl, new ExactStop(0, StopColor.FromHsl(new Hsl(0.3, 0.5, 0.7))))); CheckTrue(text.Contains("new ExactStop(0, StopColor.FromHsl(new Hsl(0.3, 0.5, 0.7)))))")); } public void AnExactStopThatIsNotOpaque_IsWrittenWithItsAlpha() { string text = TextOf(new Gradient( GradientSpace.Oklch, new ExactStop(0, StopColor.FromOklch(new Oklch(0.5, 0.1, 0.25, 0.5))))); CheckTrue(text.Contains( "new ExactStop(0, StopColor.FromOklch(new Oklch(0.5, 0.1, 0.25, 0.5)))))")); } public void AnExactStopTooLongForALine_PutsItsColorOnTheNextLine() { const double digits = 0.123456789012345; string text = TextOf(new Gradient( GradientSpace.Oklch, new ExactStop(0, StopColor.FromOklch(new Oklch(digits, digits, digits))))); string stop = "new ExactStop(0," + Environment.NewLine + DefText.Indent + " " + "StopColor.FromOklch(new Oklch(0.123456789012345, 0.123456789012345, 0.123456789012345)))))"; CheckTrue(text.EndsWith(stop)); } public void AnExactGradientInTheDefaultDirection_LeavesTheDirectionOut() { CheckFalse(TextOf(new Gradient( GradientSpace.Hsv, new ExactStop(0, StopColor.FromHsv(new Hsv(0.3, 0.004, 0.5))))).Contains( "HueDirection")); } } public class WriteTests : TestFixture { public void WithNoSnapshot_WritesEveryEditablePropertyInDeclarationOrder() { StandardEmitterDef def = Def( rate: 140, lifetime: new Variation(0.6, 1), gravity: -30, up: Axis.Y, sortDescending: true); string expected = Line("Clock = ClockBase.Game") + Line("Capacity = 10") + Line("Rate = 140") + Line("Lifespan = 0") + Line("ClipSlabs = null") + Line("ClipSoftness = 0") + Line("Up = Axis.Y") + Line("Lifetime = new Variation(0.6, 1)") + Line("Speed = 0") + Line("Heading = 0") + Line("Elevation = 0") + Line("AngularVelocity = 0") + Line("Size = 1") + Line("Gravity = -30") + Line("Drag = 0") + Line("WindInfluence = 0") + Line("Additive = 0") + Line("SortBy = ParticleSortKey.None") + Line("SortDescending = true") + Line("TintOverLife = Tint(new Gradient(" + Environment.NewLine + DefText.Indent + " GradientSpace.LinearLight," + Environment.NewLine + DefText.Indent + " new GradientStop(0, Rgb(255, 255, 255))))"); CheckEqual(expected, DefText.Write(def, null)); } public void AGradientChangedSinceTheSnapshot_IsWrittenWhole() { StandardEmitterDef def = Def(); var snapshot = new TunableSnapshot(def); Find(def, "TintOverLife").Set(def, Gradient.Constant(Colors.Red)); string expected = Line("TintOverLife = Tint(new Gradient(" + Environment.NewLine + DefText.Indent + " GradientSpace.LinearLight," + Environment.NewLine + DefText.Indent + " new GradientStop(0, Rgb(255, 0, 0))))"); CheckEqual(expected, DefText.Write(def, snapshot)); } public void WithNoSnapshot_WritesAFunctionAfterSortDescendingAndBeforeTheTint() { StandardEmitterDef def = Def( sizeOverLife: new PiecewiseLinear((0, 1), (1, 0.2)), alphaOverLife: new MonotoneSpline((0, 1), (1, 0))); string written = DefText.Write(def, null); CheckTrue(written.Contains( Line("SortDescending = false") + Line("SizeOverLife = new PiecewiseLinear((0, 1), (1, 0.2))") + Line("AlphaOverLife = new MonotoneSpline((0, 1), (1, 0))") + DefText.Indent + "TintOverLife = ")); } public void AFunctionMadeOfCodeOrAbsent_IsLeftOut() { StandardEmitterDef def = Def(sizeOverLife: new CallbackFunction(x => 1 - x)); string written = DefText.Write(def, null); CheckFalse(written.Contains("SizeOverLife")); CheckFalse(written.Contains("AlphaOverLife")); } public void AFunctionChangedSinceTheSnapshot_IsWrittenWhole() { StandardEmitterDef def = Def(sizeOverLife: new PiecewiseLinear((0, 1))); var snapshot = new TunableSnapshot(def); Find(def, "SizeOverLife").Set(def, new PiecewiseStep((0, 1), (0.5, 3))); CheckEqual( Line("SizeOverLife = new PiecewiseStep((0, 1), (0.5, 3))"), DefText.Write(def, snapshot)); } public void SlabsChangedSinceTheSnapshot_AreWrittenWhole() { StandardEmitterDef def = Def(slabs: new[] { Slab.Above(Axis.Z, 0) }); var snapshot = new TunableSnapshot(def); Find(def, "ClipSlabs").Set(def, new[] { Slab.Above(Axis.Z, 2), Slab.Below(Axis.X, 5) }); CheckEqual( Line("ClipSlabs = new[] { Slab.Above(Axis.Z, 2), Slab.Below(Axis.X, 5) }"), DefText.Write(def, snapshot)); } public void SlabsRemovedSinceTheSnapshot_AreWrittenAsNull() { StandardEmitterDef def = Def(slabs: new[] { Slab.Above(Axis.Z, 0) }); var snapshot = new TunableSnapshot(def); Find(def, "ClipSlabs").Set(def, new Slab[0]); CheckEqual(Line("ClipSlabs = null"), DefText.Write(def, snapshot)); } public void SlabsUnchangedSinceTheSnapshot_AreLeftOut() { StandardEmitterDef def = Def(slabs: new[] { Slab.Above(Axis.Z, 0) }); CheckEqual("", DefText.Write(def, new TunableSnapshot(def))); } public void ASpriteChangedSinceTheSnapshot_IsWrittenAsItsStaticField() { StandardEmitterDef def = Def(sprite: SoftDisc.Sprite); var snapshot = new TunableSnapshot(def); Find(def, "Sprite").Set(def, TestbedSprites.Star); CheckEqual(Line("Sprite = TestbedSprites.Star"), DefText.Write(def, snapshot)); } public void ASpriteMovedOffAnInlineOneSinceTheSnapshot_IsWrittenAsItsStaticField() { StandardEmitterDef def = Def(sprite: Effects.Flicker.Def.Sprite); var snapshot = new TunableSnapshot(def); Find(def, "Sprite").Set(def, TestbedSprites.Ring); CheckEqual(Line("Sprite = TestbedSprites.Ring"), DefText.Write(def, snapshot)); } public void ASpriteNoStaticFieldHolds_IsLeftOut() { StandardEmitterDef def = Def(sprite: Effects.Flicker.Def.Sprite); CheckFalse(DefText.Write(def, null).Contains("Sprite")); } public void WithNoSnapshot_WritesASpriteAfterLifespanAndBeforeTheSlabs() { StandardEmitterDef def = Def(sprite: TestbedSprites.Cross); CheckTrue(DefText.Write(def, null).Contains( Line("Lifespan = 0") + Line("Sprite = TestbedSprites.Cross") + Line("ClipSlabs = null"))); } public void WithNoSnapshot_WritesSlabsAfterTheSpriteAndBeforeClipSoftness() { StandardEmitterDef def = Def(slabs: new[] { Slab.Above(Axis.Z, 0) }); CheckTrue(DefText.Write(def, null).Contains( Line("Lifespan = 0") + Line("ClipSlabs = new[] { Slab.Above(Axis.Z, 0) }") + Line("ClipSoftness = 0"))); } public void AFunctionMadeOfCodeThatBecomesPoints_IsWritten() { StandardEmitterDef def = Def(sizeOverLife: new CallbackFunction(x => 1 - x)); var snapshot = new TunableSnapshot(def); Find(def, "SizeOverLife").Set(def, new PiecewiseLinear((0, 1), (1, 0))); CheckEqual( Line("SizeOverLife = new PiecewiseLinear((0, 1), (1, 0))"), DefText.Write(def, snapshot)); } public void NothingChangedSinceTheSnapshot_WritesNothing() { StandardEmitterDef def = Def(); CheckEqual("", DefText.Write(def, new TunableSnapshot(def))); } public void OnlyWhatChangedSinceTheSnapshot_IsWritten() { StandardEmitterDef def = Def(capacity: 10); var snapshot = new TunableSnapshot(def); Find(def, "Capacity").Set(def, 25); Find(def, "Up").Set(def, Axis.Y); CheckEqual(Line("Capacity = 25") + Line("Up = Axis.Y"), DefText.Write(def, snapshot)); } public void ARangeChangedSinceTheSnapshot_IsWrittenWhole() { StandardEmitterDef def = Def(lifetime: new Variation(2, 3)); var snapshot = new TunableSnapshot(def); Find(def, "Lifetime").Set(def, new Variation(2, 4)); CheckEqual(Line("Lifetime = new Variation(2, 4)"), DefText.Write(def, snapshot)); } public void AChangeThatWasRefused_IsNotWritten() { StandardEmitterDef def = Def(capacity: 10); var snapshot = new TunableSnapshot(def); Find(def, "Capacity").Set(def, -1); CheckEqual("", DefText.Write(def, snapshot)); } public void AValueChangedBackToItsOriginal_IsNotWritten() { StandardEmitterDef def = Def(capacity: 10); var snapshot = new TunableSnapshot(def); Find(def, "Capacity").Set(def, 25); Find(def, "Capacity").Set(def, 10); CheckEqual("", DefText.Write(def, snapshot)); } public void ASnapshotOfAnotherDef_DoesNotHideAnyLine() { StandardEmitterDef other = Def(capacity: 10); var snapshot = new TunableSnapshot(other); StandardEmitterDef def = Def(capacity: 20); CheckEqual(Line("Capacity = 20"), DefText.Write(def, snapshot)); } } } }