mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Add unit test for InsetListings::getCaption()
The regex in InsetListings::getCaption() does not work with C++11 and std::regex. This can now be checked easily by this new unit test.
This commit is contained in:
parent
ecd268ceba
commit
3b842d5a62
@ -698,12 +698,14 @@ endif
|
||||
|
||||
EXTRA_DIST += \
|
||||
tests/test_ExternalTransforms \
|
||||
tests/test_ListingsCaption \
|
||||
tests/regfiles/ExternalTransforms \
|
||||
tests/regfiles/Length \
|
||||
tests/regfiles/ListingsCaption \
|
||||
tests/test_layout \
|
||||
tests/test_Length
|
||||
|
||||
TESTS = tests/test_ExternalTransforms tests/test_Length
|
||||
TESTS = tests/test_ExternalTransforms tests/test_Length tests/test_ListingsCaption
|
||||
|
||||
alltests: check alltests-recursive
|
||||
|
||||
@ -722,6 +724,7 @@ updatetests:
|
||||
check_PROGRAMS = \
|
||||
check_ExternalTransforms \
|
||||
check_Length \
|
||||
check_ListingsCaption \
|
||||
check_layout
|
||||
|
||||
if INSTALL_MACOSX
|
||||
@ -770,4 +773,12 @@ check_Length_SOURCES = \
|
||||
tests/boost.cpp \
|
||||
tests/dummy_functions.cpp
|
||||
|
||||
check_ListingsCaption_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
check_ListingsCaption_LDADD = support/liblyxsupport.a $(LIBICONV) $(BOOST_LIBS) @LIBS@ $(QT_LIB) $(LIBSHLWAPI)
|
||||
check_ListingsCaption_LDFLAGS = $(QT_LDFLAGS) $(ADD_FRAMEWORKS)
|
||||
check_ListingsCaption_SOURCES = \
|
||||
tests/check_ListingsCaption.cpp \
|
||||
tests/boost.cpp \
|
||||
tests/dummy_functions.cpp
|
||||
|
||||
.PHONY: alltests alltests-recursive updatetests
|
||||
|
@ -400,6 +400,10 @@ docstring InsetListings::getCaption(OutputParams const & runparams) const
|
||||
otexstream os(ods, texrow);
|
||||
ins->getArgs(os, runparams);
|
||||
ins->getArgument(os, runparams);
|
||||
|
||||
// TODO: The code below should be moved to support, and then the test
|
||||
// in ../tests should be moved there as well.
|
||||
|
||||
// the caption may contain \label{} but the listings
|
||||
// package prefer caption={}, label={}
|
||||
docstring cap = ods.str();
|
||||
|
@ -104,3 +104,25 @@ add_test(NAME "check_Length"
|
||||
-P "${TOP_SRC_DIR}/src/support/tests/supporttest.cmake")
|
||||
add_dependencies(lyx_run_tests check_Length)
|
||||
|
||||
include_directories(${TOP_SRC_DIR}/src/tests)
|
||||
set(check_ListingsCaption_SOURCES)
|
||||
foreach(_f tests/check_ListingsCaption.cpp tests/boost.cpp tests/dummy_functions.cpp)
|
||||
list(APPEND check_ListingsCaption_SOURCES ${TOP_SRC_DIR}/src/${_f})
|
||||
endforeach()
|
||||
add_executable(check_ListingsCaption ${check_ListingsCaption_SOURCES})
|
||||
|
||||
target_link_libraries(check_ListingsCaption support
|
||||
${Lyx_Boost_Libraries} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
|
||||
lyx_target_link_libraries(check_ListingsCaption Magic)
|
||||
|
||||
add_dependencies(lyx_run_tests check_ListingsCaption)
|
||||
set_target_properties(check_ListingsCaption PROPERTIES FOLDER "tests/src")
|
||||
target_link_libraries(check_ListingsCaption ${ICONV_LIBRARY})
|
||||
|
||||
add_test(NAME "check_ListingsCaption"
|
||||
COMMAND ${CMAKE_COMMAND} -DCommand=$<TARGET_FILE:check_ListingsCaption>
|
||||
"-DInput=${TOP_SRC_DIR}/src/tests/regfiles/ListingsCaption"
|
||||
"-DOutput=${CMAKE_CURRENT_BINARY_DIR}/ListingsCaption_data"
|
||||
-P "${TOP_SRC_DIR}/src/support/tests/supporttest.cmake")
|
||||
add_dependencies(lyx_run_tests check_ListingsCaption)
|
||||
|
||||
|
48
src/tests/check_ListingsCaption.cpp
Normal file
48
src/tests/check_ListingsCaption.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "../support/debug.h"
|
||||
#include "../support/regex.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace lyx;
|
||||
using namespace std;
|
||||
|
||||
|
||||
// This function is unfortunately copied from ../insets/InsetListing.cpp, so we
|
||||
// should try to make sure to keep the two in sync.
|
||||
string test_ListingsCaption(string const & cap)
|
||||
{
|
||||
// convert from
|
||||
// blah1\label{blah2} blah3
|
||||
// to
|
||||
// blah1 blah3},label={blah2
|
||||
// to form options
|
||||
// caption={blah1 blah3},label={blah2}
|
||||
//
|
||||
// NOTE that } is not allowed in blah2.
|
||||
regex const reg("(.*)\\\\label\\{(.*?)\\}(.*)");
|
||||
string const new_cap("\\1\\3},label={\\2");
|
||||
return regex_replace(cap, reg, new_cap);
|
||||
}
|
||||
|
||||
void test_test_ListingsCaptions()
|
||||
{
|
||||
cout << test_ListingsCaption("\\label{}") << endl;
|
||||
cout << test_ListingsCaption("\\label{blah2}") << endl;
|
||||
cout << test_ListingsCaption("\\label{blah2} blah3") << endl;
|
||||
cout << test_ListingsCaption("\\label{} blah3") << endl;
|
||||
cout << test_ListingsCaption("blah1\\label{}") << endl;
|
||||
cout << test_ListingsCaption("blah1\\label{} blah3") << endl;
|
||||
cout << test_ListingsCaption("blah1\\label{blah2}") << endl;
|
||||
cout << test_ListingsCaption("blah1\\label{blah2} blah3") << endl;
|
||||
}
|
||||
|
||||
|
||||
int main(int, char **)
|
||||
{
|
||||
// Connect lyxerr with cout instead of cerr to catch error output
|
||||
lyx::lyxerr.setStream(cout);
|
||||
test_test_ListingsCaptions();
|
||||
}
|
8
src/tests/regfiles/ListingsCaption
Normal file
8
src/tests/regfiles/ListingsCaption
Normal file
@ -0,0 +1,8 @@
|
||||
},label={
|
||||
},label={blah2
|
||||
blah3},label={blah2
|
||||
blah3},label={
|
||||
blah1},label={
|
||||
blah1 blah3},label={
|
||||
blah1},label={blah2
|
||||
blah1 blah3},label={blah2
|
7
src/tests/test_ListingsCaption
Executable file
7
src/tests/test_ListingsCaption
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
regfile=`cat ${srcdir}/tests/regfiles/ListingsCaption`
|
||||
output=`./check_ListingsCaption`
|
||||
|
||||
test "$regfile" = "$output"
|
||||
exit $?
|
Loading…
Reference in New Issue
Block a user