package com.redhat.ceylon.compiler;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;

public class TestOptionParser {

    @Test
    public void test1() {
        ArrayList<String> args = new ArrayList<String>(Arrays.asList("-verbose", "-compact", "-nomodule", "f1.ceylon", "f2.ceylon"));
        Options o = Options.parse(args);
        Assert.assertTrue(o.isVerbose());
        Assert.assertFalse(o.isComment());
        Assert.assertFalse(o.isIndent());
        Assert.assertEquals(2, args.size());
        Assert.assertTrue(args.contains("f1.ceylon"));
        Assert.assertTrue(args.contains("f2.ceylon"));
        Assert.assertTrue(o.getRepos().isEmpty());
        Assert.assertEquals("modules", o.getOutDir());
        Assert.assertEquals("source", o.getSrcDir());
    }

    @Test
    public void test2() {
        ArrayList<String> args = new ArrayList<String>(Arrays.asList("-rep", "r1", "-user", "username", "-pass", "passwd",
                "-rep", "http://r2/", "f3.ceylon", "-src", "/tmp", "-out", "/tmp"));
        Options o = Options.parse(args);
        Assert.assertTrue(o.isComment());
        Assert.assertTrue(o.isIndent());
        Assert.assertFalse(o.isVerbose());
        Assert.assertTrue(o.getRepos().contains("r1"));
        Assert.assertTrue(o.getRepos().contains("http://r2/"));
        Assert.assertFalse(o.getRepos().contains("modules"));
        Assert.assertEquals("username", o.getUser());
        Assert.assertEquals("passwd", o.getPass());
        Assert.assertEquals("/tmp", o.getSrcDir());
        Assert.assertEquals("/tmp", o.getOutDir());
    }

    @Test
    public void testRepos() {
        ArrayList<String> args = new ArrayList<String>(Arrays.asList("-rep", "r1", "-rep", "r2", "-rep", "r3", "other"));
        List<String> repos = Options.findRepos(args, true);
        Assert.assertEquals(3, repos.size());
        Assert.assertEquals(1, args.size());
        Assert.assertTrue(args.contains("other"));
        Assert.assertTrue(repos.contains("r1"));
        Assert.assertTrue(repos.contains("r2"));
        Assert.assertTrue(repos.contains("r3"));
    }

}

@@ -30,16 +30,37 @@
 piler;%0A%0A
+import java.io.File;%0A
 import j
@@ -79,16 +79,16 @@
 ayList;%0A
-
 import j
@@ -850,33 +850,41 @@
 ce%22, o.getSrcDir
-(
+s().get(0
 ));%0A    %7D%0A%0A    @
@@ -1624,17 +1624,25 @@
 etSrcDir
-(
+s().get(0
 ));%0A    
@@ -2214,10 +2214,546 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testSourceDirs() %7B%0A        ArrayList%3CString%3E args = new ArrayList%3CString%3E(Arrays.asList(%22-src%22, %22/a%22, %22-src%22, %22/b%22,%0A                %22-src%22, %22/c%22 + File.pathSeparator + %22/d%22));%0A        Options o = Options.parse(args);%0A        Assert.assertEquals(4, o.getSrcDirs().size());%0A        Assert.assertEquals(%22/a%22, o.getSrcDirs().get(0));%0A        Assert.assertEquals(%22/b%22, o.getSrcDirs().get(1));%0A        Assert.assertEquals(%22/c%22, o.getSrcDirs().get(2));%0A        Assert.assertEquals(%22/d%22, o.getSrcDirs().get(3));%0A    %7D%0A
 %7D%0A

Test new multiple -src and -src path1:path2 args