<commit_before>using System;
using System.Text;
using NUnit.Framework;

namespace SIL.Windows.Forms.Tests.Progress.LogBox
{
	[TestFixture]
	public class LogBoxTests
	{
		private Windows.Forms.Progress.LogBox progress;
		[Test]
		[Category("KnownMonoIssue")] // this test hangs on TeamCity for Linux
		public void ShowLogBox()
		{
			Console.WriteLine("Showing LogBox");
			using (var e = new LogBoxFormForTest())
			{
				progress = e.progress;
				progress.WriteMessage("LogBox test");
				progress.ShowVerbose = true;
				for (int i = 0; i < 1000; i++)
				{
					progress.WriteVerbose(".");
				}

				progress.WriteMessage("done");

				Console.WriteLine(progress.Text);
				Console.WriteLine(progress.Rtf);
				Console.WriteLine("Finished");
			}
		}

		[Test]
		[Category("Long Running")]
		public void WriteVerbose_AtMaximumLength_RtfContainsMaximumLengthExceeded()
		{
			Console.WriteLine("Showing LogBox");
			using (var e = new LogBoxFormForTest())
			{
				var sb = new StringBuilder();
				sb.Append('a', Int32.MaxValue / 1000 - 1);
				var hugestr = sb.ToString();
				progress = e.progress;
				for (int i = 0; i < 999; i++)
					progress.WriteVerbose(hugestr);
				sb.Clear();
				sb.Append('a', Int32.MaxValue - (hugestr.Length + 1) * 999 - 1);
				progress.WriteVerbose(sb.ToString());
				progress.WriteVerbose(".");
				Assert.IsFalse(progress.Rtf.Contains("."));
				Assert.IsTrue(progress.Rtf.Contains("Maximum length exceeded!"));
			}
		}

		[Test]
		[Category("KnownMonoIssue")] // this test hangs on TeamCity for Linux
		public void WriteVerbose_PartOfMessageExceedsMaximumLength_PartialMessageWrittenFollowedByMaximumLengthExceeded()
		{
			Console.WriteLine("Showing LogBox");
			using (var e = new LogBoxFormForTest())
			{
				var sb = new StringBuilder();
				progress = e.progress;
				var lengthOfBoxLabels = progress.Text.Length;
				sb.Append('a', 83 - progress.MaxLengthErrorMessage.Length);
				progress.MaxLength = 100;
				progress.WriteVerbose(sb.ToString());
				const string partThatWillFit = "Only this much.";
				progress.WriteVerbose($"{partThatWillFit}~will fit!");
				Assert.AreEqual(progress.MaxLength + lengthOfBoxLabels, progress.Text.Length);
				var iTruncatedMessage = progress.Rtf.IndexOf(partThatWillFit);
				Assert.IsTrue(iTruncatedMessage > 83);
				Assert.AreNotEqual("~", progress.Rtf[iTruncatedMessage + partThatWillFit.Length]);
				Assert.IsTrue(iTruncatedMessage < progress.Rtf.IndexOf(progress.MaxLengthErrorMessage));
			}
		}

		[Test]
		[Category("KnownMonoIssue")] // this test hangs on TeamCity for Linux
		public void WriteMessage_PartOfMessageExceedsMaximumLength_PartialMessageWrittenFollowedByMaximumLengthExceeded()
		{
			Console.WriteLine("Showing LogBox");
			using (var e = new LogBoxFormForTest())
			{
				var sb = new StringBuilder();
				progress = e.progress;
				var lengthOfBoxLabels = progress.Text.Length;
				sb.Append('a', 83 - progress.MaxLengthErrorMessage.Length);
				progress.MaxLength = 100;
				progress.WriteMessage(sb.ToString());
				const string partThatWillFit = "Only this much.";
				progress.WriteMessage($"{partThatWillFit}~will fit!");
				// Turns out that the Text property returns the text twice, once labeled "Box:" and once labeled "Verbose:"
				Assert.AreEqual(progress.MaxLength * 2 + lengthOfBoxLabels, progress.Text.Length);
				var iTruncatedMessage = progress.Rtf.IndexOf(partThatWillFit);
				Assert.IsTrue(iTruncatedMessage > 83);
				Assert.AreNotEqual("~", progress.Rtf[iTruncatedMessage + partThatWillFit.Length]);
				Assert.IsTrue(iTruncatedMessage < progress.Rtf.IndexOf(progress.MaxLengthErrorMessage));
			}
		}
	}<commit_msg>Added additional check (ErrorEncountered) to unit tests.<commit_after>using System;
using System.Text;
using NUnit.Framework;

namespace SIL.Windows.Forms.Tests.Progress.LogBox
{
	[TestFixture]
	public class LogBoxTests
	{
		private Windows.Forms.Progress.LogBox progress;
		[Test]
		[Category("KnownMonoIssue")] // this test hangs on TeamCity for Linux
		public void ShowLogBox()
		{
			Console.WriteLine("Showing LogBox");
			using (var e = new LogBoxFormForTest())
			{
				progress = e.progress;
				progress.WriteMessage("LogBox test");
				progress.ShowVerbose = true;
				for (int i = 0; i < 1000; i++)
				{
					progress.WriteVerbose(".");
				}

				progress.WriteMessage("done");

				Console.WriteLine(progress.Text);
				Console.WriteLine(progress.Rtf);
				Console.WriteLine("Finished");
			}
		}

