~ubuntu-branches/ubuntu/trusty/grantlee/trusty

« back to all changes in this revision

Viewing changes to templates/tests/testdefaulttags.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2012-11-21 11:04:39 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20121121110439-tzyjomgtnpmdnsxn
Tags: 0.3.0-0ubuntu1
* New upsteam release
  - Update libgrantlee-core0.symbols
* Add wildcards to *.install files to avoid unneeded build failures

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#ifndef DEFAULTTAGSTEST_H
22
22
#define DEFAULTTAGSTEST_H
23
23
 
24
 
#include <QtTest>
25
 
#include <QtCore/QObject>
 
24
#include <QtTest/QTest>
 
25
#include <QtCore/QDebug>
26
26
 
27
27
#include "template.h"
28
28
#include "engine.h"
165
165
    doTest();
166
166
  }
167
167
 
 
168
  void testDebugTag_data();
 
169
  void testDebugTag() {
 
170
    doTest();
 
171
  }
 
172
 
 
173
  void testLoadTag_data();
 
174
  void testLoadTag() {
 
175
    doTest();
 
176
  }
 
177
 
168
178
  void testUrlTypes_data();
169
179
  void testUrlTypes();
170
180
 
222
232
  QCOMPARE( t->error(), NoError );
223
233
 
224
234
  QCOMPARE( result, output );
 
235
 
 
236
  if ( !result.isEmpty() && QString::fromLatin1( QTest::currentTestFunction() ) == QLatin1String( "testMediaFinderTag" ) ) {
 
237
    QVERIFY( !context.externalMedia().isEmpty() );
 
238
  }
225
239
}
226
240
 
227
241
void TestDefaultTags::testCommentTag_data()
240
254
  QTest::newRow( "comment-tag03" ) << QString::fromLatin1( "foo{% comment %} {% if %} {% endcomment %}" ) << dict << QString::fromLatin1( "foo" ) << NoError;
241
255
  QTest::newRow( "comment-tag04" ) << QString::fromLatin1( "foo{% comment %} {% endblock %} {% endcomment %}" ) << dict << QString::fromLatin1( "foo" ) << NoError;
242
256
  QTest::newRow( "comment-tag05" ) << QString::fromLatin1( "foo{% comment %} {% somerandomtag %} {% endcomment %}" ) << dict << QString::fromLatin1( "foo" ) << NoError;
 
257
  QTest::newRow( "comment-tag06" ) << QString::fromLatin1( "{% comment %}yes" ) << dict << QString() << UnclosedBlockTagError;
243
258
}
244
259
 
245
260
void TestDefaultTags::testFirstOfTag_data()
556
571
  QTest::newRow( "if-tag-error03" ) << QString::fromLatin1( "{% if foo or %}yes{% else %}no{% endif %}" ) << dict << QString() << TagSyntaxError;
557
572
  QTest::newRow( "if-tag-error04" ) << QString::fromLatin1( "{% if not foo and %}yes{% else %}no{% endif %}" ) << dict << QString() << TagSyntaxError;
558
573
  QTest::newRow( "if-tag-error05" ) << QString::fromLatin1( "{% if not foo or %}yes{% else %}no{% endif %}" ) << dict << QString() << TagSyntaxError;
 
574
  QTest::newRow( "if-tag-error06" ) << QString::fromLatin1( "{% if %}yes{% else %}no{% endif %}" ) << dict << QString() << TagSyntaxError;
 
575
  QTest::newRow( "if-tag-error07" ) << QString::fromLatin1( "{% if foo %}yes" ) << dict << QString() << UnclosedBlockTagError;
559
576
 
560
577
  // Truthiness
561
578
  dict.clear();
651
668
  list.clear();
652
669
  dict.clear();
653
670
 
 
671
  QTest::newRow( "for-tag07" ) << QString::fromLatin1( "{% for %}{% endfor %}" ) << dict << QString() << TagSyntaxError;
 
672
  QTest::newRow( "for-tag08" ) << QString::fromLatin1( "{% for foo bar bat %}{% endfor %}" ) << dict << QString() << TagSyntaxError;
 
673
  QTest::newRow( "for-tag09" ) << QString::fromLatin1( "{% for foo bar '' %}{% endfor %}" ) << dict << QString() << TagSyntaxError;
 
674
 
