public void PerformSubstitutionReplacesSimpleSingleMacro() { var substitute = new TextSubstitute(); substitute.AddMacro("$(number)", "one"); var result = substitute.PerformSubstitution("My favourite number is $(number)."); Assert.AreEqual("My favourite number is one.", result); }
public void AddMacroAddsMacroToDictionaryIsCaseInsensitive() { var substitute = new TextSubstitute(); Assert.AreEqual(0, substitute.Count); substitute.AddMacro("$(MaCrO)", "text to substitute."); Assert.AreEqual(1, substitute.Count); Assert.IsTrue(substitute.Exists("$(macro)")); }
public void PerformSubstitutionReturnsEmptyStringWhenSourceIsEmpty() { var substitute = new TextSubstitute(); substitute.AddMacro("$(number)", "one"); var result = substitute.PerformSubstitution(""); Assert.AreEqual(string.Empty, result); }
public void PerformSubstitutionGuardsAgainstAnInfinateLoop() { var substitute = new TextSubstitute(); // This macro case should cause an infinate loop so we need to guard against it. substitute.AddMacro("$(number)", "$(number)"); var result = substitute.PerformSubstitution("My favourite number is $(number)."); Assert.AreEqual("My favourite number is $(number).", result); }
public void PerformSubstitutionReplacesSingleNestedlMacro() { var substitute = new TextSubstitute(); substitute.AddMacro("$(name)", "My name is $(steve)"); substitute.AddMacro("$(steve)", "Stephen Haunts"); var result = substitute.PerformSubstitution("Hello, $(name)."); Assert.AreEqual("Hello, My name is Stephen Haunts.", result); }
public void PerformSubstitutionReplacesMultipleLayerNestedlMacros() { var substitute = new TextSubstitute(); substitute.AddMacro("$(id)", "My name is $(name)"); substitute.AddMacro("$(name)", "$(steve) $(haunts)"); substitute.AddMacro("$(steve)", "Stephen"); substitute.AddMacro("$(haunts)", "Haunts"); var result = substitute.PerformSubstitution("Hello, $(id)."); Assert.AreEqual("Hello, My name is Stephen Haunts.", result); }
private GameReply RunParser(string command) { var reply = new GameReply(); // Run the natural language parser. var parsedCommand = Parser.ParseCommand(command); _commandQueue.AddCommand(parsedCommand); reply.State = GameStateEnum.Playing; reply.Reply = TextSubstitute.PerformSubstitution(CurrentRoom.ProcessCommand(parsedCommand)); return(reply); }
/// <summary> /// Constructor : Set up the correct default initial game state. /// </summary> public Game() { Prologue = string.Empty; HelpText = string.Empty; VisitedRooms = new VisitedRooms(); Parser = new Parser(); StartRoom = null; GlobalState = new GlobalState(); Difficulty = DifficultyEnum.Easy; HintSystemEnabled = false; ContentManagement = new ContentManagement(true); Player = new Player(); TextSubstitute = new TextSubstitute(); }
/// <summary> /// Constructor : Set up the correct default initial game state. /// </summary> /// <param name="prologue">You can inject the game prologue text into this constructor.</param> /// <param name="room">Set the initial starting room.</param> /// <exception cref="ArgumentNullException">If the prologue or initial room is null then throw the /// ArgumentNullException.</exception> public Game(string prologue, IRoom room) { if (string.IsNullOrEmpty(prologue)) { throw new ArgumentNullException(nameof(prologue), "The prologue can not be empty."); } Prologue = prologue; VisitedRooms = new VisitedRooms(); Parser = new Parser(); StartRoom = room ?? throw new ArgumentNullException(nameof(room), "The initial room state can not be null."); CurrentRoom = room; HelpText = string.Empty; GlobalState = new GlobalState(); Difficulty = DifficultyEnum.Easy; HintSystemEnabled = false; ContentManagement = new ContentManagement(true); Player = new Player(); TextSubstitute = new TextSubstitute(); }
public void CheckMacroFormatReturnsTrueForValidMacroWithTrailingSpaces() { var substitute = new TextSubstitute(); Assert.IsTrue(substitute.IsValidMacroFormat("$(macro) ")); }
public void CheckMacroFormatThrowsArgumentNullExceptionIfMacroIdIsNull() { var substitute = new TextSubstitute(); substitute.IsValidMacroFormat(""); }
public void CheckMacroFormatReturnsTrueForEmptyValidMacro() { var substitute = new TextSubstitute(); Assert.IsTrue(substitute.IsValidMacroFormat("$()")); }
public void AddMacroThrowsFormatExceptionIfMacroIdIsWrongFormat() { var substitute = new TextSubstitute(); substitute.AddMacro("w4t", "gfgfdsg"); }
public void CheckMacroFormatReturnsFalseForMacroWithNoStartCharacters() { var substitute = new TextSubstitute(); Assert.IsFalse(substitute.IsValidMacroFormat("macro)")); }
public void AddMacroThrowsArgumentNullExceptionIfTextIsNull() { var substitute = new TextSubstitute(); substitute.AddMacro("$(name)", ""); }
public void CheckMacroFormatReturnsFalseForMacroWithMissingDollar() { var substitute = new TextSubstitute(); Assert.IsFalse(substitute.IsValidMacroFormat("(macro)")); }
public void CheckMacroFormatReturnsFalseForMacroWithNoTerminator() { var substitute = new TextSubstitute(); Assert.IsFalse(substitute.IsValidMacroFormat("$(macro")); }
public void CheckMacroFormatReturnsFalseForMacroWithMissingOpeningBracket() { var substitute = new TextSubstitute(); Assert.IsFalse(substitute.IsValidMacroFormat("$macro)")); }
public void CheckMacroFormatReturnsFalseForMacroWithJunkAFterMacroName() { var substitute = new TextSubstitute(); Assert.IsFalse(substitute.IsValidMacroFormat("$(macro) blah")); }