public static ApplyTextChange ( ICoreShell coreShell, string expression, int start, int oldLength, int newLength, string newText ) : |
||
coreShell | ICoreShell | |
expression | string | |
start | int | |
oldLength | int | |
newLength | int | |
newText | string | |
return |
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); } }
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); } }
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); } }
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); } }
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); } }
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); }
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); } }
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); } }
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); }
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); } }
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); }
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); } }