Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
takubokudori committed Dec 15, 2019
1 parent b5e782f commit b0757e6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
12 changes: 5 additions & 7 deletions LineFormatter/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void Translate(string orig)
{
_trans.Proxy = _proxyForm.Proxy;

_trans.Orig = orig;
_trans.OrigText = orig;
_trans.Tb = AfterBox;
_trans.Translate();
}
Expand Down Expand Up @@ -286,12 +286,10 @@ private static void SelectionFunc(RichTextBox rtb, Func<RichTextBox, bool> callb
rtb.SelectionLength = rtb.TextLength;
}
callbackFunc(rtb);
if (isStay)
{
// 選択を元に戻す
rtb.SelectionStart = start;
rtb.SelectionLength = length;
}
if (!isStay) return;
// 選択を元に戻す
rtb.SelectionStart = start;
rtb.SelectionLength = length;
}

private static void StopDrawingFunc(RichTextBox rtb, Func<RichTextBox, bool> callbackFunc)
Expand Down
14 changes: 7 additions & 7 deletions LineFormatter/Translation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ namespace LineFormatter
public class Translation
{
private const string TranslationUrl = "https://translate.googleapis.com/translate_a/single";
public string Orig = ""; // オリジナル
public string Trans = ""; // 訳文
public string OrigText = ""; // オリジナル
public string TransText = ""; // 訳文
public TextBoxBase Tb = null;
private readonly List<PTrans> _pTList = new List<PTrans>(); // 対訳リスト
public IWebProxy Proxy = null; // プロキシ
public void Translate()
{
var text = System.Web.HttpUtility.UrlEncode(Orig);
var text = System.Web.HttpUtility.UrlEncode(OrigText);
if (text == "") return;
var wc = new WebClient
{
Expand Down Expand Up @@ -56,21 +56,21 @@ public void CompleteDownloadProc1(Object sender, DownloadStringCompletedEventArg
res = (GTransResp)serializer.ReadObject(ms);
}

Trans = "";
TransText = "";
_pTList.Clear();
var transPos = 0;
var origPos = 0;
if (res?.sentences == null) return;
foreach (var sentence in res.sentences)
{
Trans += sentence.trans;
for (; Orig[origPos] != sentence.orig[0]; origPos++) { } // 先頭の空白がtrimされるのでその分位置をずらす
TransText += sentence.trans;
for (; OrigText[origPos] != sentence.orig[0]; origPos++) { } // 先頭の空白がtrimされるのでその分位置をずらす
_pTList.Add(new PTrans(origPos, transPos, sentence.orig, sentence.trans));
transPos += sentence.trans.Length;
origPos += sentence.orig.Length;
}

if (Tb != null) Tb.Text = Trans;
if (Tb != null) Tb.Text = TransText;
}

// 指定位置の対を取得
Expand Down
8 changes: 4 additions & 4 deletions LineFormatter/WinApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace LineFormatter
class WinApi
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);

public const int WM_SETREDRAW = 0x000B;
public const int EM_LINEFROMCHAR = 0xC9;
private const int WM_SETREDRAW = 0x000B;
private const int EM_LINEFROMCHAR = 0xC9;

// コントロールの描画停止
public static void StopDrawing(Control control)
Expand All @@ -28,7 +28,7 @@ public static void StartDrawing(Control control)
// 行数の取得
public static int GetNumOfLines(Control control)
{
return SendMessage( control.Handle, EM_LINEFROMCHAR, -1, 0).ToInt32() + 1;
return SendMessage(control.Handle, EM_LINEFROMCHAR, -1, 0).ToInt32() + 1;
}
}
}
1 change: 1 addition & 0 deletions UnitTest/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void FormatTest()
is
a
test.");
Format(@"example.com", "example.com"); // .の後に文字が続く場合は改行しない
Format( // e.g. i.e.は改行しない
@"This (i.e. dog) is an animal (e.g. cat).",
@"This (i.e. dog) is an animal (e.g. cat).");
Expand Down

0 comments on commit b0757e6

Please sign in to comment.