Ejemplo n.º 1
0
        public void TemplateIfCommandWorks_Nested()
        {
            StringTemplates templatesProcessor = new StringTemplates();
            string          beginning          = "The quick brown fox";
            string          middle             = " jumps over";
            string          end      = " the lazy dog";
            string          template = $"{beginning}{templatesProcessor.CreateIfBlock("outer", "1", $"{middle}{templatesProcessor.CreateIfBlock("inner", "1", end)}")}";
            string          result   = templatesProcessor.Process(template, new Dictionary <string, string>()
            {
                { "outer", "0" }, { "inner", "0" }
            });

            result.Should().Be(beginning);
            result = templatesProcessor.Process(template, new Dictionary <string, string>()
            {
                { "outer", "0" }, { "inner", "1" }
            });
            result.Should().Be(beginning);
            result = templatesProcessor.Process(template, new Dictionary <string, string>()
            {
                { "outer", "1" }, { "inner", "0" }
            });
            result.Should().Be(beginning + middle);
            result = templatesProcessor.Process(template, new Dictionary <string, string>()
            {
                { "outer", "1" }, { "inner", "1" }
            });
            result.Should().Be(beginning + middle + end);
        }
Ejemplo n.º 2
0
        public void TemplateWithoutCommandWorks()
        {
            string          template           = "The quick brown fox";
            StringTemplates templatesProcessor = new StringTemplates();
            string          result             = templatesProcessor.Process(template);

            result.Should().Be(template);
        }
Ejemplo n.º 3
0
        public void TemplateForCommand_UsingVariable()
        {
            StringTemplates templatesProcessor = new StringTemplates();
            string          text     = "The quick brown fox";
            string          template = $"{templatesProcessor.CreateForBlock("i", 0, 3, text + templatesProcessor.CreateVariableBlock("i"))}";
            string          result   = templatesProcessor.Process(template, new Dictionary <string, string>()
            {
            });

            result.Should().Be($"{text}0{text}1{text}2");
        }
Ejemplo n.º 4
0
        public void TemplateIfCommandWorks_Excluding()
        {
            StringTemplates templatesProcessor = new StringTemplates();
            string          beginning          = "The quick brown fox";
            string          template           = $"{beginning}{templatesProcessor.CreateIfBlock("include", "1", " jumps")}";
            string          result             = templatesProcessor.Process(template, new Dictionary <string, string>()
            {
                { "include", "0" }
            });

            result.Should().Be(beginning);
        }
Ejemplo n.º 5
0
        public void TemplateSetVariableCommand()
        {
            StringTemplates templatesProcessor = new StringTemplates();
            string          text           = "The quick brown fox";
            string          additionalText = " jumps";
            string          template       = $"{text}{templatesProcessor.CreateSetVariableBlock("i", "1")}{templatesProcessor.CreateIfBlock("i", "1", additionalText)}";
            string          result         = templatesProcessor.Process(template, new Dictionary <string, string>()
            {
            });

            result.Should().Be($"{text}{additionalText}");
        }
Ejemplo n.º 6
0
        public void TemplateSetVariableCommand_EarlierIfCommandLeftUnevaluated()
        {
            StringTemplates templatesProcessor = new StringTemplates();
            string          text           = "The quick brown fox";
            string          additionalText = " jumps";
            string          template       = $"{text}{templatesProcessor.CreateIfBlock("i", "1", additionalText)}{templatesProcessor.CreateSetVariableBlock("i", "1")}";
            string          result         = templatesProcessor.Process(template, new Dictionary <string, string>()
            {
            });

            result.Should().NotBe($"{text}{additionalText}");
            // the result will be {text} plus the unevaluated IF command.
        }
Ejemplo n.º 7
0
        public void TemplateSetVariableCommand_LaterChangeInVariableRegisteredByEncoding()
        {
            StringTemplates templatesProcessor = new StringTemplates();
            string          text           = "The quick brown fox";
            string          additionalText = " jumps";
            // The variable is set to 0 before the If block and to 1 after the if block. We want the If block to reflect what happens afterward. So, We can use two reprocess blocks. The inner reprocess block has a cycle constraint, and the result is that its commands are encoded so that they won't be evaluated. The initial evaluation will reduce the cycle count and then unencode, so when we get to the outer reprocess block, the inner reprocess block will need to be executed.
            string template = $"{text}{templatesProcessor.CreateSetVariableBlock("i", "0")}{templatesProcessor.CreateReprocessBlock(templatesProcessor.CreateIfBlock("i", "1", additionalText), 1)}{templatesProcessor.CreateSetVariableBlock("i", "1")}";

            template = templatesProcessor.CreateReprocessBlock(template, 0); // this is the outer reprocess block -- by the time it runs, everything within it will have run, but the inner reprocess block will have merely been unencoded, so the if command will not have run
            string result = templatesProcessor.Process(template, new Dictionary <string, string>()
            {
            });

            result.Should().Be($"{text}{additionalText}");
        }
Ejemplo n.º 8
0
        public void TemplateSetVariableCommand_LaterChangeInInitiallyNullVariableRegistered()
        {
            StringTemplates templatesProcessor = new StringTemplates();
            string          text           = "The quick brown fox";
            string          additionalText = " jumps";
            // The initial If command will see that the variable i is null and it will not be processed initially. Then it will be processed within the
            // broader reprocess block after the variable i has been set.
            string template = $"{text}{templatesProcessor.CreateIfBlock("i", "1", additionalText)}{templatesProcessor.CreateSetVariableBlock("i", "1")}";

            template = templatesProcessor.CreateReprocessBlock(template, 0);
            string result = templatesProcessor.Process(template, new Dictionary <string, string>()
            {
            });

            result.Should().Be($"{text}{additionalText}");
        }
Ejemplo n.º 9
0
 public ReprocessCommand(StringTemplates stringTemplate) : base(stringTemplate)
 {
 }
Ejemplo n.º 10
0
 public ForCommand(StringTemplates stringTemplate) : base(stringTemplate)
 {
 }
Ejemplo n.º 11
0
 public VariableCommand(StringTemplates stringTemplate) : base(stringTemplate)
 {
 }
Ejemplo n.º 12
0
 public ContainsCommand(StringTemplates stringTemplate) : base(stringTemplate)
 {
 }
Ejemplo n.º 13
0
 public CommandBase(StringTemplates stringTemplate)
 {
     StringTemplate = stringTemplate;
 }