package io.koara;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class ComplianceTest {

	private static Path TESTSUITE_FOLDER = Paths.get("src/test/resources");
	
	private String module;
	private String testcase;
	
    private static List<String> include = Arrays.asList();
	
	public ComplianceTest(String module, String testcase) {
  		this.module = module;
  		this.testcase = testcase;
    }
	
	@Parameters(name= "{0}: {1}")
	public static Iterable<Object[]> data() {
		List<Object[]> modules = new ArrayList<Object[]>();
		for(File module : TESTSUITE_FOLDER.toFile().listFiles()) {
			if(include.size() == 0 || include.contains(module.getName())) {
				for(File testcase : module.listFiles()) {
					if(testcase.getName().endsWith(".kd")) {
						modules.add(new Object[]{module.getName(), testcase.getName().substring(0, testcase.getName().length() - 3)});
					}
				}
			}
		}
		return modules;
	}

	@Test
	public void output() throws Exception {
		String html = readFile(TESTSUITE_FOLDER.resolve(module).resolve(testcase + ".htm"));
		String kd = readFile(TESTSUITE_FOLDER.resolve(module).resolve(testcase + ".kd"));
		
		Parser parser = new Parser();
		Document document = parser.parse(kd); // Generate AST
		HtmlRenderer renderer = new HtmlRenderer();
		document.accept(renderer);
		assertEquals(html, renderer.getOutput());
	}
	
	private String readFile(Path path) throws IOException {
    	byte[] encoded = Files.readAllBytes(path);
    	return Charset.forName("UTF-8").decode(ByteBuffer.wrap(encoded)).toString();
    }
	
	
	
}
@@ -73,20 +73,30 @@
 java.io.
-File
+BufferedReader
 ;%0Aimport
@@ -104,27 +104,20 @@
 java.io.
-IOException
+File
 ;%0Aimport
@@ -126,20 +126,19 @@
 ava.
-n
 io.
-ByteBuff
+FileRead
 er;%0A
@@ -153,55 +153,22 @@
 ava.
-n
 io.
-charset.Charset;%0Aimport java.nio.file.Files
+IOException
 ;%0Aim
@@ -1417,33 +1417,32 @@
 LDER
-.resolve(module).resolve(
+ + %22/%22 + module + %22/%22 + 
 test
@@ -1455,17 +1455,16 @@
  %22.htm%22)
-)
 ;%0A%09%09Stri
@@ -1500,33 +1500,32 @@
 LDER
-.resolve(module).resolve(
+ + %22/%22 + module + %22/%22 + 
 test
@@ -1537,17 +1537,16 @@
 + %22.kd%22)
-)
 ;%0A%09%09%0A%09%09P
@@ -1779,20 +1779,22 @@
 eadFile(
-Path
+String
  path) t
@@ -1817,137 +1817,443 @@
 n %7B%0A
-    %09byte%5B%5D encoded = Files.readAllBytes
+%09%09BufferedReader reader = null;%0A%09%09try %7B%0A%09%09%09StringBuffer fileData = new StringBuffer();%0A%09%09%09reader = new BufferedReader(new FileReader
 (path)
+)
 ;%0A
-    %09return Charset.forName(%22UTF-8%22).decode(ByteBuffer.wrap(encoded)).toString();
+%09%09%09char%5B%5D buf = new char%5B1024%5D;%0A%09        int numRead=0;%0A%09        while((numRead=reader.read(buf)) != -1)%7B%0A%09            String readData = String.valueOf(buf, 0, numRead);%0A%09            fileData.append(readData);%0A%09        %7D%0A%09        return fileData.toString();%0A%09%09%7D finally %7B%0A%09%09%09reader.close();%0A%09%09%7D
 %0A   

Make jdk6 compliant