summary refs log tree commit diff stats
path: root/tests/suggestion.rs
blob: 8190332434ed046b0d9204a08eb0861a511f9ada (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2021 Soni L.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// Documentation and comments licensed under CC BY-SA 4.0.

// 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 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 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 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 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 mut s = Suggestion::new(6..11, "strangers".into());
    s.expand("Hello world!", 0..12);
    assert_eq!(s, Suggestion::new(0..12, "Hello strangers!".into()));
}