diff options
Diffstat (limited to 'crates/test_utils/src')
-rw-r--r-- | crates/test_utils/src/lib.rs | 16 |
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 | ||
26 | pub use crate::fixture::Fixture; | 26 | pub use crate::fixture::Fixture; |
27 | 27 | ||
28 | pub const CURSOR_MARKER: &str = "<|>"; | 28 | pub 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. |
67 | fn try_extract_offset(text: &str) -> Option<(TextSize, String)> { | 67 | fn 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. |
86 | fn try_extract_range(text: &str) -> Option<(TextRange, String)> { | 86 | fn 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`. |
112 | pub fn extract_range_or_offset(text: &str) -> (RangeOrOffset, String) { | 112 | pub 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`. |
168 | pub fn add_cursor(text: &str, offset: TextSize) -> String { | 168 | pub 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 | } |