package pw.ian.albkit.command.parser;

import org.junit.Assert;
import org.junit.Test;
import pw.ian.albkit.command.parser.parameter.Parameter;
import pw.ian.albkit.command.parser.parameter.Params;
import pw.ian.albkit.command.parser.parameter.ParamsBase;

import java.util.Map;

public class ArgumentsTest {
    @Test
    public void test() {
        Arguments args = new Arguments("hello", "bob", "123", "1.445", "yolo",
                "cool", "-f", "banter", "--lol");

        Assert.assertFalse(
                "Arguments seems to think that hello or bob is a boolean. Either that or they were parsed wrong.",
                args.getArgument(0).isBoolean() || args.getArgument(0)
                        .isDouble());
        Assert.assertEquals("Bad parsing on hello!",
                args.getArgument(0).rawString(), "hello");
        Assert.assertEquals("Bad parsing on bob!",
                args.getArgument(1).rawString(), "bob");
        Assert.assertTrue("Bad parsing on 123!", args.getArgument(2).isInt());
        Assert.assertTrue("Bad parsing on 1.445",
                args.getArgument(3).isDouble());

        if (args.length() != 8) {
            Assert.fail("Wrong arguments length!");
        }

        Assert.assertEquals("Error parsing flag '-f'",
                args.getValueFlag("f").getRawValue(), "banter");
        Assert.assertTrue(args.hasNonValueFlag("lol"));

        ParamsBase base = ParamsBase.fromUsageString("/tree hello <hi> [lol]");
        args = new Arguments("hello", "bob", "trees");
        System.out.println(
                "Parsing: { hello, bob, trees } for usage '/tree hello <hi> [lol]' which produces parameters { hi, lol }");
        args.withParams(base.createParams(args));
        Params params = args.getParams();
        System.out.println("Got params: " + string(params));
        Assert.assertEquals("Not equal!", string(params),
                "{ [ hi, bob ] , [ lol, trees ] }");
        Assert.assertEquals(params.get("hi").get(), "bob");
        Assert.assertTrue(params.valid());
    }

    String string(Params params) {
        StringBuilder bu = new StringBuilder("{ ");
        for (Map.Entry<String, Parameter> entry : params.entries()) {
            bu.append("[ ").append(entry.getKey()).append(", ")
                    .append(entry.getValue().get()).append(" ]").append(" , ");
        }
        bu.setLength(bu.length() - 2);
        return bu.append("}").toString();
    }
}

@@ -1388,24 +1388,68 @@
 g(%22lol%22));%0A%0A
+        for (int i = 0; i %3C 100; i++) %7B%0A    
         Para
@@ -1472,16 +1472,37 @@
 ramsBase
+%0A                    
 .fromUsa
@@ -1541,24 +1541,28 @@
 %22);%0A        
+ 
+   
 args = new A
@@ -1596,32 +1596,36 @@
 rees%22);%0A        
+    
 System.out.print
@@ -1628,16 +1628,20 @@
 rintln(%0A
+    
         
@@ -1760,24 +1760,28 @@
 %22);%0A        
+  
+  
 args.withPar
@@ -1814,24 +1814,28 @@
 ));%0A        
+    
 Params param
@@ -1856,32 +1856,36 @@
 rams();%0A        
+ 
+   
 System.out.print
@@ -1929,115 +1929,8 @@
     
-    Assert.assertEquals(%22Not equal!%22, string(params),%0A                %22%7B %5B hi, bob %5D , %5B lol, trees %5D %7D%22);%0A
     
@@ -1985,32 +1985,36 @@
 %22bob%22);%0A        
+    
 Assert.assertTru
@@ -2028,24 +2028,34 @@
 s.valid());%0A
+        %7D%0A
     %7D%0A%0A    S

Remove faggotry which causes the test to fail rarely due to Sets not staying in the order you add items to them in