|
1 | 1 | import * as expect from 'expect';
|
2 | 2 | import * as model from '../../../cursor-doc/model';
|
3 | 3 | import * as handlers from '../../../paredit/commands';
|
4 |
| -import { docFromTextNotation } from '../common/text-notation'; |
| 4 | +import { docFromTextNotation, textNotationFromDoc } from '../common/text-notation'; |
5 | 5 | import _ = require('lodash');
|
6 | 6 |
|
7 | 7 | model.initScanner(20000);
|
@@ -1009,15 +1009,13 @@ describe('paredit commands', () => {
|
1009 | 1009 | it('Single-cursor: Deals with empty lines', async () => {
|
1010 | 1010 | const a = docFromTextNotation('\n|');
|
1011 | 1011 | const b = docFromTextNotation('|');
|
1012 |
| - // const expected = { range: textAndSelection(b)[1], editOptions: { skipFormat: false } }; |
1013 | 1012 | await handlers.killLeft(a, false);
|
1014 | 1013 | expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit));
|
1015 | 1014 | });
|
1016 | 1015 |
|
1017 | 1016 | it('Single-cursor: Deals with empty lines (Windows)', async () => {
|
1018 | 1017 | const a = docFromTextNotation('\r\n|');
|
1019 | 1018 | const b = docFromTextNotation('|');
|
1020 |
| - // const expected = { range: textAndSelection(b)[1], editOptions: { skipFormat: false } }; |
1021 | 1019 | await handlers.killLeft(a, false);
|
1022 | 1020 | expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit));
|
1023 | 1021 | });
|
@@ -1087,4 +1085,179 @@ describe('paredit commands', () => {
|
1087 | 1085 | });
|
1088 | 1086 | });
|
1089 | 1087 | });
|
| 1088 | + |
| 1089 | + describe('editing', () => { |
| 1090 | + describe('wrapping', () => { |
| 1091 | + describe('rewrap', () => { |
| 1092 | + it('Single-cursor: Rewraps () -> []', async () => { |
| 1093 | + const a = docFromTextNotation('a (b c|) d'); |
| 1094 | + const b = docFromTextNotation('a [b c|] d'); |
| 1095 | + await handlers.rewrapSquare(a, false); |
| 1096 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1097 | + }); |
| 1098 | + it('Multi-cursor: Rewraps () -> []', async () => { |
| 1099 | + const a = docFromTextNotation('(a|2 (b c|) |1d)|3'); |
| 1100 | + const b = docFromTextNotation('[a|2 [b c|] |1d]|3'); |
| 1101 | + await handlers.rewrapSquare(a, true); |
| 1102 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1103 | + }); |
| 1104 | + |
| 1105 | + it('Single-cursor: Rewraps [] -> ()', async () => { |
| 1106 | + const a = docFromTextNotation('[a [b c|] d]'); |
| 1107 | + const b = docFromTextNotation('[a (b c|) d]'); |
| 1108 | + await handlers.rewrapParens(a, false); |
| 1109 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1110 | + }); |
| 1111 | + it('Multi-cursor: Rewraps [] -> ()', async () => { |
| 1112 | + const a = docFromTextNotation('[a|2 [b c|] |1d]|3'); |
| 1113 | + const b = docFromTextNotation('(a|2 (b c|) |1d)|3'); |
| 1114 | + await handlers.rewrapParens(a, true); |
| 1115 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1116 | + }); |
| 1117 | + |
| 1118 | + it('Single-cursor: Rewraps [] -> {}', async () => { |
| 1119 | + const a = docFromTextNotation('[a [b c|] d]'); |
| 1120 | + const b = docFromTextNotation('[a {b c|} d]'); |
| 1121 | + await handlers.rewrapCurly(a, false); |
| 1122 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1123 | + }); |
| 1124 | + it('Multi-cursor: Rewraps [] -> {}', async () => { |
| 1125 | + const a = docFromTextNotation('[a|2 [b c|] |1d]|3'); |
| 1126 | + const b = docFromTextNotation('{a|2 {b c|} |1d}|3'); |
| 1127 | + await handlers.rewrapCurly(a, true); |
| 1128 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1129 | + }); |
| 1130 | + |
| 1131 | + it('Multi-cursor: Handles rewrapping nested forms [] -> {}', async () => { |
| 1132 | + const a = docFromTextNotation('[:d :e [a|1 [b c|]]]'); |
| 1133 | + const b = docFromTextNotation('[:d :e {a|1 {b c|}}]'); |
| 1134 | + await handlers.rewrapCurly(a, true); |
| 1135 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1136 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1137 | + }); |
| 1138 | + it('Multi-cursor: Handles rewrapping nested forms [] -> {} 2', async () => { |
| 1139 | + const a = docFromTextNotation('[|1:d :e [a|2 [b c|]]]'); |
| 1140 | + const b = docFromTextNotation('{|1:d :e {a|2 {b c|}}}'); |
| 1141 | + await handlers.rewrapCurly(a, true); |
| 1142 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1143 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1144 | + }); |
| 1145 | + it('Multi-cursor: Handles rewrapping nested forms mixed -> {}', async () => { |
| 1146 | + const a = docFromTextNotation('[:d :e (a|1 {b c|})]'); |
| 1147 | + const b = docFromTextNotation('[:d :e {a|1 {b c|}}]'); |
| 1148 | + await handlers.rewrapCurly(a, true); |
| 1149 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1150 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1151 | + }); |
| 1152 | + it('Multi-cursor: Handles rewrapping nested forms mixed -> {} 2', async () => { |
| 1153 | + const a = docFromTextNotation('[|1:d :e (a|2 {b c|})]'); |
| 1154 | + const b = docFromTextNotation('{|1:d :e {a|2 {b c|}}}'); |
| 1155 | + await handlers.rewrapCurly(a, true); |
| 1156 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1157 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1158 | + }); |
| 1159 | + |
| 1160 | + it('Single-cursor: Rewraps #{} -> {}', async () => { |
| 1161 | + const a = docFromTextNotation('#{a #{b c|} d}'); |
| 1162 | + const b = docFromTextNotation('#{a {b c|} d}'); |
| 1163 | + await handlers.rewrapCurly(a, false); |
| 1164 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1165 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1166 | + }); |
| 1167 | + it('Multi-cursor: Rewraps #{} -> {}', async () => { |
| 1168 | + const a = docFromTextNotation('#{a|2 #{b c|} |1d}|3'); |
| 1169 | + const b = docFromTextNotation('{a|2 {b c|} |1d}|3'); |
| 1170 | + await handlers.rewrapCurly(a, true); |
| 1171 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1172 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1173 | + }); |
| 1174 | + |
| 1175 | + it('Single-cursor: Rewraps #{} -> ""', async () => { |
| 1176 | + const a = docFromTextNotation('#{a #{b c|} d}'); |
| 1177 | + const b = docFromTextNotation('#{a "b c|" d}'); |
| 1178 | + await handlers.rewrapQuote(a, false); |
| 1179 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1180 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1181 | + }); |
| 1182 | + it('Multi-cursor: Rewraps #{} -> ""', async () => { |
| 1183 | + const a = docFromTextNotation('#{a|2 #{b c|} |1d}|3'); |
| 1184 | + const b = docFromTextNotation('"a|2 "b c|" |1d"|3'); |
| 1185 | + await handlers.rewrapQuote(a, true); |
| 1186 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1187 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1188 | + }); |
| 1189 | + it('Multi-cursor: Rewraps #{} -> "" 2', async () => { |
| 1190 | + const a = docFromTextNotation('#{a|2 #{b c|} |1d}|3\n#{a|6 #{b c|4} |5d}|7'); |
| 1191 | + const b = docFromTextNotation('"a|2 "b c|" |1d"|3\n"a|6 "b c|4" |5d"|7'); |
| 1192 | + await handlers.rewrapQuote(a, true); |
| 1193 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1194 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1195 | + }); |
| 1196 | + it('Multi-cursor: Rewraps #{} -> [] 3', async () => { |
| 1197 | + const a = docFromTextNotation('#{a|2 #{b c|} |1d\n#{a|6 #{b c|4} |5d}}|3'); |
| 1198 | + const b = docFromTextNotation('[a|2 [b c|] |1d\n[a|6 [b c|4] |5d]]|3'); |
| 1199 | + await handlers.rewrapSquare(a, true); |
| 1200 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1201 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1202 | + }); |
| 1203 | + |
| 1204 | + it('Single-cursor: Rewraps [] -> #{}', async () => { |
| 1205 | + const a = docFromTextNotation('[[b c|] d]'); |
| 1206 | + const b = docFromTextNotation('[#{b c|} d]'); |
| 1207 | + await handlers.rewrapSet(a, false); |
| 1208 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1209 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1210 | + }); |
| 1211 | + it('Multi-cursor: Rewraps [] -> #{}', async () => { |
| 1212 | + const a = docFromTextNotation('[[b|2 c|] |1d]|3'); |
| 1213 | + const b = docFromTextNotation('#{#{b|2 c|} |1d}|3'); |
| 1214 | + await handlers.rewrapSet(a, true); |
| 1215 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1216 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1217 | + }); |
| 1218 | + it('Multi-cursor: Rewraps [] -> #{} 2', async () => { |
| 1219 | + const a = docFromTextNotation('[[b|2 c|] |1d]|3\n[a|6 [b c|4] |5d]|7'); |
| 1220 | + const b = docFromTextNotation('#{#{b|2 c|} |1d}|3\n#{a|6 #{b c|4} |5d}|7'); |
| 1221 | + await handlers.rewrapSet(a, true); |
| 1222 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1223 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1224 | + }); |
| 1225 | + it('Multi-cursor: Rewraps [] -> #{} 3', async () => { |
| 1226 | + const a = docFromTextNotation('[[b|2 c|] |1d\n[a|6 [b c|4] |5d]]|3'); |
| 1227 | + const b = docFromTextNotation('#{#{b|2 c|} |1d\n#{a|6 #{b c|4} |5d}}|3'); |
| 1228 | + await handlers.rewrapSet(a, true); |
| 1229 | + expect(textNotationFromDoc(a)).toEqual(textNotationFromDoc(b)); |
| 1230 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1231 | + }); |
| 1232 | + |
| 1233 | + // TODO: This tests current behavior. What should happen? |
| 1234 | + it('Single-cursor: Rewraps ^{} -> #{}', async () => { |
| 1235 | + const a = docFromTextNotation('^{^{b c|} d}'); |
| 1236 | + const b = docFromTextNotation('^{#{b c|} d}'); |
| 1237 | + await handlers.rewrapSet(a, false); |
| 1238 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1239 | + }); |
| 1240 | + it('Multi-cursor: Rewraps ^{} -> #{}', async () => { |
| 1241 | + const a = docFromTextNotation('^{^{b|2 c|} |1d}|3'); |
| 1242 | + const b = docFromTextNotation('#{#{b|2 c|} |1d}|3'); |
| 1243 | + await handlers.rewrapSet(a, true); |
| 1244 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1245 | + }); |
| 1246 | + |
| 1247 | + // TODO: This tests current behavior. What should happen? |
| 1248 | + it('Single-cursor: Rewraps ~{} -> #{}', async () => { |
| 1249 | + const a = docFromTextNotation('~{~{b c|} d}'); |
| 1250 | + const b = docFromTextNotation('~{#{b c|} d}'); |
| 1251 | + await handlers.rewrapSet(a, false); |
| 1252 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1253 | + }); |
| 1254 | + it('Multi-cursor: Rewraps ~{} -> #{}', async () => { |
| 1255 | + const a = docFromTextNotation('~{~{b|2 c|} |1d}|3'); |
| 1256 | + const b = docFromTextNotation('#{#{b|2 c|} |1d}|3'); |
| 1257 | + await handlers.rewrapSet(a, true); |
| 1258 | + expect(_.omit(a, defaultDocOmit)).toEqual(_.omit(b, defaultDocOmit)); |
| 1259 | + }); |
| 1260 | + }); |
| 1261 | + }); |
| 1262 | + }); |
1090 | 1263 | });
|
0 commit comments