aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-07 12:27:17 +0000
committerGitHub <[email protected]>2021-01-07 12:27:17 +0000
commit7967ce85cfc5fc2b1996425b44f2a45d0841c8ff (patch)
tree4495b9de7ea6c8e9dd9fd347d42517e9dee511fa /crates/test_utils
parentc3e9fb183bc287d83b97b776edc87c54d18d1a73 (diff)
parent72b9a4fbd3c12f3250b9157a1d44230e04ec8b22 (diff)
Merge #7184
7184: Changes Cursor Marker To $0 r=matklad a=kevaundray Co-authored-by: Kevaundray Wedderburn <[email protected]>
Diffstat (limited to 'crates/test_utils')
-rw-r--r--crates/test_utils/src/lib.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index 656dd2072..05d6e8c9e 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -3,7 +3,7 @@
3//! Most notable things are: 3//! Most notable things are:
4//! 4//!
5//! * Rich text comparison, which outputs a diff. 5//! * Rich text comparison, which outputs a diff.
6//! * Extracting markup (mainly, `<|>` markers) out of fixture strings. 6//! * Extracting markup (mainly, `$0` markers) out of fixture strings.
7//! * marks (see the eponymous module). 7//! * marks (see the eponymous module).
8 8
9#[macro_use] 9#[macro_use]
@@ -25,7 +25,7 @@ pub use rustc_hash::FxHashMap;
25 25
26pub use crate::fixture::Fixture; 26pub use crate::fixture::Fixture;
27 27
28pub const CURSOR_MARKER: &str = "<|>"; 28pub const CURSOR_MARKER: &str = "$0";
29 29
30/// Asserts that two strings are equal, otherwise displays a rich diff between them. 30/// Asserts that two strings are equal, otherwise displays a rich diff between them.
31/// 31///
@@ -62,7 +62,7 @@ pub fn extract_offset(text: &str) -> (TextSize, String) {
62 } 62 }
63} 63}
64 64
65/// Returns the offset of the first occurence of `<|>` marker and the copy of `text` 65/// Returns the offset of the first occurence of `$0` marker and the copy of `text`
66/// without the marker. 66/// without the marker.
67fn try_extract_offset(text: &str) -> Option<(TextSize, String)> { 67fn try_extract_offset(text: &str) -> Option<(TextSize, String)> {
68 let cursor_pos = text.find(CURSOR_MARKER)?; 68 let cursor_pos = text.find(CURSOR_MARKER)?;
@@ -81,7 +81,7 @@ pub fn extract_range(text: &str) -> (TextRange, String) {
81 } 81 }
82} 82}
83 83
84/// Returns `TextRange` between the first two markers `<|>...<|>` and the copy 84/// Returns `TextRange` between the first two markers `$0...$0` and the copy
85/// of `text` without both of these markers. 85/// of `text` without both of these markers.
86fn try_extract_range(text: &str) -> Option<(TextRange, String)> { 86fn try_extract_range(text: &str) -> Option<(TextRange, String)> {
87 let (start, text) = try_extract_offset(text)?; 87 let (start, text) = try_extract_offset(text)?;
@@ -104,11 +104,11 @@ impl From<RangeOrOffset> for TextRange {
104 } 104 }
105} 105}
106 106
107/// Extracts `TextRange` or `TextSize` depending on the amount of `<|>` markers 107/// Extracts `TextRange` or `TextSize` depending on the amount of `$0` markers
108/// found in `text`. 108/// found in `text`.
109/// 109///
110/// # Panics 110/// # Panics
111/// Panics if no `<|>` marker is present in the `text`. 111/// Panics if no `$0` marker is present in the `text`.
112pub fn extract_range_or_offset(text: &str) -> (RangeOrOffset, String) { 112pub fn extract_range_or_offset(text: &str) -> (RangeOrOffset, String) {
113 if let Some((range, text)) = try_extract_range(text) { 113 if let Some((range, text)) = try_extract_range(text) {
114 return (RangeOrOffset::Range(range), text); 114 return (RangeOrOffset::Range(range), text);
@@ -164,12 +164,12 @@ fn test_extract_tags() {
164 assert_eq!(actual, vec![("fn main() {}", Some("fn".into())), ("main", None),]); 164 assert_eq!(actual, vec![("fn main() {}", Some("fn".into())), ("main", None),]);
165} 165}
166 166
167/// Inserts `<|>` marker into the `text` at `offset`. 167/// Inserts `$0` marker into the `text` at `offset`.
168pub fn add_cursor(text: &str, offset: TextSize) -> String { 168pub fn add_cursor(text: &str, offset: TextSize) -> String {
169 let offset: usize = offset.into(); 169 let offset: usize = offset.into();
170 let mut res = String::new(); 170 let mut res = String::new();
171 res.push_str(&text[..offset]); 171 res.push_str(&text[..offset]);
172 res.push_str("<|>"); 172 res.push_str("$0");
173 res.push_str(&text[offset..]); 173 res.push_str(&text[offset..]);
174 res 174 res
175} 175}