Code coverage report for multilang-extract-comments/spec/javascript-spec.js

Statements: 100% (26 / 26)      Branches: 100% (0 / 0)      Functions: 100% (8 / 8)      Lines: 100% (26 / 26)      Ignored: none     

All files » multilang-extract-comments/spec/ » javascript-spec.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82                              1 1 1 1   1 3     1 1 1                     1 1                     1 1 1 81 81     1                     1 1 1   1 1     1 1 1 1      
/*!
 * extract-comments <https://github.com/jonschlinkert/extract-comments>
 *
 * Copyright (c) 2014-2015, Jon Schlinkert.
 * Licensed under the MIT License.
 */
 
'use strict'
 
/* global describe */
/* global it */
// /* global xdescribe */
// /* global xit */
 
/* deps:mocha */
require('should')
var context = require('code-context')
var extract = require('../')
var fs = require('fs')
 
function read (fp) {
  return fs.readFileSync(__dirname + '/fixtures/' + fp, 'utf8')
}
 
describe('extract comments from javascript', function () {
  it('should extract comments from a string.', function () {
    extract('/**\n * this is\n *\n * a comment\n*/\nvar foo = "bar";\n').should.eql({
      '1': {
        content: 'this is\n\na comment\n',
        begin: 1,
        end: 5,
        code: 'var foo = "bar";',
        codeStart: 6
      }
    })
  })
 
  it('should work with comments that have slashes.', function () {
    extract('/**\n * this /is/ a/ comment\n*/\nnext line\n').should.eql({
      '1': {
        content: 'this /is/ a/ comment\n',
        begin: 1,
        end: 3,
        code: 'next line',
        codeStart: 4
      }
    })
  })
 
  it('should take a callback to transform comments:', function () {
    var str = read('assemble.js')
    var comments = extract(str, function (comment) {
      comment.context = context(comment.code)
      return comment
    })
 
    comments['1316'].context.should.eql([{
      begin: 1,
      type: 'property',
      receiver: 'module',
      name: 'exports',
      value: 'Assemble',
      string: 'module.exports',
      original: 'module.exports = Assemble;'
    }])
  })
 
  it('should add starting and ending numbers for a comment:', function () {
    var str = read('assemble.js')
    var comments = extract(str)
 
    comments['1274'].begin.should.equal(1274)
    comments['1274'].end.should.equal(1289)
  })
 
  it('should add the `codeStart`, starting line number for code following a comment:', function () {
    var str = read('assemble.js')
    var comments = extract(str)
    comments['1274'].codeStart.should.equal(1291)
  })
})