package cn.edu.seu.ise.dca.util.test;

import org.junit.Test;

import cn.edu.seu.ise.dca.global.Global;
import cn.edu.seu.ise.dca.util.FileComparator;
import cn.edu.seu.ise.dca.util.URLUtil;
import difflib.Delta;
import difflib.Patch;


public class FileComparatorTest {
	@Test
	public void testComparator() {
		compare("/trunk/phase3/includes/Interwiki.php", 1588, 1589);
	}
	
	private void compare(String url, long original, long revised) {
		String originalPath = URLUtil.generateFilePath(Global.OUTPUT_DIR, url, original);
		String revisedPath = URLUtil.generateFilePath(Global.OUTPUT_DIR, url, revised);
		FileComparator comparator = new FileComparator(originalPath, revisedPath);
		Patch patch = comparator.getPatch();
		for(Delta delta: patch.getDeltas()) {
			System.out.println(delta.getType() + "\t" + delta.getOriginal().size() + "\t" + delta.getRevised().size());
			for(Object line : delta.getOriginal().getLines()) {
				System.out.println(line);
			}
			
			
			System.out.println("-----------------------");
		}
		
	}
}
