Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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.");
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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());
        }