aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock194
-rw-r--r--crates/ra_ide/Cargo.toml6
-rw-r--r--crates/ra_ide_db/Cargo.toml6
-rw-r--r--crates/ra_ide_db/src/line_index.rs60
-rw-r--r--crates/ra_ide_db/src/line_index_utils.rs42
-rw-r--r--crates/ra_text_edit/Cargo.toml6
-rw-r--r--crates/ra_text_edit/src/lib.rs5
-rw-r--r--crates/ra_text_edit/src/test_utils.rs83
-rw-r--r--xtask/tests/tidy-tests/docs.rs6
9 files changed, 18 insertions, 390 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ee50d006c..3a4929a0f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -79,21 +79,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
79checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" 79checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
80 80
81[[package]] 81[[package]]
82name = "bit-set"
83version = "0.5.1"
84source = "registry+https://github.com/rust-lang/crates.io-index"
85checksum = "e84c238982c4b1e1ee668d136c510c67a13465279c0cb367ea6baf6310620a80"
86dependencies = [
87 "bit-vec",
88]
89
90[[package]]
91name = "bit-vec"
92version = "0.5.1"
93source = "registry+https://github.com/rust-lang/crates.io-index"
94checksum = "f59bbe95d4e52a6398ec21238d31577f2b28a9d86807f06ca59d191d8440d0bb"
95
96[[package]]
97name = "bitflags" 82name = "bitflags"
98version = "1.2.1" 83version = "1.2.1"
99source = "registry+https://github.com/rust-lang/crates.io-index" 84source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -429,12 +414,6 @@ dependencies = [
429] 414]
430 415
431[[package]] 416[[package]]
432name = "fuchsia-cprng"
433version = "0.1.1"
434source = "registry+https://github.com/rust-lang/crates.io-index"
435checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
436
437[[package]]
438name = "fuchsia-zircon" 417name = "fuchsia-zircon"
439version = "0.3.3" 418version = "0.3.3"
440source = "registry+https://github.com/rust-lang/crates.io-index" 419source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -792,15 +771,6 @@ dependencies = [
792] 771]
793 772
794[[package]] 773[[package]]
795name = "num-traits"
796version = "0.2.11"
797source = "registry+https://github.com/rust-lang/crates.io-index"
798checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
799dependencies = [
800 "autocfg 1.0.0",
801]
802
803[[package]]
804name = "num_cpus" 774name = "num_cpus"
805version = "1.12.0" 775version = "1.12.0"
806source = "registry+https://github.com/rust-lang/crates.io-index" 776source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -917,30 +887,6 @@ dependencies = [
917] 887]
918 888
919[[package]] 889[[package]]
920name = "proptest"
921version = "0.9.5"
922source = "registry+https://github.com/rust-lang/crates.io-index"
923checksum = "bf6147d103a7c9d7598f4105cf049b15c99e2ecd93179bf024f0fd349be5ada4"
924dependencies = [
925 "bit-set",
926 "bitflags",
927 "byteorder",
928 "lazy_static",
929 "num-traits",
930 "quick-error",
931 "rand 0.6.5",
932 "rand_chacha 0.1.1",
933 "rand_xorshift",
934 "regex-syntax",
935]
936
937[[package]]
938name = "quick-error"
939version = "1.2.3"
940source = "registry+https://github.com/rust-lang/crates.io-index"
941checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
942
943[[package]]
944name = "quote" 890name = "quote"
945version = "1.0.2" 891version = "1.0.2"
946source = "registry+https://github.com/rust-lang/crates.io-index" 892source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1025,7 +971,7 @@ dependencies = [
1025 "ra_ide", 971 "ra_ide",
1026 "ra_prof", 972 "ra_prof",
1027 "ra_syntax", 973 "ra_syntax",
1028 "rand 0.7.3", 974 "rand",
1029] 975]
1030 976
1031[[package]] 977[[package]]
@@ -1137,7 +1083,6 @@ dependencies = [
1137 "join_to_string", 1083 "join_to_string",
1138 "log", 1084 "log",
1139 "once_cell", 1085 "once_cell",
1140 "proptest",
1141 "ra_assists", 1086 "ra_assists",
1142 "ra_cfg", 1087 "ra_cfg",
1143 "ra_db", 1088 "ra_db",
@@ -1147,7 +1092,7 @@ dependencies = [
1147 "ra_prof", 1092 "ra_prof",
1148 "ra_syntax", 1093 "ra_syntax",
1149 "ra_text_edit", 1094 "ra_text_edit",
1150 "rand 0.7.3", 1095 "rand",
1151 "rayon", 1096 "rayon",
1152 "rustc-hash", 1097 "rustc-hash",
1153 "superslice", 1098 "superslice",
@@ -1168,7 +1113,6 @@ dependencies = [
1168 "join_to_string", 1113 "join_to_string",
1169 "log", 1114 "log",
1170 "once_cell", 1115 "once_cell",
1171 "proptest",
1172 "ra_cfg", 1116 "ra_cfg",
1173 "ra_db", 1117 "ra_db",
1174 "ra_fmt", 1118 "ra_fmt",
@@ -1281,7 +1225,6 @@ dependencies = [
1281name = "ra_text_edit" 1225name = "ra_text_edit"
1282version = "0.1.0" 1226version = "0.1.0"
1283dependencies = [ 1227dependencies = [
1284 "proptest",
1285 "test_utils", 1228 "test_utils",
1286 "text_unit", 1229 "text_unit",
1287] 1230]
@@ -1319,45 +1262,16 @@ dependencies = [
1319 1262
1320[[package]] 1263[[package]]
1321name = "rand" 1264name = "rand"
1322version = "0.6.5"
1323source = "registry+https://github.com/rust-lang/crates.io-index"
1324checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
1325dependencies = [
1326 "autocfg 0.1.7",
1327 "libc",
1328 "rand_chacha 0.1.1",
1329 "rand_core 0.4.2",
1330 "rand_hc 0.1.0",
1331 "rand_isaac",
1332 "rand_jitter",
1333 "rand_os",
1334 "rand_pcg 0.1.2",
1335 "rand_xorshift",
1336 "winapi 0.3.8",
1337]
1338
1339[[package]]
1340name = "rand"
1341version = "0.7.3" 1265version = "0.7.3"
1342source = "registry+https://github.com/rust-lang/crates.io-index" 1266source = "registry+https://github.com/rust-lang/crates.io-index"
1343checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" 1267checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
1344dependencies = [ 1268dependencies = [
1345 "getrandom", 1269 "getrandom",
1346 "libc", 1270 "libc",
1347 "rand_chacha 0.2.1", 1271 "rand_chacha",
1348 "rand_core 0.5.1", 1272 "rand_core",
1349 "rand_hc 0.2.0", 1273 "rand_hc",
1350 "rand_pcg 0.2.1", 1274 "rand_pcg",
1351]
1352
1353[[package]]
1354name = "rand_chacha"
1355version = "0.1.1"
1356source = "registry+https://github.com/rust-lang/crates.io-index"
1357checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
1358dependencies = [
1359 "autocfg 0.1.7",
1360 "rand_core 0.3.1",
1361] 1275]
1362 1276
1363[[package]] 1277[[package]]
@@ -1367,26 +1281,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1367checksum = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" 1281checksum = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853"
1368dependencies = [ 1282dependencies = [
1369 "c2-chacha", 1283 "c2-chacha",
1370 "rand_core 0.5.1", 1284 "rand_core",
1371] 1285]
1372 1286
1373[[package]] 1287[[package]]
1374name = "rand_core" 1288name = "rand_core"
1375version = "0.3.1"
1376source = "registry+https://github.com/rust-lang/crates.io-index"
1377checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
1378dependencies = [
1379 "rand_core 0.4.2",
1380]
1381
1382[[package]]
1383name = "rand_core"
1384version = "0.4.2"
1385source = "registry+https://github.com/rust-lang/crates.io-index"
1386checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
1387
1388[[package]]
1389name = "rand_core"
1390version = "0.5.1" 1289version = "0.5.1"
1391source = "registry+https://github.com/rust-lang/crates.io-index" 1290source = "registry+https://github.com/rust-lang/crates.io-index"
1392checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" 1291checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
@@ -1396,64 +1295,11 @@ dependencies = [
1396 1295
1397[[package]] 1296[[package]]
1398name = "rand_hc" 1297name = "rand_hc"
1399version = "0.1.0"
1400source = "registry+https://github.com/rust-lang/crates.io-index"
1401checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
1402dependencies = [
1403 "rand_core 0.3.1",
1404]
1405
1406[[package]]
1407name = "rand_hc"
1408version = "0.2.0" 1298version = "0.2.0"
1409source = "registry+https://github.com/rust-lang/crates.io-index" 1299source = "registry+https://github.com/rust-lang/crates.io-index"
1410checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" 1300checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
1411dependencies = [ 1301dependencies = [
1412 "rand_core 0.5.1", 1302 "rand_core",
1413]
1414
1415[[package]]
1416name = "rand_isaac"
1417version = "0.1.1"
1418source = "registry+https://github.com/rust-lang/crates.io-index"
1419checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
1420dependencies = [
1421 "rand_core 0.3.1",
1422]
1423
1424[[package]]
1425name = "rand_jitter"
1426version = "0.1.4"
1427source = "registry+https://github.com/rust-lang/crates.io-index"
1428checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
1429dependencies = [
1430 "libc",
1431 "rand_core 0.4.2",
1432 "winapi 0.3.8",
1433]
1434
1435[[package]]
1436name = "rand_os"
1437version = "0.1.3"
1438source = "registry+https://github.com/rust-lang/crates.io-index"
1439checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
1440dependencies = [
1441 "cloudabi",
1442 "fuchsia-cprng",
1443 "libc",
1444 "rand_core 0.4.2",
1445 "rdrand",
1446 "winapi 0.3.8",
1447]
1448
1449[[package]]
1450name = "rand_pcg"
1451version = "0.1.2"
1452source = "registry+https://github.com/rust-lang/crates.io-index"
1453checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
1454dependencies = [
1455 "autocfg 0.1.7",
1456 "rand_core 0.4.2",
1457] 1303]
1458 1304
1459[[package]] 1305[[package]]
@@ -1462,16 +1308,7 @@ version = "0.2.1"
1462source = "registry+https://github.com/rust-lang/crates.io-index" 1308source = "registry+https://github.com/rust-lang/crates.io-index"
1463checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" 1309checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
1464dependencies = [ 1310dependencies = [
1465 "rand_core 0.5.1", 1311 "rand_core",
1466]
1467
1468[[package]]
1469name = "rand_xorshift"
1470version = "0.1.1"
1471source = "registry+https://github.com/rust-lang/crates.io-index"
1472checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
1473dependencies = [
1474 "rand_core 0.3.1",
1475] 1312]
1476 1313
1477[[package]] 1314[[package]]
@@ -1499,15 +1336,6 @@ dependencies = [
1499] 1336]
1500 1337
1501[[package]] 1338[[package]]
1502name = "rdrand"
1503version = "0.4.0"
1504source = "registry+https://github.com/rust-lang/crates.io-index"
1505checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
1506dependencies = [
1507 "rand_core 0.3.1",
1508]
1509
1510[[package]]
1511name = "redox_syscall" 1339name = "redox_syscall"
1512version = "0.1.56" 1340version = "0.1.56"
1513source = "registry+https://github.com/rust-lang/crates.io-index" 1341source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1604,7 +1432,7 @@ dependencies = [
1604 "indexmap", 1432 "indexmap",
1605 "log", 1433 "log",
1606 "parking_lot", 1434 "parking_lot",
1607 "rand 0.7.3", 1435 "rand",
1608 "rustc-hash", 1436 "rustc-hash",
1609 "salsa-macros", 1437 "salsa-macros",
1610 "smallvec", 1438 "smallvec",
@@ -1753,7 +1581,7 @@ checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
1753dependencies = [ 1581dependencies = [
1754 "cfg-if", 1582 "cfg-if",
1755 "libc", 1583 "libc",
1756 "rand 0.7.3", 1584 "rand",
1757 "redox_syscall", 1585 "redox_syscall",
1758 "remove_dir_all", 1586 "remove_dir_all",
1759 "winapi 0.3.8", 1587 "winapi 0.3.8",
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml
index 9ace35229..d50cf1d20 100644
--- a/crates/ra_ide/Cargo.toml
+++ b/crates/ra_ide/Cargo.toml
@@ -41,9 +41,3 @@ hir = { path = "../ra_hir", package = "ra_hir" }
41 41
42[dev-dependencies] 42[dev-dependencies]
43insta = "0.13.0" 43insta = "0.13.0"
44
45[dev-dependencies.proptest]
46version = "0.9.0"
47# Disable `fork` feature to allow compiling on webassembly
48default-features = false
49features = ["std", "bit-set", "break-dead-code"]
diff --git a/crates/ra_ide_db/Cargo.toml b/crates/ra_ide_db/Cargo.toml
index 495fffb5a..ad3acce59 100644
--- a/crates/ra_ide_db/Cargo.toml
+++ b/crates/ra_ide_db/Cargo.toml
@@ -38,9 +38,3 @@ hir = { path = "../ra_hir", package = "ra_hir" }
38 38
39[dev-dependencies] 39[dev-dependencies]
40insta = "0.13.0" 40insta = "0.13.0"
41
42[dev-dependencies.proptest]
43version = "0.9.0"
44# Disable `fork` feature to allow compiling on webassembly
45default-features = false
46features = ["std", "bit-set", "break-dead-code"]
diff --git a/crates/ra_ide_db/src/line_index.rs b/crates/ra_ide_db/src/line_index.rs
index 452c87ac5..af7b759e5 100644
--- a/crates/ra_ide_db/src/line_index.rs
+++ b/crates/ra_ide_db/src/line_index.rs
@@ -125,30 +125,8 @@ impl LineIndex {
125} 125}
126 126
127#[cfg(test)] 127#[cfg(test)]
128/// Simple reference implementation to use in proptests
129pub fn to_line_col(text: &str, offset: TextUnit) -> LineCol {
130 let mut res = LineCol { line: 0, col_utf16: 0 };
131 for (i, c) in text.char_indices() {
132 if i + c.len_utf8() > offset.to_usize() {
133 // if it's an invalid offset, inside a multibyte char
134 // return as if it was at the start of the char
135 break;
136 }
137 if c == '\n' {
138 res.line += 1;
139 res.col_utf16 = 0;
140 } else {
141 res.col_utf16 += 1;
142 }
143 }
144 res
145}
146
147#[cfg(test)]
148mod test_line_index { 128mod test_line_index {
149 use super::*; 129 use super::*;
150 use proptest::{prelude::*, proptest};
151 use ra_text_edit::test_utils::{arb_offset, arb_text};
152 130
153 #[test] 131 #[test]
154 fn test_line_index() { 132 fn test_line_index() {
@@ -173,44 +151,6 @@ mod test_line_index {
173 assert_eq!(index.line_col(7.into()), LineCol { line: 2, col_utf16: 0 }); 151 assert_eq!(index.line_col(7.into()), LineCol { line: 2, col_utf16: 0 });
174 } 152 }
175 153
176 fn arb_text_with_offset() -> BoxedStrategy<(TextUnit, String)> {
177 arb_text().prop_flat_map(|text| (arb_offset(&text), Just(text))).boxed()
178 }
179
180 fn to_line_col(text: &str, offset: TextUnit) -> LineCol {
181 let mut res = LineCol { line: 0, col_utf16: 0 };
182 for (i, c) in text.char_indices() {
183 if i + c.len_utf8() > offset.to_usize() {
184 // if it's an invalid offset, inside a multibyte char
185 // return as if it was at the start of the char
186 break;
187 }
188 if c == '\n' {
189 res.line += 1;
190 res.col_utf16 = 0;
191 } else {
192 res.col_utf16 += 1;
193 }
194 }
195 res
196 }
197
198 proptest! {
199 #[test]
200 fn test_line_index_proptest((offset, text) in arb_text_with_offset()) {
201 let expected = to_line_col(&text, offset);
202 let line_index = LineIndex::new(&text);
203 let actual = line_index.line_col(offset);
204
205 assert_eq!(actual, expected);
206 }
207 }
208}
209
210#[cfg(test)]
211mod test_utf8_utf16_conv {
212 use super::*;
213
214 #[test] 154 #[test]
215 fn test_char_len() { 155 fn test_char_len() {
216 assert_eq!('メ'.len_utf8(), 3); 156 assert_eq!('メ'.len_utf8(), 3);
diff --git a/crates/ra_ide_db/src/line_index_utils.rs b/crates/ra_ide_db/src/line_index_utils.rs
index 435b06511..75a498151 100644
--- a/crates/ra_ide_db/src/line_index_utils.rs
+++ b/crates/ra_ide_db/src/line_index_utils.rs
@@ -297,45 +297,3 @@ impl RunningLineCol {
297 self.col_adjust += range.len() - TextUnit::from(1); 297 self.col_adjust += range.len() - TextUnit::from(1);
298 } 298 }
299} 299}
300
301#[cfg(test)]
302mod test {
303 use proptest::{prelude::*, proptest};
304 use ra_text_edit::test_utils::{arb_offset, arb_text_with_edit};
305 use ra_text_edit::TextEdit;
306
307 use crate::line_index;
308
309 use super::*;
310
311 #[derive(Debug)]
312 struct ArbTextWithEditAndOffset {
313 text: String,
314 edit: TextEdit,
315 edited_text: String,
316 offset: TextUnit,
317 }
318
319 fn arb_text_with_edit_and_offset() -> BoxedStrategy<ArbTextWithEditAndOffset> {
320 arb_text_with_edit()
321 .prop_flat_map(|x| {
322 let edited_text = x.edit.apply(&x.text);
323 let arb_offset = arb_offset(&edited_text);
324 (Just(x), Just(edited_text), arb_offset).prop_map(|(x, edited_text, offset)| {
325 ArbTextWithEditAndOffset { text: x.text, edit: x.edit, edited_text, offset }
326 })
327 })
328 .boxed()
329 }
330
331 proptest! {
332 #[test]
333 fn test_translate_offset_with_edit(x in arb_text_with_edit_and_offset()) {
334 let expected = line_index::to_line_col(&x.edited_text, x.offset);
335 let line_index = LineIndex::new(&x.text);
336 let actual = translate_offset_with_edit(&line_index, x.offset, &x.edit);
337
338 assert_eq!(actual, expected);
339 }
340 }
341}
diff --git a/crates/ra_text_edit/Cargo.toml b/crates/ra_text_edit/Cargo.toml
index 8573c521a..4490ae43b 100644
--- a/crates/ra_text_edit/Cargo.toml
+++ b/crates/ra_text_edit/Cargo.toml
@@ -11,11 +11,5 @@ doctest = false
11[dependencies] 11[dependencies]
12text_unit = "0.1.6" 12text_unit = "0.1.6"
13 13
14[dependencies.proptest]
15version = "0.9.0"
16# Disable `fork` feature to allow compiling on webassembly
17default-features = false
18features = ["std", "bit-set", "break-dead-code"]
19
20[dev-dependencies] 14[dev-dependencies]
21test_utils = { path = "../test_utils" } 15test_utils = { path = "../test_utils" }
diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs
index 37f23d043..f6769e6a6 100644
--- a/crates/ra_text_edit/src/lib.rs
+++ b/crates/ra_text_edit/src/lib.rs
@@ -1,12 +1,11 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3mod text_edit; 3mod text_edit;
4pub mod test_utils;
5
6pub use crate::text_edit::{TextEdit, TextEditBuilder};
7 4
8use text_unit::{TextRange, TextUnit}; 5use text_unit::{TextRange, TextUnit};
9 6
7pub use crate::text_edit::{TextEdit, TextEditBuilder};
8
10/// Must not overlap with other `AtomTextEdit`s 9/// Must not overlap with other `AtomTextEdit`s
11#[derive(Debug, Clone)] 10#[derive(Debug, Clone)]
12pub struct AtomTextEdit { 11pub struct AtomTextEdit {
diff --git a/crates/ra_text_edit/src/test_utils.rs b/crates/ra_text_edit/src/test_utils.rs
deleted file mode 100644
index d4c7840ff..000000000
--- a/crates/ra_text_edit/src/test_utils.rs
+++ /dev/null
@@ -1,83 +0,0 @@
1//! FIXME: write short doc here
2
3use crate::{AtomTextEdit, TextEdit};
4use proptest::prelude::*;
5use text_unit::{TextRange, TextUnit};
6
7pub fn arb_text() -> proptest::string::RegexGeneratorStrategy<String> {
8 // generate multiple newlines
9 proptest::string::string_regex("(.*\n?)*").unwrap()
10}
11
12fn text_offsets(text: &str) -> Vec<TextUnit> {
13 text.char_indices().map(|(i, _)| TextUnit::from_usize(i)).collect()
14}
15
16pub fn arb_offset(text: &str) -> BoxedStrategy<TextUnit> {
17 let offsets = text_offsets(text);
18 // this is necessary to avoid "Uniform::new called with `low >= high`" panic
19 if offsets.is_empty() {
20 Just(TextUnit::from(0)).boxed()
21 } else {
22 prop::sample::select(offsets).boxed()
23 }
24}
25
26pub fn arb_text_edit(text: &str) -> BoxedStrategy<TextEdit> {
27 if text.is_empty() {
28 // only valid edits
29 return Just(vec![])
30 .boxed()
31 .prop_union(
32 arb_text()
33 .prop_map(|text| vec![AtomTextEdit::insert(TextUnit::from(0), text)])
34 .boxed(),
35 )
36 .prop_map(TextEdit::from_atoms)
37 .boxed();
38 }
39
40 let offsets = text_offsets(text);
41 let max_cuts = 7.min(offsets.len());
42
43 proptest::sample::subsequence(offsets, 0..max_cuts)
44 .prop_flat_map(|cuts| {
45 let strategies: Vec<_> = cuts
46 .chunks(2)
47 .map(|chunk| match *chunk {
48 [from, to] => {
49 let range = TextRange::from_to(from, to);
50 Just(AtomTextEdit::delete(range))
51 .boxed()
52 .prop_union(
53 arb_text()
54 .prop_map(move |text| AtomTextEdit::replace(range, text))
55 .boxed(),
56 )
57 .boxed()
58 }
59 [x] => arb_text().prop_map(move |text| AtomTextEdit::insert(x, text)).boxed(),
60 _ => unreachable!(),
61 })
62 .collect();
63 strategies
64 })
65 .prop_map(TextEdit::from_atoms)
66 .boxed()
67}
68
69#[derive(Debug, Clone)]
70pub struct ArbTextWithEdit {
71 pub text: String,
72 pub edit: TextEdit,
73}
74
75pub fn arb_text_with_edit() -> BoxedStrategy<ArbTextWithEdit> {
76 let text = arb_text();
77 text.prop_flat_map(|s| {
78 let edit = arb_text_edit(&s);
79 (Just(s), edit)
80 })
81 .prop_map(|(text, edit)| ArbTextWithEdit { text, edit })
82 .boxed()
83}
diff --git a/xtask/tests/tidy-tests/docs.rs b/xtask/tests/tidy-tests/docs.rs
index 6a69e7d6a..7ae73b934 100644
--- a/xtask/tests/tidy-tests/docs.rs
+++ b/xtask/tests/tidy-tests/docs.rs
@@ -1,5 +1,6 @@
1use std::{collections::HashMap, fs, io::prelude::*, io::BufReader, path::Path}; 1use std::{collections::HashMap, fs, io::prelude::*, io::BufReader, path::Path};
2 2
3use anyhow::Context;
3use walkdir::{DirEntry, WalkDir}; 4use walkdir::{DirEntry, WalkDir};
4use xtask::project_root; 5use xtask::project_root;
5 6
@@ -50,7 +51,10 @@ fn no_docs_comments() {
50 } 51 }
51 let mut reader = BufReader::new(fs::File::open(f.path()).unwrap()); 52 let mut reader = BufReader::new(fs::File::open(f.path()).unwrap());
52 let mut line = String::new(); 53 let mut line = String::new();
53 reader.read_line(&mut line).unwrap(); 54 reader
55 .read_line(&mut line)
56 .with_context(|| format!("Failed to read {}", f.path().display()))
57 .unwrap();
54 58
55 if line.starts_with("//!") { 59 if line.starts_with("//!") {
56 if line.contains("FIXME") { 60 if line.contains("FIXME") {