From: Takashi Sawanaka Date: Thu, 21 Mar 2019 12:47:38 +0000 (+0900) Subject: editlib: Add unit test project X-Git-Tag: 2.16.4+-jp-10~110^2~60 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=8bb720869d8cf8be9119366f2077f8c5f121f392;p=winmerge-jp%2Fwinmerge-jp.git editlib: Add unit test project --- diff --git a/Externals/crystaledit/editlib/lua.cpp b/Externals/crystaledit/editlib/lua.cpp index 4371a7ae7..39bcd8163 100644 --- a/Externals/crystaledit/editlib/lua.cpp +++ b/Externals/crystaledit/editlib/lua.cpp @@ -199,6 +199,7 @@ out: std::all_of(pszChars + I - nEqualsSignCount, pszChars + I, [](const auto c) { return c == '='; })) { dwCookie &= ~COOKIE_RAWSTRING; + COOKIE_SET_LUA_EQUALS_SIGN_COUNT(dwCookie, 0); bRedefineBlock = true; } continue; @@ -212,6 +213,7 @@ out: std::all_of(pszChars + I - nEqualsSignCount, pszChars + I, [](const auto c) { return c == '='; })) { dwCookie &= ~COOKIE_EXT_COMMENT; + COOKIE_SET_LUA_EQUALS_SIGN_COUNT(dwCookie, 0); bRedefineBlock = true; } continue; diff --git a/Externals/crystaledit/test/stdafx.cpp b/Externals/crystaledit/test/stdafx.cpp new file mode 100644 index 000000000..96da92788 --- /dev/null +++ b/Externals/crystaledit/test/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// test.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/Externals/crystaledit/test/stdafx.h b/Externals/crystaledit/test/stdafx.h new file mode 100644 index 000000000..9864ae788 --- /dev/null +++ b/Externals/crystaledit/test/stdafx.h @@ -0,0 +1,16 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +// Headers for CppUnitTest +#include "CppUnitTest.h" + +// TODO: reference additional headers your program requires here +#include +#include +#define ASSERT(x) diff --git a/Externals/crystaledit/test/targetver.h b/Externals/crystaledit/test/targetver.h new file mode 100644 index 000000000..90e767bfc --- /dev/null +++ b/Externals/crystaledit/test/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/Externals/crystaledit/test/test.vs2017.vcxproj b/Externals/crystaledit/test/test.vs2017.vcxproj new file mode 100644 index 000000000..70cbe045c --- /dev/null +++ b/Externals/crystaledit/test/test.vs2017.vcxproj @@ -0,0 +1,181 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {D358EAE3-AE53-4292-9384-6DB97E8B8D40} + Win32Proj + test + 10.0.17763.0 + NativeUnitTestProject + + + + DynamicLibrary + true + v141 + Unicode + false + + + DynamicLibrary + false + v141 + true + Unicode + false + + + DynamicLibrary + true + v141 + Unicode + false + + + DynamicLibrary + false + v141 + true + Unicode + false + + + + + + + + + + + + + + + + + + + + + true + + + true + + + true + + + true + + + + Use + Level3 + Disabled + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions) + true + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + Disabled + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + true + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + true + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + true + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + + + + + + + + + NotUsing + NotUsing + NotUsing + NotUsing + + + + Create + Create + Create + Create + + + + + + + \ No newline at end of file diff --git a/Externals/crystaledit/test/test.vs2017.vcxproj.filters b/Externals/crystaledit/test/test.vs2017.vcxproj.filters new file mode 100644 index 000000000..5a035a43d --- /dev/null +++ b/Externals/crystaledit/test/test.vs2017.vcxproj.filters @@ -0,0 +1,54 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {9f474218-4f7b-40d9-803e-d13e06cdee69} + + + + + Header Files + + + Header Files + + + Source Files\editlib + + + Source Files\editlib + + + Source Files\editlib + + + + + Source Files + + + Source Files + + + Source Files\editlib + + + Source Files\editlib + + + Source Files\editlib + + + \ No newline at end of file diff --git a/Externals/crystaledit/test/unittest1.cpp b/Externals/crystaledit/test/unittest1.cpp new file mode 100644 index 000000000..386652998 --- /dev/null +++ b/Externals/crystaledit/test/unittest1.cpp @@ -0,0 +1,103 @@ +#include "stdafx.h" +#include "CppUnitTest.h" +#include "../editlib/crystallineparser.h" +#include "../editlib/SyntaxColors.h" + +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace test +{ + TEST_CLASS(UnitTest1) + { + public: + TEST_METHOD(LuaSyntax) + { + std::unique_ptr pblocks(new CrystalLineParser::TEXTBLOCK[256]); + struct TestData { + DWORD dwCookie; + TCHAR *pszChars; + } data[] = { + // 1 2 3 4 5 + // 012345678901234567890123456789012345678901234657890123456 + {0, LR"!(a="\"abc";)!" }, + {0, LR"!(ab='\'abc';)!" }, + {0, _T("return")}, + {0, _T("--comment")}, + {0, _T("return abc(1)")}, + {0, _T("--[[comment]]--[=[]]]=]--[==[]==][[]][=[s]=][==[[[]]]==]a")}, + {0, _T("--[[a")}, + {COOKIE_EXT_COMMENT, _T("]]--[=[") }, + {COOKIE_EXT_COMMENT | (1 << 28), _T("]=]--[==[") }, + {COOKIE_EXT_COMMENT | (2 << 28), _T("]==][[") }, + {COOKIE_RAWSTRING, _T("]][=[") }, + {COOKIE_RAWSTRING | (1 << 28), _T("]=][==[") }, + {COOKIE_RAWSTRING | (2 << 28), _T("]==];") }, + }; + struct Expected { + DWORD dwCookie; + CrystalLineParser::TEXTBLOCK pblocks[10]; + size_t nblocks; + } expected[] = { + { 0, { + {0, COLORINDEX_NORMALTEXT, COLORINDEX_BKGND}, + {1, COLORINDEX_OPERATOR, COLORINDEX_BKGND}, + {2, COLORINDEX_STRING, COLORINDEX_BKGND}, + {9, COLORINDEX_OPERATOR, COLORINDEX_BKGND}, + }, 4}, + { 0, { + {0, COLORINDEX_NORMALTEXT, COLORINDEX_BKGND}, + {2, COLORINDEX_OPERATOR, COLORINDEX_BKGND}, + {3, COLORINDEX_STRING, COLORINDEX_BKGND}, + {10, COLORINDEX_OPERATOR, COLORINDEX_BKGND}, + }, 4}, + { 0, { + {0, COLORINDEX_KEYWORD, COLORINDEX_BKGND}, + }, 1}, + { 0, { + {0, COLORINDEX_COMMENT, COLORINDEX_BKGND}, + }, 1}, + { 0, { + {0, COLORINDEX_KEYWORD, COLORINDEX_BKGND}, + {6, COLORINDEX_OPERATOR, COLORINDEX_BKGND}, + {7, COLORINDEX_FUNCNAME, COLORINDEX_BKGND}, + {10, COLORINDEX_OPERATOR, COLORINDEX_BKGND}, + {11, COLORINDEX_NUMBER, COLORINDEX_BKGND}, + {12, COLORINDEX_OPERATOR, COLORINDEX_BKGND}, + }, 6}, + { 0, { + {0, COLORINDEX_COMMENT, COLORINDEX_BKGND}, + {13, COLORINDEX_COMMENT, COLORINDEX_BKGND}, + {23, COLORINDEX_COMMENT, COLORINDEX_BKGND}, + {33, COLORINDEX_STRING, COLORINDEX_BKGND}, + {37, COLORINDEX_STRING, COLORINDEX_BKGND}, + {44, COLORINDEX_STRING, COLORINDEX_BKGND}, + {56, COLORINDEX_NORMALTEXT, COLORINDEX_BKGND}, + }, 7}, + { COOKIE_EXT_COMMENT, {{0, COLORINDEX_COMMENT, COLORINDEX_BKGND}}, 1 }, + { COOKIE_EXT_COMMENT | (1 << 28), {{0, COLORINDEX_COMMENT, COLORINDEX_BKGND}, {2, COLORINDEX_COMMENT, COLORINDEX_BKGND}}, 2 }, + { COOKIE_EXT_COMMENT | (2 << 28), {{0, COLORINDEX_COMMENT, COLORINDEX_BKGND}, {3, COLORINDEX_COMMENT, COLORINDEX_BKGND}}, 2 }, + { COOKIE_RAWSTRING, {{0, COLORINDEX_COMMENT, COLORINDEX_BKGND}, {4, COLORINDEX_STRING, COLORINDEX_BKGND}}, 2 }, + { COOKIE_RAWSTRING | (1 << 28), {{0, COLORINDEX_STRING, COLORINDEX_BKGND}, {2, COLORINDEX_STRING, COLORINDEX_BKGND}}, 2 }, + { COOKIE_RAWSTRING | (2 << 28), {{0, COLORINDEX_STRING, COLORINDEX_BKGND}, {3, COLORINDEX_STRING, COLORINDEX_BKGND}}, 2 }, + { 0, {{0, COLORINDEX_STRING, COLORINDEX_BKGND}, {4, COLORINDEX_OPERATOR, COLORINDEX_BKGND}}, 2 }, + }; + for (size_t i = 0; i < std::size(expected); ++i) + { + int nActualItems = 0; + std::wstring msg = L"index: " + std::to_wstring(i); + Assert::AreEqual( + static_cast(expected[i].dwCookie), + CrystalLineParser::ParseLineLua(data[i].dwCookie, data[i].pszChars, _tcslen(data[i].pszChars), pblocks.get(), nActualItems), msg.c_str()); + Assert::AreEqual(static_cast(expected[i].nblocks), nActualItems, msg.c_str()); + for (int j = 0; j < nActualItems; ++j) + { + std::wstring msg = L"index: " + std::to_wstring(i) + L"," + std::to_wstring(j); + Assert::AreEqual(expected[i].pblocks[j].m_nCharPos, pblocks[j].m_nCharPos, msg.c_str()); + Assert::AreEqual(expected[i].pblocks[j].m_nColorIndex, pblocks[j].m_nColorIndex, msg.c_str()); + Assert::AreEqual(expected[i].pblocks[j].m_nBgColorIndex, pblocks[j].m_nBgColorIndex, msg.c_str()); + } + } + } + + }; +} \ No newline at end of file