		[Test]
		[Category("Long Running")]
		public void WriteVerbose_AtMaximumLength_RtfContainsMaximumLengthExceeded()
		{
			Console.WriteLine("Showing LogBox");
			using (var e = new LogBoxFormForTest())
			{
				var sb = new StringBuilder();
				sb.Append('a', Int32.MaxValue / 1000 - 1);
				var hugestr = sb.ToString();
				progress = e.progress;
				for (int i = 0; i < 999; i++)
					progress.WriteVerbose(hugestr);
				sb.Clear();
				sb.Append('a', Int32.MaxValue - (hugestr.Length + 1) * 999 - 1);
				progress.WriteVerbose(sb.ToString());
				progress.WriteVerbose(".");
				Assert.IsTrue(progress.ErrorEncountered);
				Assert.IsFalse(progress.Rtf.Contains("."));
				Assert.IsTrue(progress.Rtf.Contains("Maximum length exceeded!"));
			}
		}

		[Test]
		[Category("KnownMonoIssue")] // this test hangs on TeamCity for Linux
		public void WriteVerbose_PartOfMessageExceedsMaximumLength_PartialMessageWrittenFollowedByMaximumLengthExceeded()
		{
			Console.WriteLine("Showing LogBox");
			using (var e = new LogBoxFormForTest())
			{
				var sb = new StringBuilder();
				progress = e.progress;
				var lengthOfBoxLabels = progress.Text.Length;
				sb.Append('a', 83 - progress.MaxLengthErrorMessage.Length);
				progress.MaxLength = 100;
				progress.WriteVerbose(sb.ToString());
				const string partThatWillFit = "Only this much.";
				progress.WriteVerbose($"{partThatWillFit}~will fit!");
				Assert.IsTrue(progress.ErrorEncountered);
				Assert.AreEqual(progress.MaxLength + lengthOfBoxLabels, progress.Text.Length);
				var iTruncatedMessage = progress.Rtf.IndexOf(partThatWillFit);
				Assert.IsTrue(iTruncatedMessage > 83);
				Assert.AreNotEqual("~", progress.Rtf[iTruncatedMessage + partThatWillFit.Length]);
				Assert.IsTrue(iTruncatedMessage < progress.Rtf.IndexOf(progress.MaxLengthErrorMessage));
			}
		}

		[Test]
		[Category("KnownMonoIssue")] // this test hangs on TeamCity for Linux
		public void WriteMessage_PartOfMessageExceedsMaximumLength_PartialMessageWrittenFollowedByMaximumLengthExceeded()
		{
			Console.WriteLine("Showing LogBox");
			using (var e = new LogBoxFormForTest())
			{
				var sb = new StringBuilder();
				progress = e.progress;
				var lengthOfBoxLabels = progress.Text.Length;
				sb.Append('a', 83 - progress.MaxLengthErrorMessage.Length);
				progress.MaxLength = 100;
				progress.WriteMessage(sb.ToString());
				const string partThatWillFit = "Only this much.";
				progress.WriteMessage($"{partThatWillFit}~will fit!");
				// Turns out that the Text property returns the text twice, once labeled "Box:" and once labeled "Verbose:"
				Assert.IsTrue(progress.ErrorEncountered);
				Assert.AreEqual(progress.MaxLength * 2 + lengthOfBoxLabels, progress.Text.Length);
				var iTruncatedMessage = progress.Rtf.IndexOf(partThatWillFit);
				Assert.IsTrue(iTruncatedMessage > 83);
				Assert.AreNotEqual("~", progress.Rtf[iTruncatedMessage + partThatWillFit.Length]);
				Assert.IsTrue(iTruncatedMessage < progress.Rtf.IndexOf(progress.MaxLengthErrorMessage));
			}
		}
	}
{'fraction_non_alphanumeric': 0.12461641094062709, 'fraction_numerical': 0.010140093395597065, 'mean_word_length': 4.216423103688239, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4225570', 'n_tokens_mistral': 2865, 'n_tokens_neox': 2304, 'n_words': 463}