Ejemplo n.º 1
0
        public void TestMachineOnEventDeclarationWithoutHandler()
        {
            var test = @"
namespace Foo {
machine M {
group G {
start state S1
{
on e;
}
}
}
}";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \"do\", \"goto\" or \"push\".",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 2
0
        public void TestMonitorStateDeclarationWithMoreThanOneEntry()
        {
            var test = @"
namespace Foo {
monitor M {
group G {
start state S
{
entry {}
entry{}
}
}
}
}";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Duplicate entry declaration.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 3
0
        public void TestMachineDeferEventDeclarationWithExtraComma()
        {
            var test = @"
namespace Foo {
machine M {
group G {
start state S
{
defer e1,e2,;
}
}
}
}";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected event identifier.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 4
0
        internal static void AssertFailedTestLog(string expectedResult, string test)
        {
            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.Equal(expectedResult, parser.GetParsingErrorLog());
        }
Ejemplo n.º 5
0
        public void TestEventDeclarationWithoutNamespace()
        {
            var test = "event e;";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Must be declared inside a namespace.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 6
0
        public void TestIncorrectUsingDeclaration()
        {
            var test = "using System.Text";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \";\".",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 7
0
        public void TestUnexpectedTokenWithoutNamespace()
        {
            var test = "private";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Unexpected token.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 8
0
        public void TestUsingDeclarationWithoutIdentifier()
        {
            var test = "using;";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected identifier.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 9
0
        public void TestIncorrectUsingDeclaration()
        {
            var test = "using System.Text";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \";\".",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 10
0
        public void TestEventDeclarationWithoutNamespace()
        {
            var test = "event e;";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Must be declared inside a namespace.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 11
0
        public void TestNamespaceDeclarationWithoutIdentifier()
        {
            var test = "namespace { }";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected namespace identifier.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 12
0
        public void TestUnexpectedTokenWithoutNamespace()
        {
            var test = "private";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Unexpected token.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 13
0
        public void TestPrivateEventDeclaration()
        {
            var test = @"
namespace Foo {
private event e;
}";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual(parser.GetParsingErrorLog(),
                            "Event and machine declarations must be internal or public.");
        }
Ejemplo n.º 14
0
        public void TestMachineDeclarationWithoutState()
        {
            var test = @"
namespace Foo {
machine M {
}
}";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("A machine must declare at least one state.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 15
0
        public void TestProtectedMonitorDeclaration()
        {
            var test = @"
namespace Foo {
protected monitor M { }
}";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.Equal("A monitor cannot be declared as protected.", parser.GetParsingErrorLog());
        }
Ejemplo n.º 16
0
        public void TestInternalFieldDeclaration()
        {
            var test = @"
namespace Foo {
machine M {
internal int k;
start state S { }
}
}";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("A field or method cannot be internal.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 17
0
        public void TestProtectedEventDeclaration()
        {
            var test = @"
namespace Foo {
protected event e;
}";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Event and machine declarations must be internal or public.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 18
0
        public void TestMachineFieldDeclarationWithoutSemicolon()
        {
            var test = @"
namespace Foo {
machine M {
machine N
start state S { }
}
}";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \"(\" or \";\".",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 19
0
        public void TestEventDeclarationWithGenericError1()
        {
            var test = @"
namespace Foo {
event e>;
}";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \"(\" or \";\".",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 20
0
        public void TestMachineDeclarationWithTwoBodies()
        {
            var test = @"
namespace Foo {
machine M {
start state S { }
}
{
}
}";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Unexpected token.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 21
0
        public void TestEntryDeclarationWithUnexpectedIdentifier()
        {
            var test = @"
namespace Foo {
machine M {
start state S
{
entry Bar {}
}
}
}";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \"{\".",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 22
0
        public void TestDeferEventDeclarationWithoutComma()
        {
            var test = @"
namespace Foo {
machine M {
start state S
{
defer e1 e2;
}
}
}";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \",\".",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 23
0
        public void TestOnEventDeclarationWithoutHandler()
        {
            var test = @"
namespace Foo {
machine M {
start state S1
{
on e;
}
}
}";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \"do\", \"goto\" or \"push\".",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 24
0
        public void TestOnEventDoActionDeclarationWithoutAction()
        {
            var test = @"
namespace Foo {
machine M {
start state S1
{
on e do;
}
}
}";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected action identifier.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 25
0
        public void TestMachineDeclarationWithMoreThanOneStartState()
        {
            var test = @"
namespace Foo {
machine M {
start state S1 {}
start state S2 { }

start state S3 { }
}
}";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("A machine can declare only a single start state.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 26
0
        public void TestMonitorColdGroup()
        {
            var test = @"
namespace Foo {
monitor M {
cold group G { }
}
}";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("A state group cannot be cold.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 27
0
        public void TestMonitorGroupName()
        {
            var test = @"
namespace Foo {
monitor M {
group G.G2 { }
}
}";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \"{\".",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 28
0
        public void TestMachineDeclarationWithoutStartState()
        {
            var test = @"
namespace Foo {
machine M {
state S { }
}
}";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("A machine must declare a start state.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 29
0
        public void TestStateDeclarationWithMoreThanOneExit()
        {
            var test = @"
namespace Foo {
machine M {
start state S
{
exit{}
exit {}
}
}
}";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Duplicate exit declaration.",
                            parser.GetParsingErrorLog());
        }
Ejemplo n.º 30
0
        public void TestIntFieldDeclarationWithoutSemicolon()
        {
            var test = @"
namespace Foo {
machine M {
int k
start state S { }
}
}";

            ParsingOptions options = ParsingOptions.CreateDefault()
                                     .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                                          SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens  = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \"(\" or \";\".",
                            parser.GetParsingErrorLog());
        }