### Define Example Executable: example Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Configures the 'example' executable, which is a sample application. It links against KTextEditor test libraries. ```cmake add_executable(example src/example.cpp) target_link_libraries(example PRIVATE ${KTEXTEDITOR_TEST_LINK_LIBS}) ``` -------------------------------- ### Build and Install KTextEditor Plugin Source: https://github.com/kde/ktexteditor/blob/master/templates/ktexteditor6-plugin/README.md Compile and install your KTextEditor plugin using CMake. ```bash mkdir build cd build cmake .. -DKDE_INSTALL_PLUGINDIR=$MYKATEPLUGINPATH make make install ``` -------------------------------- ### Install KTextEditor Application Templates Source: https://github.com/kde/ktexteditor/blob/master/templates/CMakeLists.txt Installs the defined application templates to the specified installation directory. This command is part of the KDE build system for managing application templates. ```cmake kde_package_app_templates(TEMPLATES ${apptemplate_DIRS} INSTALL_DIR ${KDE_INSTALL_KAPPTEMPLATESDIR}) ``` -------------------------------- ### Run Kate with Plugin Path Source: https://github.com/kde/ktexteditor/blob/master/templates/ktexteditor6-plugin/README.md Start Kate with the QT_PLUGIN_PATH environment variable set to include your plugin directory. ```bash export QT_PLUGIN_PATH=$MYKATEPLUGINPATH:$QT_PLUGIN_PATH kate --startanon ``` -------------------------------- ### Include Directories Setup Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Sets up include directories for various KTextEditor components, including generated headers and source files. ```cmake include_directories( # for config.h ${CMAKE_BINARY_DIR} # for generated ktexteditor headers ${CMAKE_CURRENT_BINARY_DIR}/include # for normal sources ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include/ktexteditor ${CMAKE_CURRENT_SOURCE_DIR}/buffer ${CMAKE_CURRENT_SOURCE_DIR}/completion ${CMAKE_CURRENT_SOURCE_DIR}/dialogs ${CMAKE_CURRENT_SOURCE_DIR}/document ${CMAKE_CURRENT_SOURCE_DIR}/script ${CMAKE_CURRENT_SOURCE_DIR}/mode ${CMAKE_CURRENT_SOURCE_DIR}/render ${CMAKE_CURRENT_SOURCE_DIR}/search ${CMAKE_CURRENT_SOURCE_DIR}/syntax ${CMAKE_CURRENT_SOURCE_DIR}/undo ${CMAKE_CURRENT_SOURCE_DIR}/utils ${CMAKE_CURRENT_SOURCE_DIR}/inputmode ${CMAKE_CURRENT_SOURCE_DIR}/view ${CMAKE_CURRENT_SOURCE_DIR}/swapfile ${CMAKE_CURRENT_SOURCE_DIR}/variableeditor) ``` -------------------------------- ### Install Script Tester Executable Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Installs the ktexteditor_script_tester executable with default arguments. ```cmake install(TARGETS ktexteditor_script_tester ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) ``` -------------------------------- ### Install Export Header Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Installs the ktexteditor_export.h header file to the appropriate include directory for KTextEditor. ```cmake install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ktexteditor_export.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF}/KTextEditor COMPONENT Devel ) ``` -------------------------------- ### Install KF6TextEditor Targets Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Installs the KF6TextEditor targets, including export definitions, for use by other projects. ```cmake install(TARGETS KF6TextEditor EXPORT KF6TextEditorTargets ${KF_INSTALL_TARGETS_DEFAULT_ARGS}) ``` -------------------------------- ### CMake Setup for KTextEditor Source: https://github.com/kde/ktexteditor/blob/master/README.md Include this in your CMakeLists.txt to find and link against the KF6TextEditor library. ```cmake find_package(KF6TextEditor) ``` -------------------------------- ### Cmd Function Usage Example Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Demonstrates the cmd() function, which executes a command on a document state represented by input and verifies the output against the expected state. Placeholders like '|' and '[...]' represent cursors and selections. ```javascript cmd(moveLinesDown, "[1]\n2\n3\n4\n", "2\n[1]\n3\n4\n"); // equivalent to cmd(moveLinesDown, "[1]|\n2\n3\n4\n", "2\n[1]|\n3\n4\n"); ``` -------------------------------- ### Set Plugin Installation Path Source: https://github.com/kde/ktexteditor/blob/master/templates/ktexteditor6-plugin/README.md Define a custom directory for your KTextEditor plugin installation. ```bash export MYKATEPLUGINPATH=$HOME/mykateplugins ``` -------------------------------- ### Boost MPL Style Type Definition Source: https://github.com/kde/ktexteditor/blob/master/src/script/data/indentation/cppstyle.README.md Example demonstrating the boost::mpl style for type definitions, particularly useful for complex template metaprogramming where leading commas aid in readability and error prevention. ```cpp typedef typename boost::mpl::eval_if< boost::is_same::type> , boost::mpl::int_<-1> , boost::mpl::distance::type, iter> >::type type; ``` -------------------------------- ### Precompiled Header Setup (Conditional) Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Conditionally sets up precompiled headers if ENABLE_PCH is defined. This involves creating empty source and header files and configuring a static library for precompilation. ```cmake if(ENABLE_PCH) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/pch.cpp "/*empty file*/") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/pch.h "#pragma once\n" "#include \n" "#include \n" "#include \n" ) add_library(kte_test_pch STATIC ${CMAKE_CURRENT_BINARY_DIR}/pch.cpp) target_link_libraries(kte_test_pch ${KTEXTEDITOR_TEST_LINK_LIBS} Qt6::Test) target_precompile_headers(kte_test_pch PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/pch.h) endif() ``` -------------------------------- ### Define Application Template Directories Source: https://github.com/kde/ktexteditor/blob/master/templates/CMakeLists.txt Specifies the directories containing KTextEditor application templates. This is used to organize and install plugin templates. ```cmake set(apptemplate_DIRS ktexteditor6-plugin ) ``` -------------------------------- ### SPDX License Identifier in C++ Header Source: https://github.com/kde/ktexteditor/blob/master/README.md Example of how to include the SPDX license identifier and copyright text in C++ source files. ```cpp /* SPDX-FileCopyrightText: 2021 Christoph Cullmann SPDX-License-Identifier: LGPL-2.0-or-later */ ``` -------------------------------- ### C++ Usage of KTextEditor Source: https://github.com/kde/ktexteditor/blob/master/README.md Demonstrates how to initialize the KTextEditor singleton, create a new document, and display it in a widget. ```cpp #include #include #include // get access to the global editor singleton auto editor = KTextEditor::Editor::instance(); // create a new document auto doc = editor->createDocument(this); // create a widget to display the document auto view = doc->createView(yourWidgetParent); ``` -------------------------------- ### String and Array Command Parameters Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Demonstrates how to pass string literals or arrays containing functions/strings as command parameters for execution. ```javascript eq(String, ""); // for String() eq("String()", ""); // equivalent to eval("String()") eq([String, 2e33], "2e+33"); // for String(2e33) eq(["String", 2e33], "2e+33"); // equivalent to eval("String(2e33)") ``` -------------------------------- ### Add Qt Resources Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Compiles Qt resource files for the ktexteditor library. ```cmake qt_add_resources( ktexteditor_qrc_SRCS data/ktexteditor.qrc "${CMAKE_CURRENT_BINARY_DIR}/script/data/script.qrc") ``` -------------------------------- ### Define Benchmark Executable: katemodemanager_benchmark Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Configures the 'katemodemanager_benchmark' executable, marks it as non-GUI, and adds it as a test with BENCHMARK configuration. It links against KTextEditor test libraries and Qt6::Test. ```cmake add_executable(katemodemanager_benchmark src/katemodemanager_test_base.cpp src/katemodemanager_benchmark.cpp) ecm_mark_nongui_executable(katemodemanager_benchmark) add_test(NAME katemodemanager_benchmark COMMAND katemodemanager_benchmark CONFIGURATIONS BENCHMARK) target_link_libraries(katemodemanager_benchmark ${KTEXTEDITOR_TEST_LINK_LIBS} Qt6::Test) ``` -------------------------------- ### Define a Basic Test Case Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Defines a test case with a name and a function containing commands to test. The cmd() function executes a command with input and checks against expected output. ```javascript testCase("moveLinesDown test", () => { // command input expected cmd(moveLinesDown, "[1]\n2\n3\n4\n", "2\n[1]\n3\n4\n"); cmd(moveLinesDown, "2\n[1]\n3\n4\n", "2\n3\n[1]\n4\n"); cmd(moveLinesDown, "2\n3\n[1]\n4\n", "2\n3\n4\n[1]\n"); }); ``` -------------------------------- ### Wrap UI Files with ki18n Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Processes UI files using ki18n for internationalization support. ```cmake ki18n_wrap_ui(ktexteditor_LIB_SRCS dialogs/textareaappearanceconfigwidget.ui dialogs/bordersappearanceconfigwidget.ui dialogs/completionconfigtab.ui dialogs/navigationconfigwidget.ui dialogs/editconfigwidget.ui dialogs/filetypeconfigwidget.ui dialogs/indentationconfigwidget.ui dialogs/opensaveconfigwidget.ui dialogs/opensaveconfigadvwidget.ui dialogs/statusbarconfigwidget.ui search/searchbarincremental.ui search/searchbarpower.ui spellcheck/spellcheckbar.ui dialogs/spellcheckconfigwidget.ui) ``` -------------------------------- ### Command Test with Input and Expected Output Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Use `cmd` for testing commands that involve input and expected output. It allows for detailed assertion configurations, including error checking and specific operators. ```javascript cmd(foo, 'input', 'expected output', { expected: 42, // if specified, the value will be checked op: '===', // is default error: true, // alias of {op: 'hasError', expected: true} error: "...", // alias of {op: 'errorMsg', expected: "..."} error: OtherValue, // alias of {op: 'error', expected: OtherValue} }); ``` -------------------------------- ### Define Benchmark Executable: bench_search Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Defines the 'bench_search' executable, which is a benchmark. It links against KTextEditor test libraries. ```cmake add_executable(bench_search src/benchmarks/bench_search.cpp) target_link_libraries(bench_search PRIVATE ${KTEXTEDITOR_TEST_LINK_LIBS}) ``` -------------------------------- ### Include Directories Configuration Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Configures include directories for various header files, including generated ones and those from different source modules. ```cmake include_directories( # for config.h ${CMAKE_BINARY_DIR} # for generated ktexteditor headers ${CMAKE_BINARY_DIR}/src/include # for normal sources ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/include ${CMAKE_SOURCE_DIR}/src/buffer ${CMAKE_SOURCE_DIR}/src/completion ${CMAKE_SOURCE_DIR}/src/dialogs ${CMAKE_SOURCE_DIR}/src/document ${CMAKE_SOURCE_DIR}/src/script ${CMAKE_SOURCE_DIR}/src/mode ${CMAKE_SOURCE_DIR}/src/render ${CMAKE_SOURCE_DIR}/src/search ${CMAKE_SOURCE_DIR}/src/syntax ${CMAKE_SOURCE_DIR}/src/undo ${CMAKE_SOURCE_DIR}/src/utils ${CMAKE_SOURCE_DIR}/src/view ) ``` -------------------------------- ### Add Executable for Script Tester Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Defines the ktexteditor_script_tester executable, specifying its source files and linking Qt6::Qml and KF6TextEditor. ```cmake add_executable(ktexteditor_script_tester scripttester/ktexteditorscripttester.cpp scripttester/scripttester.cpp scripttester/ktexteditorscripttester.qrc ) target_link_libraries(ktexteditor_script_tester Qt6::Qml KF6TextEditor ) ``` -------------------------------- ### Lazy Function Evaluation with fn and lazyfn Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Shows how to defer the execution of function calls as parameters using fn() or lazyfn(). ```javascript function getSep() { return "|"; } eq([obj.join, fn(getSep)], "1|2|3"); // obj.join("|") ; display: myArray.join(getSep()) ``` -------------------------------- ### Optional Libraries Configuration Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Configures optional libraries, specifically checking for EditorConfig and adding its libraries and include directories if found. ```cmake set(KTEXTEDITOR_OPTIONAL_LIBS) if(EditorConfig_FOUND) SET (CMAKE_REQUIRED_LIBRARIES ${EditorConfig_LIBRARIES}) set (KTEXTEDITOR_OPTIONAL_LIBS ${KTEXTEDITOR_OPTIONAL_LIBS} ${EditorConfig_LIBRARIES}) include_directories(${EditorConfig_INCLUDE_DIRS}) endif() ``` -------------------------------- ### Define KTextEditor Test Link Libraries Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Sets the list of libraries to be linked for KTextEditor tests, including KF6 modules and Qt6 Test. ```cmake set (KTEXTEDITOR_TEST_LINK_LIBS KF6TextEditor KF6::I18n KF6::GuiAddons KF6::SyntaxHighlighting KF6::Codecs KF6::Completion Qt6::Qml ) ``` -------------------------------- ### Add Compiler Definitions Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Adds preprocessor definitions for the compiler, specifying paths for test data, JavaScript data, and script tester data. ```cmake add_definitions(-DTEST_DATA_DIR="${CMAKE_SOURCE_DIR}/autotests/input/") add_definitions(-DJS_DATA_DIR="${CMAKE_SOURCE_DIR}/src/script/data/") add_definitions(-DJS_SCRIPTTESTER_DATA_DIR="${CMAKE_SOURCE_DIR}/src/scripttester/") ``` -------------------------------- ### Add Executable for KAuth Helper Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Defines the kauth_ktexteditor_helper executable and links it with KF6::AuthCore if HAVE_KAUTH is enabled. ```cmake if(HAVE_KAUTH) add_executable(kauth_ktexteditor_helper buffer/katesecuretextbuffer.cpp) target_link_libraries(kauth_ktexteditor_helper KF6::AuthCore) install(TARGETS kauth_ktexteditor_helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR} ) kauth_install_helper_files(kauth_ktexteditor_helper org.kde.ktexteditor6.katetextbuffer root) kauth_install_actions(org.kde.ktexteditor6.katetextbuffer buffer/org.kde.ktexteditor6.katetextbuffer.actions) endif() ``` -------------------------------- ### C++ Code Formatting with Leading Commas Source: https://github.com/kde/ktexteditor/blob/master/src/script/data/indentation/cppstyle.README.md Illustrates the application of the boost-style formatting with leading commas for various C++ constructs, including inheritance lists, function parameter lists, and for loops. This style enhances visual clarity for long or complex declarations. ```cpp // Inheritance list formatting struct sample : public base_1 , public base_2 , ... , public base_N { // Parameter list formatting void foo( const std::string& param_1 ///< A string parameter , double param_2 ///< A double parameter , ... , const some_type& param_N ///< An user defined type parameter ) { // for ( auto first = std::begin(param_1) , last = std::end(param_1) ; it != last ; ++it ) { auto val = check_some_condition() ? get_then_value() : get_else_value() ; } } }; ``` -------------------------------- ### Configure and Copy RCC File Source: https://github.com/kde/ktexteditor/blob/master/src/script/data/CMakeLists.txt This command configures the temporary RCC file generated in the previous step and copies it to the final destination. This ensures the resource file is correctly placed for the build process. ```cmake configure_file(${CMAKE_CURRENT_BINARY_DIR}/script-tmp.qrc ${CMAKE_CURRENT_BINARY_DIR}/script.qrc COPYONLY) ``` -------------------------------- ### Find Qt6 Package Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Finds the Qt6 package with the specified version and requires it for the build. Also forces assertions to be enabled. ```cmake find_package(Qt6 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test) add_definitions(-DQT_FORCE_ASSERTS=1) ``` -------------------------------- ### Add Latin-15 Encoding Test with UTF-8 Fallback Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Adds a test case for a Latin-15 encoded file, verifying that UTF-8 fallback mechanisms work correctly. ```cmake KTEXTEDITOR_ENCODING_TEST ("utf-8" "latin15.txt") ``` -------------------------------- ### Configure Precompiled Headers Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Enables and configures precompiled headers for KF6TextEditor if ENABLE_PCH is set, listing common C++ standard library headers. ```cmake if(ENABLE_PCH) target_precompile_headers(KF6TextEditor PRIVATE ) endif() ``` -------------------------------- ### Add Subdirectory for Includes Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Includes the 'include' subdirectory for header file processing. ```cmake add_subdirectory(include) ``` -------------------------------- ### Generate RCC File Content Source: https://github.com/kde/ktexteditor/blob/master/src/script/data/CMakeLists.txt This section constructs the content of a Qt Resource Collection (RCC) file. It iterates through the collected script files, creating an XML structure with file paths and aliases. The generated content is then written to a temporary file. ```cmake set(INDEXFILE "") string(APPEND INDEXFILE "\n") string(APPEND INDEXFILE "\n") string(APPEND INDEXFILE " ") foreach(highlighter ${ALL_FILES}) file(RELATIVE_PATH highlighter_base ${CMAKE_CURRENT_SOURCE_DIR} ${highlighter}) string(APPEND INDEXFILE "${highlighter}\n") endforeach() string(APPEND INDEXFILE "\n") string(APPEND INDEXFILE "\n") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/script-tmp.qrc ${INDEXFILE}) ``` -------------------------------- ### Set Executable Output Path Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Specifies the directory where executable files will be placed after compilation. ```cmake set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) ``` -------------------------------- ### Test Framework Utilities Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Utility functions provided by the TestFramework for formatting and comparison. ```APIDOC ## TestFramework.operators ### Description Provides access to various operators for testing. ``` ```APIDOC ## TestFramework.formatArgs(args, sep) ### Description Formats arguments for display or comparison. ### Method `TestFramework.formatArgs` ### Parameters - **args** (Array) - Required - The arguments to format. - **sep** (string) - Optional - The separator to use between arguments. ``` ```APIDOC ## TestFramework.toComparableString(value) ### Description Converts a value to a comparable string representation. ### Method `TestFramework.toComparableString` ### Parameters - **value** (any) - Required - The value to convert. ``` ```APIDOC ## TestFramework.functionCallToString(fn, args) ### Description Converts a function call into a string representation. ### Method `TestFramework.functionCallToString` ### Parameters - **fn** (Function) - Required - The function. - **args** (Array) - Required - The arguments to the function. ``` ```APIDOC ## TestFramework.addStringCodeFragments(value, codeFragments, ancestors, mustBeStable) ### Description Adds string code fragments to a value, potentially with stability constraints. ### Method `TestFramework.addStringCodeFragments` ### Parameters - **value** (string) - Required - The string value. - **codeFragments** (Array) - Required - The code fragments to add. - **ancestors** (Array) - Optional - Ancestor context. - **mustBeStable** (boolean) - Optional - Whether the fragments must be stable. ``` ```APIDOC ## TestFramework.addStringCodeFragments.registerClassName(name, addString) ### Description Registers a class name for code fragment generation. ### Method `TestFramework.addStringCodeFragments.registerClassName` ### Parameters - **name** (string) - Required - The name of the class. - **addString** (Function) - Required - The function to generate the string representation. ``` ```APIDOC ## TestFramework.addStringCodeFragments.registerClass(type, addString) ### Description Registers a class type for code fragment generation. ### Method `TestFramework.addStringCodeFragments.registerClass` ### Parameters - **type** (Object) - Required - The class type. - **addString** (Function) - Required - The function to generate the string representation. ``` ```APIDOC ## TestFramework.addStringCodeFragments.registerSymbol(symbol, addString) ### Description Registers a symbol for code fragment generation. ### Method `TestFramework.addStringCodeFragments.registerSymbol` ### Parameters - **symbol** (Symbol) - Required - The symbol. - **addString** (Function) - Required - The function to generate the string representation. ``` ```APIDOC ## TestFramework.addStringCodeFragments.register(addString) ### Description Registers a general function for code fragment generation. ### Method `TestFramework.addStringCodeFragments.register` ### Parameters - **addString** (Function) - Required - The function to generate the string representation. ``` -------------------------------- ### Handling 'this' Context with calleeWrapper Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Illustrates how to preserve the 'this' context for methods when used as command parameters by wrapping them with calleeWrapper. ```javascript const obj = [1,2,3]; eq(obj.join, "[1,2,3]"); // error: Value is undefined ``` ```javascript const obj = calleeWrapper("myArray", [1,2,3]); eq(obj.join, "1,2,3"); // obj.join() ; display: myArray.join() eq([obj.join, ", "], "1, 2, 3"); // obj.join(", ") ; display: myArray.join(", ") ``` ```javascript const obj = calleeWrapper("", [1,2,3]); eq(obj.join, "1,2,3"); // display: [1, 2, 3].join() eq([obj.join, ", "], "1, 2, 3"); // display: [1, 2, 3].join(", ") ``` -------------------------------- ### Define a Sequence Test Case Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Uses sequence() to define a test where the output of one command becomes the input for the next. This simplifies testing multi-step operations. ```javascript sequence("moveLinesDown test" // first input , "[1]\n2\n3\n4\n", () => { // command expected then next input cmd(moveLinesDown, "2\n[1]\n3\n4\n"); cmd(moveLinesDown, "2\n3\n[1]\n4\n"); cmd(moveLinesDown, "2\n3\n4\n[1]\n"); }); ``` -------------------------------- ### Declare Logging Category Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Declares a Qt logging category for the ktexteditor library with specified identifiers and descriptions. ```cmake ecm_qt_declare_logging_category(ktexteditor_LIB_SRCS HEADER katedebug.h IDENTIFIER LOG_KTE CATEGORY_NAME kf.texteditor OLD_CATEGORY_NAMES org.kde.ktexteditor DESCRIPTION "ktexteditor lib" EXPORT KTEXTEDITOR ) ``` -------------------------------- ### Add Executable for Encoding Tests Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Defines the main executable for running encoding tests. It links against necessary test libraries and is marked as a test executable. ```cmake add_executable(kateencodingtest src/kateencodingtest.cpp) target_link_libraries(kateencodingtest ${KTEXTEDITOR_TEST_LINK_LIBS}) ecm_mark_as_test(kateencodingtest) ``` -------------------------------- ### Lazy Argument Evaluation with arg and lazyarg Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Demonstrates how to use arg() or lazyarg() for lazy evaluation of arguments within arrays or objects passed to functions. ```javascript function foo(a, b) { return `{${a};${b}}`; } eq([foo, arg([fn(foo, "0", 1), 2]), 3], "{{0;1},2;3}"); // foo([foo("0", 1), 2], 3) ``` -------------------------------- ### Basic Test Function Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Use this function to test a command with a specific operator and expected value. The `test` function is a versatile tool for asserting outcomes. ```javascript function foo() { return 42; } test(foo, '===', 42); ``` -------------------------------- ### KTextEditor Plugin CMake Configuration Source: https://github.com/kde/ktexteditor/blob/master/templates/ktexteditor6-plugin/src/CMakeLists.txt Defines build settings, source files, and dependencies for a KTextEditor plugin. Ensure KF6::TextEditor and KF6::I18n are available. ```cmake add_definitions(-DTRANSLATION_DOMAIN="%{APPNAMELC}") set(%{APPNAMELC}_SRCS %{APPNAMELC}plugin.cpp %{APPNAMELC}view.cpp ) add_library(%{APPNAMELC} MODULE ${%{APPNAMELC}_SRCS}) target_link_libraries(%{APPNAMELC} KF6::TextEditor KF6::I18n ) install(TARGETS %{APPNAMELC} DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf6/ktexteditor) ``` -------------------------------- ### KTextEditor Interface Source Files Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Defines the source files for the KTextEditor library, focusing on text buffer and buffer helper components. ```cmake set(ktexteditor_LIB_SRCS # text buffer & buffer helpers buffer/katetextbuffer.cpp buffer/katetextblock.cpp buffer/katetextline.cpp buffer/katetextcursor.cpp buffer/katetextrange.cpp buffer/katetexthistory.cpp buffer/katetextfolding.cpp ) ``` -------------------------------- ### Add Subdirectory for Scripts Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Includes the script/data subdirectory for build processing. ```cmake add_subdirectory( script/data ) ``` -------------------------------- ### Set Target Properties for KF6TextEditor Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Sets the VERSION and SOVERSION properties for the KF6TextEditor target, along with the EXPORT_NAME. ```cmake set_target_properties(KF6TextEditor PROPERTIES VERSION ${KTEXTEDITOR_VERSION} SOVERSION ${KTEXTEDITOR_SOVERSION} EXPORT_NAME "TextEditor" ) ``` -------------------------------- ### Link Libraries for KF6TextEditor Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Specifies the public and private libraries to link against for the KF6TextEditor target. Includes KF6, Qt6, and optional libraries. ```cmake target_link_libraries(KF6TextEditor PUBLIC KF6::Parts KF6::Completion KF6::SyntaxHighlighting PRIVATE Qt6::Qml Qt6::PrintSupport Qt6::TextToSpeech KF6::I18n KF6::Archive KF6::GuiAddons KF6::ItemViews KF6::SonnetCore KF6::SonnetUi KF6::Codecs KF6::KIOWidgets KF6::ColorScheme ${KTEXTEDITOR_OPTIONAL_LIBS} ) ``` -------------------------------- ### Add UTF-16 Little Endian Test with UTF-8 Fallback Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Adds a test case for a UTF-16 little-endian encoded file, verifying UTF-8 fallback. ```cmake KTEXTEDITOR_ENCODING_TEST ("utf-8" "utf16.txt") ``` -------------------------------- ### Add UTF-32 Big Endian Test with UTF-8 Fallback Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Adds a test case for a UTF-32 big-endian encoded file, ensuring UTF-8 fallback works. ```cmake KTEXTEDITOR_ENCODING_TEST ("utf-8" "utf32be.txt") ``` -------------------------------- ### Set Source File Properties Source: https://github.com/kde/ktexteditor/blob/master/src/CMakeLists.txt Sets the SKIP_UNITY_BUILD_INCLUSION property for compiled resource source files. ```cmake set_source_files_properties(${ktexteditor_qrc_SRCS} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) ``` -------------------------------- ### Registering String Conversion Functions Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md This function is used to customize how different data types are converted to strings for display or comparison with the `eqv` operator. You can register specific functions for classes or symbols. ```javascript TestFramework.addStringCodeFragments ``` -------------------------------- ### Script Loading Functions Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Functions to load JavaScript files into the script execution environment. ```APIDOC ## loadScript(path) ### Description Loads a JavaScript file into the global execution context. ### Method `loadScript` ### Parameters - **path** (string) - Required - The path to the JavaScript file to load. ``` ```APIDOC ## loadModule(path) ### Description Loads a JavaScript file as a module. ### Method `loadModule` ### Parameters - **path** (string) - Required - The path to the JavaScript file to load as a module. ``` -------------------------------- ### Add UTF-32 Little Endian Test with UTF-8 Fallback Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Adds a test case for a UTF-32 little-endian encoded file, checking UTF-8 fallback functionality. ```cmake KTEXTEDITOR_ENCODING_TEST ("utf-8" "utf32.txt") ``` -------------------------------- ### Load KTextEditor Script Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Loads a script integrated into KTextEditor using its internal path. This is typically the first step before using script functions. ```javascript loadScript(":/ktexteditor/script/commands/utils.js"); ``` -------------------------------- ### Add UTF-8 Encoding Test Source: https://github.com/kde/ktexteditor/blob/master/autotests/CMakeLists.txt Adds a test case for a simple UTF-8 encoded file. ```cmake KTEXTEDITOR_ENCODING_TEST ("utf-8" "utf8.txt") ``` -------------------------------- ### Define an Input-Constant Test Case Source: https://github.com/kde/ktexteditor/blob/master/src/scripttester/README.md Uses withInput() for tests where the input remains constant for each cmd() call, unlike sequence() where input changes sequentially. It has an identical interface to sequence(). ```javascript withInput(); ```