Example #1
0
        public void MixedChildren()
        => OclParser.Execute(@"
                    MyBlock {
                        ChildBlock1 {


                        }
                        Child1 = 1
                        Child2 = 2


    ChildBlock2 ""Label"" {
        GrandChildBlock {}


        GrandChild = ""A""

    }
                    }
                ")
        .Should()
        .HaveChildrenExactly(new OclBlock("MyBlock")
        {
            new OclBlock("ChildBlock1"),
            new OclAttribute("Child1", 1),
            new OclAttribute("Child2", 2),

            new OclBlock("ChildBlock2", new[] { "Label" })
            {
                new OclBlock("GrandChildBlock"),
                new OclAttribute("GrandChild", "A")
            }
        });
Example #2
0
        public void CollectionTest1()
        {
            var stream = CharStreams.fromstring(@"package RobotsTestModel
            context aMotorsForward
            inv@0:
            Bag{ ""a"", ""bb"", ""ccc""}->select(self->size() = 2)->size() = 1
            inv@0:
            Bag{1,2,3}->forAll(x, y | x <> y implies x*y > 1)
            inv@0:
            Bag{1,2,3}->iterate(x; y : T = 0 | y + x) = 6
            inv@0:
            Set{""1"",""2"",""3""}->collect(self = ""0"")->size() = 3
            inv@0:
            Bag{""1"",""2"",""3""}->any(self.toInteger() > 2).toInteger() = 3
            inv@0:
            aMotorsForward->allInstances()->size() > -1
            endpackage");

            ITokenSource lexer  = new OclLexer(stream);
            ITokenStream tokens = new CommonTokenStream(lexer);
            var          parser = new OclParser(tokens)
            {
                BuildParseTree = true
            };
            IParseTree tree = parser.oclFile();

            Assert.IsTrue(tree.Accept(interpreter));
        }
Example #3
0
        public void NumberTest1()
        {
            var stream = CharStreams.fromstring(@"package RobotsTestModel
            context aMotorsForward
            inv@0:
            1->max(2) = 2
            inv@0:
            5->div(2) = 2
            inv@0:
            5->min(2) = 2
            inv@0:
            5->mod(2) = 1
            inv@0:
            5->abs() = 5
            endpackage");

            ITokenSource lexer  = new OclLexer(stream);
            ITokenStream tokens = new CommonTokenStream(lexer);
            var          parser = new OclParser(tokens)
            {
                BuildParseTree = true
            };
            IParseTree tree = parser.oclFile();

            Assert.IsTrue(tree.Accept(interpreter));
        }
Example #4
0
        public void StringTest1()
        {
            var stream = CharStreams.fromstring(@"package RobotsTestModel
            context aMotorsForward
            inv@0:
            ""ABC""->toLower() = ""abc""
            inv@0:
            ""123""->toInteger() = 123
            inv@0:
            ""123""->toReal() = 123
            inv@0:
            ""abc""->toUpper() = ""ABC""
            inv@0:
            ""abc""->concat(""cde"")->toUpper() = ""ABCCDE""
            inv@0:
            ""abc""->substring(1, 1) = ""a""
            endpackage");

            ITokenSource lexer  = new OclLexer(stream);
            ITokenStream tokens = new CommonTokenStream(lexer);
            var          parser = new OclParser(tokens)
            {
                BuildParseTree = true
            };
            IParseTree tree = parser.oclFile();

            Assert.IsTrue(tree.Accept(interpreter));
        }
Example #5
0
        public object Deserialize(string ocl, Type type)
        {
            var document = OclParser.Execute(ocl);

            return(type == typeof(OclDocument)
                ? document
                : Deserialize(document, type));
        }
Example #6
0
        public void Empty()
        => OclParser.Execute(@"
                    MyBlock {

                    }
                ")
        .Should()
        .HaveChildrenExactly(new OclBlock("MyBlock"));
 public void DictionaryEmpty()
 => OclParser.Execute(@"
         Properties = {
         }
         ")
 .Should()
 .HaveChildrenExactly(
     new OclAttribute("Properties", new Dictionary <string, string>())
     );
 public void MultipleInRoot()
 => OclParser.Execute(@"
         One = 1
         Two = 2
         ")
 .Should()
 .HaveChildrenExactly(
     new OclAttribute("One", 1),
     new OclAttribute("Two", 2)
     );
        public void Int(string input, int expected)
        {
            var result = OclParser.Execute(@"Foo = " + input);

            result
            .Should()
            .HaveChildrenExactly(new OclAttribute("Foo", expected));

            result.OfType <OclAttribute>().First().Value.Should().BeOfType(typeof(int));
        }
Example #10
0
 public void MultipleInRoot()
 => OclParser.Execute(@"
         MyBlock {}
         MyBlock {}
         ")
 .Should()
 .HaveChildrenExactly(
     new OclBlock("MyBlock"),
     new OclBlock("MyBlock")
     );
Example #11
0
 public void WithSingleAttributeChild()
 => OclParser.Execute(@"
             MyBlock {
                 Child = 1
             }
         ")
 .Should()
 .HaveChildrenExactly(new OclBlock("MyBlock")
 {
     new OclAttribute("Child", 1)
 });
Example #12
0
        public void WithMultipleAttributeChild()
        => OclParser.Execute(@"
                    MyBlock {
                        Child = 1
                        Child2 = 2

                    }
                ")
        .Should()
        .HaveChildrenExactly(new OclBlock("MyBlock")
        {
            new OclAttribute("Child", 1),
            new OclAttribute("Child2", 2)
        });
Example #13
0
        public void InvalidDocumentReportsCorrectLineNumber()
        {
            var fooBarFooBar = @"
                    Foo = ""Bar""

                    Foo = ""Bar
            ".ToUnixLineEndings();

            var(_, error) = OclParser.TryExecute(fooBarFooBar);

            var expected = "Parsing failure: unexpected '\n'; expected \" (Line 4, Column 31); recently consumed: Foo = \"Bar";

            error?.Should().Be(expected);
        }
 public void MultipleInBlock()
 => OclParser.Execute(@"
         MyBlock {
             One = 1
             Two = 2
         }
         ")
 .Should()
 .HaveChildrenExactly(
     new OclBlock("MyBlock")
 {
     new OclAttribute("One", 1),
     new OclAttribute("Two", 2)
 }
     );
 public void DictionaryOneItem()
 => OclParser.Execute(@"
         Properties = {
             ""One"" = ""1""
         }
         ")
 .Should()
 .HaveChildrenExactly(
     new OclAttribute("Properties",
                      new Dictionary <string, string>
 {
     { "One", "1" }
 }
                      )
     );
Example #16
0
 public void NestedBlocks()
 => OclParser.Execute(@"
             MyBlock {
                 ChildBlock {
                     GrandChildBlock {}
                 }
             }
         ")
 .Should()
 .HaveChildrenExactly(new OclBlock("MyBlock")
 {
     new OclBlock("ChildBlock")
     {
         new OclBlock("GrandChildBlock")
     }
 });
Example #17
0
        public void FuncTest1()
        {
            var stream = CharStreams.fromstring(@"package ObjectMetamodel
            context FunctionNode
            inv@2:
            self.params@1 <> self.callParams@2
            endpackage");

            ITokenSource lexer  = new OclLexer(stream);
            ITokenStream tokens = new CommonTokenStream(lexer);
            var          parser = new OclParser(tokens)
            {
                BuildParseTree = true
            };
            IParseTree tree = parser.oclFile();

            Assert.IsTrue(tree.Accept(interpreter));
        }
 public void Dictionary()
 => OclParser.Execute(@"
         Properties = {
             One.One = ""1""
             ""Two Two"" = ""2""
             ""Three\""Three"" = ""3""
         }
         ")
 .Should()
 .HaveChildrenExactly(
     new OclAttribute("Properties",
                      new Dictionary <string, string>
 {
     { "One.One", "1" },
     { "Two Two", "2" },
     { "Three\"Three", "3" }
 }
                      )
     );
Example #19
0
        private void CompileOCLs(string ocls)
        {
            var aspects = OclParser.ScanString(ocls);

            Console.WriteLine();

            var gens = new List <CodeGenerator>();

            foreach (Aspect aspect in aspects)
            {
                Console.WriteLine("Generating assembly for " + aspect.ConstraintName + ".");
                aspect.Print();
                gens.Add(GenCode(aspect));
            }

            Console.WriteLine();
            Console.WriteLine("Invoking Apply() methods.");
            foreach (var gen in gens)
            {
                gen.InvokeApplyMethod();
            }

            Console.WriteLine();
        }
 public void StringArray(string input)
 => OclParser.Execute(input)
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", new[] { "A", "B" }));
 public void EmptyArray(string input)
 => OclParser.Execute(input)
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", new string[0]));
 public void False()
 => OclParser.Execute("Foo = false")
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", false));
 public void True()
 => OclParser.Execute("Foo = true")
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", true));
 public void Decimal(string input, decimal expected)
 => OclParser.Execute(@"Foo = " + input)
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", expected));
 public void WithExtraWhitespace()
 => OclParser.Execute(" \t   Foo    = \t  \"Bar\"  \t  ")
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", "Bar"));
        public void StringInvalidEscape()
        {
            Action action = () => OclParser.Execute(@"Foo = ""\q""");

            action.Should().Throw <OclException>().WithMessage(@"Unrecognised character escape: \q");
        }
 public void Invalid(string input)
 {
     var(document, error) = OclParser.TryExecute(input);
     error.Should().NotBeEmpty();
     document.Should().BeNull();
 }
Example #28
0
 public void MultipleLabels()
 => OclParser.Execute(@"MyBlock ""Foo"" ""Bar"" ""Baz"" {}")
 .Should()
 .HaveChildrenExactly(new OclBlock("MyBlock", new[] { "Foo" }));
 public void String(string text, string expected)
 => OclParser.Execute($@"Foo = ""{text}""")
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", expected));
 public void Null()
 => OclParser.Execute("Foo = null")
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", null));