Пример #1
0
        public void TestRegexMatchMacroFalse()
        {
            const string          variableName   = "isMatch";
            const string          sourceVariable = "originalValue";
            RegexMatchMacroConfig macroConfig    = new RegexMatchMacroConfig(variableName, null, sourceVariable, @"(((?<=\.)|^)(?=\d)|[^\w\.])");

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = A.Fake <IRunnableProjectConfig>();
            IParameterSet          parameters = new RunnableProjectGenerator.ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(_engineEnvironmentSettings, parameters);

            const string sourceValue   = "A1234test";
            const bool   expectedValue = false;

            Parameter sourceParam = new Parameter
            {
                IsVariable = true,
                Name       = sourceVariable
            };

            variables[sourceVariable] = sourceValue;
            setter(sourceParam, sourceValue);

            RegexMatchMacro macro = new RegexMatchMacro();

            macro.EvaluateConfig(_engineEnvironmentSettings, variables, macroConfig, parameters, setter);

            Assert.True(parameters.TryGetParameterDefinition(variableName, out ITemplateParameter newParam));
            bool newValue = (bool)parameters.ResolvedValues[newParam];

            Assert.Equal(newValue, expectedValue);
        }
Пример #2
0
        public IMacroConfig CreateConfig(IEngineEnvironmentSettings environmentSettings, IMacroConfig rawConfig)
        {
            if (!(rawConfig is GeneratedSymbolDeferredMacroConfig deferredConfig))
            {
                throw new InvalidCastException("Couldn't cast the rawConfig as a GeneratedSymbolDeferredMacroConfig");
            }

            if (!deferredConfig.Parameters.TryGetValue("source", out JToken sourceVarToken))
            {
                throw new ArgumentNullException("source");
            }

            string sourceVariable = sourceVarToken.ToString();

            if (!deferredConfig.Parameters.TryGetValue("pattern", out JToken patternToken))
            {
                throw new ArgumentNullException("pattern");
            }

            string pattern = patternToken.ToString();

            //Warn the user if they explicitly specify something other than "bool" for DataType for this macro
            if (deferredConfig.DataType != null &&
                !string.Equals(deferredConfig.DataType, "bool", StringComparison.OrdinalIgnoreCase))
            {
                environmentSettings.Host.Logger.LogDebug(LocalizableStrings.Authoring_NonBoolDataTypeForRegexMatch);
            }

            IMacroConfig realConfig = new RegexMatchMacroConfig(deferredConfig.VariableName, deferredConfig.DataType, sourceVariable, pattern);

            return(realConfig);
        }