浏览代码

Removed AllowsNullTerminated property.

BDisp 2 年之前
父节点
当前提交
12465e2e50
共有 2 个文件被更改,包括 17 次插入64 次删除
  1. 1 14
      Terminal.Gui/Views/TextView.cs
  2. 16 50
      UnitTests/TextViewTests.cs

+ 1 - 14
Terminal.Gui/Views/TextView.cs

@@ -92,7 +92,7 @@ namespace Terminal.Gui {
 			var line = new List<byte> ();
 			var wasNewLine = false;
 			while ((v = buff.ReadByte ()) != -1) {
-				if ((!AllowsNullTerminated && v == '\0') || v == 13) {
+				if (v == 13) {
 					continue;
 				}
 				if (v == 10) {
@@ -142,11 +142,6 @@ namespace Terminal.Gui {
 		/// </summary>
 		public int Count => lines.Count;
 
-		/// <summary>
-		/// Gets or sets if null terminated in a buffer array is considered as part of the <see cref="lines"/>.
-		/// </summary>
-		public bool AllowsNullTerminated { get; set; }
-
 		/// <summary>
 		/// Returns the specified line as a List of Rune
 		/// </summary>
@@ -1799,14 +1794,6 @@ namespace Terminal.Gui {
 		/// </summary>
 		public ContextMenu ContextMenu { get; private set; }
 
-		/// <summary>
-		/// Gets or sets if null terminated in a buffer array is considered as part of the <see cref="Text"/>.
-		/// </summary>
-		public bool AllowsNullTerminated {
-			get => model.AllowsNullTerminated;
-			set => model.AllowsNullTerminated = value;
-		}
-
 		int GetSelectedLength ()
 		{
 			return SelectedText.Length;

+ 16 - 50
UnitTests/TextViewTests.cs

@@ -1930,81 +1930,47 @@ namespace Terminal.Gui.Views {
 		}
 
 		[Fact]
-		public void LoadStream_IsDirty_AllowsNullTerminator ()
+		public void LoadStream_IsDirty ()
 		{
 			var text = "Testing";
-			byte [] buff = System.Text.Encoding.Unicode.GetBytes (text);
-			using (System.IO.MemoryStream stream = new System.IO.MemoryStream (buff, true)) {
+			using (System.IO.MemoryStream stream = new System.IO.MemoryStream ()) {
 
-				stream.Write (buff, 0, buff.Length);
+				var writer = new System.IO.StreamWriter (stream);
+				writer.Write (text);
+				writer.Flush ();
 				stream.Position = 0;
 
 				var tv = new TextView ();
 				tv.LoadStream (stream);
 
-				Assert.Equal (14, buff.Length);
-				Assert.False (tv.AllowsNullTerminated);
+				Assert.Equal (7, text.Length);
 				Assert.Equal (text.Length, tv.Text.Length);
 				Assert.Equal (text, tv.Text);
 				Assert.False (tv.IsDirty);
 			}
-
-			buff = System.Text.Encoding.Unicode.GetBytes (text);
-			using (System.IO.MemoryStream stream = new System.IO.MemoryStream (buff, true)) {
-
-				stream.Write (buff, 0, buff.Length);
-				stream.Position = 0;
-
-				var tv = new TextView ();
-				tv.AllowsNullTerminated = true;
-				tv.LoadStream (stream);
-
-				Assert.Equal (14, buff.Length);
-				Assert.Equal (buff.Length, tv.Text.Length);
-				Assert.NotEqual (text, tv.Text);
-				Assert.Equal (buff, tv.Text);
-				Assert.False (tv.IsDirty);
-				Assert.Equal ('\u2400', ConsoleDriver.MakePrintable ((char)tv.Text [1]));
-			}
 		}
 
 		[Fact]
-		public void LoadStream_IsDirty_AllowsNullTerminator_With_Null_On_The_Text ()
+		public void LoadStream_IsDirty_With_Null_On_The_Text ()
 		{
 			var text = "Test\0ing";
-			byte [] buff = System.Text.Encoding.Unicode.GetBytes (text);
-			using (System.IO.MemoryStream stream = new System.IO.MemoryStream (buff, true)) {
+			using (System.IO.MemoryStream stream = new System.IO.MemoryStream ()) {
 
-				stream.Write (buff, 0, buff.Length);
+				var writer = new System.IO.StreamWriter (stream);
+				writer.Write (text);
+				writer.Flush ();
 				stream.Position = 0;
 
 				var tv = new TextView ();
 				tv.LoadStream (stream);
 
-				Assert.Equal (16, buff.Length);
-				Assert.False (tv.AllowsNullTerminated);
-				Assert.NotEqual (text.Length, tv.Text.Length);
 				Assert.Equal (8, text.Length);
-				Assert.Equal (7, tv.Text.Length);
-				Assert.NotEqual (text, tv.Text);
-				Assert.False (tv.IsDirty);
-			}
-
-			buff = System.Text.Encoding.Unicode.GetBytes (text);
-			using (System.IO.MemoryStream stream = new System.IO.MemoryStream (buff, true)) {
-
-				stream.Write (buff, 0, buff.Length);
-				stream.Position = 0;
-
-				var tv = new TextView ();
-				tv.AllowsNullTerminated = true;
-				tv.LoadStream (stream);
-
-				Assert.Equal (16, buff.Length);
-				Assert.Equal (buff.Length, tv.Text.Length);
-				Assert.NotEqual (text, tv.Text);
-				Assert.Equal (buff, tv.Text);
+				Assert.Equal (text.Length, tv.Text.Length);
+				Assert.Equal (8, text.Length);
+				Assert.Equal (8, tv.Text.Length);
+				Assert.Equal (text, tv.Text);
 				Assert.False (tv.IsDirty);
+				Assert.Equal ('\u2400', ConsoleDriver.MakePrintable ((Rune)tv.Text [4]));
 			}
 		}