public void TestConsoleStringEdgeCases() { ConsoleString str = ConsoleString.Empty; for(int i = 0; i < 99; i++) str.Append(""); Assert.AreEqual(0, str.Length); Assert.AreEqual(string.Empty, str.ToString()); Assert.AreEqual(ConsoleString.Empty, str); ConsoleString noSegments = new ConsoleString(); noSegments.AppendUsingCurrentFormat("Adam"); ValidateStringCharacteristics("Adam", noSegments); ConsoleString nullString = null; Assert.IsTrue(nullString == null); nullString = nullString + new ConsoleString("Adam"); Assert.AreEqual(nullString, new ConsoleString("Adam")); nullString = null; Assert.IsTrue(nullString == null); Assert.IsFalse(nullString != null); nullString = nullString + "Adam"; Assert.AreEqual(nullString, new ConsoleString("Adam")); Assert.IsTrue(nullString != null); Assert.IsFalse(new ConsoleCharacter('a').Equals(null)); Assert.IsFalse(new ConsoleCharacter('a').Equals(0)); new ConsoleCharacter('a').GetHashCode(); new ConsoleString("Adam").GetHashCode(); Assert.IsTrue(new ConsoleString("Adam").Equals("Adam")); Assert.IsTrue(new ConsoleCharacter('A').Equals('A')); Assert.IsTrue(new ConsoleCharacter('A') == 'A'); Assert.IsTrue(new ConsoleCharacter('A') != 'B'); Assert.IsFalse(new ConsoleCharacter('A') == null); Assert.IsTrue(new ConsoleCharacter('A') != null); Assert.IsTrue(new ConsoleCharacter('A') == new ConsoleCharacter('A')); Assert.IsTrue(new ConsoleCharacter('A') != new ConsoleCharacter('B')); Assert.IsTrue(new ConsoleString("A") == new ConsoleString("A")); Assert.IsTrue(new ConsoleString("A") != new ConsoleString("B")); Assert.IsFalse(null == new ConsoleString("A")); Assert.IsTrue(null != new ConsoleString("B")); Assert.IsFalse(new ConsoleString("A") == null); Assert.IsTrue(new ConsoleString("A") != null); Assert.AreEqual(new ConsoleString("A"), null + new ConsoleString("A")); ConsoleString nulla = null; ConsoleString nullb = null; string nullS = null; Assert.AreEqual(null, nulla + nullb); Assert.AreEqual(null, nulla + nullS); }
public void TestConsoleStringEdgeCases() { ConsoleString str = ConsoleString.Empty; for (int i = 0; i < 99; i++) { str += (""); } Assert.AreEqual(0, str.Length); Assert.AreEqual(string.Empty, str.ToString()); Assert.AreEqual(ConsoleString.Empty, str); ConsoleString noSegments = new ConsoleString(); noSegments = noSegments.AppendUsingCurrentFormat("Adam"); ValidateStringCharacteristics("Adam", noSegments); ConsoleString nullString = null; Assert.IsTrue(nullString == null); nullString = nullString + new ConsoleString("Adam"); Assert.AreEqual(nullString, new ConsoleString("Adam")); nullString = null; Assert.IsTrue(nullString == null); Assert.IsFalse(nullString != null); nullString = nullString + "Adam"; Assert.AreEqual(nullString, new ConsoleString("Adam")); Assert.IsTrue(nullString != null); Assert.IsFalse(new ConsoleCharacter('a').Equals(null)); Assert.IsFalse(new ConsoleCharacter('a').Equals(0)); new ConsoleCharacter('a').GetHashCode(); new ConsoleString("Adam").GetHashCode(); Assert.IsTrue(new ConsoleString("Adam").Equals("Adam")); Assert.IsTrue(new ConsoleCharacter('A').Equals('A')); Assert.IsTrue(new ConsoleCharacter('A') == 'A'); Assert.IsTrue(new ConsoleCharacter('A') != 'B'); Assert.IsFalse(new ConsoleCharacter('A') == null); Assert.IsTrue(new ConsoleCharacter('A') != null); Assert.IsTrue(new ConsoleCharacter('A') == new ConsoleCharacter('A')); Assert.IsTrue(new ConsoleCharacter('A') != new ConsoleCharacter('B')); Assert.IsTrue(new ConsoleString("A") == new ConsoleString("A")); Assert.IsTrue(new ConsoleString("A") != new ConsoleString("B")); Assert.IsFalse(null == new ConsoleString("A")); Assert.IsTrue(null != new ConsoleString("B")); Assert.IsFalse(new ConsoleString("A") == null); Assert.IsTrue(new ConsoleString("A") != null); Assert.AreEqual(new ConsoleString("A"), null + new ConsoleString("A")); ConsoleString nulla = null; ConsoleString nullb = null; string nullS = null; Assert.AreEqual(null, nulla + nullb); Assert.AreEqual(null, nulla + nullS); }
public static void RenderConsoleProgress(int percentage) { if (Progress == percentage) { return; } CursorVisible = false; const int BarHeight = 3; var BarStart = (WindowTop + WindowHeight - 1) - BarHeight; CursorTop = BarStart; if (!DisableProgressBar) { Bar.Progress = percentage / 100.00; Bar.Message = BaseMessage.AppendUsingCurrentFormat($". {percentage} %"); Bar.Render(); } else if (TextInfo && percentage != Progress) { ForegroundColor = ConsoleColor.DarkBlue; BackgroundColor = ConsoleColor.Yellow; WriteLine($" {percentage} % "); } CursorTop = BarStart - 1; Progress = percentage; /* * Progress = percentage; * CursorVisible = false; * * var BottomOfCon = WindowTop + WindowHeight - 1; * var BottomOfBuffer = BufferHeight - WindowHeight - BarHeight; * SavePos = CursorTop; * var MaxText = (WindowTop + WindowHeight - 1) - BarHeight; * var BarLine = MaxText + 1; * while (SavePos-- >= MaxText) * WriteLine("\t\t\t\t\t".PadRight(WindowWidth)); * SavePos = CursorTop; * * //if (LastProgLine != SavePos && CursorTop + BarHeight >= BufferHeight) * //WriteLine(); * * var originalColor = ForegroundColor; * var origback = BackgroundColor; * ForegroundColor = pBarColor; * CursorLeft = 0; * * //LastProgLine = CursorTop = BottomOfCon - BarHeight; * var width = Console.WindowWidth - 4; * var newWidth = ((width * percentage) / 100); // incase some change happened * * CursorTop = BarLine; * Bar.Width = newWidth; * Bar.Progress = percentage / 100.00; * Bar.Render(); * * // var progBar = new StringBuilder(new string(progressBarCharacter, newWidth)).Append(new string(' ', width - newWidth)); * // Write(progBar.ToString()); * * CursorLeft = 0; * ForegroundColor = originalColor; * CursorTop = SavePos; * CursorVisible = true; */ }