package com.redhat.ceylon.eclipse.ui.test.headless;

import static org.junit.Assert.assertEquals;

import java.util.HashSet;
import java.util.List;

import org.antlr.runtime.CommonToken;
import org.junit.Test;

import com.redhat.ceylon.compiler.typechecker.tree.Tree.Identifier;
import com.redhat.ceylon.compiler.typechecker.tree.Tree.ImportMemberOrType;
import com.redhat.ceylon.compiler.typechecker.tree.Tree.ImportMemberOrTypeList;
import com.redhat.ceylon.eclipse.code.correct.ImportProposals;
import com.redhat.ceylon.model.typechecker.model.Declaration;

public class ImportProposalTests {
    @Test
    public void testDelimiter1() {
    	ImportMemberOrTypeList imtl = prepareImportMemberOrTypeList();
		HashSet<Declaration> ignoredDeclarations = new HashSet<Declaration>();
		
		String result = ImportProposals.formatImportMembers("\n", "  ", ignoredDeclarations, imtl);
		assertEquals(result, "{\n  Bar,\n  Foo\n}");
		
	}
    
    @Test
    public void testDelimiter2() {
    	ImportMemberOrTypeList imtl = prepareImportMemberOrTypeList();
		HashSet<Declaration> ignoredDeclarations = new HashSet<Declaration>();
		
		String result = ImportProposals.formatImportMembers("\r\n", "  ", ignoredDeclarations, imtl);
		assertEquals(result, "{\r\n  Bar,\r\n  Foo\r\n}");
	}

    @Test
    public void testDelimiter3() {
    	ImportMemberOrTypeList imtl = prepareImportMemberOrTypeList();
		HashSet<Declaration> ignoredDeclarations = new HashSet<Declaration>();
		
		String result = ImportProposals.formatImportMembers("|||", "  ", ignoredDeclarations, imtl);
		assertEquals(result, "{|||  Bar,|||  Foo|||}");
	}

	private ImportMemberOrTypeList prepareImportMemberOrTypeList() {
		CommonToken noToken = new CommonToken(0);
		ImportMemberOrTypeList imtl = new ImportMemberOrTypeList(noToken);
    	List<ImportMemberOrType> importMembers = imtl.getImportMemberOrTypes();
    	
    	ImportMemberOrType importMember = new ImportMemberOrType(noToken);
    	importMember.setAlias(null);
    	importMember.setText("Bar");
    	Identifier identifier = new Identifier(noToken);
    	identifier.setText("Bar");
		importMember.setIdentifier(identifier);
    	importMembers.add(importMember);
    	
    	importMember = new ImportMemberOrType(noToken);
    	importMember.setAlias(null);
    	importMember.setText("Foo");
    	identifier = new Identifier(noToken);
    	identifier.setText("Foo");
		importMember.setIdentifier(identifier);
    	importMembers.add(importMember);
		return imtl;
	}

}

@@ -1608,16 +1608,1616 @@
 %7C%7D%22);%0A%09%7D
+%0A    %0A    @Test%0A    public void testSingleImport1() %7B%0A    %09ImportMemberOrTypeList imtl = prepareImportMemberOrTypeList();%0A%09%09HashSet%3CDeclaration%3E ignoredDeclarations = new HashSet%3CDeclaration%3E();%0A%09%09%0A%09%09String result = ImportProposals.formatImportMembers(%22%5Cr%5Cn%22, %22  %22, ignoredDeclarations, imtl);%0A%09%09assertEquals(result, %22%7B%5Cr%5Cn  Bar%22);%0A%09%7D%0A    %0A    @Test%0A    public void testSingleImport2() %7B%0A    %09ImportMemberOrTypeList imtl = prepareImportMemberOrTypeList();%0A%09%09HashSet%3CDeclaration%3E ignoredDeclarations = new HashSet%3CDeclaration%3E();%0A%09%09%0A%09%09String result = ImportProposals.formatImportMembers(%22%5Cr%5Cn%22, %22  %22, ignoredDeclarations, imtl);%0A%09%09assertEquals(result, %22%7B%5Cn  Bar%7D%22);%0A%09%7D%0A%0A%0A    @Test%0A    public void testSingleImport3() %7B%0A    %09ImportMemberOrTypeList imtl = prepareImportMemberOrTypeList();%0A%09%09HashSet%3CDeclaration%3E ignoredDeclarations = new HashSet%3CDeclaration%3E();%0A%09%09%0A%09%09String result = ImportProposals.formatImportMembers(%22%7C%7C%7C%22, %22  %22, ignoredDeclarations, imtl);%0A%09%09assertEquals(result, %22%7B%7C%7C%7C  Bar%7D%22);%0A%09%7D%0A    %0A%09private ImportMemberOrTypeList prepareSingleImportMemberOrTypeList() %7B%0A%09%09CommonToken noToken = new CommonToken(0);%0A%09%09ImportMemberOrTypeList imtl = new ImportMemberOrTypeList(noToken);%0A    %09List%3CImportMemberOrType%3E importMembers = imtl.getImportMemberOrTypes();%0A    %09%0A    %09ImportMemberOrType importMember = new ImportMemberOrType(noToken);%0A    %09importMember.setAlias(null);%0A    %09importMember.setText(%22Bar%22);%0A    %09Identifier identifier = new Identifier(noToken);%0A    %09identifier.setText(%22Bar%22);%0A%09%09importMember.setIdentifier(identifier);%0A    %09importMembers.add(importMember);%0A    %09%0A%09%09return imtl;%0A%09%7D
 %0A%0A%09priva

Implement single import tests