public void TestVariableGetSetAPI()
{
var story = CompileString(@"
VAR x = 5
{x}
* [choice]
-
{x}
* [choice]
-
{x}
* [choice]
-
{x}
-> DONE
");
// Initial state
Assert.AreEqual("5\n", story.ContinueMaximally());
Assert.AreEqual(5, story.variablesState["x"]);
story.variablesState["x"] = 10;
story.ChooseChoiceIndex(0);
Assert.AreEqual("10\n", story.ContinueMaximally());
Assert.AreEqual(10, story.variablesState["x"]);
story.variablesState["x"] = 8.5f;
story.ChooseChoiceIndex(0);
Assert.AreEqual("8"+ System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator+"5\n", story.ContinueMaximally());
Assert.AreEqual(8.5f, story.variablesState["x"]);
story.variablesState["x"] = "a string";
story.ChooseChoiceIndex(0);
Assert.AreEqual("a string\n", story.ContinueMaximally());
Assert.AreEqual("a string", story.variablesState["x"]);
Assert.AreEqual(null, story.variablesState["z"]);
// Not allowed arbitrary types
Assert.Throws<StoryException>(() =>
{
story.variablesState["x"] = new System.Text.StringBuilder();
});
}