public ContextControlStringMatcher(string context, IControlStringMatcher matcher)
        {
            if (matcher == null)
            {
                throw new ArgumentNullException("matcher");
            }

            Context = context;
            Matcher = matcher;
        }
        public ContextControlStringMatcher(string context, IControlStringMatcher matcher)
        {
            if (string.IsNullOrEmpty(context))
            {
                throw new ArgumentException("Argument cannot be null or the empty string.", nameof(context));
            }

            Context = context;
            Matcher = matcher ?? throw new ArgumentNullException(nameof(matcher));
        }
示例#3
0
 public Item()
 {
     matcher = new ControlStringMatcherCollection(new List <IControlStringMatcher>()
     {
         new ValueControlStringMatcher("Prefix", () => prefix),
         new ValueControlStringMatcher("Item", () => item),
         new ValueControlStringMatcher("Addon", () => addon),
         new ValueControlStringMatcher("FullName", () => FullName),
         new ValueControlStringMatcher("Postfix", () => postfix),
         new ValueControlStringMatcher("Name", () => name)
     });
 }
示例#4
0
        public void Matches_WhenFirstValueIsContextAndSubMatcherMatches_ReturnsTrue([Frozen] IControlStringMatcher submatcher, ContextControlStringMatcher unit)
        {
            Mock.Get(submatcher).Setup(x => x.Matches(It.IsAny <ControlString>())).Returns(true);

            unit.Context = "foo";

            var fixture = new Fixture();

            fixture.Customizations.Add(new InlineConstructorParams <ControlString>(0, 3, new Queue <string>(new[] { unit.Context })));

            var controlString = fixture.Create <ControlString>();

            unit.Matches(controlString).ShouldBeTrue();
        }
示例#5
0
            public Pronoun(string singular, string singularObject, string possessive, string reflexive, bool verbsEndInS)
            {
                Singular       = singular;
                SingularObject = singularObject;
                Possessive     = possessive;
                Reflexive      = reflexive;

                matcher = new ControlStringMatcherCollection(new List <IControlStringMatcher>()
                {
                    new ValueControlStringMatcher("Singular", () => Singular),
                    new ValueControlStringMatcher("SingularObject", () => SingularObject),
                    new ValueControlStringMatcher("Possessive", () => Possessive),
                    new ValueControlStringMatcher("Reflexive", () => Reflexive),
                    new ContextControlStringMatcher("VerbEnding", new FuncControlStringMatcher(x => verbsEndInS ? "s" :string.Empty, x => true))
                });
            }
示例#6
0
        public void Matches_WhenAnyInternalMatchersMatch_ReturnsTrue([Frozen] IControlStringMatcher internalMatcher1, [Frozen] IControlStringMatcher internalMatcher2)
        {
            const string controlStringValue = "foo";

            Mock.Get(internalMatcher1).Setup(x => x.Matches(It.IsAny <ControlString>())).Returns(false);
            Mock.Get(internalMatcher2).Setup(x => x.Matches(It.IsAny <ControlString>())).Returns(true);

            var fixture = new Fixture();

            fixture.Customizations.Add(new InlineConstructorParams <ControlString>(0, 3, new Queue <string>(new[] { controlStringValue })));
            fixture.Customizations.Add(new InlineConstructorParams <ControlStringMatcherCollection>((object)new[] { internalMatcher1, internalMatcher2 }));

            var controlString = fixture.Create <ControlString>();

            var unit = fixture.Create <ControlStringMatcherCollection>();

            unit.Matches(controlString).ShouldBeTrue();
        }
示例#7
0
        public void Match_WhenFirstValueIsContext_ExecutesSecondControlStringMatcher([Frozen] IControlStringMatcher submatcher, ContextControlStringMatcher unit)
        {
            Mock.Get(submatcher).Setup(x => x.Matches(It.IsAny <ControlString>())).Returns(true);

            unit.Context = "foo";

            var expected = "bar";

            var fixture = new Fixture();

            fixture.Customizations.Add(new InlineConstructorParams <ControlString>(0, 3, new Queue <string>(new[] { unit.Context, expected })));

            var controlString = fixture.Create <ControlString>();

            unit.Match(controlString);

            Mock.Get(unit.Matcher).Verify(x => x.Match(It.Is <ControlString>(y => y.Values.Peek() == expected)));
        }
