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|||}");
	}
    
    @Test
    public void testSingleImport1() {
    	ImportMemberOrTypeList imtl = prepareImportMemberOrTypeList();
		HashSet<Declaration> ignoredDeclarations = new HashSet<Declaration>();
		
		String result = ImportProposals.formatImportMembers("\r\n", "  ", ignoredDeclarations, imtl);
		assertEquals(result, "{\r\n  Bar");
	}
    
    @Test
    public void testSingleImport2() {
    	ImportMemberOrTypeList imtl = prepareImportMemberOrTypeList();
		HashSet<Declaration> ignoredDeclarations = new HashSet<Declaration>();
		
		String result = ImportProposals.formatImportMembers("\r\n", "  ", ignoredDeclarations, imtl);
		assertEquals(result, "{\n  Bar}");
	}


    @Test
    public void testSingleImport3() {
    	ImportMemberOrTypeList imtl = prepareImportMemberOrTypeList();
		HashSet<Declaration> ignoredDeclarations = new HashSet<Declaration>();
		
		String result = ImportProposals.formatImportMembers("|||", "  ", ignoredDeclarations, imtl);
		assertEquals(result, "{|||  Bar}");
	}
    
	private ImportMemberOrTypeList prepareSingleImportMemberOrTypeList() {
		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);
    	
		return imtl;
	}

	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;
	}

}

@@ -1696,32 +1696,38 @@
 t imtl = prepare
+Single
 ImportMemberOrTy
@@ -1942,16 +1942,21 @@
 r%5Cn  Bar
+%5Cr%5Cn%7D
 %22);%0A%09%7D%0A 
@@ -2041,32 +2041,38 @@
 t imtl = prepare
+Single
 ImportMemberOrTy
@@ -2205,34 +2205,32 @@
 ImportMembers(%22%5C
-r%5C
 n%22, %22  %22, ignore
@@ -2279,24 +2279,26 @@
 t, %22%7B%5Cn  Bar
+%5Cn
 %7D%22);%0A%09%7D%0A%0A%0A  
@@ -2377,32 +2377,38 @@
 t imtl = prepare
+Single
 ImportMemberOrTy
@@ -2621,16 +2621,19 @@
 %7C%7C%7C  Bar
+%7C%7C%7C
 %7D%22);%0A%09%7D%0A

Add proper newlines to the single member testcases and actually use the prepareSingleImportMemberOrTypeList() function