From 178bf3a43b3688c2dddcaf32431731db310424aa Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 13 May 2023 20:22:15 +0100 Subject: [PATCH] Change StringExtensions.Make to StringExtensions.ToString and added some more unit tests. --- Terminal.Gui/Text/StringExtensions.cs | 41 +--- Terminal.Gui/Text/TextFormatter.cs | 38 ++-- .../Views/AutocompleteFilepathContext.cs | 2 +- Terminal.Gui/Views/DateField.cs | 4 +- Terminal.Gui/Views/Menu.cs | 6 +- Terminal.Gui/Views/RadioGroup.cs | 2 +- Terminal.Gui/Views/TextField.cs | 20 +- Terminal.Gui/Views/TextValidateField.cs | 8 +- Terminal.Gui/Views/TextView.cs | 18 +- Terminal.Gui/Views/TimeField.cs | 8 +- UICatalog/Scenarios/Buttons.cs | 8 +- UICatalog/Scenarios/DynamicMenuBar.cs | 2 +- UICatalog/Scenarios/DynamicStatusBar.cs | 2 +- UICatalog/Scenarios/LabelsAsButtons.cs | 8 +- UnitTests/TestHelpers.cs | 2 +- UnitTests/Text/RuneTests.cs | 39 ++-- UnitTests/Text/TextFormatterTests.cs | 181 +++++++++--------- UnitTests/Views/MenuTests.cs | 20 +- 18 files changed, 187 insertions(+), 222 deletions(-) diff --git a/Terminal.Gui/Text/StringExtensions.cs b/Terminal.Gui/Text/StringExtensions.cs index 27b2e4314..5350d5c74 100644 --- a/Terminal.Gui/Text/StringExtensions.cs +++ b/Terminal.Gui/Text/StringExtensions.cs @@ -149,7 +149,7 @@ public static class StringExtensions { /// /// The rune array to convert. /// - public static string Make (Rune [] runes) + public static string ToString (Rune [] runes) { var str = string.Empty; @@ -165,7 +165,7 @@ public static class StringExtensions { /// /// The List of runes to convert. /// - public static string Make (List runes) + public static string ToString (List runes) { var str = string.Empty; foreach (var rune in runes) { @@ -175,49 +175,16 @@ public static class StringExtensions { } /// - /// Converts a rune into a string. - /// - /// The rune to convert. - /// - public static string Make (Rune rune) - { - return rune.ToString (); - } - - /// - /// Converts a numeric value of a rune into a string. - /// - /// The rune to convert. - /// - public static string Make (uint rune) - { - return ((Rune)rune).ToString (); - } - - /// - /// Converts a byte array into a string in te provided encoding (default is UTF8) + /// Converts a byte array into a string in the provided encoding (default is UTF8) /// /// The byte array to convert. /// The encoding to be used. /// - public static string Make (byte [] bytes, Encoding encoding = null) + public static string ToString (byte [] bytes, Encoding encoding = null) { if (encoding == null) { encoding = Encoding.UTF8; } return encoding.GetString (bytes); } - - /// - /// Converts a array of characters into a string. - /// - /// The array of characters to convert. - /// - public static string Make (params char [] chars) - { - var c = new char [chars.Length]; - - return new string (chars); - } } - diff --git a/Terminal.Gui/Text/TextFormatter.cs b/Terminal.Gui/Text/TextFormatter.cs index 90ed2f433..a58d3b288 100644 --- a/Terminal.Gui/Text/TextFormatter.cs +++ b/Terminal.Gui/Text/TextFormatter.cs @@ -142,7 +142,7 @@ namespace Terminal.Gui { break; } } - return StringExtensions.Make (runes); + return StringExtensions.ToString (runes); } static string ReplaceCRLFWithSpace (string str) { @@ -164,7 +164,7 @@ namespace Terminal.Gui { break; } } - return StringExtensions.Make (runes); + return StringExtensions.ToString (runes); } /// @@ -184,18 +184,18 @@ namespace Terminal.Gui { end = i; switch (runes [i].Value) { case '\n': - lines.Add (StringExtensions.Make (runes.GetRange (start, end - start))); + lines.Add (StringExtensions.ToString (runes.GetRange (start, end - start))); i++; start = i; break; case '\r': if ((i + 1) < runes.Count && runes [i + 1].Value == '\n') { - lines.Add (StringExtensions.Make (runes.GetRange (start, end - start))); + lines.Add (StringExtensions.ToString (runes.GetRange (start, end - start))); i += 2; start = i; } else { - lines.Add (StringExtensions.Make (runes.GetRange (start, end - start))); + lines.Add (StringExtensions.ToString (runes.GetRange (start, end - start))); i++; start = i; } @@ -203,9 +203,9 @@ namespace Terminal.Gui { } } if (runes.Count > 0 && lines.Count == 0) { - lines.Add (StringExtensions.Make (runes)); + lines.Add (StringExtensions.ToString (runes)); } else if (runes.Count > 0 && start < runes.Count) { - lines.Add (StringExtensions.Make (runes.GetRange (start, runes.Count - start))); + lines.Add (StringExtensions.ToString (runes.GetRange (start, runes.Count - start))); } else { lines.Add (""); } @@ -281,7 +281,7 @@ namespace Terminal.Gui { start = text.GetRuneCount (); break; } - lines.Add (StringExtensions.Make (runes.GetRange (start, end - start))); + lines.Add (StringExtensions.ToString (runes.GetRange (start, end - start))); start = end; if (incomplete) { start = text.GetRuneCount (); @@ -345,7 +345,7 @@ namespace Terminal.Gui { end--; if (end == start) end = start + GetLengthThatFits (runes.GetRange (end, runes.Count - end), width); - lines.Add (StringExtensions.Make (runes.GetRange (start, end - start))); + lines.Add (StringExtensions.ToString (runes.GetRange (start, end - start))); start = end; if (runes [end].Value == ' ') { start++; @@ -360,7 +360,7 @@ namespace Terminal.Gui { if (end == start) { end = start + width; } - lines.Add (StringExtensions.Make (runes.GetRange (start, end - start))); + lines.Add (StringExtensions.ToString (runes.GetRange (start, end - start))); start = end; if (runes [end].Value == ' ') { start++; @@ -419,7 +419,7 @@ namespace Terminal.Gui { } if (start < text.GetRuneCount ()) { - lines.Add (StringExtensions.Make (runes.GetRange (start, runes.Count - start))); + lines.Add (StringExtensions.ToString (runes.GetRange (start, runes.Count - start))); } return lines; @@ -459,15 +459,15 @@ namespace Terminal.Gui { int slen = runes.Count; if (slen > width) { if (IsHorizontalDirection (textDirection)) { - return StringExtensions.Make (runes.GetRange (0, GetLengthThatFits (text, width))); + return StringExtensions.ToString (runes.GetRange (0, GetLengthThatFits (text, width))); } else { - return StringExtensions.Make (runes.GetRange (0, width)); + return StringExtensions.ToString (runes.GetRange (0, width)); } } else { if (justify) { return Justify (text, width, ' ', textDirection); } else if (IsHorizontalDirection (textDirection) && GetTextWidth (text) > width) { - return StringExtensions.Make (runes.GetRange (0, GetLengthThatFits (text, width))); + return StringExtensions.ToString (runes.GetRange (0, GetLengthThatFits (text, width))); } return text; } @@ -601,7 +601,7 @@ namespace Terminal.Gui { for (int i = 0; i < runeCount; i++) { Rune c = runes [i]; if (c.Value == '\n') { - var wrappedLines = WordWrapText (StringExtensions.Make (runes.GetRange (lp, i - lp)), width, preserveTrailingSpaces, tabWidth, textDirection); + var wrappedLines = WordWrapText (StringExtensions.ToString (runes.GetRange (lp, i - lp)), width, preserveTrailingSpaces, tabWidth, textDirection); foreach (var line in wrappedLines) { lineResult.Add (ClipAndJustify (line, width, justify, textDirection)); } @@ -611,7 +611,7 @@ namespace Terminal.Gui { lp = i + 1; } } - foreach (var line in WordWrapText (StringExtensions.Make (runes.GetRange (lp, runeCount - lp)), width, preserveTrailingSpaces, tabWidth, textDirection)) { + foreach (var line in WordWrapText (StringExtensions.ToString (runes.GetRange (lp, runeCount - lp)), width, preserveTrailingSpaces, tabWidth, textDirection)) { lineResult.Add (ClipAndJustify (line, width, justify, textDirection)); } @@ -921,7 +921,7 @@ namespace Terminal.Gui { if (Rune.IsLetterOrDigit (runes [hotPos])) { runes [hotPos] = new Rune ((uint)runes [hotPos].Value); } - return StringExtensions.Make (runes); + return StringExtensions.ToString (runes); } /// @@ -1320,7 +1320,7 @@ namespace Terminal.Gui { x = bounds.Right - runesWidth; CursorPosition = bounds.Width - runesWidth + (_hotKeyPos > -1 ? _hotKeyPos : 0); } else { - var runesWidth = GetTextWidth (StringExtensions.Make (runes)); + var runesWidth = GetTextWidth (StringExtensions.ToString (runes)); x = bounds.Right - runesWidth; CursorPosition = bounds.Width - runesWidth + (_hotKeyPos > -1 ? _hotKeyPos : 0); } @@ -1338,7 +1338,7 @@ namespace Terminal.Gui { x = bounds.Left + line + ((bounds.Width - runesWidth) / 2); CursorPosition = (bounds.Width - runesWidth) / 2 + (_hotKeyPos > -1 ? _hotKeyPos : 0); } else { - var runesWidth = GetTextWidth (StringExtensions.Make (runes)); + var runesWidth = GetTextWidth (StringExtensions.ToString (runes)); x = bounds.Left + (bounds.Width - runesWidth) / 2; CursorPosition = (bounds.Width - runesWidth) / 2 + (_hotKeyPos > -1 ? _hotKeyPos : 0); } diff --git a/Terminal.Gui/Views/AutocompleteFilepathContext.cs b/Terminal.Gui/Views/AutocompleteFilepathContext.cs index 378605f4a..30b0b4df0 100644 --- a/Terminal.Gui/Views/AutocompleteFilepathContext.cs +++ b/Terminal.Gui/Views/AutocompleteFilepathContext.cs @@ -30,7 +30,7 @@ namespace Terminal.Gui { return Enumerable.Empty (); } - var path = StringExtensions.Make (context.CurrentLine); + var path = StringExtensions.ToString (context.CurrentLine); var last = path.LastIndexOfAny (FileDialog.Separators); if (string.IsNullOrWhiteSpace (path) || !Path.IsPathRooted (path)) { diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index d948350eb..2a4b95161 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -198,7 +198,7 @@ namespace Terminal.Gui { newText.Add (key); if (CursorPosition < fieldLen) newText = newText.Concat (text.GetRange (CursorPosition + 1, text.Count - (CursorPosition + 1))).ToList (); - return SetText (StringExtensions.Make (newText)); + return SetText (StringExtensions.ToString (newText)); } bool SetText (string text) @@ -341,7 +341,7 @@ namespace Terminal.Gui { if (ReadOnly) return true; - if (SetText (TextModel.ToRunes (StringExtensions.Make ((Rune)(uint)kb.Key)).First ())) + if (SetText (TextModel.ToRunes (((Rune)(uint)kb.Key).ToString ()).First ())) IncCursorPosition (); return true; diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index 05b68929a..d0519ef10 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -635,11 +635,11 @@ namespace Terminal.Gui { // Support Checked even though CheckType wasn't set if (item.CheckType == MenuItemCheckStyle.Checked && item.Checked == null) { - textToDraw = StringExtensions.Make (new Rune [] { nullCheckedChar, (Rune)' ' }) + item.Title; + textToDraw = $"{nullCheckedChar} {item.Title}"; } else if (item.Checked == true) { - textToDraw = StringExtensions.Make (new Rune [] { checkChar, (Rune)' ' }) + item.Title; + textToDraw = $"{checkChar} {item.Title}"; } else if (item.CheckType.HasFlag (MenuItemCheckStyle.Checked) || item.CheckType.HasFlag (MenuItemCheckStyle.Radio)) { - textToDraw = StringExtensions.Make (new Rune [] { uncheckedChar, (Rune)' ' }) + item.Title; + textToDraw = $"{uncheckedChar} {item.Title}"; } else { textToDraw = item.Title; } diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index f3b8acb3c..db4656f4f 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -206,7 +206,7 @@ namespace Terminal.Gui { } var rl = radioLabels [i]; Driver.SetAttribute (GetNormalColor ()); - Driver.AddStr (StringExtensions.Make (new Rune [] { i == selected ? CM.Glyphs.Selected : CM.Glyphs.UnSelected, (Rune)' ' })); + Driver.AddStr ($"{(i == selected ? CM.Glyphs.Selected : CM.Glyphs.UnSelected)} "); TextFormatter.FindHotKey (rl, HotKeySpecifier, true, out int hotPos, out Key hotKey); if (hotPos != -1 && (hotKey != Key.Null || hotKey != Key.Unknown)) { var rlRunes = rl.ToRunes (); diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index 0d920e54d..ea7131361 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -245,7 +245,7 @@ namespace Terminal.Gui { if (obj == null) return; - Text = StringExtensions.Make (obj?.Lines [obj.CursorPosition.Y]); + Text = StringExtensions.ToString (obj?.Lines [obj.CursorPosition.Y]); CursorPosition = obj.CursorPosition.X; Adjust (); } @@ -304,11 +304,11 @@ namespace Terminal.Gui { /// public new string Text { get { - return StringExtensions.Make (text); + return StringExtensions.ToString (text); } set { - var oldText = StringExtensions.Make (text); + var oldText = StringExtensions.ToString (text); if (oldText == value) return; @@ -568,7 +568,7 @@ namespace Terminal.Gui { void SetText (List newText) { - Text = StringExtensions.Make (newText); + Text = StringExtensions.ToString (newText); } void SetText (IEnumerable newText) @@ -585,7 +585,7 @@ namespace Terminal.Gui { void SetClipboard (IEnumerable text) { if (!Secret) - Clipboard.Contents = StringExtensions.Make (text.ToList ()); + Clipboard.Contents = StringExtensions.ToString (text.ToList ()); } int oldCursorPos; @@ -649,7 +649,7 @@ namespace Terminal.Gui { if (!useOldCursorPos) { oldCursorPos = point; } - var kbstr = TextModel.ToRunes (StringExtensions.Make ((Rune)(uint)kb.Key)); + var kbstr = TextModel.ToRunes (((Rune)(uint)kb.Key).ToString ()); if (Used) { point++; if (point == newText.Count + 1) { @@ -906,7 +906,7 @@ namespace Terminal.Gui { Adjust (); } else { var newText = DeleteSelectedText (); - Text = StringExtensions.Make (newText); + Text = StringExtensions.ToString (newText); Adjust (); } } @@ -929,7 +929,7 @@ namespace Terminal.Gui { Adjust (); } else { var newText = DeleteSelectedText (); - Text = StringExtensions.Make (newText); + Text = StringExtensions.ToString (newText); Adjust (); } } @@ -1129,7 +1129,7 @@ namespace Terminal.Gui { length = Math.Abs (x + direction <= text.Count ? x + direction - selectedStart : text.Count - selectedStart); SetSelectedStartSelectedLength (); if (start > -1 && length > 0) { - selectedText = length > 0 ? StringExtensions.Make (text).ToString ().Substring ( + selectedText = length > 0 ? StringExtensions.ToString (text).ToString ().Substring ( start < 0 ? 0 : start, length > text.Count ? text.Count : length) : ""; if (first > start) { first = start; @@ -1189,7 +1189,7 @@ namespace Terminal.Gui { Clipboard.Contents = SelectedText; var newText = DeleteSelectedText (); - Text = StringExtensions.Make (newText); + Text = StringExtensions.ToString (newText); Adjust (); } diff --git a/Terminal.Gui/Views/TextValidateField.cs b/Terminal.Gui/Views/TextValidateField.cs index 062403a20..fc9d0455c 100644 --- a/Terminal.Gui/Views/TextValidateField.cs +++ b/Terminal.Gui/Views/TextValidateField.cs @@ -232,7 +232,7 @@ namespace Terminal.Gui { /// public string Pattern { get { - return StringExtensions.Make (pattern); + return StringExtensions.ToString (pattern); } set { pattern = value.ToRuneList (); @@ -244,7 +244,7 @@ namespace Terminal.Gui { /// public string Text { get { - return StringExtensions.Make (text); + return StringExtensions.ToString (text); } set { text = value != string.Empty ? value.ToRuneList () : null; @@ -272,7 +272,7 @@ namespace Terminal.Gui { bool Validate (List text) { - var match = regex.Match (StringExtensions.Make (text).ToString ()); + var match = regex.Match (StringExtensions.ToString (text)); return match.Success; } @@ -353,7 +353,7 @@ namespace Terminal.Gui { /// private void CompileMask () { - regex = new Regex (StringExtensions.Make (pattern).ToString (), RegexOptions.Compiled); + regex = new Regex (StringExtensions.ToString (pattern), RegexOptions.Compiled); } } #endregion diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 75817550d..ea55988fb 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -75,7 +75,7 @@ namespace Terminal.Gui { void Append (List line) { - var str = StringExtensions.Make (line.ToArray ()); + var str = StringExtensions.ToString (line.ToArray ()); _lines.Add (ToRunes (str)); } @@ -125,7 +125,7 @@ namespace Terminal.Gui { { var sb = new StringBuilder (); for (int i = 0; i < _lines.Count; i++) { - sb.Append (StringExtensions.Make (_lines [i])); + sb.Append (StringExtensions.ToString (_lines [i])); if ((i + 1) < _lines.Count) { sb.AppendLine (); } @@ -394,7 +394,7 @@ namespace Terminal.Gui { string GetText (List x) { - var txt = StringExtensions.Make (x).ToString (); + var txt = StringExtensions.ToString (x); if (!matchCase) { txt = txt.ToUpper (); } @@ -406,7 +406,7 @@ namespace Terminal.Gui { string ReplaceText (List source, string textToReplace, string matchText, int col) { - var origTxt = StringExtensions.Make (source); + var origTxt = StringExtensions.ToString (source); (int _, int len) = TextModel.DisplaySize (source, 0, col, false); (int _, int len2) = TextModel.DisplaySize (source, col, col + matchText.Length, false); (int _, int len3) = TextModel.DisplaySize (source, col + matchText.Length, origTxt.GetRuneCount (), false); @@ -437,7 +437,7 @@ namespace Terminal.Gui { { for (int i = start.Y; i < linesCount; i++) { var x = _lines [i]; - var txt = StringExtensions.Make (x).ToString (); + var txt = StringExtensions.ToString (x); if (!matchCase) { txt = txt.ToUpper (); } @@ -462,7 +462,7 @@ namespace Terminal.Gui { { for (int i = linesCount; i >= 0; i--) { var x = _lines [i]; - var txt = StringExtensions.Make (x); + var txt = StringExtensions.ToString (x); if (!matchCase) { txt = txt.ToUpper (); } @@ -973,7 +973,7 @@ namespace Terminal.Gui { for (int i = 0; i < Model.Count; i++) { var line = Model.GetLine (i); var wrappedLines = ToListRune ( - TextFormatter.Format (StringExtensions.Make (line), width, TextAlignment.Left, true, preserveTrailingSpaces, tabWidth)); + TextFormatter.Format (StringExtensions.ToString (line), width, TextAlignment.Left, true, preserveTrailingSpaces, tabWidth)); int sumColWidth = 0; for (int j = 0; j < wrappedLines.Count; j++) { var wrapLine = wrappedLines [j]; @@ -2782,7 +2782,7 @@ namespace Terminal.Gui { foreach (var rune in runes) { offset += rune.Encode (encoded, offset); } - return StringExtensions.Make (encoded); + return StringExtensions.ToString (encoded); } /// @@ -4121,7 +4121,7 @@ namespace Terminal.Gui { _copyWithoutSelection = false; } else { var currentLine = GetCurrentLine (); - SetClipboard (StringExtensions.Make (currentLine)); + SetClipboard (StringExtensions.ToString (currentLine)); _copyWithoutSelection = true; } UpdateWrapModel (); diff --git a/Terminal.Gui/Views/TimeField.cs b/Terminal.Gui/Views/TimeField.cs index a1d5934d3..062e69745 100644 --- a/Terminal.Gui/Views/TimeField.cs +++ b/Terminal.Gui/Views/TimeField.cs @@ -174,12 +174,12 @@ namespace Terminal.Gui { newText.Add (key); if (CursorPosition < fieldLen) newText = newText.Concat (text.GetRange (CursorPosition + 1, text.Count - (CursorPosition + 1))).ToList (); - return SetText (StringExtensions.Make (newText)); + return SetText (StringExtensions.ToString (newText)); } bool SetText (string text) { - if (string.IsNullOrEmpty(text)) { + if (string.IsNullOrEmpty (text)) { return false; } @@ -260,7 +260,7 @@ namespace Terminal.Gui { if (ReadOnly) return true; - if (SetText (TextModel.ToRunes (StringExtensions.Make ((Rune)(uint)kb.Key)).First ())) + if (SetText (TextModel.ToRunes (((Rune)(uint)kb.Key).ToString ()).First ())) IncCursorPosition (); return true; @@ -336,7 +336,7 @@ namespace Terminal.Gui { /// The event arguments public virtual void OnTimeChanged (DateTimeEventArgs args) { - TimeChanged?.Invoke (this,args); + TimeChanged?.Invoke (this, args); } } } \ No newline at end of file diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 8961a52ed..cf67752e7 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -194,9 +194,9 @@ namespace UICatalog.Scenarios { var i = runes.IndexOf ((Rune)'_'); string start = ""; if (i > -1) { - start = StringExtensions.Make (runes.GetRange (0, i)); + start = StringExtensions.ToString (runes.GetRange (0, i)); } - txt = start + StringExtensions.Make (runes.GetRange (i + 1, runes.Count - (i + 1))); + txt = start + StringExtensions.ToString (runes.GetRange (i + 1, runes.Count - (i + 1))); runes = txt.ToRuneList (); @@ -207,8 +207,8 @@ namespace UICatalog.Scenarios { } // Slip in the '_' - start = StringExtensions.Make (runes.GetRange (0, i)); - return start + '_' + StringExtensions.Make (runes.GetRange (i, runes.Count - i)); + start = StringExtensions.ToString (runes.GetRange (0, i)); + return start + '_' + StringExtensions.ToString (runes.GetRange (i, runes.Count - i)); } var mhkb = "Click to Change th_is Button's Hotkey"; diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index 971aedb40..f77905391 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -1122,7 +1122,7 @@ namespace UICatalog.Scenarios { public object Convert (object value, object parameter = null) { var data = Encoding.ASCII.GetBytes (value.ToString ()); - return StringExtensions.Make (data); + return StringExtensions.ToString (data); } } } diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs index 9f1f3ffa6..ded4bea7b 100644 --- a/UICatalog/Scenarios/DynamicStatusBar.cs +++ b/UICatalog/Scenarios/DynamicStatusBar.cs @@ -651,7 +651,7 @@ namespace UICatalog.Scenarios { public object Convert (object value, object parameter = null) { var data = Encoding.ASCII.GetBytes (value.ToString ()); - return StringExtensions.Make (data); + return StringExtensions.ToString (data); } } } diff --git a/UICatalog/Scenarios/LabelsAsButtons.cs b/UICatalog/Scenarios/LabelsAsButtons.cs index c164caa97..d5e5e21f9 100644 --- a/UICatalog/Scenarios/LabelsAsButtons.cs +++ b/UICatalog/Scenarios/LabelsAsButtons.cs @@ -224,9 +224,9 @@ namespace UICatalog.Scenarios { var i = runes.IndexOf ((Rune)'_'); string start = ""; if (i > -1) { - start = StringExtensions.Make (runes.GetRange (0, i)); + start = StringExtensions.ToString (runes.GetRange (0, i)); } - txt = start + StringExtensions.Make (runes.GetRange (i + 1, runes.Count - (i + 1))); + txt = start + StringExtensions.ToString (runes.GetRange (i + 1, runes.Count - (i + 1))); runes = txt.ToRuneList (); @@ -237,8 +237,8 @@ namespace UICatalog.Scenarios { } // Slip in the '_' - start = StringExtensions.Make (runes.GetRange (0, i)); - return start + '_' + StringExtensions.Make (runes.GetRange (i, runes.Count - i)); + start = StringExtensions.ToString (runes.GetRange (0, i)); + return start + '_' + StringExtensions.ToString (runes.GetRange (i, runes.Count - i)); } var mhkb = "Click to Change th_is Label's Hotkey"; diff --git a/UnitTests/TestHelpers.cs b/UnitTests/TestHelpers.cs index 8f71d89c8..896f3a4a1 100644 --- a/UnitTests/TestHelpers.cs +++ b/UnitTests/TestHelpers.cs @@ -226,7 +226,7 @@ class TestHelpers { // Convert Rune list to string for (int r = 0; r < lines.Count; r++) { - var line = Terminal.Gui.StringExtensions.Make (lines [r]).ToString (); + var line = Terminal.Gui.StringExtensions.ToString (lines [r]).ToString (); if (r == lines.Count - 1) { sb.Append (line); } else { diff --git a/UnitTests/Text/RuneTests.cs b/UnitTests/Text/RuneTests.cs index fc0c4afdf..58a1a0a35 100644 --- a/UnitTests/Text/RuneTests.cs +++ b/UnitTests/Text/RuneTests.cs @@ -160,9 +160,12 @@ public class RuneTests { [Theory] [InlineData ("\u2615\ufe0f", "☕️", 2, 2, 2)] // \ufe0f forces it to be rendered as a colorful image as compared to a monochrome text variant. + [InlineData ("\u1107\u1165\u11b8", "법", 3, 2, 1)] // the letters 법 join to form the Korean word for "rice:" U+BC95 법 (read from top left to bottom right) + [InlineData ("\U0001F468\u200D\U0001F469\u200D\U0001F467", "👨‍👩‍👧", 8, 6, 8)] // Man, Woman and Girl emoji. + [InlineData ("\u0915\u093f", "कि", 2, 2, 2)] // Hindi "कि" with DEVANAGARI LETTER KA and DEVANAGARI VOWEL SIGN I public void GetColumns_String_Without_SurrogatePair (string code, string str, int codeLength, int runesLength, int stringLength) { - Assert.Equal (str, code); + Assert.Equal (str, code.Normalize ()); Assert.Equal (codeLength, code.Length); Assert.Equal (runesLength, code.EnumerateRunes ().Sum (x => x.GetColumns ())); Assert.Equal (runesLength, str.GetColumns ()); @@ -189,15 +192,11 @@ public class RuneTests { public void GetColumns_GetRuneCount () { PrintTextElementCount ('\u00e1'.ToString (), "á", 1, 1, 1, 1); - PrintTextElementCount (new string (new char [] { '\u0061', '\u0301' }), "á", 1, 2, 2, 1); - PrintTextElementCount (StringExtensions.Make ('\u0061', '\u0301'), "á", 1, 2, 2, 1); - PrintTextElementCount (StringExtensions.Make ('\u0065', '\u0301'), "é", 1, 2, 2, 1); - PrintTextElementCount (StringExtensions.Make (new Rune [] { new Rune (0x1f469), new Rune (0x1f3fd), new Rune ('\u200d'), new Rune (0x1f692) }), - "👩🏽‍🚒", 6, 4, 7, 1); - PrintTextElementCount (StringExtensions.Make (new Rune [] { new Rune (0x1f469), new Rune (0x1f3fd), new Rune ('\u200d'), new Rune (0x1f692) }), - "\U0001f469\U0001f3fd\u200d\U0001f692", 6, 4, 7, 1); - PrintTextElementCount (StringExtensions.Make (new Rune ('\ud801', '\udccf')), - "𐓏", 1, 1, 2, 1); + PrintTextElementCount ("\u0061\u0301", "á", 1, 2, 2, 1); + PrintTextElementCount ("\u0061\u0301", "á", 1, 2, 2, 1); + PrintTextElementCount ("\u0065\u0301", "é", 1, 2, 2, 1); + PrintTextElementCount ("\U0001f469\U0001f3fd\u200d\U0001f692", "👩🏽‍🚒", 6, 4, 7, 1); + PrintTextElementCount ("\ud801\udccf", "𐓏", 1, 1, 2, 1); } private void PrintTextElementCount (string us, string s, int consoleWidth, int runeCount, int stringCount, int txtElementCount) @@ -317,7 +316,7 @@ public class RuneTests { } Assert.Equal (us.GetColumns (), colWidth); Assert.Equal (s, rs); - Assert.Equal (s, StringExtensions.Make (runes)); + Assert.Equal (s, StringExtensions.ToString (runes)); return true; } @@ -370,9 +369,9 @@ public class RuneTests { var nsRune = new Rune (code2); Assert.Equal (rune1Length, rune.GetColumns ()); Assert.Equal (rune2Length, nsRune.GetColumns ()); - var ul = StringExtensions.Make (rune); + var ul = rune.ToString (); Assert.Equal (code1String, ul); - var uns = StringExtensions.Make (nsRune); + var uns = nsRune.ToString (); Assert.Equal (code2String, uns); var f = $"{rune}{nsRune}".Normalize (); Assert.Equal (f, joinString); @@ -408,7 +407,7 @@ public class RuneTests { continue; } Rune r = new Rune ((uint)i); - string us = StringExtensions.Make (r); + string us = r.ToString (); string hex = i.ToString ("x6"); int v = int.Parse (hex, System.Globalization.NumberStyles.HexNumber); string s = char.ConvertFromUtf32 (v); @@ -443,7 +442,7 @@ public class RuneTests { { for (int i = start; i <= end; i++) { Rune r = new Rune ((uint)i); - string us = StringExtensions.Make (r); + string us = r.ToString (); string hex = i.ToString ("x6"); int v = int.Parse (hex, System.Globalization.NumberStyles.HexNumber); string s = char.ConvertFromUtf32 (v); @@ -520,7 +519,7 @@ public class RuneTests { for (uint h = 0xd800; h <= 0xdbff; h++) { for (uint l = 0xdc00; l <= 0xdfff; l++) { Rune r = new Rune ((char)h, (char)l); - string us = StringExtensions.Make (r); + string us = r.ToString (); string hex = r.Value.ToString ("x6"); int v = int.Parse (hex, System.Globalization.NumberStyles.HexNumber); string s = char.ConvertFromUtf32 (v); @@ -548,7 +547,7 @@ public class RuneTests { runes.Add (rune); tSize += size; } - string result = StringExtensions.Make (runes); + string result = StringExtensions.ToString (runes); Assert.Equal (text, result); Assert.Equal (bytesLength, tSize); Assert.Equal (colsLength, result.GetColumns ()); @@ -567,7 +566,7 @@ public class RuneTests { runes.Add (rune); tSize += size; } - string result = StringExtensions.Make (runes); + string result = StringExtensions.ToString (runes); Assert.Equal (encoded, result); Assert.Equal (bytesLength, tSize); Assert.Equal (colsLength, result.GetColumns ()); @@ -590,7 +589,7 @@ public class RuneTests { Assert.False (RuneExtensions.CanBeEncodedAsRune (Encoding.Unicode.GetBytes (str.ToCharArray ()))); } } else if (text is byte []) { - str = StringExtensions.Make ((byte [])text); + str = StringExtensions.ToString ((byte [])text); if (canBeEncodedAsRune) { Assert.True (RuneExtensions.CanBeEncodedAsRune (Encoding.Unicode.GetBytes (str.ToCharArray ()))); } else { @@ -647,7 +646,7 @@ public class RuneTests { int sumConsoleWidth = 0; for (uint i = 0; i < 32; i++) { sumRuneWidth += ((Rune)i).GetColumns (); - sumConsoleWidth += StringExtensions.Make (i).GetColumns (); + sumConsoleWidth += ((Rune)i).ToString ().GetColumns (); } Assert.Equal (-32, sumRuneWidth); diff --git a/UnitTests/Text/TextFormatterTests.cs b/UnitTests/Text/TextFormatterTests.cs index c5275694f..4a0b3e3c5 100644 --- a/UnitTests/Text/TextFormatterTests.cs +++ b/UnitTests/Text/TextFormatterTests.cs @@ -645,7 +645,7 @@ namespace Terminal.Gui.TextTests { text = "test"; maxWidth = 2; - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..maxWidth]), justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align)); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..maxWidth]), justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align)); text = "test"; maxWidth = int.MaxValue; @@ -661,7 +661,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should fit. maxWidth = text.GetRuneCount () + 0; @@ -670,7 +670,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should fit. maxWidth = int.MaxValue; @@ -679,7 +679,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should not fit maxWidth = text.GetRuneCount () - 1; @@ -688,7 +688,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should not fit maxWidth = 10; @@ -697,7 +697,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "A\tsentence\thas\twords."; maxWidth = int.MaxValue; @@ -706,7 +706,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "A\tsentence\thas\twords."; maxWidth = 10; @@ -715,7 +715,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "line1\nline2\nline3long!"; maxWidth = int.MaxValue; @@ -724,7 +724,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "line1\nline2\nline3long!"; maxWidth = 10; @@ -733,7 +733,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Unicode text = " ~  s  gui.cs   master ↑10"; @@ -743,7 +743,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // should fit text = "Ð ÑÐ"; @@ -753,7 +753,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should fit. maxWidth = text.GetRuneCount () + 0; @@ -762,7 +762,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should not fit maxWidth = text.GetRuneCount () - 1; @@ -771,7 +771,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); } [Fact] @@ -790,7 +790,7 @@ namespace Terminal.Gui.TextTests { text = "test"; maxWidth = 2; - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..maxWidth]), justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align)); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..maxWidth]), justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align)); text = "test"; maxWidth = int.MaxValue; @@ -806,7 +806,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should fit. maxWidth = text.GetRuneCount () + 0; @@ -815,7 +815,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should fit. maxWidth = int.MaxValue; @@ -824,7 +824,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should not fit maxWidth = text.GetRuneCount () - 1; @@ -833,7 +833,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should not fit maxWidth = 10; @@ -842,7 +842,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "A\tsentence\thas\twords."; maxWidth = int.MaxValue; @@ -851,7 +851,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "A\tsentence\thas\twords."; maxWidth = 10; @@ -860,7 +860,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "line1\nline2\nline3long!"; maxWidth = int.MaxValue; @@ -869,7 +869,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "line1\nline2\nline3long!"; maxWidth = 10; @@ -878,7 +878,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Unicode text = " ~  s  gui.cs   master ↑10"; @@ -888,7 +888,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // should fit text = "Ð ÑÐ"; @@ -898,7 +898,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should fit. maxWidth = text.GetRuneCount () + 0; @@ -907,7 +907,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should not fit maxWidth = text.GetRuneCount () - 1; @@ -916,7 +916,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); } [Fact] @@ -935,7 +935,7 @@ namespace Terminal.Gui.TextTests { text = "test"; maxWidth = 2; - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..maxWidth]), justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align)); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..maxWidth]), justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align)); text = "test"; maxWidth = int.MaxValue; @@ -951,7 +951,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should fit. maxWidth = text.GetRuneCount () + 0; @@ -960,7 +960,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should fit. maxWidth = int.MaxValue; @@ -969,7 +969,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should not fit maxWidth = text.GetRuneCount () - 1; @@ -978,7 +978,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should not fit maxWidth = 10; @@ -987,7 +987,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "A\tsentence\thas\twords."; maxWidth = int.MaxValue; @@ -996,7 +996,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "A\tsentence\thas\twords."; maxWidth = 10; @@ -1005,7 +1005,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "line1\nline2\nline3long!"; maxWidth = int.MaxValue; @@ -1014,7 +1014,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "line1\nline2\nline3long!"; maxWidth = 10; @@ -1023,7 +1023,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Unicode text = " ~  s  gui.cs   master ↑10"; @@ -1033,7 +1033,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // should fit text = "Ð ÑÐ"; @@ -1043,7 +1043,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should fit. maxWidth = text.GetRuneCount () + 0; @@ -1052,7 +1052,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should not fit maxWidth = text.GetRuneCount () - 1; @@ -1061,7 +1061,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); } [Fact] @@ -1080,7 +1080,7 @@ namespace Terminal.Gui.TextTests { text = "test"; maxWidth = 2; - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..maxWidth]), justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align)); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..maxWidth]), justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align)); text = "test"; maxWidth = int.MaxValue; @@ -1094,7 +1094,7 @@ namespace Terminal.Gui.TextTests { justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align); Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Throws (() => StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth])); + Assert.Throws (() => StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth])); // Should fit. maxWidth = text.GetRuneCount () + 0; @@ -1102,7 +1102,7 @@ namespace Terminal.Gui.TextTests { justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align); //Assert.Equal (expectedClippedWidth, justifiedText.RuneCount ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should fit. maxWidth = 500; @@ -1118,7 +1118,7 @@ namespace Terminal.Gui.TextTests { justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align); //Assert.Equal (expectedClippedWidth, justifiedText.RuneCount ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should not fit maxWidth = 10; @@ -1126,7 +1126,7 @@ namespace Terminal.Gui.TextTests { justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align); //Assert.Equal (expectedClippedWidth, justifiedText.RuneCount ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "A\tsentence\thas\twords."; maxWidth = int.MaxValue; @@ -1134,7 +1134,7 @@ namespace Terminal.Gui.TextTests { justifiedText = TextFormatter.ClipAndJustify (text, maxWidth, align); //Assert.Equal (expectedClippedWidth, justifiedText.RuneCount ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "A\tsentence\thas\twords."; maxWidth = 10; @@ -1143,7 +1143,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "line1\nline2\nline3long!"; maxWidth = int.MaxValue; @@ -1152,7 +1152,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); text = "line1\nline2\nline3long!"; maxWidth = 10; @@ -1161,7 +1161,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Unicode text = " ~  s  gui.cs   master ↑10"; @@ -1171,7 +1171,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // should fit text = "Ð ÑÐ"; @@ -1189,7 +1189,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // Should not fit maxWidth = text.GetRuneCount () - 1; @@ -1198,7 +1198,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ()); Assert.Equal (expectedClippedWidth, justifiedText.GetColumns ()); Assert.True (expectedClippedWidth <= maxWidth); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), justifiedText); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), justifiedText); // see Justify_ tests below } @@ -1629,15 +1629,15 @@ namespace Terminal.Gui.TextTests { width = text.GetRuneCount () - 1; wrappedLines = TextFormatter.WordWrapText (text, width); Assert.Equal (2, wrappedLines.Count); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..(text.GetRuneCount () - 1)]), wrappedLines [0]); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..(text.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1)) - 1)]), wrappedLines [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..(text.GetRuneCount () - 1)]), wrappedLines [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..(text.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1)) - 1)]), wrappedLines [0]); Assert.Equal ("ำ", wrappedLines [1]); width = text.GetRuneCount () - 2; wrappedLines = TextFormatter.WordWrapText (text, width); Assert.Equal (2, wrappedLines.Count); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..(text.GetRuneCount () - 2)]), wrappedLines [0]); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..(text.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1)) - 2)]), wrappedLines [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..(text.GetRuneCount () - 2)]), wrappedLines [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..(text.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1)) - 2)]), wrappedLines [0]); width = text.GetRuneCount () - 5; wrappedLines = TextFormatter.WordWrapText (text, width); @@ -1685,15 +1685,15 @@ namespace Terminal.Gui.TextTests { width = text.GetRuneCount () - 1; wrappedLines = TextFormatter.WordWrapText (text, width); Assert.Equal (2, wrappedLines.Count); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..(text.GetRuneCount () - 1)]), wrappedLines [0]); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..(text.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1)) - 1)]), wrappedLines [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..(text.GetRuneCount () - 1)]), wrappedLines [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..(text.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1)) - 1)]), wrappedLines [0]); Assert.Equal (".", wrappedLines [1]); width = text.GetRuneCount () - 2; wrappedLines = TextFormatter.WordWrapText (text, width); Assert.Equal (2, wrappedLines.Count); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..(text.GetRuneCount () - 2)]), wrappedLines [0]); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..(text.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1)) - 2)]), wrappedLines [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..(text.GetRuneCount () - 2)]), wrappedLines [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..(text.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1)) - 2)]), wrappedLines [0]); width = text.GetRuneCount () - 5; wrappedLines = TextFormatter.WordWrapText (text, width); @@ -3137,37 +3137,36 @@ namespace Terminal.Gui.TextTests { var tf = new TextFormatter (); string text = "test"; int hotPos = 0; - uint tag = 't'; + var tag = (Rune)'t'; - Assert.Equal (StringExtensions.Make (new Rune [] { (Rune)tag, (Rune)'e', (Rune)'s', (Rune)'t' }), tf.ReplaceHotKeyWithTag (text, hotPos)); + Assert.Equal ($"{tag}est", tf.ReplaceHotKeyWithTag (text, hotPos)); - tag = 'e'; + tag = (Rune)'e'; hotPos = 1; - Assert.Equal (StringExtensions.Make (new Rune [] { (Rune)'t', (Rune)tag, (Rune)'s', (Rune)'t' }), tf.ReplaceHotKeyWithTag (text, hotPos)); + Assert.Equal ($"t{tag}st", tf.ReplaceHotKeyWithTag (text, hotPos)); var result = tf.ReplaceHotKeyWithTag (text, hotPos); Assert.Equal ((Rune)'e', result.ToRunes () [1]); text = "Ok"; - tag = 'O'; + tag = new Rune ('O'); hotPos = 0; - Assert.Equal (StringExtensions.Make (new Rune [] { (Rune)tag, (Rune)'k' }), result = tf.ReplaceHotKeyWithTag (text, hotPos)); + Assert.Equal ($"{tag}k", result = tf.ReplaceHotKeyWithTag (text, hotPos)); Assert.Equal ((Rune)'O', result.ToRunes () [0]); text = "[◦ Ok ◦]"; - text = StringExtensions.Make (new Rune [] { (Rune)'[', (Rune)'◦', (Rune)' ', (Rune)'O', (Rune)'k', (Rune)' ', (Rune)'◦', (Rune)']' }); var runes = text.ToRuneList (); Assert.Equal (text.GetRuneCount (), runes.Count); - Assert.Equal (text, StringExtensions.Make (runes)); - tag = 'O'; + Assert.Equal (text, StringExtensions.ToString (runes)); + tag = new Rune ('O'); hotPos = 3; - Assert.Equal (StringExtensions.Make (new Rune [] { (Rune)'[', (Rune)'◦', (Rune)' ', (Rune)tag, (Rune)'k', (Rune)' ', (Rune)'◦', (Rune)']' }), result = tf.ReplaceHotKeyWithTag (text, hotPos)); + Assert.Equal ($"[◦ {tag}k ◦]", result = tf.ReplaceHotKeyWithTag (text, hotPos)); Assert.Equal ((Rune)'O', result.ToRunes () [3]); text = "^k"; - tag = '^'; + tag = new Rune ('^'); hotPos = 0; - Assert.Equal (StringExtensions.Make (new Rune [] { (Rune)tag, (Rune)'k' }), result = tf.ReplaceHotKeyWithTag (text, hotPos)); + Assert.Equal ($"{tag}k", result = tf.ReplaceHotKeyWithTag (text, hotPos)); Assert.Equal ((Rune)'^', result.ToRunes () [0]); } @@ -3223,32 +3222,32 @@ namespace Terminal.Gui.TextTests { expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), list [0]); maxWidth = 5; expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), list [0]); maxWidth = text.GetRuneCount () - 1; expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), list [0]); // no clip maxWidth = text.GetRuneCount () + 0; expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), list [0]); maxWidth = text.GetRuneCount () + 1; expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), list [0]); } [Fact] @@ -3270,32 +3269,32 @@ namespace Terminal.Gui.TextTests { expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), list [0]); maxWidth = 5; expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), list [0]); maxWidth = text.GetRuneCount () - 1; expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]).Replace ("\n", " "), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]).Replace ("\n", " "), list [0]); // no clip maxWidth = text.GetRuneCount () + 0; expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]).Replace ("\n", " "), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]).Replace ("\n", " "), list [0]); maxWidth = text.GetRuneCount () + 1; expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]).Replace ("\n", " "), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]).Replace ("\n", " "), list [0]); text = "A sentence has words.\r\nLine 2."; maxWidth = 0; @@ -3307,32 +3306,32 @@ namespace Terminal.Gui.TextTests { expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), list [0]); maxWidth = 5; expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), list [0]); maxWidth = text.GetRuneCount () - 1; expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth) + 1; list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]).Replace ("\r\n", " "), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]).Replace ("\r\n", " "), list [0]); // no clip maxWidth = text.GetRuneCount () + 0; expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]).Replace ("\r\n", " "), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]).Replace ("\r\n", " "), list [0]); maxWidth = text.GetRuneCount () + 1; expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.True (list.Count == 1); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]).Replace ("\r\n", " "), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]).Replace ("\r\n", " "), list [0]); } [Fact] @@ -3374,7 +3373,7 @@ namespace Terminal.Gui.TextTests { expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth - text.Sum (r => r == ' ' ? 1 : 0)); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap); Assert.Equal (expectedClippedWidth, list.Count); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), list [0]); Assert.Equal ("01245689", string.Join ("", list.ToArray ())); maxWidth = 5; @@ -3382,7 +3381,7 @@ namespace Terminal.Gui.TextTests { expectedClippedWidth = Math.Min (text.GetRuneCount (), (int)Math.Ceiling ((double)(text.GetRuneCount () / 3F))); list = TextFormatter.Format (text, maxWidth, TextAlignment.Left, wrap, preserveTrailingSpaces); Assert.Equal (expectedClippedWidth - (maxWidth - expectedClippedWidth), list.Count); - Assert.Equal (StringExtensions.Make (text.ToRunes () [0..expectedClippedWidth]), list [0]); + Assert.Equal (StringExtensions.ToString (text.ToRunes () [0..expectedClippedWidth]), list [0]); Assert.Equal ("012 456 89", string.Join ("", list.ToArray ())); maxWidth = text.GetRuneCount () - 1; diff --git a/UnitTests/Views/MenuTests.cs b/UnitTests/Views/MenuTests.cs index 00d0b84af..661ad0bed 100644 --- a/UnitTests/Views/MenuTests.cs +++ b/UnitTests/Views/MenuTests.cs @@ -1999,10 +1999,10 @@ Edit }; mi.Action = mi.ToggleChecked; var menu = new MenuBar (new MenuBarItem [] { - new MenuBarItem("Nullable Checked",new MenuItem [] { - mi - }) - }); + new MenuBarItem("Nullable Checked",new MenuItem [] { + mi + }) + }); new CheckBox (); var top = Application.Top; top.Add (menu); @@ -2086,12 +2086,12 @@ Edit public void Menu_With_Separator () { var menu = new MenuBar (new MenuBarItem [] { - new MenuBarItem("File",new MenuItem [] { - new MenuItem("_Open", "Open a file", () => { }, null, null, Key.CtrlMask | Key.O), - null, - new MenuItem("_Quit","",null) - }) - }); + new MenuBarItem("File",new MenuItem [] { + new MenuItem("_Open", "Open a file", () => { }, null, null, Key.CtrlMask | Key.O), + null, + new MenuItem("_Quit","",null) + }) + }); Application.Top.Add (menu); Application.Begin (Application.Top);