コード例 #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")
            }
        });
コード例 #2
0
ファイル: OclPluginTests.cs プロジェクト: SkyForce/REAL.NET
        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));
        }
コード例 #3
0
ファイル: OclPluginTests.cs プロジェクト: SkyForce/REAL.NET
        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));
        }
コード例 #4
0
ファイル: OclPluginTests.cs プロジェクト: SkyForce/REAL.NET
        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));
        }
コード例 #5
0
        public object Deserialize(string ocl, Type type)
        {
            var document = OclParser.Execute(ocl);

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

                    }
                ")
        .Should()
        .HaveChildrenExactly(new OclBlock("MyBlock"));
コード例 #7
0
 public void DictionaryEmpty()
 => OclParser.Execute(@"
         Properties = {
         }
         ")
 .Should()
 .HaveChildrenExactly(
     new OclAttribute("Properties", new Dictionary <string, string>())
     );
コード例 #8
0
 public void MultipleInRoot()
 => OclParser.Execute(@"
         One = 1
         Two = 2
         ")
 .Should()
 .HaveChildrenExactly(
     new OclAttribute("One", 1),
     new OclAttribute("Two", 2)
     );
コード例 #9
0
        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));
        }
コード例 #10
0
 public void MultipleInRoot()
 => OclParser.Execute(@"
         MyBlock {}
         MyBlock {}
         ")
 .Should()
 .HaveChildrenExactly(
     new OclBlock("MyBlock"),
     new OclBlock("MyBlock")
     );
コード例 #11
0
 public void WithSingleAttributeChild()
 => OclParser.Execute(@"
             MyBlock {
                 Child = 1
             }
         ")
 .Should()
 .HaveChildrenExactly(new OclBlock("MyBlock")
 {
     new OclAttribute("Child", 1)
 });
コード例 #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)
        });
コード例 #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);
        }
コード例 #14
0
 public void MultipleInBlock()
 => OclParser.Execute(@"
         MyBlock {
             One = 1
             Two = 2
         }
         ")
 .Should()
 .HaveChildrenExactly(
     new OclBlock("MyBlock")
 {
     new OclAttribute("One", 1),
     new OclAttribute("Two", 2)
 }
     );
コード例 #15
0
 public void DictionaryOneItem()
 => OclParser.Execute(@"
         Properties = {
             ""One"" = ""1""
         }
         ")
 .Should()
 .HaveChildrenExactly(
     new OclAttribute("Properties",
                      new Dictionary <string, string>
 {
     { "One", "1" }
 }
                      )
     );
コード例 #16
0
 public void NestedBlocks()
 => OclParser.Execute(@"
             MyBlock {
                 ChildBlock {
                     GrandChildBlock {}
                 }
             }
         ")
 .Should()
 .HaveChildrenExactly(new OclBlock("MyBlock")
 {
     new OclBlock("ChildBlock")
     {
         new OclBlock("GrandChildBlock")
     }
 });
コード例 #17
0
ファイル: OclPluginTests.cs プロジェクト: SkyForce/REAL.NET
        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));
        }
コード例 #18
0
 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" }
 }
                      )
     );
コード例 #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();
        }
コード例 #20
0
 public void StringArray(string input)
 => OclParser.Execute(input)
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", new[] { "A", "B" }));
コード例 #21
0
 public void EmptyArray(string input)
 => OclParser.Execute(input)
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", new string[0]));
コード例 #22
0
 public void False()
 => OclParser.Execute("Foo = false")
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", false));
コード例 #23
0
 public void True()
 => OclParser.Execute("Foo = true")
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", true));
コード例 #24
0
 public void Decimal(string input, decimal expected)
 => OclParser.Execute(@"Foo = " + input)
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", expected));
コード例 #25
0
 public void WithExtraWhitespace()
 => OclParser.Execute(" \t   Foo    = \t  \"Bar\"  \t  ")
 .Should()
 .HaveChildrenExactly(new OclAttribute("Foo", "Bar"));
コード例 #26
0
        public void StringInvalidEscape()
        {
            Action action = () => OclParser.Execute(@"Foo = ""\q""");

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