Exemplo n.º 1
0
        public void TestIsPrefixedByOneOfPrefixes()
        {
            var good0 = "%s%foo";
            var good1 = "%d%foo";
            var bad0  = "%sfoo";
            var bad1  = "%%dfoo";
            var bad2  = "foo";

            Assert.True(StrHelper.IsPrefixedByOneOfPrefixes(good0, JsMrgHtmlVarRunner.HtmlVarPrefixes));
            Assert.True(StrHelper.IsPrefixedByOneOfPrefixes(good1, JsMrgHtmlVarRunner.HtmlVarPrefixes));
            Assert.False(StrHelper.IsPrefixedByOneOfPrefixes(bad0, JsMrgHtmlVarRunner.HtmlVarPrefixes));
            Assert.False(StrHelper.IsPrefixedByOneOfPrefixes(bad1, JsMrgHtmlVarRunner.HtmlVarPrefixes));
            Assert.False(StrHelper.IsPrefixedByOneOfPrefixes(bad2, JsMrgHtmlVarRunner.HtmlVarPrefixes));
        }
        /// <summary>
        /// This method verifies if all html vars that should be handled in given file have the right prefix.
        /// </summary>
        private void VerifyVarCommands(string commandParamAndVars, out List <string> varParams)
        {
            varParams = StrHelper.GetWhiteSpaceSplittedStrArr(commandParamAndVars);
            if (varParams.Count > 1)
            {
                varParams.RemoveAt(0);
                foreach (var varParam in varParams)
                {
                    if (false == StrHelper.IsPrefixedByOneOfPrefixes(varParam, HtmlVarPrefixes))
                    {
                        throw new JsMrgRunnerException($"htmlvar var replacements have to start with either <''> or <\"\">, found: {varParam} in command {MatchInspection.Match.Value}");
                    }
                }
            }

            // Else: Nothing to do.
        }