summary refs log tree commit diff stats
path: root/tests/suggestion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/suggestion.rs')
-rw-r--r--tests/suggestion.rs89
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/suggestion.rs b/tests/suggestion.rs
new file mode 100644
index 0000000..0e1b9fe
--- /dev/null
+++ b/tests/suggestion.rs
@@ -0,0 +1,89 @@
+// Copyright (c) 2021 Soni L.
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license.
+
+// because we wanna use double underscore (__) for test names
+#![allow(non_snake_case)]
+
+use ::iosonism::suggestion::Suggestion;
+
+#[test]
+fn test_apply__insertion_start() {
+    let s = Suggestion::new(0..0, "And so I said: ".into());
+    assert_eq!(s.apply("Hello world!".into()), "And so I said: Hello world!");
+}
+
+#[test]
+fn test_apply__insertion_middle() {
+    let s = Suggestion::new(6..6, "small ".into());
+    assert_eq!(s.apply("Hello world!".into()), "Hello small world!");
+}
+
+#[test]
+fn test_apply__insertion_end() {
+    let s = Suggestion::new(5..5, " world!".into());
+    assert_eq!(s.apply("Hello".into()), "Hello world!");
+}
+
+#[test]
+fn test_apply__replacement_start() {
+    let s = Suggestion::new(0..5, "Goodbye".into());
+    assert_eq!(s.apply("Hello world!".into()), "Goodbye world!");
+}
+
+#[test]
+fn test_apply__replacement_middle() {
+    let s = Suggestion::new(6..11, "Alex".into());
+    assert_eq!(s.apply("Hello world!".into()), "Hello Alex!");
+}
+
+#[test]
+fn test_apply__replacement_end() {
+    let s = Suggestion::new(6..12, "Creeper!".into());
+    assert_eq!(s.apply("Hello world!".into()), "Hello Creeper!");
+}
+
+#[test]
+fn test_apply__replacement_everything() {
+    let s = Suggestion::new(0..12, "Oh dear.".into());
+    assert_eq!(s.apply("Hello world!".into()), "Oh dear.");
+}
+
+#[test]
+fn test_expand__unchanged() {
+    let s = Suggestion::new(1..1, "oo".into());
+    assert_eq!(s.expand("f".into(), 1..1), s);
+}
+
+#[test]
+fn test_expand__left() {
+    let s = Suggestion::new(1..1, "oo".into());
+    assert_eq!(s.expand("f".into(), 0..1), Suggestion::new(0..1, "foo".into()));
+}
+
+#[test]
+fn test_expand__right() {
+    let s = Suggestion::new(0..0, "minecraft:".into());
+    assert_eq!(
+        s.expand("fish".into(), 0..4),
+        Suggestion::new(0..4, "minecraft:fish".into()),
+    );
+}
+
+#[test]
+fn test_expand__both() {
+    let s = Suggestion::new(11..11, "minecraft:".into());
+    assert_eq!(
+        s.expand("give Steve fish_block".into(), 5..21),
+        Suggestion::new(5..21, "Steve minecraft:fish_block".into()),
+    );
+}
+
+#[test]
+fn test_expand__replacement() {
+    let s = Suggestion::new(6..11, "strangers".into());
+    assert_eq!(
+        s.expand("Hello world!".into(), 0..12),
+        Suggestion::new(0..12, "Hello strangers!".into()),
+    );
+}