Пример #1
0
        public void EditorTree_InvalidateAll()
        {
            EditorTree tree = EditorTreeTest.MakeTree("if(true) x <- a + b");

            tree.Invalidate();
            tree.AstRoot.Children.Should().BeEmpty();
        }
Пример #2
0
 public void ElsePosition(string content, int start, int oldLength, int newLength, string text)
 {
     using (var tree = EditorTreeTest.ApplyTextChange(_services, content, start, oldLength, newLength, text)) {
         tree.IsDirty.Should().BeTrue();
         tree.PendingChanges.TextChangeType.Should().Be(TextChangeType.Structure);
     }
 }
Пример #3
0
        public void TextChange_EditComment04()
        {
            string expression = "# comment\n a <- b + c";

            using (var tree = EditorTreeTest.ApplyTextChange(_services, expression, 9, 1, 0, string.Empty)) {
                tree.PendingChanges.TextChangeType.Should().Be(TextChangeType.Structure);
            }
        }
Пример #4
0
        public void TextChange_EditComment01(int oldLength, int newLength, string newText, TextChangeType expected)
        {
            string expression = "x <- a + b # comment";

            using (var tree = EditorTreeTest.ApplyTextChange(_services, expression, 12, oldLength, newLength, newText)) {
                tree.PendingChanges.TextChangeType.Should().Be(expected);
            }
        }
Пример #5
0
        public void TextChange_EditWhitespaceTest(int start, int oldLength, int newLength, string newText, TextChangeType expected)
        {
            string expression = "x <- a + b";

            using (var tree = EditorTreeTest.ApplyTextChange(_services, expression, start, oldLength, newLength, newText)) {
                tree.PendingChanges.TextChangeType.Should().Be(expected);
            }
        }
Пример #6
0
        public void TextChange_EditString(int oldLength, int newLength, string newText, TextChangeType expected)
        {
            string expression = "x <- a + \"boo\"";

            using (var tree = EditorTreeTest.ApplyTextChange(_shell, expression, 10, oldLength, newLength, newText)) {
                tree.PendingChanges.TextChangeType.Should().Be(expected);
            }
        }
Пример #7
0
 public void InvalidateAll()
 {
     using (var tree = EditorTreeTest.MakeTree(_coreShell, "if(true) x <- a + b")) {
         tree.Invalidate();
         tree.AstRoot.Children.Should().ContainSingle();
         tree.AstRoot.Children[0].Children.Should().BeEmpty();
     }
 }
Пример #8
0
        public void TextChange_AddWhitespace(int start, int oldLength, int newLength, string newText, TextChangeType expected)
        {
            string expression = "x <- aa";

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, start, oldLength, newLength, newText);

            tree.PendingChanges.TextChangeType.Should().Be(expected);
        }
Пример #9
0
        public void TextChange_CurlyBrace()
        {
            string expression = "if(true) {x <- 1} else ";

            using (var tree = EditorTreeTest.ApplyTextChange(_services, expression, expression.Length, 0, 1, "{")) {
                tree.IsDirty.Should().BeTrue();
                tree.PendingChanges.TextChangeType.Should().Be(TextChangeType.Structure);
            }
        }
Пример #10
0
        public void EditorTree_InvalidateInRangeTest()
        {
            EditorTree tree = EditorTreeTest.MakeTree("if(true) x <- a + b");

            bool nodesChanged = false;
            bool result       = tree.InvalidateInRange(tree.AstRoot, new TextRange(4, 1), out nodesChanged);

            result.Should().BeTrue();
            nodesChanged.Should().BeTrue();
        }
Пример #11
0
        public void InvalidateAllInRange(string content, int start, int length)
        {
            using (var tree = EditorTreeTest.MakeTree(_coreShell, content)) {
                bool nodesChanged = tree.InvalidateInRange(new TextRange(start, length));
                nodesChanged.Should().BeTrue();

                tree.AstRoot.Children.Should().ContainSingle();
                tree.AstRoot.Children[0].Should().BeOfType <GlobalScope>();
                tree.AstRoot.Children[0].Children.Should().BeEmpty();
            }
        }
