Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

render_test.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. var fs = require("fs");
  2. var path = require("path");
  3. var assert = require("assert");
  4. var vows = require("vows");
  5. var Mustache = require("./../mustache");
  6. var _files = path.join(__dirname, "_files");
  7. function getContents(testName, ext) {
  8. return fs.readFileSync(path.join(_files, testName + "." + ext), "utf8");
  9. }
  10. // You can put the name of a specific test to run in the TEST environment
  11. // variable (e.g. TEST=backslashes vows test/render_test.js)
  12. var testToRun = process.env["TEST"];
  13. var testNames;
  14. if (testToRun) {
  15. testNames = [testToRun];
  16. } else {
  17. testNames = fs.readdirSync(_files).filter(function (file) {
  18. return (/\.js$/).test(file);
  19. }).map(function (file) {
  20. return path.basename(file).replace(/\.js$/, "");
  21. });
  22. }
  23. var spec = {};
  24. testNames.forEach(function (testName) {
  25. var view = getContents(testName, "js");
  26. if (view) {
  27. view = eval(view);
  28. } else {
  29. console.log("Cannot find view for test: " + testName);
  30. process.exit();
  31. }
  32. var template = getContents(testName, "mustache");
  33. var expect = getContents(testName, "txt");
  34. var partial;
  35. try {
  36. partial = getContents(testName, "partial");
  37. } catch (e) {
  38. // No big deal.
  39. }
  40. spec["knows how to render " + testName] = function () {
  41. Mustache.clearCache();
  42. var output;
  43. if (partial) {
  44. output = Mustache.render(template, view, {partial: partial});
  45. } else {
  46. output = Mustache.render(template, view);
  47. }
  48. assert.equal(output, expect);
  49. };
  50. });
  51. vows.describe("Mustache.render").addBatch({
  52. "render": spec
  53. }).export(module);