redeyed-comments.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 'use strict'
  2. var test = require('tape')
  3. var util = require('util')
  4. var redeyed = require('..')
  5. function inspect(obj) {
  6. return util.inspect(obj, false, 5, true)
  7. }
  8. test('adding custom asserts ... ', function(t) {
  9. t.constructor.prototype.assertSurrounds = function(code, opts, expected) {
  10. var result = redeyed(code, opts)
  11. this.equals(result.code, expected, inspect(code) + ' => ' + inspect(expected))
  12. return this
  13. }
  14. t.end()
  15. })
  16. test('\nstring config, Line comments', function(t) {
  17. var opts = { Line: { _default: '*:&' } }
  18. t.test('\n# ' + inspect(opts), function(t) {
  19. t.assertSurrounds(
  20. '// a comment'
  21. , opts
  22. , '*// a comment&'
  23. )
  24. t.assertSurrounds(
  25. '// comment then new line\nif (a == 1) return'
  26. , opts
  27. , '*// comment then new line&\nif (a == 1) return'
  28. )
  29. t.assertSurrounds(
  30. 'var n = new Test();// some comment after\n//more comment\nvar s = 3;'
  31. , opts
  32. , 'var n = new Test();*// some comment after&\n*//more comment&\nvar s = 3;'
  33. )
  34. t.end()
  35. })
  36. t.end()
  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. t.end()
  64. })