654
675
  list << 1 << 2 << 3;
655
676
  dict.insert( QLatin1String( "values" ), list );
656
677
  QTest::newRow( "for-tag-vars01" ) << QString::fromLatin1( "{% for val in values %}{{ forloop.counter }}{% endfor %}" ) << dict << QString::fromLatin1( "123" ) << NoError;
871
892
  dict.clear();
872
893
  dict.insert( QLatin1String( "x" ), 2 );
873
894
 
874
 
  QTest::newRow( "ifequal-numeric07" ) << QString::fromLatin1( "{% ifequal x 2. %}yes{% endifequal %}" ) << dict << QString() << NoError;
 
895
  QTest::newRow( "ifequal-numeric07" ) << QString::fromLatin1( "{% ifequal x 2. %}yes{% endifequal %}" ) << dict << QString() << TagSyntaxError;
875
896
 
876
897
  dict.clear();
877
898
  dict.insert( QLatin1String( "x" ), 5 );
918
939
 
919
940
  QTest::newRow( "ifequal-filter05" ) << "{% ifequal x|slice:\"1\"|upper \"A\" %}x{% endifequal %}" << dict << QString::fromLatin1( "x" ) << NoError;
920
941
 
 
942
  QTest::newRow( "ifequal-error01" ) << "{% ifequal x|slice:\"1\"|upper %}x{% endifequal %}" << dict << QString() << TagSyntaxError;
 
943
 
921
944
}
922
945
 
923
946
void TestDefaultTags::testIfNotEqualTag_data()
1033
1056
  dict.insert( QLatin1String( "one" ), QLatin1String( "A" ) );
1034
1057
  dict.insert( QLatin1String( "two" ), QLatin1String( "2" ) );
1035
1058
  QTest::newRow( "cycle16" ) << QString::fromLatin1( "{% cycle one|lower two as foo %}{% cycle foo %}" ) << dict << QString::fromLatin1( "a2" ) << NoError;
 
1059
 
 
1060
  QTest::newRow( "cycle17" ) << QString::fromLatin1( "{% cycle %}" ) << dict << QString() << TagSyntaxError;
 
1061
  QTest::newRow( "cycle18" ) << QString::fromLatin1( "{% cycle var %}" ) << dict << QString() << TagSyntaxError;
 
1062
 
 
1063
  dict.insert( QLatin1String( "three" ), QLatin1String( "B" ) );
 
1064
  dict.insert( QLatin1String( "four" ), QLatin1String( "4" ) );
 
1065
 
 
1066
  QTest::newRow( "cycle19" ) << QString::fromLatin1( "{% cycle one two three foo %}" ) << dict << QString::fromLatin1( "A" ) << NoError;
 
1067
  QTest::newRow( "cycle20" ) << QString::fromLatin1( "{% cycle one two as foo %}{% cycle three four as bar %}" ) << dict << QString::fromLatin1( "AB" ) << NoError;
1036
1068
}
1037
1069
 
1038
1070
void TestDefaultTags::testWidthRatioTag_data()
1325
1357
  dict.insert( QLatin1String( "numx" ), QVariantList() << 2 << 2 << 2 );
1326
1358
  dict.insert( QLatin1String( "numy" ), QVariantList() << 3 << 3 << 3 );
1327
1359
  QTest::newRow( "ifchanged07" ) << QString::fromLatin1( "{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% for x in numx %}{% ifchanged %}{{ x }}{% endifchanged %}{% for y in numy %}{% ifchanged %}{{ y }}{% endifchanged %}{% endfor %}{% endfor %}{% endfor %}" ) << dict << QString::fromLatin1( "1233323332333" ) << NoError;
 
1360
  QTest::newRow( "ifchanged08" ) << QString::fromLatin1( "{% ifchanged %}{{ num.0 }}{% endifchanged %}" ) << dict << QString::fromLatin1( "1" ) << NoError;
1328
1361
 
1329
1362
  // datalist': [[(1, 'a'), (1, 'a'), (0, 'b'), (1, 'c')], [(0, 'a'), (1, 'c'), (1, 'd'), (1, 'd'), (0, 'e')]]}
1330
1363
  dict.clear();
1454
1487
  dict.clear();
1455
1488
  dict.insert( QLatin1String( "var" ), QVariant() );
