File tree Expand file tree Collapse file tree 2 files changed +118
-41
lines changed Expand file tree Collapse file tree 2 files changed +118
-41
lines changed Original file line number Diff line number Diff line change @@ -992,12 +992,10 @@ if (a > b) {
992
992
) ;
993
993
994
994
// `if` statements without braces can run individual expressions
995
- // TODO: This is a tree-sitter bug! It should only go to row: 2, column: 7.
996
995
statement_range_test (
997
996
"
998
997
<<if (@a > b)
999
- 1 + 1
1000
- >>" ,
998
+ 1 + 1>>" ,
1001
999
) ;
1002
1000
statement_range_test (
1003
1001
"
@@ -1006,79 +1004,158 @@ if (a > b)
1006
1004
" ,
1007
1005
) ;
1008
1006
1009
- // `if`-else statements without braces can run individual expressions
1007
+ // Top level `if`-else statements without braces can run individual expressions if
1008
+ // the `else` is in a valid location
1010
1009
statement_range_test (
1011
1010
"
1012
1011
<<if @(a > b)
1013
- 1 + 1
1014
- else if (b > c)
1015
- 2 + 2
1016
- else
1017
- 4 + 4>>
1012
+ 1 + 1 else if (b > c)
1013
+ 2 + 2 else 4 + 4>>
1018
1014
" ,
1019
1015
) ;
1020
1016
statement_range_test (
1021
1017
"
1022
1018
if (a > b)
1023
- <<@1 + 1>>
1024
- else if (b > c)
1025
- 2 + 2
1026
- else
1027
- 4 + 4
1019
+ <<@1 + 1>> else if (b > c)
1020
+ 2 + 2 else 4 + 4
1028
1021
" ,
1029
1022
) ;
1023
+ // TODO: I'm not exactly sure what this should run, but this seems strange
1030
1024
statement_range_test (
1031
1025
"
1032
- <<if (a > b)
1033
- 1 + 1
1034
- else if @(b > c)
1035
- 2 + 2
1036
- else
1037
- 4 + 4>>
1026
+ if (a > b)
1027
+ <<1 + 1>> else if @(b > c)
1028
+ 2 + 2 else 4 + 4
1038
1029
" ,
1039
1030
) ;
1040
1031
statement_range_test (
1041
1032
"
1042
1033
if (a > b)
1043
- 1 + 1
1044
- else if (b > c)
1045
- <<2 + @2>>
1046
- else
1047
- 4 + 4
1034
+ 1 + 1 else if (b > c)
1035
+ <<2 + @2>> else 4 + 4
1048
1036
" ,
1049
1037
) ;
1038
+ // TODO: I'm not exactly sure what this should run, but this seems strange
1050
1039
statement_range_test (
1051
1040
"
1052
- <<if (a > b)
1053
- 1 + 1
1054
- else if (b > c)
1055
- 2 + 2
1056
- else@
1057
- 4 + 4>>
1041
+ if (a > b)
1042
+ 1 + 1 else if (b > c)
1043
+ <<2 + 2>> else@ 4 + 4
1058
1044
" ,
1059
1045
) ;
1046
+ // TODO: I'm not exactly sure what this should run, but this seems strange
1060
1047
statement_range_test (
1061
1048
"
1062
1049
if (a > b)
1063
- 1 + 1
1064
- else if (b > c)
1065
- 2 + 2
1066
- else
1067
- <<4 @+ 4>>
1050
+ 1 + 1 else if (b > c)
1051
+ <<2 + 2>> else 4 @+ 4
1052
+ " ,
1053
+ ) ;
1054
+
1055
+ // `if`-else statements without braces but inside an outer `{` scope is recognized
1056
+ // as valid R code
1057
+ statement_range_test (
1058
+ "
1059
+ {
1060
+ <<if @(a > b)
1061
+ 1 + 1
1062
+ else if (b > c)
1063
+ 2 + 2
1064
+ else
1065
+ 4 + 4>>
1066
+ }
1067
+ " ,
1068
+ ) ;
1069
+ statement_range_test (
1070
+ "
1071
+ {
1072
+ if (a > b)
1073
+ <<@1 + 1>>
1074
+ else if (b > c)
1075
+ 2 + 2
1076
+ else
1077
+ 4 + 4
1078
+ }
1079
+ " ,
1080
+ ) ;
1081
+ statement_range_test (
1082
+ "
1083
+ {
1084
+ <<if (a > b)
1085
+ 1 + 1
1086
+ else if @(b > c)
1087
+ 2 + 2
1088
+ else
1089
+ 4 + 4>>
1090
+ }
1091
+ " ,
1092
+ ) ;
1093
+ statement_range_test (
1094
+ "
1095
+ {
1096
+ if (a > b)
1097
+ 1 + 1
1098
+ else if (b > c)
1099
+ <<2 + @2>>
1100
+ else
1101
+ 4 + 4
1102
+ }
1103
+ " ,
1104
+ ) ;
1105
+ statement_range_test (
1106
+ "
1107
+ {
1108
+ <<if (a > b)
1109
+ 1 + 1
1110
+ else if (b > c)
1111
+ 2 + 2
1112
+ else@
1113
+ 4 + 4>>
1114
+ }
1115
+ " ,
1116
+ ) ;
1117
+ statement_range_test (
1118
+ "
1119
+ {
1120
+ if (a > b)
1121
+ 1 + 1
1122
+ else if (b > c)
1123
+ 2 + 2
1124
+ else
1125
+ <<4 @+ 4>>
1126
+ }
1068
1127
" ,
1069
1128
) ;
1070
1129
1071
- // TODO: This test should fail once we fix the tree-sitter bug.
1072
- // TODO: It should only go to row: 3, column: 1.
1073
1130
// `if` statements without an `else` don't consume newlines
1131
+ // https://github.com/posit-dev/positron/issues/1464
1132
+ statement_range_test (
1133
+ "
1134
+ <<if @(a > b)
1135
+ 1 + 1>>
1136
+
1137
+
1138
+ " ,
1139
+ ) ;
1074
1140
statement_range_test (
1075
1141
"
1076
1142
<<if @(a > b) {
1077
1143
1 + 1
1078
- }
1144
+ }>>
1079
1145
1080
1146
1081
- >>" ,
1147
+ " ,
1148
+ ) ;
1149
+ statement_range_test (
1150
+ "
1151
+ <<if @(a > b) {
1152
+ 1 + 1
1153
+ }>>
1154
+
1155
+
1156
+ if (b > c) {
1157
+ 2 + 2
1158
+ }" ,
1082
1159
) ;
1083
1160
1084
1161
// Subsetting runs whole expression
You can’t perform that action at this time.
0 commit comments