1
0

concat_test.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use strict';
  2. var grunt = require('grunt');
  3. var comment = require('../tasks/lib/comment').init(grunt);
  4. function getNormalizedFile(filepath) {
  5. return grunt.util.normalizelf(grunt.file.read(filepath));
  6. }
  7. exports.concat = {
  8. default_options: function(test) {
  9. test.expect(1);
  10. var actual = getNormalizedFile('tmp/default_options');
  11. var expected = getNormalizedFile('test/expected/default_options');
  12. test.equal(actual, expected, 'should describe what the default behavior is.');
  13. test.done();
  14. },
  15. custom_options: function(test) {
  16. test.expect(1);
  17. var actual = getNormalizedFile('tmp/custom_options');
  18. var expected = getNormalizedFile('test/expected/custom_options');
  19. test.equal(actual, expected, 'should utilize custom banner, footer and separator.');
  20. test.done();
  21. },
  22. handling_invalid_files: function(test) {
  23. test.expect(1);
  24. var actual = getNormalizedFile('tmp/handling_invalid_files');
  25. var expected = getNormalizedFile('test/expected/handling_invalid_files');
  26. test.equal(actual, expected, 'will have warned, but should not fail.');
  27. test.done();
  28. },
  29. strip_banner: function(test) {
  30. test.expect(7);
  31. var src = getNormalizedFile('test/fixtures/banner.js');
  32. test.equal(comment.stripBanner(src), grunt.util.normalizelf('// Comment\n\n/* Comment */\n'), 'It should strip the top banner.');
  33. test.equal(comment.stripBanner(src, {block: true}), grunt.util.normalizelf('// Comment\n\n/* Comment */\n'), 'It should strip the top banner.');
  34. src = getNormalizedFile('test/fixtures/banner2.js');
  35. test.equal(comment.stripBanner(src), grunt.util.normalizelf('\n/*! SAMPLE\n * BANNER */\n\n// Comment\n\n/* Comment */\n'), 'It should not strip the top banner.');
  36. test.equal(comment.stripBanner(src, {block: true}), grunt.util.normalizelf('// Comment\n\n/* Comment */\n'), 'It should strip the top banner.');
  37. src = getNormalizedFile('test/fixtures/banner3.js');
  38. test.equal(comment.stripBanner(src), grunt.util.normalizelf('\n// This is\n// A sample\n// Banner\n\n// But this is not\n\n/* And neither\n * is this\n */\n'), 'It should not strip the top banner.');
  39. test.equal(comment.stripBanner(src, {block: true}), grunt.util.normalizelf('\n// This is\n// A sample\n// Banner\n\n// But this is not\n\n/* And neither\n * is this\n */\n'), 'It should not strip the top banner.');
  40. test.equal(comment.stripBanner(src, {line: true}), grunt.util.normalizelf('// But this is not\n\n/* And neither\n * is this\n */\n'), 'It should strip the top banner.');
  41. test.done();
  42. },
  43. process_function: function(test) {
  44. test.expect(1);
  45. var actual = getNormalizedFile('tmp/process_function');
  46. var expected = getNormalizedFile('test/expected/process_function');
  47. test.equal(actual, expected, 'should have processed file content.');
  48. test.done();
  49. }
  50. };