aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils
diff options
context:
space:
mode:
Diffstat (limited to 'crates/test_utils')
-rw-r--r--crates/test_utils/Cargo.toml2
-rw-r--r--crates/test_utils/src/lib.rs26
2 files changed, 14 insertions, 14 deletions
diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml
index 6a7c6d6f9..8ec986bcb 100644
--- a/crates/test_utils/Cargo.toml
+++ b/crates/test_utils/Cargo.toml
@@ -9,5 +9,5 @@ doctest = false
9 9
10[dependencies] 10[dependencies]
11difference = "2.0.0" 11difference = "2.0.0"
12text_unit = "0.1.10" 12text-size = "1.0.0"
13serde_json = "1.0.48" 13serde_json = "1.0.48"
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index 4164bfd5e..b1365444a 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -15,7 +15,7 @@ use std::{
15}; 15};
16 16
17use serde_json::Value; 17use serde_json::Value;
18use text_unit::{TextRange, TextUnit}; 18use text_size::{TextRange, TextSize};
19 19
20pub use difference::Changeset as __Changeset; 20pub use difference::Changeset as __Changeset;
21 21
@@ -49,7 +49,7 @@ macro_rules! assert_eq_text {
49} 49}
50 50
51/// Infallible version of `try_extract_offset()`. 51/// Infallible version of `try_extract_offset()`.
52pub fn extract_offset(text: &str) -> (TextUnit, String) { 52pub fn extract_offset(text: &str) -> (TextSize, String) {
53 match try_extract_offset(text) { 53 match try_extract_offset(text) {
54 None => panic!("text should contain cursor marker"), 54 None => panic!("text should contain cursor marker"),
55 Some(result) => result, 55 Some(result) => result,
@@ -58,12 +58,12 @@ pub fn extract_offset(text: &str) -> (TextUnit, String) {
58 58
59/// Returns the offset of the first occurence of `<|>` marker and the copy of `text` 59/// Returns the offset of the first occurence of `<|>` marker and the copy of `text`
60/// without the marker. 60/// without the marker.
61fn try_extract_offset(text: &str) -> Option<(TextUnit, String)> { 61fn try_extract_offset(text: &str) -> Option<(TextSize, String)> {
62 let cursor_pos = text.find(CURSOR_MARKER)?; 62 let cursor_pos = text.find(CURSOR_MARKER)?;
63 let mut new_text = String::with_capacity(text.len() - CURSOR_MARKER.len()); 63 let mut new_text = String::with_capacity(text.len() - CURSOR_MARKER.len());
64 new_text.push_str(&text[..cursor_pos]); 64 new_text.push_str(&text[..cursor_pos]);
65 new_text.push_str(&text[cursor_pos + CURSOR_MARKER.len()..]); 65 new_text.push_str(&text[cursor_pos + CURSOR_MARKER.len()..]);
66 let cursor_pos = TextUnit::from(cursor_pos as u32); 66 let cursor_pos = TextSize::from(cursor_pos as u32);
67 Some((cursor_pos, new_text)) 67 Some((cursor_pos, new_text))
68} 68}
69 69
@@ -80,25 +80,25 @@ pub fn extract_range(text: &str) -> (TextRange, String) {
80fn try_extract_range(text: &str) -> Option<(TextRange, String)> { 80fn try_extract_range(text: &str) -> Option<(TextRange, String)> {
81 let (start, text) = try_extract_offset(text)?; 81 let (start, text) = try_extract_offset(text)?;
82 let (end, text) = try_extract_offset(&text)?; 82 let (end, text) = try_extract_offset(&text)?;
83 Some((TextRange::from_to(start, end), text)) 83 Some((TextRange::new(start, end), text))
84} 84}
85 85
86#[derive(Clone, Copy)] 86#[derive(Clone, Copy)]
87pub enum RangeOrOffset { 87pub enum RangeOrOffset {
88 Range(TextRange), 88 Range(TextRange),
89 Offset(TextUnit), 89 Offset(TextSize),
90} 90}
91 91
92impl From<RangeOrOffset> for TextRange { 92impl From<RangeOrOffset> for TextRange {
93 fn from(selection: RangeOrOffset) -> Self { 93 fn from(selection: RangeOrOffset) -> Self {
94 match selection { 94 match selection {
95 RangeOrOffset::Range(it) => it, 95 RangeOrOffset::Range(it) => it,
96 RangeOrOffset::Offset(it) => TextRange::from_to(it, it), 96 RangeOrOffset::Offset(it) => TextRange::new(it, it),
97 } 97 }
98 } 98 }
99} 99}
100 100
101/// Extracts `TextRange` or `TextUnit` depending on the amount of `<|>` markers 101/// Extracts `TextRange` or `TextSize` depending on the amount of `<|>` markers
102/// found in `text`. 102/// found in `text`.
103/// 103///
104/// # Panics 104/// # Panics
@@ -129,13 +129,13 @@ pub fn extract_ranges(mut text: &str, tag: &str) -> (Vec<TextRange>, String) {
129 text = &text[i..]; 129 text = &text[i..];
130 if text.starts_with(&open) { 130 if text.starts_with(&open) {
131 text = &text[open.len()..]; 131 text = &text[open.len()..];
132 let from = TextUnit::of_str(&res); 132 let from = TextSize::of(&res);
133 stack.push(from); 133 stack.push(from);
134 } else if text.starts_with(&close) { 134 } else if text.starts_with(&close) {
135 text = &text[close.len()..]; 135 text = &text[close.len()..];
136 let from = stack.pop().unwrap_or_else(|| panic!("unmatched </{}>", tag)); 136 let from = stack.pop().unwrap_or_else(|| panic!("unmatched </{}>", tag));
137 let to = TextUnit::of_str(&res); 137 let to = TextSize::of(&res);
138 ranges.push(TextRange::from_to(from, to)); 138 ranges.push(TextRange::new(from, to));
139 } 139 }
140 } 140 }
141 } 141 }
@@ -146,8 +146,8 @@ pub fn extract_ranges(mut text: &str, tag: &str) -> (Vec<TextRange>, String) {
146} 146}
147 147
148/// Inserts `<|>` marker into the `text` at `offset`. 148/// Inserts `<|>` marker into the `text` at `offset`.
149pub fn add_cursor(text: &str, offset: TextUnit) -> String { 149pub fn add_cursor(text: &str, offset: TextSize) -> String {
150 let offset: usize = offset.to_usize(); 150 let offset: usize = offset.into();
151 let mut res = String::new(); 151 let mut res = String::new();
152 res.push_str(&text[..offset]); 152 res.push_str(&text[..offset]);
153 res.push_str("<|>"); 153 res.push_str("<|>");