Warning, file /multimedia/subtitlecomposer/src/tests/richcsstest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2021-2022 Mladen Milinkovic <max@smoothware.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #define private public // TODO: FIXME: compare selectors with final stylesheet
0008 #include "richcsstest.h"
0009 #undef private
0010 
0011 #include "helpers/common.h"
0012 
0013 #include <QDebug>
0014 #include <QTest>
0015 
0016 using namespace SubtitleComposer;
0017 
0018 void
0019 RichCssTest::testParseSelector_data()
0020 {
0021     QTest::addColumn<QString>("selIn");
0022     QTest::addColumn<QString>("selOut");
0023 
0024     QTest::newRow("spaces around")
0025             << "\t tag.class1.class2 "
0026             << "tag.class1.class2";
0027     QTest::newRow("spaces inside")
0028             << "tag\t.class1  \t .class2   .class3 .class4"
0029             << "tag .class1 .class2 .class3 .class4";
0030     QTest::newRow("attribute selector")
0031             << "tag[attr = value]"
0032             << "tag[attr=value]";
0033     QTest::newRow("attribute selector quoted")
0034             << "tag[attr   =   \"value with spaces\"]"
0035             << "tag[attr=\"value with spaces\"]";
0036     QTest::newRow("selector with symbols 1")
0037             << "tag::first-child"
0038             << "tag::first-child";
0039     QTest::newRow("selector with symbols 2")
0040             << "tag::nth-child(2n + 1)"
0041             << "tag::nth-child(2n+1)";
0042     QTest::newRow("child selector")
0043             << "tag1   >   tag2"
0044             << "tag1>tag2";
0045     QTest::newRow("immediate sibling selector")
0046             << "tag1  +  tag2"
0047             << "tag1+tag2";
0048     QTest::newRow("sibling selector")
0049             << "tag1 ~ tag2"
0050             << "tag1~tag2";
0051     QTest::newRow("descendant selector")
0052             << "tag1   tag2"
0053             << "tag1 tag2";
0054     QTest::newRow("unicode escape 1")
0055             << "\\31 23"
0056             << "123";
0057     QTest::newRow("unicode escape 2")
0058             << "\\20AC ab"
0059             << "€ab";
0060     QTest::newRow("unicode escape 3")
0061             << "\\20AC  ab"
0062             << "€ ab";
0063     QTest::newRow("unicode escape 4")
0064             << "\\0020ACab"
0065             << "€ab";
0066     QTest::newRow("unicode escape 5")
0067             << "\\0020acab"
0068             << "€ab";
0069     QTest::newRow("unicode escape 6")
0070             << "\\0020AC  ab"
0071             << "€ ab";
0072     QTest::newRow("unicode escape 7")
0073             << "\\E9motion"
0074             << "émotion";
0075     QTest::newRow("unicode escape 8")
0076             << "\\E9 dition"
0077             << "édition";
0078     QTest::newRow("unicode escape 9")
0079             << "\\0000E9dition"
0080             << "édition";
0081     QTest::newRow("comments+spaces around")
0082             << "   /* comm */ tag.class1.class2  /* comm */  "
0083             << "tag.class1.class2";
0084 }
0085 
0086 void
0087 RichCssTest::testParseSelector()
0088 {
0089     QFETCH(QString, selIn);
0090     QFETCH(QString, selOut);
0091 
0092     const QChar *data = selIn.data();
0093     QCOMPARE(RichCSS::parseCssSelector(&data), selOut);
0094 }
0095 
0096 void
0097 RichCssTest::testParseRules_data()
0098 {
0099     QTest::addColumn<QString>("cssIn");
0100     QTest::addColumn<QString>("cssOut");
0101 
0102     QTest::newRow("no spaces, no semicolon")
0103             << "line-height:0"
0104             << "line-height:0;";
0105     QTest::newRow("spaces around")
0106             << "\t line-height:1px; "
0107             << "line-height:1px;";
0108     QTest::newRow("spaces inside")
0109             << "\t line-height \t : \t 1px \t ; "
0110             << "line-height:1px;";
0111     QTest::newRow("multiple same rules")
0112             << "\t line-height \t : \t 1px \t ; \t line-height \t : \t 3px \t ; "
0113             << "line-height:3px;";
0114     QTest::newRow("attribute selector quoted")
0115             << "\t line-height \t : \t 1px \t ; \t font-weight \t : \t bold \t ; "
0116             << "line-height:1px;font-weight:bold;";
0117     QTest::newRow("apostrophe")
0118             << "background : url ( \t '  something somewhere with \t spaces  ' \t )  "
0119             << "background:url('  something somewhere with \t spaces  ');";
0120     QTest::newRow("quote with unicode")
0121             << "background:url(\"  something som\\E9where with \t spaces \")"
0122             << "background:url(\"  something soméwhere with \t spaces \");";
0123     QTest::newRow("quote with escaped quote")
0124             << "background:url(\"  something som\\\"where with \t spaces \")"
0125             << "background:url(\"  something som\\\"where with \t spaces \");";
0126     QTest::newRow("gradient")
0127             << " background-image : linear-gradient  (  to \t  bottom  ,  dimgray  ,   lightgray  )  ;  "
0128             << "background-image:linear-gradient(to bottom,dimgray,lightgray);";
0129     QTest::newRow("invalid stuff")
0130             << "tag1 tag2"
0131             << "";
0132 }
0133 
0134 void
0135 RichCssTest::testParseRules()
0136 {
0137     QFETCH(QString, cssIn);
0138     QFETCH(QString, cssOut);
0139 
0140     const QChar *data = cssIn.data();
0141     QCOMPARE(RichCSS::parseCssRules(&data).toString(), cssOut);
0142 }
0143 
0144 QTEST_GUILESS_MAIN(RichCssTest)