harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r434337 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/StreamTokenizer.java test/java/tests/api/java/io/StreamTokenizerTest.java
Date Thu, 24 Aug 2006 08:04:19 GMT
Author: mloenko
Date: Thu Aug 24 01:04:18 2006
New Revision: 434337

URL: http://svn.apache.org/viewvc?rev=434337&view=rev
Log:
applied patch for HARMONY-1262
[classlib][luni] StreamTokenizer does not work with block comments

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamTokenizer.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamTokenizer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamTokenizer.java?rev=434337&r1=434336&r2=434337&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamTokenizer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamTokenizer.java
Thu Aug 24 01:04:18 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -411,16 +411,6 @@
 			sval = quoteString.toString();
 			return ttype;
 		}
-		// Check for comment character
-		if (currentType == TOKEN_COMMENT) {
-			// Skip to EOF or new line then return the next token
-			while ((currentChar = read()) >= 0 && currentChar != '\r'
-					&& currentChar != '\n') {
-				// Intentionally empty
-			}
-			peekChar = currentChar;
-			return nextToken();
-		}
 		// Do comments, both "//" and "/*stuff*/"
 		if (currentChar == '/' && (slashSlashComments || slashStarComments)) {
 			if ((currentChar = read()) == '*' && slashStarComments) {
@@ -451,12 +441,23 @@
 				}
 				peekChar = currentChar;
 				return nextToken();
-			} else {
+			} else if(currentType != TOKEN_COMMENT){
 				// Was just a slash by itself
 				peekChar = currentChar;
 				return (ttype = '/');
 			}
 		}
+        // Check for comment character
+        if (currentType == TOKEN_COMMENT) {
+            // Skip to EOF or new line then return the next token
+            while ((currentChar = read()) >= 0 && currentChar != '\r'
+                    && currentChar != '\n') {
+                // Intentionally empty
+            }
+            peekChar = currentChar;
+            return nextToken();
+        }
+        
 		peekChar = read();
 		return (ttype = currentChar);
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java?rev=434337&r1=434336&r2=434337&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java
Thu Aug 24 01:04:18 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,9 +15,11 @@
 
 package tests.api.java.io;
 
+import java.io.CharArrayReader;
 import java.io.IOException;
 import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
+import java.io.Reader;
 import java.io.StreamTokenizer;
 import java.io.StringBufferInputStream;
 
@@ -352,7 +354,48 @@
 			fail("Exception during test : " + e.getMessage());
 		}
 	}
-
+    
+    /**
+     * @tests java.io.StreamTokenizer#slashSlashComments(boolean)
+     */
+    public void test_slashSlashComments_withSSOpen() throws IOException {
+        Reader reader = new CharArrayReader( "t // t t t".toCharArray());
+
+        StreamTokenizer st = new StreamTokenizer(reader);
+        st.slashSlashComments(true);
+
+        assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
+        assertEquals(StreamTokenizer.TT_EOF,st.nextToken());
+    }
+
+    /**
+     * @tests java.io.StreamTokenizer#slashSlashComments(boolean)
+     */
+    public void test_slashSlashComments_withSSOpen_NoComment() throws IOException {
+        Reader reader = new CharArrayReader( "// t".toCharArray());
+
+        StreamTokenizer st = new StreamTokenizer(reader);
+        st.slashSlashComments(true);
+        st.ordinaryChar('/');
+
+        assertEquals(StreamTokenizer.TT_EOF,st.nextToken());
+    }
+    
+    /**
+     * @tests java.io.StreamTokenizer#slashSlashComments(boolean)
+     */
+    public void test_slashSlashComments_withSSClosed() throws IOException {
+        Reader reader = new CharArrayReader( "// t".toCharArray());
+
+        StreamTokenizer st = new StreamTokenizer(reader);
+        st.slashSlashComments(false);
+        st.ordinaryChar('/');
+
+        assertEquals('/',st.nextToken());
+        assertEquals('/',st.nextToken());
+        assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
+    }
+    
 	/**
 	 * @tests java.io.StreamTokenizer#slashStarComments(boolean)
 	 */
@@ -368,6 +411,33 @@
 		}
 	}
 
+    /**
+     * @tests java.io.StreamTokenizer#slashStarComments(boolean)
+     */
+    public void test_slashStarComments_withSTOpen() throws IOException {
+        Reader reader = new CharArrayReader( "t /* t */ t".toCharArray());
+
+        StreamTokenizer st = new StreamTokenizer(reader);
+        st.slashStarComments(true);
+
+        assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
+        assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
+        assertEquals(StreamTokenizer.TT_EOF,st.nextToken());
+    }
+
+    /**
+     * @tests java.io.StreamTokenizer#slashStarComments(boolean)
+     */
+    public void test_slashStarComments_withSTClosed() throws IOException {
+        Reader reader = new CharArrayReader( "t /* t */ t".toCharArray());
+
+        StreamTokenizer st = new StreamTokenizer(reader);
+        st.slashStarComments(false);
+
+        assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
+        assertEquals(StreamTokenizer.TT_EOF,st.nextToken());
+    }
+    
 	/**
 	 * @tests java.io.StreamTokenizer#toString()
 	 */



Mime
View raw message