]> git.lyx.org Git - features.git/commitdiff
Fixed Advanced F&R issue in matching things at environment borders with ignore-format...
authorTommaso Cucinotta <tommaso@lyx.org>
Fri, 27 May 2011 20:39:58 +0000 (20:39 +0000)
committerTommaso Cucinotta <tommaso@lyx.org>
Fri, 27 May 2011 20:39:58 +0000 (20:39 +0000)
Added accompanying regression tests for displayed math and numbered equations.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38860 a592a061-630c-0410-9148-cb99ea01b6c8

development/autotests/findadv-14-in.txt [new file with mode: 0644]
development/autotests/findadv-15-in.txt [new file with mode: 0644]
src/lyxfind.cpp

diff --git a/development/autotests/findadv-14-in.txt b/development/autotests/findadv-14-in.txt
new file mode 100644 (file)
index 0000000..a5ae4c4
--- /dev/null
@@ -0,0 +1,37 @@
+# Finding displayed maths with ignore-format on&off (might affect #7596)
+#
+Lang it_IT.utf8
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \Axmath-display\[Return]
+KK: x^2 +x^2\C\[Home]
+KK: \Cs
+KK: \CF
+# Uncheck ignore format
+KK: \Az\Ag\Ae
+KK: \Axmath-display\[Return]
+KK: x^2\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 0\n with len: 1' lyx-log.txt
+
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CF
+# Uncheck ignore format
+KK: \Az\Ag\Ae
+KK: \Axmath-display\[Return]
+KK: x^2\[Return]\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 2\n with len: 1' lyx-log.txt
+
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CF
+KK: \Axmath-display\[Return]
+KK: x^2\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 0\n with len: 1' lyx-log.txt
+
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CF
+KK: \Axmath-display\[Return]
+KK: x^2\[Return]\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 2\n with len: 1' lyx-log.txt
diff --git a/development/autotests/findadv-15-in.txt b/development/autotests/findadv-15-in.txt
new file mode 100644 (file)
index 0000000..c615e60
--- /dev/null
@@ -0,0 +1,37 @@
+# Finding numbered maths with ignore-format on&off (might affect #7596)
+#
+Lang it_IT.utf8
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CM\Axmath-number-toggle\[Return]
+KK: x^2 +x^2\C\[Home]
+KK: \Cs
+KK: \CF
+# Uncheck ignore format
+KK: \Az\Ag\Ae
+KK: \CM\Axmath-number-toggle\[Return]
+KK: x^2\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 0\n with len: 1' lyx-log.txt
+
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CF
+# Uncheck ignore format
+KK: \Az\Ag\Ae
+KK: \CM\Axmath-number-toggle\[Return]
+KK: x^2\[Return]\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 2\n with len: 1' lyx-log.txt
+
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CF
+KK: \CM\Axmath-number-toggle\[Return]
+KK: x^2\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 0\n with len: 1' lyx-log.txt
+
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CF
+KK: \CM\Axmath-number-toggle\[Return]
+KK: x^2\[Return]\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 2\n with len: 1' lyx-log.txt
index 1aa228b4a56c83c53634574e052b982d95c4447e..ac3db2d6e34d6675ea773e4fd77aa9ecbe81d2bb 100644 (file)
@@ -769,8 +769,9 @@ static size_t identifyLeading(string const & s)  {
        while (regex_replace(t, t, "\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)\\{", "")
               || regex_replace(t, t, "^\\$", "")
               || regex_replace(t, t, "^\\\\\\[ ", "")
-              || regex_replace(t, t, "^\\\\item ", ""))
-               LYXERR(Debug::FIND, "  after removing leading $, \\[ , \\emph{, \\textbf{, etc.: " << t);
+              || regex_replace(t, t, "^\\\\item ", "")
+              || regex_replace(t, t, "^\\\\begin\\{[a-zA-Z_]*\\} ", ""))
+               LYXERR(Debug::FIND, "  after removing leading $, \\[ , \\emph{, \\textbf{, etc.: '" << t << "'");
        return s.find(t);
 }
 
@@ -789,14 +790,14 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
                // Remove trailing closure of math, macros and environments, so to catch parts of them.
                do {
                        LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'");
-                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) ?\\$\\'", "$1"))
+                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\])\\$\\'", "$1"))
                                        continue;
                        // @todo need to account for open square braces as well ?
-                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) ?\\\\\\]\\'", "$1"))
+                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) \\\\\\]\\'", "$1"))
                                        continue;
-                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) ?\\\\end\\{[a-zA-Z_]*\\}\\'", "$1"))
+                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) \\\\end\\{[a-zA-Z_]*\\}\\'", "$1"))
                                        continue;
-                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) ?\\}\\'", "$1")) {
+                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\])\\}\\'", "$1")) {
                                ++open_braces;
                                continue;
                        }
@@ -820,10 +821,10 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
                        // Insert .* before trailing '\$' ('$' has been escaped by escape_for_regex)
                        regex_replace(par_as_string, par_as_string, "(.*[^\\\\])(\\\\\\$)\\'", "$1(.*?)$2")
                                // Insert .* before trailing '\\\]' ('\]' has been escaped by escape_for_regex)
-                               || regex_replace(par_as_string, par_as_string, "(.*[^\\\\])(\\\\\\\\\\\\\\])\\'", "$1(.*?)$2")
+                               || regex_replace(par_as_string, par_as_string, "(.*[^\\\\])( \\\\\\\\\\\\\\])\\'", "$1(.*?)$2")
                                // Insert .* before trailing '\\end\{...}' ('\end{...}' has been escaped by escape_for_regex)
                                || regex_replace(par_as_string, par_as_string, 
-                                       "(.*[^\\\\])(\\\\\\\\end\\\\\\{[a-zA-Z_]*\\\\\\})\\'", "$1(.*?)$2")
+                                       "(.*[^\\\\])( \\\\\\\\end\\\\\\{[a-zA-Z_]*\\\\\\})\\'", "$1(.*?)$2")
                                // Insert .* before trailing '\}' ('}' has been escaped by escape_for_regex)
                                || regex_replace(par_as_string, par_as_string, "(.*[^\\\\])(\\\\\\})\\'", "$1(.*?)$2")
                ) {
@@ -1096,10 +1097,14 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
                return 0;
        while (cur) {
                LYXERR(Debug::FIND, "findForwardAdv() cur: " << cur);
-               if (match(cur, -1, false)) {
+               int match_len = match(cur, -1, false);
+               LYXERR(Debug::FIND, "match_len: " << match_len);
+               if (match_len) {
                        for (; cur; cur.forwardPos()) {
                                LYXERR(Debug::FIND, "Advancing cur: " << cur);
-                               if (match(cur)) {
+                               int match_len = match(cur);
+                               LYXERR(Debug::FIND, "match_len: " << match_len);
+                               if (match_len) {
                                        // Sometimes in finalize we understand it wasn't a match
                                        // and we need to continue the outest loop
                                        int len = findAdvFinalize(cur, match);