Browse Source

[java] fix sys.io.FileInput.eof, add java to sys tests

Dan Korostelev 10 years ago
parent
commit
da775e45bf

+ 11 - 10
std/java/_std/sys/io/FileInput.hx

@@ -29,9 +29,11 @@ import java.io.IOException;
 
 
 class FileInput extends Input {
 class FileInput extends Input {
 	var f:java.io.RandomAccessFile;
 	var f:java.io.RandomAccessFile;
+	var _eof:Bool;
 	public function new(f)
 	public function new(f)
 	{
 	{
 		this.f = f;
 		this.f = f;
+		this._eof = false;
 	}
 	}
 
 
 	override public function close()
 	override public function close()
@@ -47,6 +49,7 @@ class FileInput extends Input {
 		}
 		}
 
 
 		catch (e:EOFException) {
 		catch (e:EOFException) {
+			_eof = true;
 			throw new Eof();
 			throw new Eof();
 		}
 		}
 
 
@@ -64,6 +67,7 @@ class FileInput extends Input {
 		}
 		}
 
 
 		catch (e:EOFException) {
 		catch (e:EOFException) {
+			_eof = true;
 			throw new Eof();
 			throw new Eof();
 		}
 		}
 
 
@@ -71,14 +75,17 @@ class FileInput extends Input {
 			throw haxe.io.Error.Custom(e);
 			throw haxe.io.Error.Custom(e);
 		}
 		}
 
 
-		if (ret == -1)
+		if (ret == -1) {
+			_eof = true;
 			throw new Eof();
 			throw new Eof();
+		}
 
 
 		return ret;
 		return ret;
 	}
 	}
 
 
 	public function seek( p : Int, pos : FileSeek ) : Void
 	public function seek( p : Int, pos : FileSeek ) : Void
 	{
 	{
+		_eof = false;
 		try
 		try
 		{
 		{
 			switch(pos)
 			switch(pos)
@@ -90,6 +97,7 @@ class FileInput extends Input {
 		}
 		}
 
 
 		catch (e:EOFException) {
 		catch (e:EOFException) {
+			_eof = true;
 			throw new Eof();
 			throw new Eof();
 		}
 		}
 
 
@@ -110,15 +118,8 @@ class FileInput extends Input {
 		}
 		}
 	}
 	}
 
 
-	public function eof() : Bool
+	public inline function eof() : Bool
 	{
 	{
-		try
-		{
-			return f.getFilePointer() == f.length();
-		}
-
-		catch (e:IOException) {
-			throw haxe.io.Error.Custom(e);
-		}
+		return _eof;
 	}
 	}
 }
 }

+ 2 - 0
tests/sys/compile-java.hxml

@@ -0,0 +1,2 @@
+compile-each.hxml
+-java bin/java

+ 2 - 1
tests/sys/compile.hxml

@@ -1,3 +1,4 @@
 --next compile-neko.hxml
 --next compile-neko.hxml
 --next compile-python.hxml
 --next compile-python.hxml
---next compile-cpp.hxml
+--next compile-cpp.hxml
+--next compile-java.hxml

+ 8 - 2
tests/sys/src/TestSys.hx

@@ -4,18 +4,23 @@ class TestSys extends haxe.unit.TestCase {
 		assertEquals(3, args.length);
 		assertEquals(3, args.length);
 		assertEquals("foo", args[0]);
 		assertEquals("foo", args[0]);
 		assertEquals("12", args[1]);
 		assertEquals("12", args[1]);
-		assertEquals("a b  %PATH% $HOME c\\&<>[\"]#{}|%$", args[2]);		
+		assertEquals("a b  %PATH% $HOME c\\&<>[\"]#{}|%$", args[2]);
 	}
 	}
 
 
 	function testEnv() {
 	function testEnv() {
+		#if !java
 		Sys.putEnv("foo", "value");
 		Sys.putEnv("foo", "value");
 		assertEquals("value", Sys.getEnv("foo"));
 		assertEquals("value", Sys.getEnv("foo"));
+		#end
 		assertEquals(null, Sys.getEnv("doesn't exist"));
 		assertEquals(null, Sys.getEnv("doesn't exist"));
 
 
+		#if !java
 		var env = Sys.environment();
 		var env = Sys.environment();
 		assertEquals("value", env.get("foo"));
 		assertEquals("value", env.get("foo"));
+		#end
 	}
 	}
 
 
+	#if !java
 	function testCwd() {
 	function testCwd() {
 		var cur = Sys.getCwd();
 		var cur = Sys.getCwd();
 		Sys.setCwd("../");
 		Sys.setCwd("../");
@@ -25,4 +30,5 @@ class TestSys extends haxe.unit.TestCase {
 		}
 		}
 		assertEquals(normalize(newCwd), normalize(Sys.getCwd()));
 		assertEquals(normalize(newCwd), normalize(Sys.getCwd()));
 	}
 	}
-}
+	#end
+}