public string ConstructorShouldWorkCorrectly(string displayName, string description, string pattern, string complete)
 {
     var isMatchProcedure = (pattern != null) ? (v, o) => v == pattern : (Func<string, MatchingOption, bool>)null;
     var completeProcedure = (complete != null) ? (v, o) => complete : (Func<string, MatchingOption, string>)null;
     var testee = new RegexAutoCompleteItem(displayName, description, isMatchProcedure, completeProcedure);
     return String.Format("{0}:{1}", testee.DisplayName, testee.Description);
 }
        public void RegisterVariableShouldWorkCorrectly(string pattern, object value)
        {
            var item = new RegexAutoCompleteItem("", "", (v, o) => true, (v, o) => v);
            testee.RegisterVariable(pattern, o => value, item);

            Assert.AreEqual(1, evaluators.Count);
            Assert.AreEqual(1, testee.AutocompleteItems.Count());
            Assert.AreSame(item, testee.AutocompleteItems.ElementAt(0));
        }
        /// <summary>
        /// Registers a new mapping between a regular expression and a value generator.
        /// </summary>
        /// <param name="regex">The regular expression to find out a variable.</param>
        /// <param name="procedure">The value generator.</param>
        /// <param name="item">The autocomplete item.</param>
        public void RegisterVariable(Regex regex, Func<Match, object> procedure, RegexAutoCompleteItem item)
        {
            if (regex == null) throw new ArgumentNullException("regex");
            if (procedure == null) throw new ArgumentNullException("procedure");
            if (item == null) throw new ArgumentNullException("item");

            Logger.Verbose("Registered the specified pattern '{0}'.", regex.ToString());

            evaluators[regex] = procedure;
            Register(item);
        }
        public object EvaluateShouldWorkCorrectly(string value)
        {
            var item = new RegexAutoCompleteItem("", "", (v, o) => true, (v, o) => v);
            testee.RegisterVariable("^x.*$", o => 10, item);
            testee.RegisterVariable("^y.*$", o => "foo", item);
            testee.RegisterVariable("^z.*$", o => true, item);

            var operand = testee.Evaluate(null, value);

            return Expression.Lambda(operand.Expression).Compile().DynamicInvoke();
        }
        public void CompleteShouldCallCompleteProcedure()
        {
            var counter = 0;
            Func<string, MatchingOption, string> proc = (v, o) =>
            {
                counter++;
                return v;
            };

            var testee = new RegexAutoCompleteItem("value", "description", (v, o) => true, proc);
            testee.Complete("", new MatchingOption());

            Assert.AreEqual(1, counter);
        }
        public void IsMatchShouldCallIsMatchProcedure()
        {
            var counter = 0;
            Func<string, MatchingOption, bool> proc = (v, o) =>
            {
                counter++;
                return true;
            };

            var testee = new RegexAutoCompleteItem("value", "description", proc, (v, o) => v);
            testee.IsMatch("", new MatchingOption());

            Assert.AreEqual(1, counter);
        }
 /// <summary>
 /// Registers a new mapping between a pattern of regular expression and a value generator.
 /// </summary>
 /// <param name="pattern">The pattern of regular expression to find out a variable.</param>
 /// <param name="procedure">The value generator.</param>
 /// <param name="item">The autocomplete item.</param>
 public void RegisterVariable(string pattern, Func<Match, object> procedure, RegexAutoCompleteItem item)
 {
     if (pattern == null) throw new ArgumentNullException("pattern");
     RegisterVariable(new Regex(pattern, RegexOptions.Compiled), procedure, item);
 }
        public void EvaluateShouldReturnNullWhenSpecifiedVariableIsNotMatchedAnyPattnens(string value)
        {
            var item = new RegexAutoCompleteItem("", "", (v, o) => true, (v, o) => v);
            testee.RegisterVariable("^x.*$", o => 10, item);
            testee.RegisterVariable("^y.*$", o => "foo", item);
            testee.RegisterVariable("^z.*$", o => true, item);

            Assert.IsNull(testee.Evaluate(null, value));
        }
 public void RegisterVariableShouldThrowExceptionWhenProcedureIsNull()
 {
     var regex = new Regex("");
     var item = new RegexAutoCompleteItem("", "", (v, o) => true, (v, o) => v);
     Assert.Throws<ArgumentNullException>(() => testee.RegisterVariable(regex, null, item));
 }
 public void RegisterVariableShouldThrowExcepionWhenRegexIsNull()
 {
     Regex regex = null;
     var item = new RegexAutoCompleteItem("", "", (v, o) => true, (v, o) => v);
     Assert.Throws<ArgumentNullException>(() => testee.RegisterVariable(regex, o => o, item));
 }