<commit_before>'use strict'

var assert = require('insist')
var shackles = require('../index.js')
var _ = require('lodash')

describe('shackles', function() {

	it('should be able to set an initial value and retrieve it with .value()', function () {
		var C = shackles({})
		var result = C('test').value()
		assert.equal(result, 'test')
	})

	it('should not break if no host is provided (default to empty object)', function () {
		var C = shackles()
		var result = C('test').value()
		assert.equal(result, 'test')
	})

	it('should have a toString method that returns the string represention of the boxed value', function () {
		var C = shackles({})
		var result = C('test').toString()
		assert.equal(result, 'test')
	})

	it('should chain a string library', function () {
		var stringlib = {
			prepend: function(str, chr, chr2) {
				return (chr || '') + (chr2 || '') + str
			},
			append: function(str, chr, chr2) {
				return str + (chr || '') + (chr2 || '')
			}
		}

		var C = shackles(stringlib)

		var result = C('Hello')
			.prepend('(')
			.append('!', '?')
			.append(')')
			.value()

		assert.equal(result, '(Hello!?)')
	})

	it('should chain lodash', function () {

		var C = shackles(_)

		var result = C([1,2,3])
			.map(function (x) { return x*x })
			.filter(function (x) { return x > 2 })
			.value()

		assert.deepEqual(result, [4, 9])
	})

	it('should override the boxed value with any scalar properties that are called as chained functions', function () {

		var C = shackles({
			num: 10
		})

		var result = C('dummy')
			.num()
			.value()

		assert.equal(result, 10)
	})

	it('should have a chainable spy function that passes the value to a function', function () {

		var C = shackles({})

		var spied = null

		var result = C(10)
			.spy(function(value) {
				spied = value * 2
			})
			.value()

		assert.equal(result, 10)
		assert.equal(spied, 20)
	})

	it('should have a chainable spy function that uses an overrideable logger', function () {
	})
})
<commit_msg>Add spy (fix)<commit_after>'use strict'

var assert = require('insist')
var shackles = require('../index.js')
var _ = require('lodash')

describe('shackles', function() {

	it('should be able to set an initial value and retrieve it with .value()', function () {
		var C = shackles({})
		var result = C('test').value()
		assert.equal(result, 'test')
	})

	it('should not break if no host is provided (default to empty object)', function () {
		var C = shackles()
		var result = C('test').value()
		assert.equal(result, 'test')
	})

	it('should have a toString method that returns the string represention of the boxed value', function () {
		var C = shackles({})
		var result = C('test').toString()
		assert.equal(result, 'test')
	})

	it('should chain a string library', function () {
		var stringlib = {
			prepend: function(str, chr, chr2) {
				return (chr || '') + (chr2 || '') + str
			},
			append: function(str, chr, chr2) {
				return str + (chr || '') + (chr2 || '')
			}
		}

		var C = shackles(stringlib)

		var result = C('Hello')
			.prepend('(')
			.append('!', '?')
			.append(')')
			.value()

		assert.equal(result, '(Hello!?)')
	})

	it('should chain lodash', function () {

		var C = shackles(_)

		var result = C([1,2,3])
			.map(function (x) { return x*x })
			.filter(function (x) { return x > 2 })
			.value()

		assert.deepEqual(result, [4, 9])
	})

	it('should override the boxed value with any scalar properties that are called as chained functions', function () {

		var C = shackles({
			num: 10
		})

		var result = C('dummy')
			.num()
			.value()

		assert.equal(result, 10)
	})

	it('should have a chainable spy function that passes the value to a function', function () {

		var C = shackles({})

		var spied = null

		var result = C(10)
			.spy(function(value) {
				spied = value * 2
			})
			.value()

		assert.equal(result, 10)
		assert.equal(spied, 20)
	})

	it('should have a chainable spy function that uses an overrideable logger', function () {

		var spied = null

		var C = shackles({
			logger: function(value) {
				spied = value * 2
			}
		})

		var result = C(10)
			.spy()
			.value()

		assert.equal(result, 10)
		assert.equal(spied, 20)
	})
})

{'fraction_non_alphanumeric': 0.170050155242417, 'fraction_numerical': 0.01170288989730117, 'mean_word_length': 3.2006018054162486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2167701', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1408, 'n_words': 440}