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 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);
        }
Exemplo n.º 6
0
        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);
        }