summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2021-11-28 12:39:19 -0300
committerSoniEx2 <endermoneymod@gmail.com>2021-11-28 12:39:19 -0300
commit8ae6936564142572066d8c17109ff7205a1d6111 (patch)
tree6a8bf0be4ca0ffeccd84997b280b4efa5e87c1a9 /tests
parentbe4c770a7c65bb1eb3d8b96128abfc5fa89d63d1 (diff)
Implement Suggestions
Diffstat (limited to 'tests')
-rw-r--r--tests/suggestion.rs34
-rw-r--r--tests/suggestions.rs53
2 files changed, 68 insertions, 19 deletions
diff --git a/tests/suggestion.rs b/tests/suggestion.rs
index 0e1b9fe..5886f16 100644
--- a/tests/suggestion.rs
+++ b/tests/suggestion.rs
@@ -51,39 +51,35 @@ fn test_apply__replacement_everything() {
 
 #[test]
 fn test_expand__unchanged() {
-    let s = Suggestion::new(1..1, "oo".into());
-    assert_eq!(s.expand("f".into(), 1..1), s);
+    let mut s = Suggestion::new(1..1, "oo".into());
+    s.expand("f", 1..1);
+    assert_eq!(s, Suggestion::new(1..1, "oo".into()));
 }
 
 #[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()));
+    let mut s = Suggestion::new(1..1, "oo".into());
+    s.expand("f", 0..1);
+    assert_eq!(s, 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()),
-    );
+    let mut s = Suggestion::new(0..0, "minecraft:".into());
+    s.expand("fish", 0..4);
+    assert_eq!(s, 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()),
-    );
+    let mut s = Suggestion::new(11..11, "minecraft:".into());
+    s.expand("give Steve fish_block", 5..21);
+    assert_eq!(s, 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()),
-    );
+    let mut s = Suggestion::new(6..11, "strangers".into());
+    s.expand("Hello world!", 0..12);
+    assert_eq!(s, Suggestion::new(0..12, "Hello strangers!".into()));
 }
diff --git a/tests/suggestions.rs b/tests/suggestions.rs
new file mode 100644
index 0000000..d7f3631
--- /dev/null
+++ b/tests/suggestions.rs
@@ -0,0 +1,53 @@
+// 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;
+use ::iosonism::suggestion::Suggestions;
+
+#[test]
+fn test_merge__empty() {
+    let merged = Suggestions::merge("foo b", Vec::new());
+    assert!(merged.is_empty());
+}
+
+#[test]
+fn test_merge__single() {
+    let suggestions = Suggestions::create("foo b", vec![
+        Suggestion::new(5..5, "ar".into()),
+    ]);
+    let merged = Suggestions::merge("foo b", vec![suggestions.clone()]);
+    assert_eq!(merged, suggestions);
+}
+
+#[test]
+fn test_merge__multiple() {
+    // it is possible the equivalent of this test fails sometimes in brigdier,
+    // but it should never fail here.
+    // also we use ASCII/UTF-8 ordering rather than locale-sensitive ordering.
+    let a = Suggestions::create("foo b", vec![
+        Suggestion::new(5..5, "ar".into()),
+        Suggestion::new(5..5, "az".into()),
+        Suggestion::new(5..5, "Ar".into()),
+    ]);
+    let b = Suggestions::create("foo b", vec![
+        Suggestion::new(4..5, "foo".into()),
+        Suggestion::new(4..5, "qux".into()),
+        Suggestion::new(4..5, "apple".into()),
+        Suggestion::new(4..5, "Bar".into()),
+    ]);
+    let merged = Suggestions::merge("foo b", vec![a, b]);
+    assert_eq!(merged.get_range(), 4..5);
+    assert_eq!(merged.take_list(), vec![
+        Suggestion::new(4..5, "Bar".into()),
+        Suggestion::new(4..5, "apple".into()),
+        Suggestion::new(4..5, "bAr".into()),
+        Suggestion::new(4..5, "bar".into()),
+        Suggestion::new(4..5, "baz".into()),
+        Suggestion::new(4..5, "foo".into()),
+        Suggestion::new(4..5, "qux".into()),
+    ]);
+}