package cat.nyaa.nyaacore;

import org.junit.Test;

import static org.junit.Assert.*;

public class ArgumentsTest {
    @Test
    public void test1() throws Exception {
        String cmd = "`foo bar` far `bar \\`foo`";
        CommandReceiver.Arguments arg = CommandReceiver.Arguments.parse(cmd.split(" "));
        assertNotNull(arg);
        assertEquals("foo bar", arg.nextString());
        assertEquals("far", arg.nextString());
        assertEquals("bar `foo", arg.nextString());
    }

    @Test
    public void test2() throws Exception {
        String cmd = "key:33 a key:66 b key:13 `key2:a b c` `key 3:d e f`";
        CommandReceiver.Arguments arg = CommandReceiver.Arguments.parse(cmd.split(" "));
        assertNotNull(arg);
        assertEquals("key:33", arg.nextString());
        assertEquals(66, arg.argInt("key"));
        assertEquals("a b c", arg.argString("key2"));
        assertEquals("d e f", arg.argString("key 3"));

        assertEquals("a", arg.nextString());
        assertEquals("b", arg.nextString());
        assertEquals("key:13", arg.nextString());
        assertNull(arg.next());
    }

    @Test
    public void test3() throws Exception {
        String cmd = "t w key:`3` key2:`/co l u:miu_bug` ke3y:`12`";
        CommandReceiver.Arguments arg = CommandReceiver.Arguments.parse(cmd.split(" "));
        assertNotNull(arg);
        assertEquals(3, arg.argInt("key"));
        assertEquals("/co l u:miu_bug", arg.argString("key2"));
        assertEquals("t", arg.next());
        assertEquals("12", arg.argString("ke3y"));
        assertEquals("w", arg.nextString());
        try {
            arg.nextString();
        } catch (CommandReceiver.BadCommandException e) {//seems that no expectThrows available here
            assertEquals("internal.error.no_more_string", e.getMessage());//magic string, but no impact...
        }
    }

    @Test
    public void test4() throws Exception {
        String cmd = "key :`3`";
        CommandReceiver.Arguments arg = CommandReceiver.Arguments.parse(cmd.split(" "));
        assertNull(arg);
    }

    @Test
    public void test5() throws Exception {
        String cmd = "key: `3`";
        CommandReceiver.Arguments arg = CommandReceiver.Arguments.parse(cmd.split(" "));
        assertNotNull(arg);
        assertEquals("key:", arg.top());
        assertEquals("", arg.argString("key"));
        assertEquals("3", arg.nextString());
        assertNull(arg.next());
    }
}

@@ -291,35 +291,41 @@
 e(cmd.split(%22 %22)
+, null
 );%0A
-
         assertNo
@@ -700,32 +700,38 @@
 e(cmd.split(%22 %22)
+, null
 );%0A        asser
@@ -1329,32 +1329,38 @@
 e(cmd.split(%22 %22)
+, null
 );%0A        asser
@@ -2050,32 +2050,38 @@
 e(cmd.split(%22 %22)
+, null
 );%0A        asser
@@ -2181,24 +2181,24 @@
 %22key: %603%60%22;%0A
-
         Comm
@@ -2271,16 +2271,22 @@
 lit(%22 %22)
+, null
 );%0A     

fix test