Example #1
0
        void ShouldIgnoreEmptyMacros()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?Mac={}1", inputDevice);

            Assert.Equal("http://example.com?Mac={}1", parsed);
        }
Example #2
0
        void ShouldIgnoreUnfinishedMacros2()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?Mac={Mac&Ip={Ip}", inputDevice);

            Assert.Equal("http://example.com?Mac={Mac&Ip=192.168.1.1", parsed);
        }
Example #3
0
        void ShouldIgnoreUnfinishedMacros4()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?Mac=}Mac&Ip=1234", inputDevice);

            Assert.Equal("http://example.com?Mac=}Mac&Ip=1234", parsed);
        }
Example #4
0
        void ShouldNotTranslateNonMacroStrings()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?Mac={Mac}&Ip={Ip}", inputDevice);

            Assert.Equal("http://example.com?Mac=001122334455&Ip=192.168.1.1", parsed);
        }
Example #5
0
        void ShouldIgnoreUnfinishedMacros()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?Mac={Mac}&Ip={Ip", inputDevice);

            Assert.Equal("http://example.com?Mac=001122334455&Ip={Ip", parsed);
        }
Example #6
0
        void ShouldTranslateMac()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?mac={Mac}", inputDevice);

            Assert.Equal("http://example.com?mac=001122334455", parsed);
        }
Example #7
0
        void ShouldTranslateMacAndIpAndName()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?mac={Mac}&ip={Ip}&name={Name}", inputDevice);

            Assert.Equal("http://example.com?mac=001122334455&ip=192.168.1.1&name=server", parsed);
        }
Example #8
0
        void ShouldNotParseMissingProperties()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?Mac={aaa}1", inputDevice);

            Assert.Equal("http://example.com?Mac={aaa}1", parsed);
        }
Example #9
0
        private string ParsePath(string path)
        {
            if (macroVariables == null)
            {
                macroVariables = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
                {
                    { "slot", Root }
                }
            }
            ;

            var macro = new MacroParser(macroVariables, VariableProviders.Default);

            return(Environment.ExpandEnvironmentVariables(macro.Parse(path)));
        }
    }
Example #10
0
        protected string ExpandVariables(string value)
        {
            if (value == null)
            {
                return(value);
            }

            var macros = new MacroParser(ParentTask.Variables, VariableProviders.Default);
            var val    = macros.Parse(value);

            if (val.IndexOfAny(new char[] { ' ', '\t' }) != -1)
            {
                val = $"\"{value}\"";
            }

            return(val);
        }
Example #11
0
        public void TestMacro()
        {
            string testInput =
                "//# wait 15000 Assembly QtVsTools => GetAssembly(\"QtVsTools\")" + "\r\n" +
                "var VsixType = QtVsTools.GetType(\"QtVsTools.Vsix\");" + "\r\n" +
                "var VsixInstance = VsixType.GetProperty(\"Instance\"," + "\r\n" +
                "    BindingFlags.Public | BindingFlags.Static);" + "\r\n" +
                "//# wait 15000 object Vsix => VsixInstance.GetValue(null)" + "\r\n" +
                "Result = \"(ok)\";";

            var macroLines = Parser.Parse(testInput);

            Debug.Assert(macroLines != null);
            Debug.Assert(macroLines.Count() == 6);
            Debug.Assert(macroLines.Skip(0).First() is Statement);
            Debug.Assert(macroLines.Skip(1).First() is CodeLine);
            Debug.Assert(macroLines.Skip(2).First() is CodeLine);
            Debug.Assert(macroLines.Skip(3).First() is CodeLine);
            Debug.Assert(macroLines.Skip(4).First() is Statement);
            Debug.Assert(macroLines.Skip(5).First() is CodeLine);
        }
Example #12
0
 public ActiveMacro(MacroNode node, string contents)
 {
     this.Node  = node;
     this.Steps = MacroParser.Parse(contents).ToList();
 }