public void Rules_are_persisted_in_transformer()
        {
            var rules       = new List <IGrammarTransformRule>();
            var transformer = new GrammarTransformer(rules);

            Assert.Same(rules, transformer.Rules);
        }
        public void Throws_on_no_applicable_rule()
        {
            var rules       = new List <IGrammarTransformRule>();
            var transformer = new GrammarTransformer(rules);

            Assert.Throws <NoMatchingGrammarRuleException>(
                () => transformer.Transform("foo"));
        }
        public void Does_not_use_non_applicable_rule()
        {
            var rules = new List <IGrammarTransformRule> {
                new TestUselessRule()
            };
            var transformer = new GrammarTransformer(rules);

            Assert.Throws <NoMatchingGrammarRuleException>(
                () => transformer.Transform("foo"));
        }
        public void Rules_are_used_to_transform_string()
        {
            var rules = new List <IGrammarTransformRule> {
                new TestRule()
            };
            var transformer = new GrammarTransformer(rules);
            var result      = transformer.Transform("foo");

            Assert.Equal("bar", result);
        }
        /// <summary>
        /// Apply the given grammar rules to the input string
        /// </summary>
        /// <param name="str">Current string instance</param>
        /// <param name="rules">Rules to apply</param>
        public static string PerformGrammarTransformation(this string str, IEnumerable <IGrammarTransformRule> rules)
        {
            var transformer = new GrammarTransformer(rules);

            return(transformer.Transform(str));
        }