<commit_before>`require = require('../Source/cov_require.js')(require)`
expect = require 'expect.js'

describe "Paws' utilities:", ->
   utilities = require "../Source/utilities.coffee"
   it 'should exist', ->
      expect(utilities).to.be.ok()
   
   describe 'chain()', ->
      composed = utilities.chain -> 'whee'
      it 'should always return the `this` value', ->
         object = new Object
         expect(composed.call object).to.be object
   
   describe 'modifier()', ->
      composed = utilities.modifier (foo) -> return 'yep' if foo == 'foo'
      it 'should return the return-value of the body ...', ->
         expect(composed 'foo').to.be 'yep'
      it '... unless the body returns nothing', ->
         object = new Object
         expect(composed object).to.be object
   
   construct = utilities.construct
   describe 'construct()', ->
      describe '(from a constructor)', ->
         Ctor = -> it = construct this
         
         it 'should not error out', ->
            expect(-> new Ctor).to.not.throwException()
            expect(->  Ctor() ).to.not.throwException()
         it 'should return an instance of the constructor', ->
            expect(new Ctor).to.be.a Ctor
            expect( Ctor() ).to.be.a Ctor
      
      describe '(from a subclass)', ->
         class Parent
            constructor: -> @parent_called = yes
         class Child extends Parent
            constructor: -> return it = construct this
         
         it 'should not error out', ->
            expect(-> Child()).to.not.throwException()
         it "should call the superclass's constructor", ->
            expect(Child().parent_called).to.be true
   
      describe '(from another function)', ->
         class Parent
            constructor: -> @parent_called = yes
         class Child extends Parent
            constructor: -> @child_called = yes
         
         func = -> it = construct this, Child
         
         it 'should not error out', ->
            expect(-> new func).to.not.throwException()
            expect(->  func() ).to.not.throwException()
         it 'should *not* call either constructor', ->
            expect(func().child_called ).to.not.be true
            expect(func().parent_called).to.not.be true
         it 'should return an instance of the passed class', ->
            expect(func()).to.be.a Child
   
      
   describe 'parameterizable()', ->
      utilities.parameterizable class Twat
         constructor: -> return this
      
      it 'should create a parameterizable constructor', ->
         constructor = new Twat.with(foo: 'bar')
         expect(constructor).to.be.a 'function'
         expect(constructor()).to.be.a Twat
         expect(constructor()._.foo).to.be 'bar'
      
      it 'should provide parameterizable methods', ->
         twat = new Twat
         expect(twat.with(foo: 'bar')).to.be twat
         expect(twat._.foo).to.be 'bar'
      
      it 'should not leave cruft around on the object', (complete) ->
         twat = new Twat.with({})()
         setTimeout => # *Intentionally* using setTimeout instead of nextTick
            expect(twat._).to.be undefined
            complete()
         , 0
   <commit_msg>(- tests fix) Adding a regression for constructor-forwarding.<commit_after>`require = require('../Source/cov_require.js')(require)`
expect = require 'expect.js'

describe "Paws' utilities:", ->
   utilities = require "../Source/utilities.coffee"
   it 'should exist', ->
      expect(utilities).to.be.ok()
   
   describe 'chain()', ->
      composed = utilities.chain -> 'whee'
      it 'should always return the `this` value', ->
         object = new Object
         expect(composed.call object).to.be object
   
   describe 'modifier()', ->
      composed = utilities.modifier (foo) -> return 'yep' if foo == 'foo'
      it 'should return the return-value of the body ...', ->
         expect(composed 'foo').to.be 'yep'
      it '... unless the body returns nothing', ->
         object = new Object
         expect(composed object).to.be object
   
   construct = utilities.construct
   describe 'construct()', ->
      describe '(from a constructor)', ->
         Ctor = -> it = construct this
         
         it 'should not error out', ->
            expect(-> new Ctor).to.not.throwException()
            expect(->  Ctor() ).to.not.throwException()
         it 'should return an instance of the constructor', ->
            expect(new Ctor).to.be.a Ctor
            expect( Ctor() ).to.be.a Ctor
      
      describe '(from a subclass)', ->
         class Parent
            constructor: -> @parent_called = yes
         class Child extends Parent
            constructor: -> return it = construct this
         
         it 'should not error out', ->
            expect(-> Child()).to.not.throwException()
         it "should call the superclass's constructor", ->
            expect(Child().parent_called).to.be true
   
      describe '(from another function)', ->
         class Parent
            constructor: -> @parent_called = yes
         class Child extends Parent
            constructor: -> @child_called = yes
         
         func = -> it = construct this, Child
         
         it 'should not error out', ->
            expect(-> new func).to.not.throwException()
            expect(->  func() ).to.not.throwException()
         it 'should *not* call either constructor', ->
            expect(func().child_called ).to.not.be true
            expect(func().parent_called).to.not.be true
         it 'should return an instance of the passed class', ->
            expect(func()).to.be.a Child
      
      it 'should not prevent constructor-forwarding /re', ->
         class Ancestor
            constructor: -> @ancestor_called = yes
         class Parent extends Ancestor
            constructor: (forward) ->
               return new Child if forward
               it = construct this
               it.parent_called = yes
               return it
         class Child extends Parent
            constructor: ->
               it = construct this
               it.child_called = yes
               return it
         
         expect(-> new Parent yes).to.not.throwException()
         expect(new Parent yes).to.be.a Child
         expect(new Parent yes).to.be.a Parent
         
         child = new Parent yes
         expect(child.ancestor_called).to.be.ok()
         expect(child.parent_called)  .to.be.ok()
         expect(child.child_called)  .to.be.ok()
   
   
   describe 'parameterizable()', ->
      utilities.parameterizable class Twat
         constructor: -> return this
      
      it 'should create a parameterizable constructor', ->
         constructor = new Twat.with(foo: 'bar')
         expect(constructor).to.be.a 'function'
         expect(constructor()).to.be.a Twat
         expect(constructor()._.foo).to.be 'bar'
      
      it 'should provide parameterizable methods', ->
         twat = new Twat
         expect(twat.with(foo: 'bar')).to.be twat
         expect(twat._.foo).to.be 'bar'
      
      it 'should not leave cruft around on the object', (complete) ->
         twat = new Twat.with({})()
         setTimeout => # *Intentionally* using setTimeout instead of nextTick
            expect(twat._).to.be undefined
            complete()
         , 0
   
{'fraction_non_alphanumeric': 0.12220708446866485, 'fraction_numerical': 0.00027247956403269756, 'mean_word_length': 1.854199066874028, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 82, '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': '2949996', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1942, 'n_words': 573}