1456
1489
  QTest::newRow( "autoescape-tag08" ) << "{% autoescape on %}{{ var|default_if_none:\"endquote\\\" hah\" }}{% endautoescape %}" << dict << "endquote\" hah" << NoError;
 
1490
 
 
1491
  QTest::newRow( "autoescape-tag09" ) << "{% autoescape on extra %}{{ var|default_if_none:\"endquote\\\" hah\" }}{% endautoescape %}" << dict << "" << TagSyntaxError;
 
1492
  QTest::newRow( "autoescape-tag10" ) << "{% autoescape bad %}{{ var|default_if_none:\"endquote\\\" hah\" }}{% endautoescape %}" << dict << "" << TagSyntaxError;
 
1493
 
1457
1494
  // Objects which return safe strings as their __unicode__ method
1458
1495
  // won't get double-escaped.
1459
1496
//   'autoescape-tag09': (r'{{ unsafe }}', {'unsafe': filters.UnsafeClass()}, 'you &amp; me'),
1464
1501
  dict.clear();
1465
1502
  dict.insert( QLatin1String( "first" ), QLatin1String( "<a>" ) );
1466
1503
  QTest::newRow( "autoescape-filtertag01" ) << QString::fromLatin1( "{{ first }}{% filter safe %}{{ first }} x<y{% endfilter %}" ) << dict << QString() << TagSyntaxError;
 
1504
  QTest::newRow( "autoescape-filtertag02" ) << QString::fromLatin1( "{{ first }}{% filter escape %}{{ first }} x<y{% endfilter %}" ) << dict << QString() << TagSyntaxError;
1467
1505
}
1468
1506
 
1469
1507
 
1520
1558
  QTest::newRow( "range-tag04" ) << QString::fromLatin1( "{% range values.0 values.1 values.2 as i %}{{ i }};{% endrange %}" ) << dict << QString::fromLatin1( "10;12;14;" ) << NoError;
1521
1559
 
1522
1560
  QTest::newRow( "range-tag05" ) << QString::fromLatin1( "{% range 5 %}Foo;{% endrange %}" ) << dict << QString::fromLatin1( "Foo;Foo;Foo;Foo;Foo;" ) << NoError;
 
1561
  QTest::newRow( "range-tag06" ) << QString::fromLatin1( "{% range 5 6 %}Foo;{% endrange %}" ) << dict << QString() << TagSyntaxError;
 
1562
  QTest::newRow( "range-tag07" ) << QString::fromLatin1( "{% range 5 6 7 %}Foo;{% endrange %}" ) << dict << QString() << TagSyntaxError;
 
1563
}
 
1564
 
 
1565
void TestDefaultTags::testDebugTag_data()
 
1566
{
 
1567
 
 
1568
  QTest::addColumn<QString>( "input" );
 
1569
  QTest::addColumn<Dict>( "dict" );
 
1570
  QTest::addColumn<QString>( "output" );
 
1571
  QTest::addColumn<Grantlee::Error>( "error" );
 
1572
 
 
1573
  Dict dict;
 
1574
 
 
1575
  QTest::newRow( "debug-tag01" ) << QString::fromLatin1( "{% debug %}" ) << dict << QString::fromLatin1( "\n\nContext:\nEnd context:\n\n" ) << NoError;
 
1576
  dict.insert( QLatin1String( "answer" ), 42 );
 
1577
  QTest::newRow( "debug-tag02" ) << QString::fromLatin1( "{% debug %}" ) << dict << QString::fromLatin1( "\n\nContext:\nkey answer, type int\nEnd context:\n\n" ) << NoError;
 
1578
}
 
1579
 
 
1580
void TestDefaultTags::testLoadTag_data()
 
1581
{
 
1582
 
 
1583
  QTest::addColumn<QString>( "input" );
 
1584
  QTest::addColumn<Dict>( "dict" );
 
1585
  QTest::addColumn<QString>( "output" );
 
1586
  QTest::addColumn<Grantlee::Error>( "error" );
 
1587
 
 
1588
  Dict dict;
 
1589
 
 
1590
  QTest::newRow( "load-tag01" ) << QString::fromLatin1( "{% load does_not_exist %}foo" ) << dict << QString() << TagSyntaxError;
1523
1591
}
1524
1592
 
1525
1593
void TestDefaultTags::testUrlTypes_data()