redeyed-comments.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. t.end()
  38. })
  39. test('\nstring config, Block comments', function (t) {
  40. var opts = { Block: { _default: '_:-' } };
  41. t.test('\n# ' + inspect(opts), function (t) {
  42. t.assertSurrounds(
  43. '/* a comment */'
  44. , opts
  45. , '_/* a comment */-'
  46. )
  47. t.assertSurrounds(
  48. '/* comment then new line*/\nif (a == 1) /* inline */ return'
  49. , opts
  50. , '_/* comment then new line*/-\nif (a == 1) _/* inline */- return'
  51. )
  52. t.assertSurrounds(
  53. 'var n = new Test();/* some comment after*/\n/*more comment*/\nvar s = 3;'
  54. , opts
  55. , 'var n = new Test();_/* some comment after*/-\n_/*more comment*/-\nvar s = 3;'
  56. )
  57. t.assertSurrounds(
  58. 'var a = 4;\n/* Multi line comment\n * Next line\n * and another\n*/ var morecode = "here";'
  59. , opts
  60. , 'var a = 4;\n_/* Multi line comment\n * Next line\n * and another\n*/- var morecode = "here";'
  61. )
  62. t.end()
  63. })
  64. t.end()
  65. })