public void TestCaseDirectiveEquality()
        {
            var directive1 = new RippedOpenDirective(
                Tag.Parse("IF ? IS (BAD GOOD) TO $ THEN"),
                Tag.Parse("ELSE IF NOT SET"),
                Tag.Parse("END ALL $ LIFE"));

            var directive2 = new RippedOpenDirective(
                Tag.Parse("if ? is (good bad) to $ then"),
                Tag.Parse("else if not set"),
                Tag.Parse("end all $ life"));

            Assert.AreEqual(directive1, directive1);
            Assert.IsFalse(directive1.Equals(null, StringComparer.OrdinalIgnoreCase));
            Assert.IsTrue(directive1.Equals(directive1, StringComparer.OrdinalIgnoreCase));
            Assert.IsTrue(directive1.Equals(directive1, StringComparer.CurrentCulture));

            Assert.AreEqual(directive2, directive2);
            Assert.IsFalse(directive2.Equals(null, StringComparer.OrdinalIgnoreCase));
            Assert.IsTrue(directive2.Equals(directive2, StringComparer.OrdinalIgnoreCase));
            Assert.IsTrue(directive2.Equals(directive2, StringComparer.CurrentCulture));

            Assert.AreNotEqual(directive1, directive2);
            Assert.IsTrue(directive1.Equals(directive2, StringComparer.OrdinalIgnoreCase));
            Assert.IsFalse(directive1.Equals(directive2, StringComparer.CurrentCulture));

            Assert.AreNotEqual(directive1.GetHashCode(), directive2.GetHashCode());
            Assert.AreEqual(directive1.GetHashCode(StringComparer.CurrentCultureIgnoreCase), directive2.GetHashCode(StringComparer.CurrentCultureIgnoreCase));
        }
Example #2
0
        public void TestCaseInterpreterRegistrationAndExceptions()
        {
            var interpreter = new Interpreter(new Tokenizer("irrelevant"), ExpressionFlowSymbols.Default, StringComparer.CurrentCulture);

            ExpectArgumentNullException("directive", () => interpreter.RegisterDirective(null));
            ExpectArgumentNullException("operator", () => interpreter.RegisterOperator(null));

            interpreter.RegisterOperator(new ArithmeticNeutralOperator("A", TypeConverter));
            ExpectOperatorAlreadyRegisteredException("A", () => interpreter.RegisterOperator(new ArithmeticNeutralOperator("A", TypeConverter)));
            interpreter.RegisterOperator(new ArithmeticSumOperator("A", TypeConverter));
            ExpectOperatorAlreadyRegisteredException("A", () => interpreter.RegisterOperator(new ArithmeticSumOperator("A", TypeConverter)));

            ExpectOperatorAlreadyRegisteredException("(", () => interpreter.RegisterOperator(new ArithmeticNeutralOperator("(", TypeConverter)));
            interpreter.RegisterOperator(new ArithmeticNeutralOperator(")", TypeConverter));
            interpreter.RegisterOperator(new ArithmeticNeutralOperator(".", TypeConverter));
            interpreter.RegisterOperator(new ArithmeticNeutralOperator(",", TypeConverter));

            interpreter.RegisterOperator(new ArithmeticSumOperator("(", TypeConverter));
            ExpectOperatorAlreadyRegisteredException(")", () => interpreter.RegisterOperator(new ArithmeticSumOperator(")", TypeConverter)));
            ExpectOperatorAlreadyRegisteredException(".", () => interpreter.RegisterOperator(new ArithmeticSumOperator(".", TypeConverter)));
            ExpectOperatorAlreadyRegisteredException(",", () => interpreter.RegisterOperator(new ArithmeticSumOperator(",", TypeConverter)));

            var d1 = new RippedOpenDirective(Tag.Parse("HELLO"));
            var d2 = new RippedOpenDirective(Tag.Parse("WORLD"));

            interpreter.RegisterDirective(d1);
            interpreter.RegisterDirective(d2);
            interpreter.RegisterDirective(d1);
        }
        public void TestCaseDirectiveEqualityExceptions()
        {
            var directive1 = new RippedOpenDirective(Tag.Parse("NOTHING"));

            ExpectArgumentNullException("comparer", () => directive1.Equals(directive1, null));
            ExpectArgumentNullException("comparer", () => directive1.GetHashCode(null));
        }
        public void TestCaseDirectiveConstructorSameTagAFewTimes()
        {
            var tag = Tag.Parse("I AM ? TAG");

            var directive = new RippedOpenDirective(tag, tag, tag);
            var repr      = directive.ToString();

            Assert.AreEqual("{I AM ? TAG}...{I AM ? TAG}...{I AM ? TAG}", repr);
        }
        public void TestCaseDirectiveConstructorOneTag()
        {
            var tag = Tag.Parse("HELLO $ WORLD");

            var directive = new RippedOpenDirective(tag);
            var repr      = directive.ToString();

            Assert.AreEqual("{HELLO $ WORLD}", repr);
        }
        public void TestCaseDirectiveConstructorTwoTags()
        {
            var tag1 = Tag.Parse("IF $ THEN");
            var tag2 = Tag.Parse("END IF");

            var directive = new RippedOpenDirective(tag1, tag2);
            var repr      = directive.ToString();

            Assert.AreEqual("{IF $ THEN}...{END IF}", repr);
        }
