diff src/org/tmatesoft/hg/internal/NewlineFilter.java @ 352:7b34d24b8f4d

Tests for newline filter (eol extension) functionality
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 30 Nov 2011 05:11:07 +0100
parents a37ce7145c3f
children 0f3687e79f5a
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/NewlineFilter.java	Wed Nov 30 04:39:50 2011 +0100
+++ b/src/org/tmatesoft/hg/internal/NewlineFilter.java	Wed Nov 30 05:11:07 2011 +0100
@@ -21,8 +21,6 @@
 import static org.tmatesoft.hg.internal.KeywordFilter.copySlice;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
@@ -44,6 +42,15 @@
 	private final boolean allowInconsistent;
 	private final boolean winToNix;
 
+	// next two factory methods for testsing purposes
+	public static NewlineFilter createWin2Nix(boolean allowMixed) {
+		return new NewlineFilter(!allowMixed, 0);
+	}
+	
+	public static NewlineFilter createNix2Win(boolean allowMixed) {
+		return new NewlineFilter(!allowMixed, 1);
+	}
+
 	private NewlineFilter(boolean failIfInconsistent, int transform) {
 		winToNix = transform == 0;
 		allowInconsistent = !failIfInconsistent;
@@ -250,25 +257,4 @@
 			return null;
 		}
 	}
-
-	public static void main(String[] args) throws Exception {
-		FileInputStream fis = new FileInputStream(new File("/temp/design.lf.txt"));
-		FileOutputStream fos = new FileOutputStream(new File("/temp/design.newline.out"));
-		ByteBuffer b = ByteBuffer.allocate(12);
-		NewlineFilter nlFilter = new NewlineFilter(true, 1);
-		while (fis.getChannel().read(b) != -1) {
-			b.flip(); // get ready to be read
-			ByteBuffer f = nlFilter.filter(b);
-			fos.getChannel().write(f); // XXX in fact, f may not be fully consumed
-			if (b.hasRemaining()) {
-				b.compact();
-			} else {
-				b.clear();
-			}
-		}
-		fis.close();
-		fos.flush();
-		fos.close();
-	}
-
 }