160 lines
4.8KB

  1. 'use strict';
  2. var figlet = require('../lib/node-figlet'),
  3. grunt = require('grunt'),
  4. fs = require('fs'),
  5. path = require('path'),
  6. async = require('async');
  7. /*
  8. ======== A Handy Little Nodeunit Reference ========
  9. https://github.com/caolan/nodeunit
  10. Test methods:
  11. test.expect(numAssertions)
  12. test.done()
  13. Test assertions:
  14. test.ok(value, [message])
  15. test.equal(actual, expected, [message])
  16. test.notEqual(actual, expected, [message])
  17. test.deepEqual(actual, expected, [message])
  18. test.notDeepEqual(actual, expected, [message])
  19. test.strictEqual(actual, expected, [message])
  20. test.notStrictEqual(actual, expected, [message])
  21. test.throws(block, [error], [message])
  22. test.doesNotThrow(block, [error], [message])
  23. test.ifError(value)
  24. */
  25. exports.figlet = {
  26. setUp: function(done) {
  27. // setup here if necessary
  28. done();
  29. },
  30. standard: function(test) {
  31. test.expect(1);
  32. figlet('FIGlet\nFONTS', {
  33. font: 'Standard',
  34. verticalLayout: 'fitted'
  35. }, function(err, actual) {
  36. var expected = grunt.file.read('test/expected/standard');
  37. test.equal(actual, expected, 'Standard font with a vertical layout of "fitted".');
  38. test.done();
  39. });
  40. },
  41. standardSync: function(test) {
  42. test.expect(1);
  43. var expected = grunt.file.read('test/expected/standard');
  44. var actual = figlet.textSync('FIGlet\nFONTS', {font: 'Standard', verticalLayout: 'fitted'});
  45. test.equal(actual, expected, 'Standard font with a vertical layout of "fitted".');
  46. test.done();
  47. },
  48. standardParse: function(test) {
  49. test.expect(1);
  50. var expected = grunt.file.read('test/expected/standard');
  51. var data = fs.readFileSync(path.join(__dirname, '../fonts/Standard.flf'), 'utf8');
  52. var font = figlet.parseFont('StandardParseFontName', data);
  53. var actual = figlet.textSync('FIGlet\nFONTS', {font: 'StandardParseFontName', verticalLayout: 'fitted'});
  54. test.equal(actual, expected, 'Standard font with a vertical layout of "fitted" loaded using parseFont().');
  55. test.done();
  56. },
  57. graffiti: function(test) {
  58. test.expect(1);
  59. figlet.text('ABC.123', {
  60. font: 'Graffiti',
  61. horizontalLayout: 'fitted'
  62. }, function(err, actual) {
  63. var expected = grunt.file.read('test/expected/graffiti');
  64. test.equal(actual, expected, 'Graffiti font with a horizontal layout of "fitted".');
  65. test.done();
  66. });
  67. },
  68. graffitiSync: function(test) {
  69. test.expect(1);
  70. var expected = grunt.file.read('test/expected/graffiti');
  71. var actual = figlet.textSync('ABC.123', {font: 'Graffiti', horizontalLayout: 'fitted'});
  72. test.equal(actual, expected, 'Graffiti font with a horizontal layout of "fitted".');
  73. test.done();
  74. },
  75. dancingFont: function(test) {
  76. test.expect(1);
  77. figlet.text('pizzapie', {
  78. font: 'Dancing Font',
  79. horizontalLayout: 'full'
  80. }, function(err, actual) {
  81. var expected = grunt.file.read('test/expected/dancingFont');
  82. test.equal(actual, expected, 'Dancing Font with a horizontal layout of "full".');
  83. test.done();
  84. });
  85. },
  86. dancingFontSync: function(test) {
  87. test.expect(1);
  88. var expected = grunt.file.read('test/expected/dancingFont');
  89. var actual = figlet.textSync('pizzapie', {font: 'Dancing Font', horizontalLayout: 'full'});
  90. test.equal(actual, expected, 'Dancing Font with a horizontal layout of "full".');
  91. test.done();
  92. },
  93. printDirection: function(test) {
  94. test.expect(1);
  95. figlet.text('pizzapie', {
  96. font: 'Dancing Font',
  97. horizontalLayout: 'full',
  98. printDirection: 1
  99. }, function(err, actual) {
  100. var expected = grunt.file.read('test/expected/dancingFontReverse');
  101. test.equal(actual, expected, 'Dancing Font with a reversed print direction.');
  102. test.done();
  103. });
  104. },
  105. /*
  106. This test ensures that all fonts will load without error
  107. */
  108. loadAll: function(test) {
  109. var errCount = 0;
  110. test.expect(1);
  111. figlet.fonts(function(err, fonts) {
  112. if (err) {
  113. errCount++;
  114. return;
  115. }
  116. async.eachSeries(fonts, function(font, next) {
  117. figlet.text('abc ABC ...', {
  118. font: font
  119. }, function(err, data) {
  120. if (err) {
  121. errCount++;
  122. }
  123. next();
  124. });
  125. }, function(err) {
  126. test.equal(errCount, 0, 'A problem occurred while testing one of the fonts.');
  127. test.done();
  128. });
  129. });
  130. }
  131. };