Example #7
0
        public void TestCaseInterpreterConstructNoMatchingTag1()
        {
            var directive = new RippedOpenDirective(
                Tag.Parse("OPEN"),
                Tag.Parse("CLOSE"));

            var interpreter = new Interpreter(new Tokenizer("{OPEN}text goes here"),
                                              ExpressionFlowSymbols.Default, StringComparer.OrdinalIgnoreCase)
                              .RegisterDirective(directive);

            ExpectUnmatchedDirectiveTagException(new Directive[] { directive }, 0, () => interpreter.Compile());
        }
Example #8
0
        public void TestCaseInterpreterConstructUnexpectedTag1()
        {
            var directive = new RippedOpenDirective(
                Tag.Parse("A"),
                Tag.Parse("B"));

            var interpreter = new Interpreter(new Tokenizer("{B}"),
                                              ExpressionFlowSymbols.Default, StringComparer.OrdinalIgnoreCase)
                              .RegisterDirective(directive);

            ExpectUnexpectedTagException("B", 0, () => interpreter.Compile());
        }
        public void TestCaseEvaluationSingleTagDirective()
        {
            var directive = new RippedOpenDirective(
                Tag.Parse("T"));

            var evaluable = new Interpreter(new Tokenizer("{T}"), ExpressionFlowSymbols.Default,
                                            StringComparer.OrdinalIgnoreCase)
                            .RegisterDirective(directive).Compile();

            var exo = Evaluate(evaluable, StringComparer.OrdinalIgnoreCase);

            Assert.AreEqual("-> {T} -> Restart -> () -> {T} -> Terminate ->", exo);
        }
        public void TestCaseEvaluationThreeTagDirective()
        {
            var directive = new RippedOpenDirective(
                Tag.Parse("T1"),
                Tag.Parse("T2"),
                Tag.Parse("T3"));

            var evaluable = new Interpreter(new Tokenizer("{T1}first{T2}second{T3}"),
                                            ExpressionFlowSymbols.Default, StringComparer.OrdinalIgnoreCase)
                            .RegisterDirective(directive).Compile();

            var exo = Evaluate(evaluable, StringComparer.OrdinalIgnoreCase);

            Assert.AreEqual("-> {T1} -> Evaluate -> (first) -> {T2} -> Evaluate -> (second) -> {T3} -> Restart -> () -> {T1} -> Skip -> () -> {T2} -> Skip -> () -> {T3} -> Terminate ->", exo);
        }
