aboutsummaryrefslogtreecommitdiff
path: root/azalea-brigadier/tests/builder/argument_builder_test.rs
blob: ee44f5e665822b0885a96bf882761c9f1f640d0d (plain)
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
use std::rc::Rc;

use crate::{
    arguments::integer_argument_type::integer,
    builder::{literal_argument_builder::literal, required_argument_builder::argument},
};

use super::ArgumentBuilder;

// public class ArgumentBuilderTest {
//     private TestableArgumentBuilder<Object> builder;

//     @Before
//     public void setUp() throws Exception {
//         builder = new TestableArgumentBuilder<>();
//     }

//     @Test
//     public void testArguments() throws Exception {
//         final RequiredArgumentBuilder<Object, ?> argument = argument("bar",
// integer());

//         builder.then(argument);

//         assertThat(builder.getArguments(), hasSize(1));
//         assertThat(builder.getArguments(), hasItem((CommandNode<Object>)
// argument.build()));     }

#[test]
fn test_arguments() {
    let mut builder: ArgumentBuilder<()> = literal("foo");

    let argument: ArgumentBuilder<()> = argument("bar", integer());
    builder.then(argument.clone());
    assert_eq!(builder.arguments.children.len(), 1);
    let built_argument = Rc::new(argument.build());
    assert!(builder
        .arguments
        .children
        .values()
        .any(|e| *e.read() == *built_argument));
}

//     @Test
//     public void testRedirect() throws Exception {
//         final CommandNode<Object> target = mock(CommandNode.class);
//         builder.redirect(target);
//         assertThat(builder.getRedirect(), is(target));
//     }

//     @Test(expected = IllegalStateException.class)
//     public void testRedirect_withChild() throws Exception {
//         final CommandNode<Object> target = mock(CommandNode.class);
//         builder.then(literal("foo"));
//         builder.redirect(target);
//     }

//     @Test(expected = IllegalStateException.class)
//     public void testThen_withRedirect() throws Exception {
//         final CommandNode<Object> target = mock(CommandNode.class);
//         builder.redirect(target);
//         builder.then(literal("foo"));
//     }

//     private static class TestableArgumentBuilder<S> extends
// ArgumentBuilder<S, TestableArgumentBuilder<S>> {         @Override
//         protected TestableArgumentBuilder<S> getThis() {
//             return this;
//         }

//         @Override
//         public CommandNode<S> build() {
//             return null;
//         }
//     }
// }