Пример #12
0
        public void TextChange_EditComment05()
        {
            string expression = "#";

            using (var tree = EditorTreeTest.ApplyTextChange(_services, expression, 1, 0, 1, "a")) {
                tree.PendingChanges.TextChangeType.Should().Be(TextChangeType.Trivial);

                tree.AstRoot.Comments.Should().ContainSingle();
                var comment = tree.AstRoot.Comments[0];
                comment.Start.Should().Be(0);
                comment.Length.Should().Be(2);
            }
        }
Пример #13
0
        public void ProcessChange_EditExpression01()
        {
            string expression = "if(true) x <- 1";
            string expected1  =
                @"GlobalScope  [Global]
    If  []
        TokenNode  [if [0...2)]
        TokenNode  [( [2...3)]
        Expression  [true]
            Variable  [true]
        TokenNode  [) [7...8)]
        SimpleScope  [9...15)
            ExpressionStatement  [x <- 1]
                Expression  [x <- 1]
                    TokenOperator  [<- [11...13)]
                        Variable  [x]
                        TokenNode  [<- [11...13)]
                        NumericalValue  [1 [14...15)]
";

            ParserTest.VerifyParse(expected1, expression);

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, 3, 4, 5, "false");

            tree.IsDirty.Should().BeTrue();
            tree.ProcessChanges();

            string expected2 =
                @"GlobalScope  [Global]
    If  []
        TokenNode  [if [0...2)]
        TokenNode  [( [2...3)]
        Expression  [false]
            Variable  [false]
        TokenNode  [) [8...9)]
        SimpleScope  [10...16)
            ExpressionStatement  [x <- 1]
                Expression  [x <- 1]
                    TokenOperator  [<- [12...14)]
                        Variable  [x]
                        TokenNode  [<- [12...14)]
                        NumericalValue  [1 [15...16)]
";

            ParserTest.CompareTrees(expected2, tree.AstRoot);
        }
Пример #14
0
        public void InvalidatePartsInRange01(string content, int start, int length)
        {
            using (var tree = EditorTreeTest.MakeTree(_coreShell, content)) {
                bool nodesChanged = tree.InvalidateInRange(new TextRange(start, length));
                nodesChanged.Should().BeTrue();

                tree.AstRoot.Children.Should().ContainSingle();
                tree.AstRoot.Children[0].Should().BeOfType <GlobalScope>();

                tree.AstRoot.Children[0].Children.Should().NotBeEmpty();
                tree.AstRoot.Children[0].Children[0].Should().BeOfType <If>();

                var ifStatement = tree.AstRoot.Children[0].Children[0] as If;
                ifStatement.Should().NotBeNull();
                ifStatement.Scope.Should().NotBeNull();
                ifStatement.Scope.Children.Count.Should().Be(2);
                ifStatement.Scope.OpenCurlyBrace.Should().NotBeNull();
                ifStatement.Scope.CloseCurlyBrace.Should().NotBeNull();
            }
        }
Пример #15
0
        public void TextChange_EditString04()
        {
            string expression = "\"boo\"";

            using (var tree = EditorTreeTest.ApplyTextChange(_services, expression, 1, 0, 1, "a")) {
                tree.PendingChanges.TextChangeType.Should().Be(TextChangeType.Trivial);

                var token = tree.AstRoot.Children.Should().ContainSingle()
                            .Which.Should().BeAssignableTo <IScope>()
                            .Which.Children.Should().ContainSingle()
                            .Which.Should().BeAssignableTo <IStatement>()
                            .Which.Children.Should().ContainSingle()
                            .Which.Should().BeAssignableTo <IExpression>()
                            .Which.Children.Should().ContainSingle()
                            .Which.Should().BeAssignableTo <TokenNode>()
                            .Which.Token;

                token.TokenType.Should().Be(RTokenType.String);
                token.Start.Should().Be(0);
                token.Length.Should().Be(6);
            }
        }
