diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-06-26 01:56:07 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-06-27 00:10:53 +0200 |
| commit | 113f1062f131577cb169fe1516d49d1f79fa16cf (patch) | |
| tree | b43a85bc04833f2ac9cca24e30765f040785049e /test/test.h | |
| parent | c72e832423ceb81f30e8ca19bfeb87fca26298c1 (diff) | |
Move Editor class from verify_test.cc to test.cc
Diffstat (limited to 'test/test.h')
| -rw-r--r-- | test/test.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/test.h b/test/test.h index 82e6afd5..bacb9311 100644 --- a/test/test.h +++ b/test/test.h @@ -26,6 +26,7 @@ #include "reel_asset.h" #include <boost/filesystem.hpp> #include <boost/optional.hpp> +#include <boost/test/unit_test.hpp> namespace xmlpp { class Element; @@ -85,3 +86,48 @@ public: RNGFixer (); ~RNGFixer (); }; + + +/** Class that can alter a file by searching and replacing strings within it. + * On destruction modifies the file whose name was given to the constructor. + */ +class Editor +{ +public: + Editor(boost::filesystem::path path); + ~Editor(); + + class ChangeChecker + { + public: + ChangeChecker(Editor* editor) + : _editor(editor) + { + _old_content = _editor->_content; + } + + ~ChangeChecker() + { + BOOST_REQUIRE(_old_content != _editor->_content); + } + private: + Editor* _editor; + std::string _old_content; + }; + + void replace(std::string a, std::string b); + void delete_first_line_containing(std::string s); + void delete_lines(std::string from, std::string to); + void insert(std::string after, std::string line); + void delete_lines_after(std::string after, int lines_to_delete); + +private: + friend class ChangeChecker; + + std::vector<std::string> as_lines() const; + + boost::filesystem::path _path; + std::string _content; +}; + + |
