示例#1
0
        public void TestMessedUpFieldSource()
        {
            Lexer   lexer                   = new Lexer();
            var     tokenStream             = lexer.Lex(@"
type Person =
    FirstName:
        String ;
    LastName: String & min 12 & max
    30;
");
            IParser parser                  = new Parser(tokenStream);
            IEnumerable <IASTNode> nodeTree = parser.Parse();

            VisitorSource visitor = new VisitorSource(nodeTree);
            string        result  = string.Join("\n\n", visitor.Start());

            string resultTest = @"
type Person =
    FirstName: String;
    LastName: String
        & min 12
        & max 30
    ;
".Trim();

            Assert.Equal(resultTest, result);
        }
        public void TestMultipleTypesFormatting()
        {
            var code       = @"
type Person =
    FirstName: String;
    LastName: String
        & min 12
        @ annotation
        & max 30;
type School
type Other =
    Something: String;
";
            var generator  = new ASTGenerator(code);
            var visitor    = new VisitorSource(generator);
            var result     = string.Join(Environment.NewLine + Environment.NewLine, visitor.Start());
            var resultTest = @"
type Person =
    FirstName: String;
    LastName: String
        & min 12

        @ annotation
        & max 30
    ;

type School

type Other =
    Something: String;
".Trim();

            Assert.Equal(resultTest, result);
        }
        public void TestFieldRestrictionAnnotations()
        {
            var code       = @"
type Person =
    FirstName:
        String ;
    LastName: String & min 12
    @ annotation
    & max 30;
";
            var generator  = new ASTGenerator(code);
            var visitor    = new VisitorSource(generator);
            var result     = string.Join(Environment.NewLine + Environment.NewLine, visitor.Start());
            var resultTest = @"
type Person =
    FirstName: String;
    LastName: String
        & min 12

        @ annotation
        & max 30
    ;
".Trim();

            Assert.Equal(resultTest, result);
        }
        public void TestAliasRestrictionAnnotations()
        {
            Lexer   lexer                   = new Lexer();
            var     tokenStream             = lexer.Lex(@"
alias Name = String
    @ Minimum of 12
    & min 12
    @ Maximum of 40
    & max 40
");
            IParser parser                  = new Parser(tokenStream);
            IEnumerable <IASTNode> nodeTree = parser.Parse();

            VisitorSource visitor        = new VisitorSource(nodeTree);
            string        result         = string.Join("\n\n", visitor.Start());
            string        resultExpected = @"
alias Name = String

    @ Minimum of 12
    & min 12

    @ Maximum of 40
    & max 40
".Trim();

            Assert.Equal(resultExpected, result);
        }
示例#5
0
        public void TestASTVisitor()
        {
            var code      = @"
type Person
";
            var generator = new ASTGenerator(code);
            var visitor   = new VisitorSource(generator);
            var result    = string.Join(Environment.NewLine + Environment.NewLine, visitor.Start());

            Assert.True(result.Length > 0);
        }
        public void TestASTVisitor()
        {
            var code      = @"
alias Name = String
";
            var generator = new ASTGenerator(code);
            var visitor   = new VisitorSource(generator);
            var result    = string.Join(Environment.NewLine + Environment.NewLine, visitor.Start());

            Assert.Equal("alias Name = String;", result);
        }
        public void TestASTVisitor()
        {
            Lexer   lexer                   = new Lexer();
            var     tokenStream             = lexer.Lex(@"
type Person
");
            IParser parser                  = new Parser(tokenStream);
            IEnumerable <IASTNode> nodeTree = parser.Parse();

            VisitorSource visitor = new VisitorSource(nodeTree);
            string        result  = string.Join("\n\n", visitor.Start());
        }
        public void TestDirectivesSource()
        {
            var code      = @"
% api: /root/{param}
type Person
";
            var generator = new ASTGenerator(code);
            var visitor   = new VisitorSource(generator);
            var result    = string.Join(Environment.NewLine + Environment.NewLine, visitor.Start());

            Assert.Equal(@"
% api: /root/{param}
type Person".Trim(), result);
        }
        public void TestASTVisitor()
        {
            Lexer   lexer                   = new Lexer();
            var     tokenStream             = lexer.Lex(@"
alias Name = String
");
            IParser parser                  = new Parser(tokenStream);
            IEnumerable <IASTNode> nodeTree = parser.Parse();

            VisitorSource visitor = new VisitorSource(nodeTree);
            string        result  = string.Join("\n\n", visitor.Start());

            Assert.Equal("alias Name = String", result);
        }
        public void TestAnnotationsSource()
        {
            var code      = @"
@ The Person
@ Another annotation
type Person
";
            var generator = new ASTGenerator(code);
            var visitor   = new VisitorSource(generator);
            var result    = string.Join(Environment.NewLine + Environment.NewLine, visitor.Start());

            Assert.Equal(@"@ The Person
@ Another annotation
type Person", result);
        }
        public void TestAliasAnnotations()
        {
            var code           = @"
@ This is the Name alias
alias Name = String;
";
            var generator      = new ASTGenerator(code);
            var visitor        = new VisitorSource(generator);
            var result         = string.Join(Environment.NewLine + Environment.NewLine, visitor.Start());
            var resultExpected = @"
@ This is the Name alias
alias Name = String;
".Trim();

            Assert.Equal(resultExpected, result);
        }
示例#12
0
        public void TestDirectivesSource()
        {
            Lexer   lexer                   = new Lexer();
            var     tokenStream             = lexer.Lex(@"
% api: /root/{param}
type Person
");
            IParser parser                  = new Parser(tokenStream);
            IEnumerable <IASTNode> nodeTree = parser.Parse();

            VisitorSource visitor = new VisitorSource(nodeTree);
            string        result  = string.Join("\n\n", visitor.Start());

            Assert.Equal(@"
% api: /root/{param}
type Person".Trim(), result);
        }
示例#13
0
        public void TestAnnotationsSource()
        {
            Lexer   lexer                   = new Lexer();
            var     tokenStream             = lexer.Lex(@"
@ The Person
@ Another annotation
type Person
");
            IParser parser                  = new Parser(tokenStream);
            IEnumerable <IASTNode> nodeTree = parser.Parse();

            VisitorSource visitor = new VisitorSource(nodeTree);
            string        result  = string.Join("\n\n", visitor.Start());

            Assert.Equal(@"@ The Person
@ Another annotation
type Person", result);
        }
        public void TestAliasAnnotations()
        {
            Lexer   lexer                   = new Lexer();
            var     tokenStream             = lexer.Lex(@"
@ This is the Name alias
alias Name = String;
");
            IParser parser                  = new Parser(tokenStream);
            IEnumerable <IASTNode> nodeTree = parser.Parse();

            VisitorSource visitor        = new VisitorSource(nodeTree);
            string        result         = string.Join("\n\n", visitor.Start());
            string        resultExpected = @"
@ This is the Name alias
alias Name = String
".Trim();

            Assert.Equal(resultExpected, result);
        }
示例#15
0
        public void TestMultipleTypesFormatting()
        {
            Lexer   lexer                   = new Lexer();
            var     tokenStream             = lexer.Lex(@"
type Person =
    FirstName: String;
    LastName: String
        & min 12
        @ annotation
        & max 30;
type School
type Other =
    Something: String;
");
            IParser parser                  = new Parser(tokenStream);
            IEnumerable <IASTNode> nodeTree = parser.Parse();

            VisitorSource visitor = new VisitorSource(nodeTree);
            string        result  = string.Join("\n\n", visitor.Start());

            string resultTest = @"
type Person =
    FirstName: String;
    LastName: String
        & min 12

        @ annotation
        & max 30
    ;

type School

type Other =
    Something: String;
".Trim();

            Assert.Equal(resultTest, result);
        }
        public void TestAliasRestrictionAnnotations()
        {
            var code           = @"
alias Name = String
    @ Minimum of 12
    & min 12
    @ Maximum of 40
    & max 40
";
            var generator      = new ASTGenerator(code);
            var visitor        = new VisitorSource(generator);
            var result         = string.Join(Environment.NewLine + Environment.NewLine, visitor.Start());
            var resultExpected = @"
alias Name = String

    @ Minimum of 12
    & min 12

    @ Maximum of 40
    & max 40;
".Trim();

            Assert.Equal(resultExpected, result);
        }