Example #11
0
        public void TestCaseInterpreterConstructNoMatchingTag6()
        {
            var directive1 = new RippedOpenDirective(
                Tag.Parse("T"),
                Tag.Parse("T1"));
            var directive2 = new RippedOpenDirective(
                Tag.Parse("T"),
                Tag.Parse("T2"));

            var interpreter = new Interpreter(new Tokenizer("{T}{T}{T2}"),
                                              ExpressionFlowSymbols.Default, StringComparer.OrdinalIgnoreCase)
                              .RegisterDirective(directive1).RegisterDirective(directive2);

            ExpectUnmatchedDirectiveTagException(new Directive[] { directive1, directive2 }, 0, () => interpreter.Compile());
        }
Example #12
0
        public void TestCaseInterpreterConstructSelection2()
        {
            var directive1 = new RippedOpenDirective(Tag.Parse("MATCH ME ?"));
            var directive2 = new RippedOpenDirective(Tag.Parse("MATCH ME $"));

            var interpreter1 = new Interpreter(new Tokenizer("{MATCH ME identifier}"),
                                               ExpressionFlowSymbols.Default, StringComparer.OrdinalIgnoreCase)
                               .RegisterDirective(directive1).RegisterDirective(directive2);
            var interpreter2 = new Interpreter(new Tokenizer("{MATCH ME identifier}"),
                                               ExpressionFlowSymbols.Default, StringComparer.OrdinalIgnoreCase)
                               .RegisterDirective(directive2).RegisterDirective(directive1);

            var repr1 = interpreter1.Compile().ToString();
            var repr2 = interpreter2.Compile().ToString();

            Assert.AreEqual("(({MATCH ME identifier}))", repr1);
            Assert.AreEqual("(({MATCH ME identifier}))", repr2);
        }
Example #13
0
        public void TestCaseInterpreterConstructSelection1()
        {
            var directive1 = new RippedOpenDirective(
                Tag.Parse("A"),
                Tag.Parse("B"));
            var directive2 = new RippedOpenDirective(
                Tag.Parse("C"),
                Tag.Parse("D"));

            var interpreter = new Interpreter(new Tokenizer("{A}1{C}2{A}3{B}4{D}5{B}"),
                                              ExpressionFlowSymbols.Default, StringComparer.OrdinalIgnoreCase)
                              .RegisterDirective(directive1).RegisterDirective(directive2);

            var evaluable = interpreter.Compile();
            var repr      = evaluable.ToString();

            Assert.AreEqual("(({A}1({C}2({A}3{B})4{D})5{B}))", repr);
        }
Example #14
0
        public void TestCaseInterpreterConstructSelection4()
        {
            var directive1 = new RippedOpenDirective(
                Tag.Parse("IF ?"),
                Tag.Parse("END"));
            var directive2 = new RippedOpenDirective(
                Tag.Parse("IF ?"),
                Tag.Parse("ELSE"),
                Tag.Parse("END"));

            var repr = new Interpreter(new Tokenizer("{IF A}1{IF B}2{ELSE}3{END}4{IF A}5{END}6{END}"),
                                       ExpressionFlowSymbols.Default, StringComparer.OrdinalIgnoreCase)
                       .RegisterDirective(directive1)
                       .RegisterDirective(directive2)
                       .Compile()
                       .ToString();

            Assert.AreEqual("(({IF A}1({IF B}2{ELSE}3{END})4({IF A}5{END})6{END}))", repr);
        }
Example #15
0
        public void TestCaseInterpreterConstructSelection3()
        {
            var directive1 = new RippedOpenDirective(
                Tag.Parse("START"),
                Tag.Parse("MID"),
                Tag.Parse("END"));
            var directive2 = new RippedOpenDirective(
                Tag.Parse("START"),
                Tag.Parse("MID"),
                Tag.Parse("OTHER END"));

            var repr = new Interpreter(new Tokenizer("{START}{MID}{OTHER END}"),
                                       ExpressionFlowSymbols.Default, StringComparer.OrdinalIgnoreCase)
                       .RegisterDirective(directive1)
                       .RegisterDirective(directive2)
                       .Compile()
                       .ToString();

            Assert.AreEqual("(({START}{MID}{OTHER END}))", repr);
        }