示例#8
0
        public void Match_PassesToFirstMatchingInternalMatcher([Frozen] IControlStringMatcher internalMatcher1, [Frozen] IControlStringMatcher internalMatcher2)
        {
            const string controlStringValue = "foo";

            var internalMatcher1Mock = Mock.Get(internalMatcher1);

            internalMatcher1Mock.Setup(x => x.Matches(It.IsAny <ControlString>())).Returns(false);
            Mock.Get(internalMatcher2).Setup(x => x.Matches(It.IsAny <ControlString>())).Returns(true);

            var fixture = new Fixture();

            fixture.Customizations.Add(new InlineConstructorParams <ControlString>(0, 3, new Queue <string>(new[] { controlStringValue })));
            fixture.Customizations.Add(new InlineConstructorParams <ControlStringMatcherCollection>((object)new[] { internalMatcher1, internalMatcher2 }));

            var controlString = fixture.Create <ControlString>();

            var unit = fixture.Create <ControlStringMatcherCollection>();

            unit.Match(controlString);

            internalMatcher1Mock.Verify(x => x.Match(It.IsAny <ControlString>()));
        }
示例#9
0
        public void Parse_WhenMatchingTransformerCannotBeFound_ThrowsMissingTransformerException([Frozen] IControlStringFinder finder, [Frozen] IControlStringMatcher matcher, [Frozen] ITransformer transformer, Parser unit)
        {
            var fixture = new Fixture();

            fixture.Customizations.Add(new InlineConstructorParams <ControlString>(0, 9, new Queue <string>(new[] { "foo" }), new Queue <string>(new[] { "baz" })));

            var controlString = fixture.Create <ControlString>();

            Mock.Get(finder).Setup(x => x.FindAllControlStrings(It.IsAny <string>())).Returns(new[] { controlString });

            Mock.Get(matcher).Setup(x => x.Matches(It.IsAny <ControlString>())).Returns(true);
            Mock.Get(matcher).Setup(x => x.Match(It.IsAny <ControlString>())).Returns("bar");

            Mock.Get(transformer).Setup(x => x.Matches(It.IsAny <string>())).Returns(false);

            Should.Throw <MissingTransformerException>(() => unit.Parse("{foo|baz}"));
        }
示例#10
0
        public void Parse_WhenTransformerSyntaxIsUsed_TransformsMatchedControlStrings([Frozen] IControlStringFinder finder, [Frozen] IControlStringMatcher matcher, [Frozen] ITransformer transformer, Parser unit)
        {
            var fixture = new Fixture();

            fixture.Customizations.Add(new InlineConstructorParams <ControlString>(0, 9, new Queue <string>(new[] { "foo" }), new Queue <string>(new[] { "baz" })));

            var controlString = fixture.Create <ControlString>();

            Mock.Get(finder).Setup(x => x.FindAllControlStrings(It.IsAny <string>())).Returns(new[] { controlString });

            Mock.Get(matcher).Setup(x => x.Matches(It.IsAny <ControlString>())).Returns(true);
            Mock.Get(matcher).Setup(x => x.Match(It.IsAny <ControlString>())).Returns("bar");

            Mock.Get(transformer).Setup(x => x.Transform(It.IsAny <string>(), It.IsAny <string>())).Returns("bash");
            Mock.Get(transformer).Setup(x => x.Matches(It.IsAny <string>())).Returns(true);

            var actual = unit.Parse("{foo|baz}");

            actual.ShouldBe("bash");
        }
示例#11
0
        public void Parse_ReplacesControlStringsInInputWithMatcherOutput([Frozen] IControlStringFinder finder, [Frozen] IControlStringMatcher matcher, Parser unit)
        {
            var fixture = new Fixture();

            fixture.Customizations.Add(new InlineConstructorParams <ControlString>(0, 5, new Queue <string>(new[] { "foo" })));

            var controlString = fixture.Create <ControlString>();

            Mock.Get(finder).Setup(x => x.FindAllControlStrings(It.IsAny <string>())).Returns(new[] { controlString });

            Mock.Get(matcher).Setup(x => x.Matches(It.IsAny <ControlString>())).Returns(true);
            Mock.Get(matcher).Setup(x => x.Match(It.IsAny <ControlString>())).Returns("bar");

            var actual = unit.Parse("{foo}");

            actual.ShouldBe("bar");
        }
示例#12
0
 public Parser(IControlStringFinder finder, IControlStringMatcher matcher, ITransformer transformer)
 {
     this.finder      = finder ?? throw new System.ArgumentNullException(nameof(finder));
     this.matcher     = matcher ?? throw new System.ArgumentNullException(nameof(matcher));
     this.transformer = transformer;
 }
示例#13
0
 public Parser(IControlStringMatcher matcher)
 {
     this.matcher = matcher;
 }