2013-06-13 14:01:16 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2013 Rainmeter Team
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StringUtil.h"
|
2013-08-11 11:29:07 +00:00
|
|
|
#include "UnitTest.h"
|
2013-06-13 17:23:42 +00:00
|
|
|
|
2013-06-13 14:01:16 +00:00
|
|
|
namespace StringUtil {
|
|
|
|
|
|
|
|
TEST_CLASS(Common_StringUtil_Test)
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TEST_METHOD(TestWiden)
|
|
|
|
{
|
2013-12-23 16:19:19 +00:00
|
|
|
Assert::AreEqual(L"test", Widen("test").c_str());
|
|
|
|
Assert::AreEqual(L"te", Widen("test", 2).c_str());
|
|
|
|
Assert::AreEqual(L"\u0422\u0114st", WidenUTF8("\xd0\xa2\xc4\x94st").c_str());
|
|
|
|
Assert::AreEqual(L"\u0422", WidenUTF8("\xd0\xa2\xc4\x94st", 2).c_str());
|
2013-06-13 14:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestNarrow)
|
|
|
|
{
|
2013-12-23 16:19:19 +00:00
|
|
|
Assert::AreEqual("test", Narrow(L"test").c_str());
|
|
|
|
Assert::AreEqual("te", Narrow(L"test", 2).c_str());
|
|
|
|
Assert::AreEqual("\xd0\xa2\xc4\x94st", NarrowUTF8(L"\u0422\u0114st").c_str());
|
|
|
|
Assert::AreEqual("\xd0\xa2", NarrowUTF8(L"\u0422\u0114st", 1).c_str());
|
2013-06-13 14:01:16 +00:00
|
|
|
}
|
2014-01-04 17:01:21 +00:00
|
|
|
|
|
|
|
TEST_METHOD(TestEscapeRegExp)
|
|
|
|
{
|
|
|
|
std::wstring str = L"\\^$|(test)[{. ing+*?";
|
|
|
|
EscapeRegExp(str);
|
|
|
|
Assert::AreEqual(L"\\\\\\^\\$\\|\\(test\\)\\[\\{\\. ing\\+\\*\\?", str.c_str());
|
|
|
|
}
|
2014-01-04 17:19:10 +00:00
|
|
|
|
2014-01-04 19:47:45 +00:00
|
|
|
TEST_METHOD(TestEncodeUrl)
|
2014-01-04 17:19:10 +00:00
|
|
|
{
|
|
|
|
std::wstring str = L" !*'();:@test&=+$,/?#[ing]";
|
2014-01-04 19:47:45 +00:00
|
|
|
EncodeUrl(str);
|
2014-01-04 17:19:10 +00:00
|
|
|
Assert::AreEqual(L"%20%21%2A%27%28%29%3B%3A%40test%26%3D%2B%24%2C%2F%3F%23%5Bing%5D", str.c_str());
|
|
|
|
}
|
2013-06-13 14:01:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace StringUtil
|