summary refs log tree commit diff stats
path: root/tests/suggestion.rs
blob: 0e1b9fe967327a1d578486f263af869ecb2a2241 (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
87
88
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()),
    );
}