use super::*;
#[test]
fn growing_snapshots_become_appending_deltas() {
let mut deltas = TextDeltaBuilder::new();
assert_eq!(deltas.update("hello").as_deref(), Some("hello"));
assert_eq!(deltas.update("hello world").as_deref(), Some(" world"));
assert_eq!(deltas.update("hello world!").as_deref(), Some("!"));
assert_eq!(deltas.sent(), "hello world!");
}
#[test]
fn a_rollback_snapshot_sends_nothing_and_resyncs_on_reextension() {
let mut deltas = TextDeltaBuilder::new();
assert_eq!(deltas.update("hello worl").as_deref(), Some("hello worl"));
assert_eq!(deltas.update("hello").as_deref(), None);
assert_eq!(deltas.update("help").as_deref(), None);
assert_eq!(deltas.update("hello world").as_deref(), Some("d"));
assert_eq!(deltas.sent(), "hello world");
}
#[test]
fn a_corrected_utterance_skips_until_done_carries_the_truth() {
let mut deltas = TextDeltaBuilder::new();
assert_eq!(
deltas.update("今天天气很号").as_deref(),
Some("今天天气很号")
);
assert_eq!(deltas.update("今天天气很好").as_deref(), None);
assert_eq!(deltas.sent(), "今天天气很号");
}
#[test]
fn unchanged_snapshots_yield_no_delta() {
let mut deltas = TextDeltaBuilder::new();
assert_eq!(deltas.update("你好").as_deref(), Some("你好"));
assert_eq!(deltas.update("你好").as_deref(), None);
}
#[test]
fn a_snapshot_that_only_shrinks_still_blocks_until_reextension() {
let mut deltas = TextDeltaBuilder::new();
assert_eq!(
deltas.update("你好世界再见").as_deref(),
Some("你好世界再见")
);
assert_eq!(deltas.update("你好").as_deref(), None);
assert_eq!(deltas.update("你好世界再见!").as_deref(), Some("!"));
}