<commit_before>import {EOL} from 'os'
import {EventEmitter} from 'events'

import Promise from 'bluebird'
import _ from 'lodash'
import sinon from 'sinon'

import expect from './Chai'
import {Engine, EngineChain} from '../src'
import {childProcessMock} from './util'

Promise.onPossiblyUnhandledRejection(_.noop)

describe('Engine', () => {
	let cpMock

	function engineInit() {
		const p = new Engine('').init()
		cpMock.uciok()
		return p
	}

	beforeEach(() => {
		cpMock = childProcessMock()
	})

	afterEach(() => {
		cpMock.destroy()
	})

	describe('constructor', () => {
		it('should throw if path is empty', () => {
			expect(() => new Engine()).to.throw
		})
	})

	describe('getBufferUntil')

	describe('write')

	describe('chain', () => {
		it('should return an instance of EngineChain', () => {
			const chain = new Engine('').chain()
			expect(chain).to.be.an.instanceof(EngineChain)
		})
	})

	describe('init', () => {
		it('should reject if "error" is sent', () => {
			const p = new Engine('').init()
			cpMock.emit('error', new Error('test'))
			return expect(p).to.be.rejectedWith('test')
		})

		it('should reject if "close" is sent', () => {
			const p = new Engine('').init()
			cpMock.emit('close', new Error('test'))
			return expect(p).to.be.rejectedWith('test')
		})

		it('should reject if already initialized', async () => {
			let p = new Engine('').init()
			cpMock.uciok()
			p = await p
			return expect(p.init()).to.be.rejected
		})

		it('should send "uci" command to proc.stdin', () => {
			new Engine('').init()
			expect(cpMock.stdin.write).to.have.been.calledWithExactly(`uci${EOL}`)<commit_msg>test stubs<commit_after>import {EOL} from 'os'
import {EventEmitter} from 'events'

import Promise from 'bluebird'
import _ from 'lodash'
import sinon from 'sinon'

import expect from './Chai'
import {Engine, EngineChain} from '../src'
import {childProcessMock} from './util'

Promise.onPossiblyUnhandledRejection(_.noop)

describe('Engine', () => {
	let cpMock

	function engineInit() {
		const p = new Engine('').init()
		cpMock.uciok()
		return p
	}

	beforeEach(() => {
		cpMock = childProcessMock()
	})

	afterEach(() => {
		cpMock.destroy()
	})

	describe('constructor', () => {
		it('should throw if path is empty', () => {
			expect(() => new Engine()).to.throw
		})
	})

	describe('getBufferUntil', () => {})

	describe('write', () => {})

	describe('chain', () => {
		it('should return an instance of EngineChain', () => {
			const chain = new Engine('').chain()
			expect(chain).to.be.an.instanceof(EngineChain)
		})
	})

	describe('init', () => {
		it('should reject if "error" is sent', () => {
			const p = new Engine('').init()
			cpMock.emit('error', new Error('test'))
			return expect(p).to.be.rejectedWith('test')
		})

		it('should reject if "close" is sent', () => {
			const p = new Engine('').init()
			cpMock.emit('close', new Error('test'))
			return expect(p).to.be.rejectedWith('test')
		})

		it('should reject if already initialized', async () => {
			let p = new Engine('').init()
			cpMock.uciok()
			p = await p
			return expect(p.init()).to.be.rejected
		})

		it('should send "uci" command to proc.stdin', () => {
			new Engine('').init()
			expect(cpMock.stdin.write).to.have.been.calledWithExactly(`uci${EOL}`)
{'fraction_non_alphanumeric': 0.19786259541984733, 'fraction_numerical': 0.0, 'mean_word_length': 3.875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '3264103', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1100, 'n_words': 260}