redeyed-comments.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 'use strict';
  2. /*jshint asi: true*/
  3. var test = require('tap').test
  4. , util = require('util')
  5. , redeyed = require('..')
  6. function inspect (obj) {
  7. return util.inspect(obj, false, 5, true)
  8. }
  9. test('adding custom asserts ... ', function (t) {
  10. t.constructor.prototype.assertSurrounds = function (code, opts, expected) {
  11. var result = redeyed(code, opts)
  12. this.equals(result.code, expected, inspect(code) + ' => ' + inspect(expected))
  13. return this;
  14. }
  15. t.end()
  16. })
  17. test('\nstring config, Line comments', function (t) {
  18. var opts = { Line: { _default: '*:&' } };
  19. t.test('\n# ' + inspect(opts), function (t) {
  20. t.assertSurrounds(
  21. '// a comment'
  22. , opts
  23. , '*// a comment&'
  24. )
  25. t.assertSurrounds(
  26. '// comment then new line\nif (a == 1) return'
  27. , opts
  28. , '*// comment then new line&\nif (a == 1) return'
  29. )
  30. t.assertSurrounds(
  31. 'var n = new Test();// some comment after\n//more comment\nvar s = 3;'
  32. , opts
  33. , 'var n = new Test();*// some comment after&\n*//more comment&\nvar s = 3;'
  34. )
  35. t.end()
  36. })
  37. })
  38. test('\nstring config, Block comments', function (t) {
  39. var opts = { Block: { _default: '_:-' } };
  40. t.test('\n# ' + inspect(opts), function (t) {
  41. t.assertSurrounds(
  42. '/* a comment */'
  43. , opts
  44. , '_/* a comment */-'
  45. )
  46. t.assertSurrounds(
  47. '/* comment then new line*/\nif (a == 1) /* inline */ return'
  48. , opts
  49. , '_/* comment then new line*/-\nif (a == 1) _/* inline */- return'
  50. )
  51. t.assertSurrounds(
  52. 'var n = new Test();/* some comment after*/\n/*more comment*/\nvar s = 3;'
  53. , opts
  54. , 'var n = new Test();_/* some comment after*/-\n_/*more comment*/-\nvar s = 3;'
  55. )
  56. t.assertSurrounds(
  57. 'var a = 4;\n/* Multi line comment\n * Next line\n * and another\n*/ var morecode = "here";'
  58. , opts
  59. , 'var a = 4;\n_/* Multi line comment\n * Next line\n * and another\n*/- var morecode = "here";'
  60. )
  61. t.end()
  62. })
  63. })