Skip to content

Commit 8bebd5a

Browse files
committed
Update test
1 parent b7b711a commit 8bebd5a

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/channel.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ pub struct Channel {
7474
pub buffer: Arc<Mutex<String>>,
7575
pub lines: Vec<String>,
7676
pub savepoints: HashMap<usize,usize>,
77-
pub current_offset: Option<usize>
7877
}
7978

8079
impl Channel {
@@ -92,7 +91,6 @@ impl Channel {
9291
// savepoint
9392
Entry::Occupied(occupied_entry) => {
9493
let offset = occupied_entry.get();
95-
self.current_offset = Some(*offset);
9694
content[0..*offset].lines().map(|s|s.to_string()).collect()
9795
}
9896
Entry::Vacant(_) => {
@@ -107,7 +105,6 @@ impl Channel {
107105
buffer: Arc::new(Mutex::new(String::new())),
108106
lines: vec![],
109107
savepoints: HashMap::new(),
110-
current_offset: None,
111108
}
112109
}
113110

@@ -148,22 +145,43 @@ mod test {
148145
channel.write("baf\nbaz\n".to_string()).await;
149146

150147
assert_eq!(0, channel.lines.len());
151-
channel.unload(100).await;
148+
channel.savepoint(0).await;
149+
channel.unload(0).await;
152150

153151
assert_eq!(6, channel.lines.len());
154152
}
155153

154+
#[tokio::test]
155+
pub async fn test_savepoint() {
156+
let mut channel = Channel::new("test".to_string());
157+
channel.write("foobar\nbar".to_string()).await;
158+
channel.savepoint(0).await;
159+
channel.write("\nbarfoo\nbaz\none\ntwo".to_string()).await;
160+
channel.savepoint(1).await;
161+
channel.write("baf\nbaz\n".to_string()).await;
162+
163+
assert_eq!(0, channel.lines.len());
164+
channel.savepoint(1).await;
165+
channel.unload(1).await;
166+
assert_eq!(7, channel.lines.len());
167+
channel.unload(0).await;
168+
assert_eq!(2, channel.lines.len());
169+
}
170+
156171
#[tokio::test]
157172
pub async fn test_channel_lines_with_unterminated_previous() {
158173
let mut channel = Channel::default();
159174
channel.write("foobar".to_string()).await;
160-
channel.unload(100).await;
175+
channel.savepoint(0).await;
176+
channel.unload(0).await;
161177
assert_eq!(1, channel.lines.len());
162178
channel.write("barfoo".to_string()).await;
163-
channel.unload(100).await;
179+
channel.savepoint(0).await;
180+
channel.unload(0).await;
164181
assert_eq!(1, channel.lines.len());
165182
channel.write("barfoo\n".to_string()).await;
166-
channel.unload(100).await;
183+
channel.savepoint(0).await;
184+
channel.unload(0).await;
167185
assert_eq!(1, channel.lines.len());
168186
}
169187

0 commit comments

Comments
 (0)