tst_cstlcompilerif.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "tst_cstlcompilerif.h"
  2. #include <cwf/cstlcompiler.h>
  3. #include <cwf/variant.h>
  4. void TST_CSTLCompilerIf::test()
  5. {
  6. {
  7. CWF::Variant var(1);
  8. QMap<QString, QObject *> objects({{"var", &var}});
  9. QByteArray r = CWF::CSTLCompiler(buildHtml(), QDir().currentPath(), objects, false).output();
  10. QVERIFY2(r.contains("One"), "Should contains 'One'");
  11. QVERIFY2(r.contains("Greater than Zero"), "Should contains 'Greater than Zero'");
  12. QVERIFY2(r.contains("Less Two"), "Should contains 'Less Two'");
  13. QVERIFY2(r.contains("Less equal Two"), "Should contains 'Less equal Two'");
  14. QVERIFY2(r.contains("Greater equal One"), "Should contains 'Greater equal One'");
  15. QVERIFY2(!r.contains("Test"), "Should not contains 'Test'");
  16. }
  17. }
  18. QByteArray TST_CSTLCompilerIf::buildHtml()
  19. {
  20. QByteArray html;
  21. html = "<html>";
  22. html += "<body>";
  23. html += "<if var=\"#{var.toInt}\" equal=\"2\">";
  24. html += "Test";
  25. html += "</if>";
  26. html += "<if var=\"#{var.toInt}\" equal=\"1\">";
  27. html += "One";
  28. html += "<if var=\"#{var.toInt}\" greater=\"0\">";
  29. html += "Greater than Zero";
  30. html += "</if>";
  31. html += "</if>";
  32. html += "<if var=\"#{var.toInt}\" less=\"2\">";
  33. html += "<if var=\"#{var.toInt}\" less_equal=\"2\">";
  34. html += "<if var=\"#{var.toInt}\" greater_equal=\"1\">";
  35. html += "Greater equal One";
  36. html += "</if>";
  37. html += "Less equal Two";
  38. html += "</if>";
  39. html += "Less Two";
  40. html += "</if>";
  41. html += "</body>";
  42. html += "</html>";
  43. return html;
  44. }