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