Пример #16
0
        public void ProcessChange_EditIfElse02()
        {
            string expression = "if(true) {x <- 1} else x <- 2";
            string expected1  =
                @"GlobalScope  [Global]
    If  []
        TokenNode  [if [0...2)]
        TokenNode  [( [2...3)]
        Expression  [true]
            Variable  [true]
        TokenNode  [) [7...8)]
        Scope  []
            TokenNode  [{ [9...10)]
            ExpressionStatement  [x <- 1]
                Expression  [x <- 1]
                    TokenOperator  [<- [12...14)]
                        Variable  [x]
                        TokenNode  [<- [12...14)]
                        NumericalValue  [1 [15...16)]
            TokenNode  [} [16...17)]
        KeywordScopeStatement  []
            TokenNode  [else [18...22)]
            SimpleScope  [23...29)
                ExpressionStatement  [x <- 2]
                    Expression  [x <- 2]
                        TokenOperator  [<- [25...27)]
                            Variable  [x]
                            TokenNode  [<- [25...27)]
                            NumericalValue  [2 [28...29)]
";

            ParserTest.VerifyParse(expected1, expression);

            using (var tree = EditorTreeTest.ApplyTextChange(_coreShell, expression, 17, 0, 1, "\n")) {
                tree.IsDirty.Should().BeTrue();
                tree.ProcessChanges();

                string expected2 =
                    @"GlobalScope  [Global]
    If  []
        TokenNode  [if [0...2)]
        TokenNode  [( [2...3)]
        Expression  [true]
            Variable  [true]
        TokenNode  [) [7...8)]
        Scope  []
            TokenNode  [{ [9...10)]
            ExpressionStatement  [x <- 1]
                Expression  [x <- 1]
                    TokenOperator  [<- [12...14)]
                        Variable  [x]
                        TokenNode  [<- [12...14)]
                        NumericalValue  [1 [15...16)]
            TokenNode  [} [16...17)]
    ExpressionStatement  [x <- 2]
        Expression  [x <- 2]
            TokenOperator  [<- [26...28)]
                Variable  [x]
                TokenNode  [<- [26...28)]
                NumericalValue  [2 [29...30)]

UnexpectedToken Token [19...23)
";
                ParserTest.CompareTrees(expected2, tree.AstRoot);
            }
        }
Пример #17
0
        public void ProcessChange_EditIfElse01()
        {
            string expression = "if(true) x <- 1 else x <- 2";
            string expected1  =
                @"GlobalScope  [Global]
    If  []
        TokenNode  [if [0...2)]
        TokenNode  [( [2...3)]
        Expression  [true]
            Variable  [true]
        TokenNode  [) [7...8)]
        SimpleScope  [9...15)
            ExpressionStatement  [x <- 1]
                Expression  [x <- 1]
                    TokenOperator  [<- [11...13)]
                        Variable  [x]
                        TokenNode  [<- [11...13)]
                        NumericalValue  [1 [14...15)]
        KeywordScopeStatement  []
            TokenNode  [else [16...20)]
            SimpleScope  [21...27)
                ExpressionStatement  [x <- 2]
                    Expression  [x <- 2]
                        TokenOperator  [<- [23...25)]
                            Variable  [x]
                            TokenNode  [<- [23...25)]
                            NumericalValue  [2 [26...27)]
";

            ParserTest.VerifyParse(expected1, expression);

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, 15, 0, 1, "\n");

            tree.IsDirty.Should().BeTrue();
            tree.ProcessChanges();

            string expected2 =
                @"GlobalScope  [Global]
    If  []
        TokenNode  [if [0...2)]
        TokenNode  [( [2...3)]
        Expression  [true]
            Variable  [true]
        TokenNode  [) [7...8)]
        SimpleScope  [9...15)
            ExpressionStatement  [x <- 1]
                Expression  [x <- 1]
                    TokenOperator  [<- [11...13)]
                        Variable  [x]
                        TokenNode  [<- [11...13)]
                        NumericalValue  [1 [14...15)]
    ExpressionStatement  [x <- 2]
        Expression  [x <- 2]
            TokenOperator  [<- [24...26)]
                Variable  [x]
                TokenNode  [<- [24...26)]
                NumericalValue  [2 [27...28)]

UnexpectedToken Token [17...21)
";

            ParserTest.CompareTrees(expected2, tree.AstRoot);
        }