Skip to content

Commit

Permalink
「URLからの全角文字列の切り離し」のテストケースを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed Dec 14, 2023
1 parent d80ba7c commit d9b59e2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
20 changes: 20 additions & 0 deletions OpenTween.Tests/TweenMainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ public void FormatStatusText_NewLineInDMTest()
});
}

[WinFormsFact]
public void FormatStatusText_SeparateUrlAndFullwidthCharacter_EnabledTest()
{
this.UsingTweenMain((tweenMain, context) =>
{
tweenMain.UpdateSeparateUrlAndFullwidthCharacter(true);
Assert.Equal("https://example.com/ あああ", tweenMain.FormatStatusText("https://example.com/あああ"));
});
}

[WinFormsFact]
public void FormatStatusText_SeparateUrlAndFullwidthCharacter_DisabledTest()
{
this.UsingTweenMain((tweenMain, context) =>
{
tweenMain.UpdateSeparateUrlAndFullwidthCharacter(false);
Assert.Equal("https://example.com/あああ", tweenMain.FormatStatusText("https://example.com/あああ"));
});
}

[WinFormsFact]
public void FormatStatusText_ReplaceFullwidthSpace_EnabledTest()
{
Expand Down
20 changes: 15 additions & 5 deletions OpenTween/Tween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public partial class TweenMain : OTBaseForm
private readonly DebounceTimer saveConfigDebouncer;

private readonly string recommendedStatusFooter;
private bool urlMultibyteSplit = false;
private bool separateUrlAndFullwidthCharacter = false;
private bool preventSmsCommand = true;

// URL短縮のUndo用
Expand Down Expand Up @@ -3538,7 +3538,7 @@ internal string FormatStatusText(string statusText, Keys modifierKeys)
{
statusText = statusText.Replace("\r\n", "\n");

if (this.urlMultibyteSplit)
if (this.separateUrlAndFullwidthCharacter)
{
// URLと全角文字の切り離し
statusText = Regex.Replace(statusText, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+", "$& ");
Expand Down Expand Up @@ -8196,7 +8196,17 @@ private void MenuItemHelp_DropDownOpening(object sender, EventArgs e)
}

private void UrlMultibyteSplitMenuItem_CheckedChanged(object sender, EventArgs e)
=> this.urlMultibyteSplit = ((ToolStripMenuItem)sender).Checked;
=> this.UpdateSeparateUrlAndFullwidthCharacter(((ToolStripMenuItem)sender).Checked);

internal void UpdateSeparateUrlAndFullwidthCharacter(bool value)
{
if (this.separateUrlAndFullwidthCharacter == value)
return;

this.separateUrlAndFullwidthCharacter = value;
this.UrlMultibyteSplitMenuItem.Checked = value;
this.UrlMultibyteSplitPullDownMenuItem.Checked = value;
}

private void PreventSmsCommandMenuItem_CheckedChanged(object sender, EventArgs e)
=> this.preventSmsCommand = ((ToolStripMenuItem)sender).Checked;
Expand All @@ -8218,7 +8228,7 @@ private void FocusLockMenuItem_CheckedChanged(object sender, EventArgs e)

private void PostModeMenuItem_DropDownOpening(object sender, EventArgs e)
{
this.UrlMultibyteSplitMenuItem.Checked = this.urlMultibyteSplit;
this.UrlMultibyteSplitMenuItem.Checked = this.separateUrlAndFullwidthCharacter;
this.PreventSmsCommandMenuItem.Checked = this.preventSmsCommand;
this.UrlAutoShortenMenuItem.Checked = this.settings.Common.UrlConvertAuto;
this.IdeographicSpaceToSpaceMenuItem.Checked = this.settings.Common.WideSpaceConvert;
Expand All @@ -8228,7 +8238,7 @@ private void PostModeMenuItem_DropDownOpening(object sender, EventArgs e)

private void ContextMenuPostMode_Opening(object sender, CancelEventArgs e)
{
this.UrlMultibyteSplitPullDownMenuItem.Checked = this.urlMultibyteSplit;
this.UrlMultibyteSplitPullDownMenuItem.Checked = this.separateUrlAndFullwidthCharacter;
this.PreventSmsCommandPullDownMenuItem.Checked = this.preventSmsCommand;
this.UrlAutoShortenPullDownMenuItem.Checked = this.settings.Common.UrlConvertAuto;
this.IdeographicSpaceToSpacePullDownMenuItem.Checked = this.settings.Common.WideSpaceConvert;
Expand Down

0 comments on commit d9b59e2

Please sign in to comment.