[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mono-patches
Subject:    [Mono-patches] r114504 - in branches/rocks-playground: . Mono.Rocks
From:       "Jonathan Pryor" <mono-patches-list () lists ! ximian ! com>
Date:       2008-09-30 19:41:04
Message-ID: 20080930194104.2405A9472C () mono-cvs ! ximian ! com
[Download RAW message or body]

Author: jonpryor
Date: 2008-09-30 15:41:03 -0400 (Tue, 30 Sep 2008)
New Revision: 114504

Modified:
   branches/rocks-playground/ChangeLog
   branches/rocks-playground/Mono.Rocks/ChangeLog
   branches/rocks-playground/Mono.Rocks/TextReader.cs
   branches/rocks-playground/Tests/Mono.Rocks.Tests/ChangeLog
   branches/rocks-playground/Tests/Mono.Rocks.Tests/TextReaderTest.cs
   branches/rocks-playground/doc/en/Mono.Rocks/TextReaderRocks.xml
   branches/rocks-playground/doc/en/index.xml
Log:
	* doc/en/**: Flush TextReader changes.
	* Mono.Rocks/TextReader.cs: Change the default semantics of .Lines(), 
	  .Words(), and .Tokens() so that the TextReader is disposed by default.
	* Tests/Mono.Rocks.Tests/TextReaderTest.cs: Update tests to check for 
	  TextReader disposal by default.


Modified: branches/rocks-playground/ChangeLog
===================================================================
--- branches/rocks-playground/ChangeLog	2008-09-30 19:37:03 UTC (rev 114503)
+++ branches/rocks-playground/ChangeLog	2008-09-30 19:41:03 UTC (rev 114504)
@@ -1,5 +1,9 @@
 2008-09-27  Jonathan Pryor  <jpryor@novell.com>
 
+	* doc/en/**: Flush TextReader changes.
+
+2008-09-27  Jonathan Pryor  <jpryor@novell.com>
+
 	* Makefile: Ignore more warnings when building unit tests.
 	* doc/en/**: Flush .Tokens() changes.
 

Modified: branches/rocks-playground/Mono.Rocks/ChangeLog
===================================================================
--- branches/rocks-playground/Mono.Rocks/ChangeLog	2008-09-30 19:37:03 UTC (rev \
                114503)
+++ branches/rocks-playground/Mono.Rocks/ChangeLog	2008-09-30 19:41:03 UTC (rev \
114504) @@ -1,3 +1,8 @@
+2008-09-30  Jonathan Pryor  <jpryor@novell.com>
+
+	* TextReader.cs: Change the default semantics of .Lines(), .Words(),
+	  and .Tokens() so that the TextReader *is* disposed by default.
+
 2008-09-27  Jonathan Pryor  <jpryor@novell.com>
 
 	* Either.cs: Finish the "expend all efforts to convert values"

Modified: branches/rocks-playground/Mono.Rocks/TextReader.cs
===================================================================
--- branches/rocks-playground/Mono.Rocks/TextReader.cs	2008-09-30 19:37:03 UTC (rev \
                114503)
+++ branches/rocks-playground/Mono.Rocks/TextReader.cs	2008-09-30 19:41:03 UTC (rev \
114504) @@ -44,7 +44,7 @@
 
 		public static IEnumerable<string> Lines (this TextReader self)
 		{
-			return Lines (self, TextReaderRocksOptions.None);
+			return Lines (self, TextReaderRocksOptions.CloseReader);
 		}
 
 		public static IEnumerable<string> Lines (this TextReader self, \
TextReaderRocksOptions options) @@ -70,6 +70,7 @@
 			} finally {
 				if ((options & TextReaderRocksOptions.CloseReader) != 0) {
 					self.Close ();
+					self.Dispose ();
 				}
 			}
 		}
@@ -80,7 +81,7 @@
 			Check.Categories (categories);
 			if (categories.Length == 0)
 				throw new ArgumentException ("categories", "Must provide at least one \
                catagory");
-			return Tokens (self, TextReaderRocksOptions.None, categories);
+			return Tokens (self, TextReaderRocksOptions.CloseReader, categories);
 		}
 
 		public static IEnumerable<string> Tokens (this TextReader self, \
TextReaderRocksOptions options, params Func<char?, char, bool>[] categories) @@ \
-144,6 +145,7 @@  } finally {
 				if ((options & TextReaderRocksOptions.CloseReader) != 0) {
 					self.Close ();
+					self.Dispose ();
 				}
 			}
 		}
@@ -157,7 +159,7 @@
 
 		public static IEnumerable<string> Words (this TextReader self)
 		{
-			return Words (self, TextReaderRocksOptions.None);
+			return Words (self, TextReaderRocksOptions.CloseReader);
 		}
 
 		public static IEnumerable<string> Words (this TextReader self, \
TextReaderRocksOptions options)

Modified: branches/rocks-playground/Tests/Mono.Rocks.Tests/ChangeLog
===================================================================
--- branches/rocks-playground/Tests/Mono.Rocks.Tests/ChangeLog	2008-09-30 19:37:03 \
                UTC (rev 114503)
+++ branches/rocks-playground/Tests/Mono.Rocks.Tests/ChangeLog	2008-09-30 19:41:03 \
UTC (rev 114504) @@ -1,5 +1,10 @@
 2008-09-27  Jonathan Pryor  <jpryor@novell.com>
 
+	* TextReaderTest.cs: Update tests to check for TextReader disposal 
+	  by default.
+
+2008-09-27  Jonathan Pryor  <jpryor@novell.com>
+
 	* EitherTest.cs: Add some tests for IConvertible support within
 	  Either.TryParse().
 	* MaybeTest.cs: int->bool is now valid (via Convert.ChangeType), so

Modified: branches/rocks-playground/Tests/Mono.Rocks.Tests/TextReaderTest.cs
===================================================================
--- branches/rocks-playground/Tests/Mono.Rocks.Tests/TextReaderTest.cs	2008-09-30 \
                19:37:03 UTC (rev 114503)
+++ branches/rocks-playground/Tests/Mono.Rocks.Tests/TextReaderTest.cs	2008-09-30 \
19:41:03 UTC (rev 114504) @@ -76,7 +76,7 @@
 		{
 			MyStringReader r = new MyStringReader ("hello\nout\rthere\r\nin\nTV\nland!");
 			string[] lines = r.Lines ().ToArray ();
-			Assert.IsFalse (r.WasDisposed);
+			Assert.IsTrue (r.WasDisposed);
 			Assert.AreEqual (6, lines.Length);
 			Assert.AreEqual ("hello", lines [0]);
 			Assert.AreEqual ("out",   lines [1]);
@@ -86,8 +86,8 @@
 			Assert.AreEqual ("land!", lines [5]);
 
 			r = new MyStringReader ("\nhello\n\nworld!");
-			lines = r.Lines (TextReaderRocksOptions.CloseReader).ToArray ();
-			Assert.IsTrue (r.WasDisposed);
+			lines = r.Lines (TextReaderRocksOptions.None).ToArray ();
+			Assert.IsFalse (r.WasDisposed);
 			Assert.AreEqual (4, lines.Length);
 			Assert.AreEqual ("",        lines [0]);
 			Assert.AreEqual ("hello",   lines [1]);
@@ -150,16 +150,16 @@
 				(p, c) => char.IsLetterOrDigit (c) || c == '.',
 				(p, c) => !char.IsWhiteSpace (c))
 				.ToArray ();
-			Assert.IsFalse (r.WasDisposed);
+			Assert.IsTrue (r.WasDisposed);
 			Assert.IsTrue (
 					new[]{"(", "append", "3.5", "\"", "hello", ",", "world", "!\")"}
 					.SequenceEqual (words));
 
 			r = new MyStringReader ("Hello, world!");
 			Assert.AreEqual (false, 
-				r.Tokens (TextReaderRocksOptions.CloseReader,
+				r.Tokens (TextReaderRocksOptions.None,
 					(p, c) => false).Any ());
-			Assert.IsTrue (r.WasDisposed);
+			Assert.IsFalse (r.WasDisposed);
 			#endregion
 		}
 
@@ -184,7 +184,7 @@
 			#region Words
 			MyStringReader r = new MyStringReader ("   (skip  leading,\r\n\tand \
trailing\vwhitespace)   ");  string[] words = r.Words ().ToArray ();
-			Assert.IsFalse (r.WasDisposed);
+			Assert.IsTrue (r.WasDisposed);
 			Assert.AreEqual (5, words.Length);
 			Assert.AreEqual ("(skip",       words [0]);
 			Assert.AreEqual ("leading,",    words [1]);
@@ -193,8 +193,8 @@
 			Assert.AreEqual ("whitespace)", words [4]);
 
 			r = new MyStringReader ("notext");
-			words = r.Words (TextReaderRocksOptions.CloseReader).ToArray ();
-			Assert.IsTrue (r.WasDisposed);
+			words = r.Words (TextReaderRocksOptions.None).ToArray ();
+			Assert.IsFalse (r.WasDisposed);
 			Assert.AreEqual (1, words.Length);
 			Assert.AreEqual ("notext", words [0]);
 

Modified: branches/rocks-playground/doc/en/Mono.Rocks/TextReaderRocks.xml
===================================================================
--- branches/rocks-playground/doc/en/Mono.Rocks/TextReaderRocks.xml	2008-09-30 \
                19:37:03 UTC (rev 114503)
+++ branches/rocks-playground/doc/en/Mono.Rocks/TextReaderRocks.xml	2008-09-30 \
19:41:03 UTC (rev 114504) @@ -46,7 +46,7 @@
           Creates an
           <see cref="T:System.Collections.Generic.IEnumerable{System.String}" />
           which will return all lines of text from <paramref name="self" /> 
-          without <see cref="M:System.IO.TextReader.Close" />ing 
+          while <see cref="M:System.IO.TextReader.Close" />ing 
           <paramref name="self" />.
         </summary>
         <returns>
@@ -59,8 +59,7 @@
             This method is implemented by using deferred execution.
           </para>
           <para>
-            <paramref name="self" /> is not disposed.  
-            <see cref="T:System.IO.TextReader" /> disposal is up to the caller.
+            <paramref name="self" /> is disposed.  
           </para>
           <block subset="none" type="note">
             A "line of text" is the same as that used by 
@@ -120,7 +119,10 @@
             <see cref="F:Mono.Rocks.TextReaderRocksOptions.CloseReader" />,
             then <paramref name="self" /> will be 
             <see cref="M:System.IO.TextReader.Close" />ed once all lines have
-            been returned.
+            been returned; if 
+            <see cref="F:Mono.Rocks.TextReaderRocksOptions.CloseReader" />
+						is not specified, then the 
+            <see cref="T:System.IO.TextReader" /> will not be disposed.
           </para>
           <block subset="none" type="note">
             A "line of text" is the same as that used by 
@@ -163,17 +165,17 @@
         </param>
         <param name="categories">
           A
-					<see cref="T:System.Func{System.Nullable{System.Char},System.Char,System.Boolean}" \
                />
-					array containing the different categories of characters that 
-					determines what makes up a "token."  If the 
-					<see cref="T:System.Nullable{System.Char}" /> parameter is 
-					<see langword="null" />, then the <see cref="T:System.Char" /> is
-					the first character within the token; otherwise, the
-					<see cref="T:System.Nullable{System.Char}" /> parameter contains the
-					character preceding the <see cref="T:System.Char" />.
-					The delegate should return <see langword="true" /> if the
-					<see cref="T:System.Char" /> is a supported character; otherwise,
-					<see langword="false" /> should be returned.
+          <see cref="T:System.Func{System.Nullable{System.Char},System.Char,System.Boolean}" \
/> +          array containing the different categories of characters that 
+          determines what makes up a "token."  If the 
+          <see cref="T:System.Nullable{System.Char}" /> parameter is 
+          <see langword="null" />, then the <see cref="T:System.Char" /> is
+          the first character within the token; otherwise, the
+          <see cref="T:System.Nullable{System.Char}" /> parameter contains the
+          character preceding the <see cref="T:System.Char" />.
+          The delegate should return <see langword="true" /> if the
+          <see cref="T:System.Char" /> is a supported character; otherwise,
+          <see langword="false" /> should be returned.
         </param>
         <summary>
           Creates an
@@ -201,7 +203,7 @@
           <block subset="none" type="note">
             <para>
               A "token" is determined by <paramref name="categories" />, and
-							is any contiguous sequence of characters for which the
+              is any contiguous sequence of characters for which the
               same <paramref name="categories" /> index returns 
               <see langword="true" />, starting from the first delegate.  This
               allows a "some characters are more important than others"
@@ -215,16 +217,16 @@
 	(p, c) =&gt; char.IsLetterOrDigit (c) || c == '.',
 	(p, c) =&gt; !char.IsWhiteSpace (c))
 	.ToArray ();
-Assert.IsFalse (r.WasDisposed);
+Assert.IsTrue (r.WasDisposed);
 Assert.IsTrue (
 		new[]{"(", "append", "3.5", "\"", "hello", ",", "world", "!\")"}
 		.SequenceEqual (words));
 
 r = new MyStringReader ("Hello, world!");
 Assert.AreEqual (false, 
-	r.Tokens (TextReaderRocksOptions.CloseReader,
+	r.Tokens (TextReaderRocksOptions.None,
 		(p, c) =&gt; false).Any ());
-Assert.IsTrue (r.WasDisposed);
+Assert.IsFalse (r.WasDisposed);
 </code>
         </remarks>
         <exception cref="T:System.ArgumentException">
@@ -271,17 +273,17 @@
         </param>
         <param name="categories">
           A
-					<see cref="T:System.Func{System.Nullable{System.Char},System.Char,System.Boolean}" \
                />
-					array containing the different categories of characters that 
-					determines what makes up a "token."  If the 
-					<see cref="T:System.Nullable{System.Char}" /> parameter is 
-					<see langword="null" />, then the <see cref="T:System.Char" /> is
-					the first character within the token; otherwise, the
-					<see cref="T:System.Nullable{System.Char}" /> parameter contains the
-					character preceding the <see cref="T:System.Char" />.
-					The delegate should return <see langword="true" /> if the
-					<see cref="T:System.Char" /> is a supported character; otherwise,
-					<see langword="false" /> should be returned.
+          <see cref="T:System.Func{System.Nullable{System.Char},System.Char,System.Boolean}" \
/> +          array containing the different categories of characters that 
+          determines what makes up a "token."  If the 
+          <see cref="T:System.Nullable{System.Char}" /> parameter is 
+          <see langword="null" />, then the <see cref="T:System.Char" /> is
+          the first character within the token; otherwise, the
+          <see cref="T:System.Nullable{System.Char}" /> parameter contains the
+          character preceding the <see cref="T:System.Char" />.
+          The delegate should return <see langword="true" /> if the
+          <see cref="T:System.Char" /> is a supported character; otherwise,
+          <see langword="false" /> should be returned.
         </param>
         <summary>
           Creates an
@@ -309,7 +311,7 @@
           <block subset="none" type="note">
             <para>
               A "token" is determined by <paramref name="categories" />, and
-							is any contiguous sequence of characters for which the
+              is any contiguous sequence of characters for which the
               same <paramref name="categories" /> index returns 
               <see langword="true" />, starting from the first delegate.  This
               allows a "some characters are more important than others"
@@ -323,16 +325,16 @@
 	(p, c) =&gt; char.IsLetterOrDigit (c) || c == '.',
 	(p, c) =&gt; !char.IsWhiteSpace (c))
 	.ToArray ();
-Assert.IsFalse (r.WasDisposed);
+Assert.IsTrue (r.WasDisposed);
 Assert.IsTrue (
 		new[]{"(", "append", "3.5", "\"", "hello", ",", "world", "!\")"}
 		.SequenceEqual (words));
 
 r = new MyStringReader ("Hello, world!");
 Assert.AreEqual (false, 
-	r.Tokens (TextReaderRocksOptions.CloseReader,
+	r.Tokens (TextReaderRocksOptions.None,
 		(p, c) =&gt; false).Any ());
-Assert.IsTrue (r.WasDisposed);
+Assert.IsFalse (r.WasDisposed);
 </code>
         </remarks>
         <exception cref="T:System.ArgumentException">
@@ -370,7 +372,7 @@
           Creates an
           <see cref="T:System.Collections.Generic.IEnumerable{System.String}" />
           which will return all words from <paramref name="self" />
-          without <see cref="M:System.IO.TextReader.Close" />ing 
+          while <see cref="M:System.IO.TextReader.Close" />ing 
           <paramref name="self" />.
         </summary>
         <returns>
@@ -383,19 +385,18 @@
             This method is implemented by using deferred execution.
           </para>
           <para>
-            <paramref name="self" /> is not disposed.  
-            <see cref="T:System.IO.TextReader" /> disposal is up to the caller.
+            <paramref name="self" /> is disposed.  
           </para>
           <block subset="none" type="note">
             <para>
               A "word" is any contiguous sequence of characters for which
-							<see cref="M:System.Char.IsWhiteSpace(System.Char)" />
-							returns <see langword="false" />.
+              <see cref="M:System.Char.IsWhiteSpace(System.Char)" />
+              returns <see langword="false" />.
             </para>
           </block>
           <code lang="C#" \
src="../../Tests/Mono.Rocks.Tests/TextReaderTest.cs#Words">MyStringReader r = new \
MyStringReader ("   (skip  leading,\r\n\tand trailing\vwhitespace)   ");  string[] \
                words = r.Words ().ToArray ();
-Assert.IsFalse (r.WasDisposed);
+Assert.IsTrue (r.WasDisposed);
 Assert.AreEqual (5, words.Length);
 Assert.AreEqual ("(skip",       words [0]);
 Assert.AreEqual ("leading,",    words [1]);
@@ -404,8 +405,8 @@
 Assert.AreEqual ("whitespace)", words [4]);
 
 r = new MyStringReader ("notext");
-words = r.Words (TextReaderRocksOptions.CloseReader).ToArray ();
-Assert.IsTrue (r.WasDisposed);
+words = r.Words (TextReaderRocksOptions.None).ToArray ();
+Assert.IsFalse (r.WasDisposed);
 Assert.AreEqual (1, words.Length);
 Assert.AreEqual ("notext", words [0]);
 
@@ -470,18 +471,21 @@
             <see cref="F:Mono.Rocks.TextReaderRocksOptions.CloseReader" />,
             then <paramref name="self" /> will be 
             <see cref="M:System.IO.TextReader.Close" />ed once all lines have
-            been returned.
+            been returned; if 
+            <see cref="F:Mono.Rocks.TextReaderRocksOptions.CloseReader" />
+            is not specified, then the 
+            <see cref="T:System.IO.TextReader" /> will not be disposed.
           </para>
           <block subset="none" type="note">
             <para>
               A "word" is any contiguous sequence of characters for which
-							<see cref="M:System.Char.IsWhiteSpace(System.Char)" />
-							returns <see langword="false" />.
+              <see cref="M:System.Char.IsWhiteSpace(System.Char)" />
+              returns <see langword="false" />.
             </para>
           </block>
           <code lang="C#" \
src="../../Tests/Mono.Rocks.Tests/TextReaderTest.cs#Words">MyStringReader r = new \
MyStringReader ("   (skip  leading,\r\n\tand trailing\vwhitespace)   ");  string[] \
                words = r.Words ().ToArray ();
-Assert.IsFalse (r.WasDisposed);
+Assert.IsTrue (r.WasDisposed);
 Assert.AreEqual (5, words.Length);
 Assert.AreEqual ("(skip",       words [0]);
 Assert.AreEqual ("leading,",    words [1]);
@@ -490,8 +494,8 @@
 Assert.AreEqual ("whitespace)", words [4]);
 
 r = new MyStringReader ("notext");
-words = r.Words (TextReaderRocksOptions.CloseReader).ToArray ();
-Assert.IsTrue (r.WasDisposed);
+words = r.Words (TextReaderRocksOptions.None).ToArray ();
+Assert.IsFalse (r.WasDisposed);
 Assert.AreEqual (1, words.Length);
 Assert.AreEqual ("notext", words [0]);
 

Modified: branches/rocks-playground/doc/en/index.xml
===================================================================
--- branches/rocks-playground/doc/en/index.xml	2008-09-30 19:37:03 UTC (rev 114503)
+++ branches/rocks-playground/doc/en/index.xml	2008-09-30 19:41:03 UTC (rev 114504)
@@ -5930,7 +5930,7 @@
           Creates an
           <see cref="T:System.Collections.Generic.IEnumerable{System.String}" />
           which will return all lines of text from <paramref name="self" /> 
-          without <see cref="M:System.IO.TextReader.Close" />ing 
+          while <see cref="M:System.IO.TextReader.Close" />ing 
           <paramref name="self" />.
         </summary>
         </Docs>
@@ -6094,7 +6094,7 @@
           Creates an
           <see cref="T:System.Collections.Generic.IEnumerable{System.String}" />
           which will return all words from <paramref name="self" />
-          without <see cref="M:System.IO.TextReader.Close" />ing 
+          while <see cref="M:System.IO.TextReader.Close" />ing 
           <paramref name="self" />.
         </summary>
         </Docs>

_______________________________________________
Mono-patches maillist  -  Mono-patches@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-patches


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic