Fix possible problems with "intend to add" staged files
[TortoiseGit.git] / test / UnitTests / StringUtilsTest.cpp
blob9cd5f653193e7318544f3e90e05bdca64cf3b362
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015 - TortoiseGit
4 // Copyright (C) 2003-2011 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "stdafx.h"
22 #include "StringUtils.h"
24 TEST(CStringUtils, WordWrap)
26 CString longline = _T("this is a test of how a string can be splitted into several lines");
27 CString splittedline = CStringUtils::WordWrap(longline, 10, true, false, 4);
28 EXPECT_STREQ(_T("this is a\n test of\n how a\n string\n can be\n splitted\n into\n several\n lines"), splittedline);
29 longline = _T("c:\\this_is_a_very_long\\path_on_windows and of course some other words added to make the line longer");
30 splittedline = CStringUtils::WordWrap(longline, 10, true, false, 4);
31 EXPECT_STREQ(_T("...\\pat...\n and of\n course\n some\n other\n words\n added to\n make the\n line\n longer"), splittedline);
32 longline = _T("Forced failure in https://myserver.com/a_long_url_to_split PROPFIND error");
33 splittedline = CStringUtils::WordWrap(longline, 20, true, false, 4);
34 EXPECT_STREQ(_T("Forced failure in\n https://myserver.com/a_long_url_to_split\n PROPFIND error"), splittedline);
35 longline = _T("Forced\nfailure in https://myserver.com/a_long_url_to_split PROPFIND\nerror");
36 splittedline = CStringUtils::WordWrap(longline, 40, true, false, 4);
37 EXPECT_STREQ(_T("Forced\nfailure in\n https://myserver.com/a_long_url_to_split\n PROPFIND\nerror"), splittedline);
38 longline = _T("Failed to add file\nc:\\export\\spare\\Devl-JBoss\\development\\head\\src\\something\\CoreApplication\\somethingelse\\src\\com\\yetsomthingelse\\shipper\\DAO\\ShipmentInfoDAO1.java\nc:\\export\\spare\\Devl-JBoss\\development\\head\\src\\something\\CoreApplication\\somethingelse\\src\\com\\yetsomthingelse\\shipper\\DAO\\ShipmentInfoDAO2.java");
39 splittedline = CStringUtils::WordWrap(longline, 80, true, false, 4);
40 EXPECT_STREQ(_T("Failed to add\n file\nc:\\export\\spare\\Devl-JBoss\\development\\head\\src\\something\\CoreApplication\\somethingelse\\src\\com\\yetsomthingelse\\shipper\\DAO\\ShipmentInfoDAO1.java\nc:\\export\\spare\\Devl-JBoss\\development\\head\\src\\something\\CoreApplication\\somethingelse\\src\\com\\yetsomthing\n"), splittedline);
43 TEST(CStringUtils, LinesWrap)
45 CString longline = _T("this is a test of how a string can be splitted into several lines");
46 CString splittedline = CStringUtils::LinesWrap(longline, 10, true);
47 EXPECT_STREQ(_T("this is a\n test of\n how a\n string\n can be\n splitted\n into\n several\n lines"), splittedline);
48 longline = _T("c:\\this_is_a_very_long\\path_on_windows and of course some other words added to make the line longer");
49 splittedline = CStringUtils::LinesWrap(longline, 10);
50 EXPECT_STREQ(_T("c:\\this_is_a_very_long\\path_on_windows\n and of\n course\n some\n other\n words\n added to\n make the\n line\n longer"), splittedline);
51 longline = _T("Forced failure in https://myserver.com/a_long_url_to_split PROPFIND error");
52 splittedline = CStringUtils::LinesWrap(longline, 20, true);
53 EXPECT_STREQ(_T("Forced failure in\n https://myserver.com/a_long_url_to_split\n PROPFIND error"), splittedline);
54 longline = _T("Forced\nfailure in https://myserver.com/a_long_url_to_split PROPFIND\nerror");
55 splittedline = CStringUtils::LinesWrap(longline, 40);
56 EXPECT_STREQ(_T("Forced\nfailure in\n https://myserver.com/a_long_url_to_split\n PROPFIND\nerror"), splittedline);
57 longline = _T("Failed to add file\nc:\\export\\spare\\Devl-JBoss\\development\\head\\src\\something\\CoreApplication\\somethingelse\\src\\com\\yetsomthingelse\\shipper\\DAO\\ShipmentInfoDAO1.java\nc:\\export\\spare\\Devl-JBoss\\development\\head\\src\\something\\CoreApplication\\somethingelse\\src\\com\\yetsomthingelse\\shipper\\DAO\\ShipmentInfoDAO2.java");
58 splittedline = CStringUtils::LinesWrap(longline);
59 EXPECT_STREQ(_T("Failed to add file\nc:\\export\\spare\\Devl-JBoss\\development\\head\\src\\something\\CoreApplication\\somethingelse\\src\\com\\yetsomthingelse\\shipper\\DAO\\ShipmentInfoDAO1.java\n\nc:\\export\\spare\\Devl-JBoss\\development\\head\\src\\something\\CoreApplication\\somethingelse\\src\\com\\yetsomthingelse\\shipper\\DAO\\ShipmentInfoDAO2.java"), splittedline);
60 longline = _T("The commit comment is not properly formatted.\nFormat:\n Field 1 : Field 2 : Field 3\nWhere:\nField 1 - Team Name|Triage|Merge|Goal\nField 2 - V1 Backlog Item ID|Triage Number|SVNBranch|Goal Name\nField 3 - Description of change\nExamples:\n\nTeam Gamma : B-12345 : Changed some code\n Triage : 123 : Fixed production release bug\n Merge : sprint0812 : Merged sprint0812 into prod\n Goal : Implement Pre-Commit Hook : Commit message hook impl");
61 splittedline = CStringUtils::LinesWrap(longline, 80);
62 EXPECT_STREQ(_T("The commit comment is not properly formatted.\nFormat:\n Field 1 : Field 2 : Field 3\nWhere:\nField 1 - Team Name|Triage|Merge|Goal\nField 2 - V1 Backlog Item ID|Triage Number|SVNBranch|Goal Name\nField 3 - Description of change\nExamples:\n\nTeam Gamma : B-12345 : Changed some code\n Triage : 123 : Fixed production release bug\n Merge : sprint0812 : Merged sprint0812 into prod\n Goal : Implement Pre-Commit Hook : Commit message hook impl"), splittedline);
65 TEST(CStringUtils, RemoveAccelerators)
67 CString empty;
68 CStringUtils::RemoveAccelerators(empty);
69 EXPECT_TRUE(empty.IsEmpty());
71 CString text1 = L"&Accellerator";
72 CStringUtils::RemoveAccelerators(text1);
73 EXPECT_STREQ(L"Accellerator", text1);
75 CString text1a = L"Ac&cellerator";
76 CStringUtils::RemoveAccelerators(text1a);
77 EXPECT_STREQ(L"Accellerator", text1a);
79 CString text2 = L"Accellerator&";
80 CStringUtils::RemoveAccelerators(text2);
81 EXPECT_STREQ(L"Accellerator", text2);
83 CString text3 = L"Some & text";
84 CStringUtils::RemoveAccelerators(text3);
85 EXPECT_STREQ(L"Some & text", text3);
87 CString text4 = L"&&Accellerator";
88 CStringUtils::RemoveAccelerators(text4);
89 EXPECT_STREQ(L"&Accellerator", text4);
91 CString text5 = L"Acce&&&llerator";
92 CStringUtils::RemoveAccelerators(text5);
93 EXPECT_STREQ(L"Acce&llerator", text5);
95 CString text6 = L"Some & te&xt";
96 CStringUtils::RemoveAccelerators(text6);
97 EXPECT_STREQ(L"Some & text", text6);
100 TEST(CStringUtils, ParseEmailAddress)
102 CString mail, name;
103 CStringUtils::ParseEmailAddress(_T(""), mail, &name);
104 EXPECT_STREQ(_T(""), mail);
105 EXPECT_STREQ(_T(""), name);
107 CStringUtils::ParseEmailAddress(_T(" "), mail, &name);
108 EXPECT_STREQ(_T(""), mail);
109 EXPECT_STREQ(_T(""), name);
111 mail.Empty();
112 CStringUtils::ParseEmailAddress(_T("test@example.com "), mail);
113 EXPECT_STREQ(_T("test@example.com"), mail);
115 mail.Empty();
116 CStringUtils::ParseEmailAddress(_T(" test@example.com"), mail);
117 EXPECT_STREQ(_T("test@example.com"), mail);
119 mail.Empty();
120 CStringUtils::ParseEmailAddress(_T("test@example.com"), mail);
121 EXPECT_STREQ(_T("test@example.com"), mail);
123 mail.Empty();
124 CStringUtils::ParseEmailAddress(_T("John Doe <johndoe>"), mail);
125 EXPECT_STREQ(_T("johndoe"), mail);
127 mail.Empty();
128 name.Empty();
129 CStringUtils::ParseEmailAddress(_T("test@example.com"), mail, &name);
130 EXPECT_STREQ(_T("test@example.com"), mail);
131 EXPECT_STREQ(_T("test@example.com"), name);
133 mail.Empty();
134 name.Empty();
135 CStringUtils::ParseEmailAddress(_T("<test@example.com>"), mail, &name);
136 EXPECT_STREQ(_T("test@example.com"), mail);
137 EXPECT_STREQ(_T("test@example.com"), name);
139 mail.Empty();
140 name.Empty();
141 CStringUtils::ParseEmailAddress(_T("John Doe <test@example.com>"), mail, &name);
142 EXPECT_STREQ(_T("test@example.com"), mail);
143 EXPECT_STREQ(_T("John Doe"), name);
145 mail.Empty();
146 name.Empty();
147 CStringUtils::ParseEmailAddress(_T("\"John Doe\" <test@example.com>"), mail, &name);
148 EXPECT_STREQ(_T("test@example.com"), mail);
149 EXPECT_STREQ(_T("John Doe"), name);
151 mail.Empty();
152 name.Empty();
153 CStringUtils::ParseEmailAddress(_T("<test@example.com"), mail, &name);
154 EXPECT_STREQ(_T("test@example.com"), mail);
155 EXPECT_STREQ(_T("test@example.com"), name);
157 mail.Empty();
158 name.Empty();
159 CStringUtils::ParseEmailAddress(_T("test@example.com>"), mail, &name);
160 EXPECT_STREQ(_T("test@example.com"), mail);
161 EXPECT_STREQ(_T("test@example.com"), name);
163 mail.Empty();
164 name.Empty();
165 CStringUtils::ParseEmailAddress(_T("John Doe <johndoe>"), mail, &name);
166 EXPECT_STREQ(_T("johndoe"), mail);
167 EXPECT_STREQ(_T("John Doe"), name);
169 mail.Empty();
170 name.Empty();
171 CStringUtils::ParseEmailAddress(_T("john.doe@example.com (John Doe)"), mail, &name);
172 EXPECT_STREQ(_T("john.doe@example.com"), mail);
173 EXPECT_STREQ(_T("John Doe"), name);
175 mail.Empty();
176 name.Empty();
177 CStringUtils::ParseEmailAddress(_T("John (zzz) Doe <john.doe@example.com> (Comment)"), mail, &name);
178 EXPECT_STREQ(_T("john.doe@example.com"), mail);
179 EXPECT_STREQ(_T("John (zzz) Doe (Comment)"), name);