redeyed-result.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict'
  2. var test = require('tape')
  3. var redeyed = require('..')
  4. var esprima = require('esprima')
  5. test('redeyed result does not have esprima ast by default', function(t) {
  6. var code = '// a comment\nvar a = 3;'
  7. var conf = { Keyword: { _default: '_:-' } }
  8. var ast = esprima.parse(code, { tokens: true, comment: true, range: true, loc: true, tolerant: true })
  9. var tokens = ast.tokens
  10. var comments = ast.comments
  11. var result = redeyed(code, conf)
  12. t.equal(typeof result.ast, 'undefined', 'ast')
  13. t.deepEquals(result.tokens, tokens, 'tokens')
  14. t.deepEquals(result.comments, comments, 'comments')
  15. t.notEquals(result.code, undefined, 'code')
  16. t.end()
  17. })
  18. test('redeyed result has esprima ast, tokens, comments and splits and transformed code', function(t) {
  19. var code = '// a comment\nvar a = 3;'
  20. var conf = { Keyword: { _default: '_:-' } }
  21. var ast = esprima.parse(code, { tokens: true, comment: true, range: true, loc: true, tolerant: true })
  22. var tokens = ast.tokens
  23. var comments = ast.comments
  24. var result = redeyed(code, conf, { buildAst: true })
  25. t.deepEquals(result.ast, ast, 'ast')
  26. t.deepEquals(result.tokens, tokens, 'tokens')
  27. t.deepEquals(result.comments, comments, 'comments')
  28. t.notEquals(result.code, undefined, 'code')
  29. t.end()
  30. })
  31. test('redeyed result - { nojoin } has esprima ast, tokens, comments and splits but no transformed code', function(t) {
  32. var code = '// a comment\nvar a = 3;'
  33. var conf = { Keyword: { _default: '_:-' } }
  34. var ast = esprima.parse(code, { tokens: true, comment: true, range: true, loc: true, tolerant: true })
  35. var tokens = ast.tokens
  36. var comments = ast.comments
  37. var result = redeyed(code, conf, { nojoin: true, buildAst: true })
  38. t.deepEquals(result.ast, ast, 'ast')
  39. t.deepEquals(result.tokens, tokens, 'tokens')
  40. t.deepEquals(result.comments, comments, 'comments')
  41. t.equals(result.code, undefined, 'code')
  42. t.end()
  43. })