diff --git a/src/syntaxcheck.cpp b/src/syntaxcheck.cpp index 5db13d107..7ee13c6d3 100644 --- a/src/syntaxcheck.cpp +++ b/src/syntaxcheck.cpp @@ -994,17 +994,7 @@ void SyntaxCheck::checkLine(const QString &line, Ranges &newRanges, StackEnviron if(env=="tikztimingtable"){ option="ll"; // is always 2 columns }else{ - for (int k = i + 1; k < tl.length(); k++) { - Token elem = tl.at(k); - if (elem.level < tk.level) - break; - if (elem.level > tk.level) - continue; - if (elem.subtype == Token::colDef) { - option = line.mid(elem.start + 1, elem.length - 2); // strip {} - break; - } - } + option = Parsing::getArg(tl.mid(i+1),Token::colDef); } } if(option.contains("colspec")){ diff --git a/src/tests/syntaxcheck_t.cpp b/src/tests/syntaxcheck_t.cpp index e2acee0c5..601b132fe 100644 --- a/src/tests/syntaxcheck_t.cpp +++ b/src/tests/syntaxcheck_t.cpp @@ -95,71 +95,81 @@ void SyntaxCheckTest::checktabular_data(){ << "\\usepackage{tabu}\\begin{tabu}{lll}\n\\multicolumn{2}{c}{Hallo}\\\\c&d&e&f\\\\\n\\end{tabu}\n" << 1 << 26 << "cols in tabular missing"; + QTest::newRow("tabu2") << "\\usepackage{tabu}\\begin{tabu}to \\linewidth {lll}\n\\multicolumn{2}{c}{Hallo}\\\\c&d&e&f\\\\\n\\end{tabu}\n" << 1 << 26 << "cols in tabular missing"; + QTest::newRow("tabu3") << "\\usepackage{tabu}\\begin{tabu}to \\linewidth {|*{3}{l|}}\n\\multicolumn{2}{c}{Hallo}\\\\c&d&e&f\\\\\n\\end{tabu}\n" << 1 << 26 << "cols in tabular missing"; - if (globalExecuteAllTests) { - QTest::newRow("no error 3 cols") - << "\\begin{tabular}{lll}\n&&\\\\c&d&e&f\\\\\n\\end{tabular}\n" - << 1 << 3 - << "no error"; - - QTest::newRow("no error 3 cols") - << "\\begin{tabular}{lll}\n&&\\\\c&d&e&f\\\\\n\\end{tabular}\n" - << 1 << 2 - << "no error"; - - QTest::newRow("no error 3 cols,multiple lines") - << "\\begin{tabular}{lll}\na&\n&\\\\c&d&e&f\\\\\n\\end{tabular}\n" - << 2 << 1 - << "no error"; - - QTest::newRow("no error 3 cols,multiple lines 1/1") - << "\\begin{tabular}{lll}\na&\n&\\\\c&d&e&f\\\\\n\\end{tabular}\n" - << 2 << 1 - << "no error"; - - QTest::newRow("no error 3 cols,multiple lines") - << "\\begin{tabular}{lll}\na&\n&\\\\c&d&e&f\\\\\n\\end{tabular}\n" - << 2 << 2 - << "no error"; - - QTest::newRow("too little cols, 3 cols,multiple lines 1") - << "\\begin{tabular}{lll}\na&\n\\\\c&d&e&f\\\\\n\\end{tabular}\n" - << 2 << 1 - << "cols in tabular missing"; - - QTest::newRow("too many cols, 3 cols,multiple lines 2") - << "\\begin{tabular}{lll}\na&\n&&a\\\\c&d&e&f\\\\\n\\end{tabular}\n" - << 2 << 3 - << "more cols in tabular than specified"; - - QTest::newRow("too many cols, 3 cols,multiple lines 3") - << "\\begin{tabular}{lll}\na&\n&&\na\\\\c&d&e&f\\\\\n\\end{tabular}\n" - << 2 << 2 - << "more cols in tabular than specified"; - - QTest::newRow("too many cols, 3 cols,multiple lines 4") - << "\\begin{tabular}{lll}\na&&\\multicolumn{2}{c}{test}\na\\\\c&d&e&f\\\\\n\\end{tabular}\n" - << 1 << 4 - << "more cols in tabular than specified"; - - QTest::newRow("too many cols, 3 cols,multiple lines 5") - << "\\begin{tabular}{lll}\na\\multicolumn{4}{c}{test}\na\\\\c&d&e&f\\\\\n\\end{tabular}\n" - << 1 << 4 - << "more cols in tabular than specified"; - - QTest::newRow("hline") - << "\\begin{tabular}{ll}\na&b\\\\\\hline\nc&d\\\\\ne&f\\\\\n\\end{tabular}\n" - << 1 << 4 - << "no error"; - } else qDebug("skipped some tests"); + QTest::newRow("multiline preamble") + << "\\begin{tabular}{\nll\n}\na&b&b2\\\\c&d\\\\\ne&f\\\\\n\\end{tabular}\n" + << 3 << 11 + << "no error"; + + QTest::newRow("multiline preamble, error") + << "\\begin{tabular}{\nl\n}\na&b&b2\\\\c&d\\\\\ne&f\\\\\n\\end{tabular}\n" + << 3 << 1 + << "more cols in tabular than specified"; + + QTest::newRow("no error 3 cols") + << "\\begin{tabular}{lll}\n&&\\\\c&d&e&f\\\\\n\\end{tabular}\n" + << 1 << 3 + << "no error"; + + QTest::newRow("no error 3 cols") + << "\\begin{tabular}{lll}\n&&\\\\c&d&e&f\\\\\n\\end{tabular}\n" + << 1 << 2 + << "no error"; + + QTest::newRow("no error 3 cols,multiple lines") + << "\\begin{tabular}{lll}\na&\n&\\\\c&d&e&f\\\\\n\\end{tabular}\n" + << 2 << 1 + << "no error"; + + QTest::newRow("no error 3 cols,multiple lines 1/1") + << "\\begin{tabular}{lll}\na&\n&\\\\c&d&e&f\\\\\n\\end{tabular}\n" + << 2 << 1 + << "no error"; + + QTest::newRow("no error 3 cols,multiple lines") + << "\\begin{tabular}{lll}\na&\n&\\\\c&d&e&f\\\\\n\\end{tabular}\n" + << 2 << 2 + << "no error"; + + QTest::newRow("too little cols, 3 cols,multiple lines 1") + << "\\begin{tabular}{lll}\na&\n\\\\c&d&e&f\\\\\n\\end{tabular}\n" + << 2 << 1 + << "cols in tabular missing"; + + QTest::newRow("too many cols, 3 cols,multiple lines 2") + << "\\begin{tabular}{lll}\na&\n&&a\\\\c&d&e&f\\\\\n\\end{tabular}\n" + << 2 << 3 + << "more cols in tabular than specified"; + + QTest::newRow("too many cols, 3 cols,multiple lines 3") + << "\\begin{tabular}{lll}\na&\n&&\na\\\\c&d&e&f\\\\\n\\end{tabular}\n" + << 2 << 2 + << "more cols in tabular than specified"; + + QTest::newRow("too many cols, 3 cols,multiple lines 4") + << "\\begin{tabular}{lll}\na&&\\multicolumn{2}{c}{test}\na\\\\c&d&e&f\\\\\n\\end{tabular}\n" + << 1 << 4 + << "more cols in tabular than specified"; + + QTest::newRow("too many cols, 3 cols,multiple lines 5") + << "\\begin{tabular}{lll}\na\\multicolumn{4}{c}{test}\na\\\\c&d&e&f\\\\\n\\end{tabular}\n" + << 1 << 4 + << "more cols in tabular than specified"; + + QTest::newRow("hline") + << "\\begin{tabular}{ll}\na&b\\\\\\hline\nc&d\\\\\ne&f\\\\\n\\end{tabular}\n" + << 1 << 4 + << "no error"; } void SyntaxCheckTest::checktabular(){