<commit_before>es = require 'event-stream'
fs = require 'fs'
should = require 'should'
mocha = require 'mocha'
gulp = require 'gulp'
gutil = require 'gulp-util'
tmp = require 'tmp'
assert = require 'stream-assert'

delete require.cache[ require.resolve '../' ]

gutil = require 'gulp-util'
markdox = require '../'
defaultFormatter = require('markdox').defaultFormatter

describe "gulp-markdox", ->

	files = []

	before ->
		files.push file = tmp.fileSync prefix: 'markdox'
		fs.writeFileSync file.name, '/** comment0 */'
		files.push file = tmp.fileSync prefix: 'markdox'
		fs.writeFileSync file.name, '/** comment1 */'
	after ->
		while files.length
			files.shift().removeCallback()

	it 'should generate output files with contents of all passed source files', (done) ->
		testedStream = markdox()

		generatedFiles = []
		testedStream.on "data", (newFile) ->
			generatedFiles.push(newFile)

		gulp.src(files.map (file) -> file.name)
			.pipe testedStream
			.pipe assert.end ->
				should.exist generatedFiles[0]
				String(generatedFiles[0].contents).should.match /.*comment0.*/
				should.exist generatedFiles[1]
				String(generatedFiles[1].contents).should.match /.*comment1.*/
				done()

	it 'should call custom compiler passed in options', (done) ->
		compiledCode = []

		testedStream = markdox compiler: (filename, code) ->
			compiledCode.push [ filename, code ]
			code

		gulp.src(files.map (file) -> file.name)
			.pipe testedStream
			.pipe assert.end ->
				should.exist compiledCode[0]
				compiledCode[0].should.be.eql [ files[0].name, '/** comment0 */' ]
				should.exist compiledCode[1]
				compiledCode[1].should.be.eql [ files[1].name, '/** comment1 */' ]
				done()
<commit_msg>tested passing custom formatter to markdox<commit_after>es = require 'event-stream'
fs = require 'fs'
should = require 'should'
mocha = require 'mocha'
gulp = require 'gulp'
gutil = require 'gulp-util'
tmp = require 'tmp'
assert = require 'stream-assert'

delete require.cache[ require.resolve '../' ]

gutil = require 'gulp-util'
markdox = require '../'
defaultFormatter = require('markdox').defaultFormatter

describe "gulp-markdox", ->

	files = []

	before ->
		files.push file = tmp.fileSync prefix: 'markdox'
		fs.writeFileSync file.name, '/** comment0 */'
		files.push file = tmp.fileSync prefix: 'markdox'
		fs.writeFileSync file.name, '/** comment1 */'
	after ->
		while files.length
			files.shift().removeCallback()

	it 'should generate output files with contents of all passed source files', (done) ->
		testedStream = markdox()

		generatedFiles = []
		testedStream.on "data", (newFile) ->
			generatedFiles.push(newFile)

		gulp.src(files.map (file) -> file.name)
			.pipe testedStream
			.pipe assert.end ->
				should.exist generatedFiles[0]
				String(generatedFiles[0].contents).should.match /.*comment0.*/
				should.exist generatedFiles[1]
				String(generatedFiles[1].contents).should.match /.*comment1.*/
				done()

	it 'should call custom compiler passed in options', (done) ->
		compiledCode = []

		testedStream = markdox compiler: (filename, code) ->
			compiledCode.push [ filename, code ]
			code

		gulp.src(files.map (file) -> file.name)
			.pipe testedStream
			.pipe assert.end ->
				should.exist compiledCode[0]
				compiledCode[0].should.be.eql [ files[0].name, '/** comment0 */' ]
				should.exist compiledCode[1]
				compiledCode[1].should.be.eql [ files[1].name, '/** comment1 */' ]
				done()

	it 'should call custom formatter passed in options', (done) ->
		formattedCode = []

		testedStream = markdox formatter: (docfile) ->
			formattedCode.push [
				docfile.filename.replace(/^(\.\.\/)+/, '/'),
				docfile.javadoc[0].description.full
			]
			defaultFormatter docfile

		gulp.src(files.map (file) -> file.name)
			.pipe testedStream
			.pipe assert.end ->
				should.exist formattedCode[0]
				formattedCode[0].should.be.eql [ files[0].name, 'comment0' ]
				should.exist formattedCode[1]
				formattedCode[1].should.be.eql [ files[1].name, 'comment1' ]
				done()

{'fraction_non_alphanumeric': 0.15156794425087108, 'fraction_numerical': 0.01020408163265306, 'mean_word_length': 3.551528878822197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1728027', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1300, 'n_words': 304}