<commit_before>describe('Mixin', function() {

  var IdMixin = {
    getId: function() {
      return this._riot_id
    }
  }

  /*eslint-disable */

  // generated from babeljs
  // src: http://babeljs.io/repl/#?experimental=false&evaluate=true&loose=false&spec=false&code=class%20FunctMixin%20{%0A%20%20init%28%29%20{%0A%20%20%20%20this.type%20%3D%20%27func%27%0A%20%20}%0A%20%20get%20message%28%29%20{%0A%20%20%20%20return%20%27Initialized%27%3B%0A%20%20}%0A}

  var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

  function inheritsFrom(child, parent) {
    child.prototype = Object.create(parent.prototype)
  }

  var FunctMixin = (function() {
    function FunctMixin() {
      _classCallCheck(this, FunctMixin)
    }

    _createClass(FunctMixin, [{
      key: 'init',
      value: function init() {
        this.type = 'func'
      }
    }, {
      key: 'message',
      get: function get() {
        return 'Initialized';
      }
    }]);

    return FunctMixin
  })();

  function ChildMixin() {}

  inheritsFrom(ChildMixin, FunctMixin)

  /*eslint-enable */

  var OptsMixin = {
    getOpts: function() {
      return this.opts
    },

    setOpts: function(options, update) {
      this.opts = options

      if (!update) {
        this.update()
      }

      return this
    }
  }

  var MixinWithInit = {
    init: function() {
      this.message = 'initialized'
    },
    message: 'not yet'
  }

  var globalMixin = {
    init: function() {
      this.globalAttr = 'initialized'
    },
    getGlobal: function() {
      return 'global'
    }
  }

  var globalMixin2 = {
    init: function() {
      this.globalAttr2 = 'initialized2'
    },
    getGlobal2: function() {
      return 'global2'
    }
  }

  var getterSetterMixin = {
    _value: false
  }

  Object.defineProperty(getterSetterMixin, 'value', {
    get: function() {
      return this._value
    },
    set: function(value) {
      this._value = value
    }
  })

  it('Will register a mixin with getter/setter functions', function() {
    injectHTML('<my-mixin></my-mixin>')
    riot.tag('my-mixin', 'some tag')

    var tag = riot.mount('my-mixin')[0]

    tag.mixin(getterSetterMixin)

    tag.value = true

    expect(true).to.be(tag._value)

    tag.unmount()
  })

  it('Will register a global mixin without name and mount a tag with global mixed-in attributes and methods', function() {
    riot.mixin(globalMixin)
    injectHTML('<my-mixin></my-mixin>')
    riot.tag('my-mixin', 'some tag')

    var tag = riot.mount('my-mixin')[0]

    expect('initialized').to.be(tag.globalAttr)
    expect('global').to.be(tag.getGlobal())
    tag.unmount()
  })

  it('Will register multiple global mixin without name and mount a tag with global mixed-in attributes and methods', function() {
    riot.mixin(globalMixin)
    riot.mixin(globalMixin2)
    injectHTML('<my-mixin></my-mixin>')
    riot.tag('my-mixin', 'some tag')

    var tag = riot.mount('my-mixin')[0]

    expect('initialized').to.be(tag.globalAttr)
    expect('initialized2').to.be(tag.globalAttr2)
    expect('global').to.be(tag.getGlobal())
    expect('global2').to.be(tag.getGlobal2())
    tag.unmount()
  })

  it('Will register a global mixin with name and mount a tag with global mixed-in attributes and methods', function() {
    riot.mixin('global', globalMixin, true)
    injectHTML('<my-mixin></my-mixin>')
    riot.tag('my-mixin', 'some tag')

    var tag = riot.mount('my-mixin')[0]

    expect('initialized').to.be(tag.globalAttr)
    expect('global').to.be(tag.getGlobal())
    tag.unmount()
  })

  it('Will register multiple global mixin with name and mount a tag with global mixed-in attributes and methods', function() {
    riot.mixin('global', globalMixin, true)
    riot.mixin('global2', globalMixin2, true)
    injectHTML('<my-mixin></my-mixin>')
    riot.tag('my-mixin', 'some tag')

    var tag = riot.mount('my-mixin')[0]

    expect('initialized').to.be(tag.globalAttr)
    expect('initialized2').to.be(tag.globalAttr2)
    expect('global').to.be(tag.getGlobal())
    expect('global2').to.be(tag.getGlobal2())
    tag.unmount()
  })

  it('Will mount a tag and provide mixed-in methods', function() {

    injectHTML('<my-mixin></my-mixin>')

    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin(IdMixin)
    })

    var tag = riot.mount('my-mixin')[0]

    expect(tag._riot_id).to.be(tag.getId())
    tag.unmount()
  })

  it('Will mount a tag and provide mixed-in methods from an function constructor instance', function() {
    injectHTML('<my-mixin></my-mixin>')

    function RootMixin() {
      this.getRoot = function() {
        return this.root
      }
    }

    var rootmixin = new RootMixin()

    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin(rootmixin)
    })

    var tag = riot.mount('my-mixin')[0]

    expect(tag.root).to.be(tag.getRoot())
    tag.unmount()
  })

  it('Will mount two tags, each having separate mix-in methods', function() {

    injectHTML([
      '<my-mixin2 id="one"></my-mixin2>',
      '<my-mixin2 id="two"></my-mixin2>'
    ])

    riot.tag('my-mixin2', 'some tag', function(opts) {
      this.mixin(IdMixin)
    })

    var first = riot.mount('#one')[0],
      second = riot.mount('#two')[0]

    expect(first._riot_id).to.be(first.getId())
    expect(second._riot_id).to.be(second.getId())
    expect(first._riot_id).not.to.be(second._riot_id)
    expect(first.getId()).not.to.be(second.getId())
    first.unmount()
    second.unmount()
  })

  it('Will mount a tag with multiple mixins mixed-in', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin(IdMixin, OptsMixin)
    })

    var tag = riot.mount('my-mixin')[0],
      newOpts = {
        'some': 'option',
        'value': Math.random()
      }

    expect(tag._riot_id).to.be(tag.getId())
    expect(tag.opts).to.be(tag.getOpts())
    tag.setOpts(newOpts)
    expect(tag.opts).to.be(tag.getOpts())

    tag.unmount()
  })

  it('Will mount a parent tag with a mixin and a sub-tag wtih a mixin', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin(IdMixin, OptsMixin)
    })

    riot.tag('sub-mixin', 'sub mixin', function(opts) {
      this.mixin(IdMixin)
    })

    var tag = riot.mount('my-mixin')[0]

    expect(tag._riot_id).to.be(tag.getId())
    expect(tag.tags['sub-mixin']).not.to.be('undefined')
    expect(tag.tags['sub-mixin']._riot_id).to.be(tag.tags['sub-mixin'].getId())
    expect(tag.getId()).not.to.be(tag.tags['sub-mixin'].getId())
    tag.unmount()
  })

  it('use and initialize raw functions as mixin', function() {
    injectHTML('<my-mixin></my-mixin>')
    riot.tag('my-mixin', '{ message }', function() {
      this.mixin(FunctMixin)
    })
    var tag = riot.mount('my-mixin')[0]
    expect(tag.root.innerHTML).to.be('Initialized')
    expect(tag.type).to.be('func')
    tag.unmount()
  })

  it('binds this-reference to the tag object', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.tag('my-mixin', 'some tag { getId() }', function(opts) {
      this.mixin(IdMixin)
    })

    var tag = riot.mount('my-mixin')[0]

    expect(tag.root.innerHTML).to.be('some tag ' + tag._riot_id + '')
    tag.unmount()
  })

  it('initializes the mixin', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin(MixinWithInit)
    })

    var tag = riot.mount('my-mixin')[0]

    expect(tag.message).to.be('initialized')
    tag.unmount()
  })

  it('register a mixin to Riot and load mixin to a tag', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.mixin('idMixin', IdMixin) // register mixin
    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin('idMixin') // load mixin
    })

    var tag = riot.mount('my-mixin')[0]

    expect(tag._riot_id).to.be(tag.getId())
    tag.unmount()
  })

  it('register a function mixin to Riot and load mixin to a tag', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.mixin('functMixin', FunctMixin) // register mixin
    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin('functMixin') // load mixin
    })

    var tag = riot.mount('my-mixin')[0]
    expect(tag.type).to.be('func')
    tag.unmount()
  })

  it('register a child function mixin to Riot and load mixin to a tag', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.mixin('childMixin', ChildMixin) // register mixin
    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin('childMixin') // load mixin
    })

    var tag = riot.mount('my-mixin')[0]
    expect(tag.type).to.be('func')
    tag.unmount()
  })
})
<commit_msg>check for getter too<commit_after>describe('Mixin', function() {

  var IdMixin = {
    getId: function() {
      return this._riot_id
    }
  }

  /*eslint-disable */

  // generated from babeljs
  // src: http://babeljs.io/repl/#?experimental=false&evaluate=true&loose=false&spec=false&code=class%20FunctMixin%20{%0A%20%20init%28%29%20{%0A%20%20%20%20this.type%20%3D%20%27func%27%0A%20%20}%0A%20%20get%20message%28%29%20{%0A%20%20%20%20return%20%27Initialized%27%3B%0A%20%20}%0A}

  var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

  function inheritsFrom(child, parent) {
    child.prototype = Object.create(parent.prototype)
  }

  var FunctMixin = (function() {
    function FunctMixin() {
      _classCallCheck(this, FunctMixin)
    }

    _createClass(FunctMixin, [{
      key: 'init',
      value: function init() {
        this.type = 'func'
      }
    }, {
      key: 'message',
      get: function get() {
        return 'Initialized';
      }
    }]);

    return FunctMixin
  })();

  function ChildMixin() {}

  inheritsFrom(ChildMixin, FunctMixin)

  /*eslint-enable */

  var OptsMixin = {
    getOpts: function() {
      return this.opts
    },

    setOpts: function(options, update) {
      this.opts = options

      if (!update) {
        this.update()
      }

      return this
    }
  }

  var MixinWithInit = {
    init: function() {
      this.message = 'initialized'
    },
    message: 'not yet'
  }

  var globalMixin = {
    init: function() {
      this.globalAttr = 'initialized'
    },
    getGlobal: function() {
      return 'global'
    }
  }

  var globalMixin2 = {
    init: function() {
      this.globalAttr2 = 'initialized2'
    },
    getGlobal2: function() {
      return 'global2'
    }
  }

  var getterSetterMixin = {
    _value: false
  }

  Object.defineProperty(getterSetterMixin, 'value', {
    get: function() {
      return this._value
    },
    set: function(value) {
      this._value = value
    }
  })

  it('Will register a mixin with getter/setter functions', function() {
    injectHTML('<my-mixin></my-mixin>')
    riot.tag('my-mixin', 'some tag')

    var tag = riot.mount('my-mixin')[0]

    tag.mixin(getterSetterMixin)

    tag.value = true

    expect(true).to.be(tag._value)
    expect(true).to.be(tag.value)

    tag.unmount()
  })

  it('Will register a global mixin without name and mount a tag with global mixed-in attributes and methods', function() {
    riot.mixin(globalMixin)
    injectHTML('<my-mixin></my-mixin>')
    riot.tag('my-mixin', 'some tag')

    var tag = riot.mount('my-mixin')[0]

    expect('initialized').to.be(tag.globalAttr)
    expect('global').to.be(tag.getGlobal())
    tag.unmount()
  })

  it('Will register multiple global mixin without name and mount a tag with global mixed-in attributes and methods', function() {
    riot.mixin(globalMixin)
    riot.mixin(globalMixin2)
    injectHTML('<my-mixin></my-mixin>')
    riot.tag('my-mixin', 'some tag')

    var tag = riot.mount('my-mixin')[0]

    expect('initialized').to.be(tag.globalAttr)
    expect('initialized2').to.be(tag.globalAttr2)
    expect('global').to.be(tag.getGlobal())
    expect('global2').to.be(tag.getGlobal2())
    tag.unmount()
  })

  it('Will register a global mixin with name and mount a tag with global mixed-in attributes and methods', function() {
    riot.mixin('global', globalMixin, true)
    injectHTML('<my-mixin></my-mixin>')
    riot.tag('my-mixin', 'some tag')

    var tag = riot.mount('my-mixin')[0]

    expect('initialized').to.be(tag.globalAttr)
    expect('global').to.be(tag.getGlobal())
    tag.unmount()
  })

  it('Will register multiple global mixin with name and mount a tag with global mixed-in attributes and methods', function() {
    riot.mixin('global', globalMixin, true)
    riot.mixin('global2', globalMixin2, true)
    injectHTML('<my-mixin></my-mixin>')
    riot.tag('my-mixin', 'some tag')

    var tag = riot.mount('my-mixin')[0]

    expect('initialized').to.be(tag.globalAttr)
    expect('initialized2').to.be(tag.globalAttr2)
    expect('global').to.be(tag.getGlobal())
    expect('global2').to.be(tag.getGlobal2())
    tag.unmount()
  })

  it('Will mount a tag and provide mixed-in methods', function() {

    injectHTML('<my-mixin></my-mixin>')

    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin(IdMixin)
    })

    var tag = riot.mount('my-mixin')[0]

    expect(tag._riot_id).to.be(tag.getId())
    tag.unmount()
  })

  it('Will mount a tag and provide mixed-in methods from an function constructor instance', function() {
    injectHTML('<my-mixin></my-mixin>')

    function RootMixin() {
      this.getRoot = function() {
        return this.root
      }
    }

    var rootmixin = new RootMixin()

    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin(rootmixin)
    })

    var tag = riot.mount('my-mixin')[0]

    expect(tag.root).to.be(tag.getRoot())
    tag.unmount()
  })

  it('Will mount two tags, each having separate mix-in methods', function() {

    injectHTML([
      '<my-mixin2 id="one"></my-mixin2>',
      '<my-mixin2 id="two"></my-mixin2>'
    ])

    riot.tag('my-mixin2', 'some tag', function(opts) {
      this.mixin(IdMixin)
    })

    var first = riot.mount('#one')[0],
      second = riot.mount('#two')[0]

    expect(first._riot_id).to.be(first.getId())
    expect(second._riot_id).to.be(second.getId())
    expect(first._riot_id).not.to.be(second._riot_id)
    expect(first.getId()).not.to.be(second.getId())
    first.unmount()
    second.unmount()
  })

  it('Will mount a tag with multiple mixins mixed-in', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin(IdMixin, OptsMixin)
    })

    var tag = riot.mount('my-mixin')[0],
      newOpts = {
        'some': 'option',
        'value': Math.random()
      }

    expect(tag._riot_id).to.be(tag.getId())
    expect(tag.opts).to.be(tag.getOpts())
    tag.setOpts(newOpts)
    expect(tag.opts).to.be(tag.getOpts())

    tag.unmount()
  })

  it('Will mount a parent tag with a mixin and a sub-tag wtih a mixin', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin(IdMixin, OptsMixin)
    })

    riot.tag('sub-mixin', 'sub mixin', function(opts) {
      this.mixin(IdMixin)
    })

    var tag = riot.mount('my-mixin')[0]

    expect(tag._riot_id).to.be(tag.getId())
    expect(tag.tags['sub-mixin']).not.to.be('undefined')
    expect(tag.tags['sub-mixin']._riot_id).to.be(tag.tags['sub-mixin'].getId())
    expect(tag.getId()).not.to.be(tag.tags['sub-mixin'].getId())
    tag.unmount()
  })

  it('use and initialize raw functions as mixin', function() {
    injectHTML('<my-mixin></my-mixin>')
    riot.tag('my-mixin', '{ message }', function() {
      this.mixin(FunctMixin)
    })
    var tag = riot.mount('my-mixin')[0]
    expect(tag.root.innerHTML).to.be('Initialized')
    expect(tag.type).to.be('func')
    tag.unmount()
  })

  it('binds this-reference to the tag object', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.tag('my-mixin', 'some tag { getId() }', function(opts) {
      this.mixin(IdMixin)
    })

    var tag = riot.mount('my-mixin')[0]

    expect(tag.root.innerHTML).to.be('some tag ' + tag._riot_id + '')
    tag.unmount()
  })

  it('initializes the mixin', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin(MixinWithInit)
    })

    var tag = riot.mount('my-mixin')[0]

    expect(tag.message).to.be('initialized')
    tag.unmount()
  })

  it('register a mixin to Riot and load mixin to a tag', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.mixin('idMixin', IdMixin) // register mixin
    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin('idMixin') // load mixin
    })

    var tag = riot.mount('my-mixin')[0]

    expect(tag._riot_id).to.be(tag.getId())
    tag.unmount()
  })

  it('register a function mixin to Riot and load mixin to a tag', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.mixin('functMixin', FunctMixin) // register mixin
    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin('functMixin') // load mixin
    })

    var tag = riot.mount('my-mixin')[0]
    expect(tag.type).to.be('func')
    tag.unmount()
  })

  it('register a child function mixin to Riot and load mixin to a tag', function() {
    injectHTML('<my-mixin></my-mixin>')

    riot.mixin('childMixin', ChildMixin) // register mixin
    riot.tag('my-mixin', 'some tag', function(opts) {
      this.mixin('childMixin') // load mixin
    })

    var tag = riot.mount('my-mixin')[0]
    expect(tag.type).to.be('func')
    tag.unmount()
  })
})
<|endoftext|>


<commit_before>var should = require("should");
var parser = require('../src/index');

describe('Test strings', function() {

  it('...', function() {
    var ast = parser.parseEval('$a = b\'\\t\\ra\';');
  });
  it('...', function() {
    var ast = parser.parseEval('echo b"\\colors contains >$colors<\\n";');
  });
  it('...', function() {
    var ast = parser.parseEval('echo B"\\colors[1] contains >$colors[1]<\\n";');
  });
  it('binary cast', function() {
    var ast = parser.parseEval('echo (binary)"\\colors[1] contains >$colors[1]<\\n";');
    // @todo console.log(ast.children[0].arguments[0]);
  });
  it('...', function() {
    var ast = parser.parseEval('echo "\\colors[1] contains >$colors [1]<\\n";');
  });
  it('...', function() {
    var ast = parser.parseEval('echo "~\'.{{$expectedLength}}\'\\$~s";');
  });
  it('test encapsed variable', function() {
    var ast = parser.parseEval([
      'echo "Hello $obj->name !";',
      'echo "Hello $obj->foo->bar !";',
      'echo "Hello $obj[1]->foo !";'
    ].join('\n'));

    ast.children[0].arguments[0].kind.should.be.exactly('encapsed');
    ast.children[0].arguments[0].value[0].value.should.be.exactly('Hello ');
    ast.children[0].arguments[0].value[2].value.should.be.exactly(' !');

    ast.children[1].arguments[0].kind.should.be.exactly('encapsed');
    ast.children[1].arguments[0].value[0].value.should.be.exactly('Hello ');
    ast.children[1].arguments[0].value[2].value.should.be.exactly('->bar !');

    ast.children[2].arguments[0].kind.should.be.exactly('encapsed');
    ast.children[2].arguments[0].value[0].value.should.be.exactly('Hello ');
    ast.children[2].arguments[0].value[2].value.should.be.exactly('->foo !');
  });
  it('...', function() {
    var ast = parser.parseEval('echo "Hello {".$obj->name."} !";');
  });
  it('...', function() {
    var ast = parser.parseEval('echo "Hello {$obj->name} !";');
  });
  it('...', function() {
    var ast = parser.parseEval('echo "Hello ${obj}->name !";');
  });
  it('...', function() {
    var ast = parser.parseEval('echo "\\"$parts[0]\\"\\n";');
  });
  it('...', function() {
    var ast = parser.parseEval('echo "${$parts[$i]}\\n";');
  });
  it('...', function() {
    var ast = parser.parseEval('echo "yo : {$feeds[0][\'title[0][value]\']}";');
  });
  it('...', function() {
    var ast = parser.parseEval('return "\\x1B[{$color}m{$str}\\x1B[0m";');
  });
  it('test double quotes', function() {
    var ast = parser.parseEval([
      '$a = "$";',
      '$a = "{";',
      '$a = "-$-";',
      '$a = "-{";',
      '$a = "$b";',
      '$a = "{$b}";',
      '$a = "${$b}";',
      '$a = "-$b?";',
      '$a = "-{$b}";',
      '$a = "-${$b}";',
      '$a = "";',
      '$a = "\\"";',
    ].join('\r\n'), {
      lexer: {
        debug: false
      },
      parser: {
        debug: false
      }
    });
  });
  it('...', function() {
    var ast = parser.parseEval('$foo = array("v1.09azAZ-._~!$", true);');
  });
  it('...', function() {
    var ast = parser.parseEval('$v = strtolower("$i.$j.$k-$rel");');
  });
  it('...', function() {
    var ast = parser.parseEval('$text = "$text at line $line";');
  });
  it('...', function() {
    var ast = parser.parseEval('return "Class.create(\'$package$className\',{";');
  });
  it('test encapsed elements', function() {
    var ast = parser.parseEval([
      '$code = <<<\t EOFX',
      '{$this->docStar}',
      '${$foo}',
      '${targetDirs[1]}',
      '$test[1]',
      '$test->foo',
      'EOFX;'
    ].join('\r'), {
      parser: {
        debug: false
      }
    });
    var expr = ast.children[0].right.value;
    expr[0].kind.should.be.exactly('propertylookup');
    expr[2].kind.should.be.exactly('variable');
    expr[4].kind.should.be.exactly('variable');
    expr[6].kind.should.be.exactly('offsetlookup');
    expr[8].kind.should.be.exactly('propertylookup');
    // @todo : improve assertions
  });
  it('test nowdoc label and contents', function() {
    var ast = parser.parseEval([
      '$code .= <<<\'EOF\'',
      '  }',
      'EOF;'
    ].join('\r\n'), {
      parser: {
        debug: false
      }
    });
    var expr = ast.children[0].right;
    expr.kind.should.be.exactly('nowdoc');
    expr.label.should.be.exactly('EOF');
    expr.value.should.be.exactly('  }');
  });
  it('heredoc ...', function() {
    var ast = parser.parseEval([
      '$fallbackContent .= sprintf(<<<EOF2',
      '\\$catalogue%s = new MessageCatalogue(\'%s\', %s);',
      '\\$catalogue%s->addFallbackCatalogue(\\$catalogue%s);',
      'EOF2',
      ');',
    ].join('\r\n'));
  });
  it('test empty nowdoc & heredoc contents', function() {
    var ast = parser.parseEval([
      'echo <<<HDOC',
      'HDOC',
      ';',
      'echo <<<\'NDOC\'',
      'NDOC',
      ';',
    ].join('\r\n'));
    ast.children[0].arguments[0].kind.should.be.exactly('encapsed');
    ast.children[0].arguments[0].label.should.be.exactly('HDOC');
    ast.children[0].arguments[0].value.length.should.be.exactly(0);

    ast.children[1].arguments[0].kind.should.be.exactly('nowdoc');
    ast.children[1].arguments[0].label.should.be.exactly('NDOC');
    ast.children[1].arguments[0].value.should.be.exactly('');
  });
  it('test heredoc end of doc', function() {
    var ast = parser.parseEval([
      '$a = <<<EOF2',
      'SOMETHING'
    ].join('\r'), {
      parser: {
        suppressErrors: true
      }
    });
    ast.errors.length.should.be.exactly(1);
    ast.errors[0].line.should.be.exactly(2);
    ast.errors[0].message.indexOf('T_END_HEREDOC').should.be.greaterThan(-1);
    ast.children[0].right.kind.should.be.exactly('encapsed');
    ast.children[0].right.type.should.be.exactly('heredoc');
    ast.children[0].right.label.should.be.exactly('EOF2');
    ast.children[0].right.value[0].value.should.be.exactly('SOMETHING');
  });
  it('test nowdoc end of doc', function() {
    var ast = parser.parseEval([
      '$a = <<<\'EOF2\'',
      'FOO'
    ].join('\r'), {
      parser: {
        suppressErrors: true
      }
    });
    ast.errors.length.should.be.exactly(1);
    ast.errors[0].line.should.be.exactly(2);
    ast.errors[0].message.indexOf('T_END_HEREDOC').should.be.greaterThan(-1);
    ast.children[0].right.kind.should.be.exactly('nowdoc');
    ast.children[0].right.label.should.be.exactly('EOF2');
    ast.children[0].right.value.should.be.exactly('FOO');
  });
  it('test backquotes', function() {
    var ast = parser.parseEval([
      '$a = `ls $cwd`;',
      '$a = `ls ${$cwd}`;',
      '$a = `ls {$cwd}`;',
      '$a = `$var`;',
      '$a = `${var}`;',
      '$a = `{$var}`;',
      '$a = ``;',
      '$a = `\\``;',
      '$a = `{`;',
      '$a = `-{`;',
      '$a = `-$`;',
      '$a = `$`;',
    ].join('\r'));
    ast.children[0].right.kind.should.be.exactly('encapsed');
    ast.children[0].right.type.should.be.exactly('shell');
    ast.children[0].right.value.length.should.be.exactly(2);
    ast.children[0].right.value[0].kind.should.be.exactly('string');
    ast.children[0].right.value[0].value.should.be.exactly('ls ');
    ast.children[0].right.value[1].kind.should.be.exactly('variable');
    ast.children[0].right.value[1].name.should.be.exactly('cwd');
    // @todo test the rest of childs
  });

});
<commit_msg>https://github.com/glayzzle/php-parser/issues/73 add tests<commit_after>var should = require("should");
var parser = require('../src/index');

describe('Test strings', function() {

  it('...', function() {
    var ast = parser.parseEval('$a = b\'\\t\\ra\';');
  });
  it('...', function() {
    var ast = parser.parseEval('echo b"\\colors contains >$colors<\\n";');
  });
  it('...', function() {
    var ast = parser.parseEval('echo B"\\colors[1] contains >$colors[1]<\\n";');
  });
  it('binary cast', function() {
    var ast = parser.parseEval('echo (binary)"\\colors[1] contains >$colors[1]<\\n";');
    // @todo console.log(ast.children[0].arguments[0]);
  });
  it('...', function() {
    var ast = parser.parseEval('echo "\\colors[1] contains >$colors [1]<\\n";');
  });
  it('...', function() {
    var ast = parser.parseEval('echo "~\'.{{$expectedLength}}\'\\$~s";');
  });
  it('test encapsed variable', function() {
    var ast = parser.parseEval([
      'echo "Hello $obj->name !";',
      'echo "Hello $obj->foo->bar !";',
      'echo "Hello $obj[1]->foo !";'
    ].join('\n'));

    ast.children[0].arguments[0].kind.should.be.exactly('encapsed');
    ast.children[0].arguments[0].value[0].value.should.be.exactly('Hello ');
    ast.children[0].arguments[0].value[2].value.should.be.exactly(' !');

    ast.children[1].arguments[0].kind.should.be.exactly('encapsed');
    ast.children[1].arguments[0].value[0].value.should.be.exactly('Hello ');
    ast.children[1].arguments[0].value[2].value.should.be.exactly('->bar !');

    ast.children[2].arguments[0].kind.should.be.exactly('encapsed');
    ast.children[2].arguments[0].value[0].value.should.be.exactly('Hello ');
    ast.children[2].arguments[0].value[2].value.should.be.exactly('->foo !');
  });
  it('...', function() {
    var ast = parser.parseEval('echo "Hello {".$obj->name."} !";');
  });
  it('...', function() {
    var ast = parser.parseEval('echo "Hello {$obj->name} !";');
  });
  it('Encapsed variable / curly varname', function() {
    var ast = parser.parseEval('echo "Hello ${obj}->name !";');
    ast.children[0].kind.should.be.exactly('echo');
    ast.children[0].arguments.length.should.be.exactly(1);
    var arg1 = ast.children[0].arguments[0];
    arg1.kind.should.be.exactly('encapsed');
    arg1.type.should.be.exactly('string');
    arg1.value.length.should.be.exactly(3);
    // test constant parts
    arg1.value[0].kind.should.be.exactly('string');
    arg1.value[0].value.should.be.exactly('Hello ');
    arg1.value[2].kind.should.be.exactly('string');
    arg1.value[2].value.should.be.exactly('->name !');
    // test the varname
    arg1.value[1].kind.should.be.exactly('variable');
    arg1.value[1].name.should.be.exactly('obj');
    arg1.value[1].curly.should.be.exactly(true);
  });
  it('Encapsed variable / curly constant', function() {
    var ast = parser.parseEval('echo "Hello ${ obj }";');
    ast.children[0].kind.should.be.exactly('echo');
    ast.children[0].arguments.length.should.be.exactly(1);
    var arg1 = ast.children[0].arguments[0];
    arg1.kind.should.be.exactly('encapsed');
    arg1.type.should.be.exactly('string');
    arg1.value.length.should.be.exactly(2);
    // test constant parts
    arg1.value[0].kind.should.be.exactly('string');
    arg1.value[0].value.should.be.exactly('Hello ');
    // test the varname
    arg1.value[1].kind.should.be.exactly('variable');
    arg1.value[1].name.kind.should.be.exactly('constref');
    arg1.value[1].name.name.kind.should.be.exactly('identifier');
    arg1.value[1].name.name.name.should.be.exactly('obj');
    arg1.value[1].curly.should.be.exactly(true);
  });
  it('...', function() {
    var ast = parser.parseEval('echo "\\"$parts[0]\\"\\n";');
  });
  it('Encapsed variable / offsetlookup', function() {
    var ast = parser.parseEval('echo "${$parts[$i]}\\n";');
    ast.children[0].kind.should.be.exactly('echo');
    ast.children[0].arguments.length.should.be.exactly(1);
    var arg1 = ast.children[0].arguments[0];
    arg1.kind.should.be.exactly('encapsed');
    arg1.type.should.be.exactly('string');
    arg1.value.length.should.be.exactly(2);
    // check the varvar
    arg1.value[0].kind.should.be.exactly('variable');
    // check the lookup structure
    arg1.value[0].name.kind.should.be.exactly('offsetlookup');
    arg1.value[0].name.what.name.should.be.exactly('parts');
    arg1.value[0].name.offset.name.should.be.exactly('i');
    // check ending string
    arg1.value[1].kind.should.be.exactly('string');
    arg1.value[1].value.should.be.exactly('\n');
  });
  it('...', function() {
    var ast = parser.parseEval('echo "yo : {$feeds[0][\'title[0][value]\']}";');
  });
  it('...', function() {
    var ast = parser.parseEval('return "\\x1B[{$color}m{$str}\\x1B[0m";');
  });
  it('test double quotes', function() {
    var ast = parser.parseEval([
      '$a = "$";',
      '$a = "{";',
      '$a = "-$-";',
      '$a = "-{";',
      '$a = "$b";',
      '$a = "{$b}";',
      '$a = "${$b}";',
      '$a = "-$b?";',
      '$a = "-{$b}";',
      '$a = "-${$b}";',
      '$a = "";',
      '$a = "\\"";',
    ].join('\r\n'), {
      lexer: {
        debug: false
      },
      parser: {
        debug: false
      }
    });
  });
  it('...', function() {
    var ast = parser.parseEval('$foo = array("v1.09azAZ-._~!$", true);');
  });
  it('...', function() {
    var ast = parser.parseEval('$v = strtolower("$i.$j.$k-$rel");');
  });
  it('...', function() {
    var ast = parser.parseEval('$text = "$text at line $line";');
  });
  it('...', function() {
    var ast = parser.parseEval('return "Class.create(\'$package$className\',{";');
  });
  it('test encapsed elements', function() {
    var ast = parser.parseEval([
      '$code = <<<\t EOFX',
      '{$this->docStar}',
      '${$foo}',
      '${targetDirs[1]}',
      '$test[1]',
      '$test->foo',
      'EOFX;'
    ].join('\r'), {
      parser: {
        debug: false
      }
    });
    var expr = ast.children[0].right.value;
    expr[0].kind.should.be.exactly('propertylookup');
    expr[2].kind.should.be.exactly('variable');
    expr[4].kind.should.be.exactly('variable');
    expr[6].kind.should.be.exactly('offsetlookup');
    expr[8].kind.should.be.exactly('propertylookup');
    // @todo : improve assertions
  });
  it('test nowdoc label and contents', function() {
    var ast = parser.parseEval([
      '$code .= <<<\'EOF\'',
      '  }',
      'EOF;'
    ].join('\r\n'), {
      parser: {
        debug: false
      }
    });
    var expr = ast.children[0].right;
    expr.kind.should.be.exactly('nowdoc');
    expr.label.should.be.exactly('EOF');
    expr.value.should.be.exactly('  }');
  });
  it('heredoc ...', function() {
    var ast = parser.parseEval([
      '$fallbackContent .= sprintf(<<<EOF2',
      '\\$catalogue%s = new MessageCatalogue(\'%s\', %s);',
      '\\$catalogue%s->addFallbackCatalogue(\\$catalogue%s);',
      'EOF2',
      ');',
    ].join('\r\n'));
  });
  it('test empty nowdoc & heredoc contents', function() {
    var ast = parser.parseEval([
      'echo <<<HDOC',
      'HDOC',
      ';',
      'echo <<<\'NDOC\'',
      'NDOC',
      ';',
    ].join('\r\n'));
    ast.children[0].arguments[0].kind.should.be.exactly('encapsed');
    ast.children[0].arguments[0].label.should.be.exactly('HDOC');
    ast.children[0].arguments[0].value.length.should.be.exactly(0);

    ast.children[1].arguments[0].kind.should.be.exactly('nowdoc');
    ast.children[1].arguments[0].label.should.be.exactly('NDOC');
    ast.children[1].arguments[0].value.should.be.exactly('');
  });
  it('test heredoc end of doc', function() {
    var ast = parser.parseEval([
      '$a = <<<EOF2',
      'SOMETHING'
    ].join('\r'), {
      parser: {
        suppressErrors: true
      }
    });
    ast.errors.length.should.be.exactly(1);
    ast.errors[0].line.should.be.exactly(2);
    ast.errors[0].message.indexOf('T_END_HEREDOC').should.be.greaterThan(-1);
    ast.children[0].right.kind.should.be.exactly('encapsed');
    ast.children[0].right.type.should.be.exactly('heredoc');
    ast.children[0].right.label.should.be.exactly('EOF2');
    ast.children[0].right.value[0].value.should.be.exactly('SOMETHING');
  });
  it('test nowdoc end of doc', function() {
    var ast = parser.parseEval([
      '$a = <<<\'EOF2\'',
      'FOO'
    ].join('\r'), {
      parser: {
        suppressErrors: true
      }
    });
    ast.errors.length.should.be.exactly(1);
    ast.errors[0].line.should.be.exactly(2);
    ast.errors[0].message.indexOf('T_END_HEREDOC').should.be.greaterThan(-1);
    ast.children[0].right.kind.should.be.exactly('nowdoc');
    ast.children[0].right.label.should.be.exactly('EOF2');
    ast.children[0].right.value.should.be.exactly('FOO');
  });
  it('test backquotes', function() {
    var ast = parser.parseEval([
      '$a = `ls $cwd`;',
      '$a = `ls ${$cwd}`;',
      '$a = `ls {$cwd}`;',
      '$a = `$var`;',
      '$a = `${var}`;',
      '$a = `{$var}`;',
      '$a = ``;',
      '$a = `\\``;',
      '$a = `{`;',
      '$a = `-{`;',
      '$a = `-$`;',
      '$a = `$`;',
    ].join('\r'));
    ast.children[0].right.kind.should.be.exactly('encapsed');
    ast.children[0].right.type.should.be.exactly('shell');
    ast.children[0].right.value.length.should.be.exactly(2);
    ast.children[0].right.value[0].kind.should.be.exactly('string');
    ast.children[0].right.value[0].value.should.be.exactly('ls ');
    ast.children[0].right.value[1].kind.should.be.exactly('variable');
    ast.children[0].right.value[1].name.should.be.exactly('cwd');
    // @todo test the rest of childs
  });

});
<|endoftext|>


<commit_before>(function() {
  'use strict';

  const chai = require('chai');
  const expect = chai.expect;

  describe('System test', () => {
    it('Sanity test, should indicate that testing environment is working properly', () => {
      expect(true).to.equal(true);
    });
  });

})();<commit_msg>Review and hound fixes<commit_after>/* jshint esversion:6 */
/* global __dirname */

(function() {
  'use strict';

  const chai = require('chai');
  const expect = chai.expect;

  describe('System test', () => {
    it('Sanity test, should indicate that testing environment is working properly', () => {
      expect(true).to.equal(true);
    });
  });

})();<|endoftext|>


<commit_before>"use strict";

var pack = require('../pack');
var unpack = require('../unpack');

function packAndUnpack(test, name, suffix, callback) {
  var buf = new Buffer(128);
  pack(buf, 0, null, name, suffix, function(error, pLen) {
    test.equal(error, null, 'pack callback error');

    unpack(buf, 0, function(error, uLen, uName, uSuffix) {
      test.equal(error, null, 'unpack callback error');
      test.equal(uName, name, 'unpacked name');
      test.equal(uSuffix, suffix, 'unpacked suffix');
      callback();
    });
  });
}

module.exports.testSimpleName = function(test) {
  test.expect(4);

  packAndUnpack(test, 'foobar', 0x20, function() {
    test.done();
  });
};

module.exports.testFullName = function(test) {
  test.expect(4);

  packAndUnpack(test, 'foobar.example.com', 0x20, function() {
    test.done();
  });
};
<commit_msg>Reimplement unpack tests and add tests for pointer logic and buffer underrun.<commit_after>"use strict";

var pack = require('../pack');
var unpack = require('../unpack');

module.exports.testSimpleName = function(test) {
  test.expect(4);

  verifyList(test, {}, ['foobar'], function() {
    test.done();
  });
};

module.exports.testFullName = function(test) {
  test.expect(4);

  verifyList(test, {}, ['foobar.example.com'], function() {
    test.done();
  });
};

module.exports.testSimpleNameWithPointer = function(test) {
  test.expect(7);

  var nameList = ['foobar', 'foobar'];
  var expectedLength = 1 + 32 + 1;  // first foobar
  expectedLength += 2;              // second foobar as pointer

  verifyList(test, {}, nameList, function(len) {
    test.equal(len, expectedLength, 'unpacked number of bytes');
    test.done();
  });
};

module.exports.testSimpleNameWithoutPointer = function(test) {
  test.expect(7);

  var nameList = ['foobar', 'foobar'];
  var expectedLength = 1 + 32 + 1;  // first foobar
  expectedLength += 1 + 32 + 1;     // second foobar without pointer

  verifyList(test, null, nameList, function(len) {
    test.equal(len, expectedLength, 'unpacked number of bytes');
    test.done();
  });
};

module.exports.testFullNameWithPointer = function(test) {
  test.expect(7);

  var name = 'foobar';
  var scopeId = '.example.com';
  var fullName = name + scopeId;
  var nameList = [fullName, fullName];
  var expectedLength = 1 + 32 + scopeId.length + 1;   // 1st full name
  expectedLength += 2;                                // 2nd full name w/ ptr

  verifyList(test, {}, nameList, function(len) {
    test.equal(len, expectedLength, 'unpacked number of bytes');
    test.done();
  });
};

module.exports.testFullNameWithoutPointer = function(test) {
  test.expect(7);

  var name = 'foobar';
  var scopeId = '.example.com';
  var fullName = name + scopeId;
  var nameList = [fullName, fullName];
  var expectedLength = 1 + 32 + scopeId.length + 1;   // 1st full name
  expectedLength += 1 + 32 + scopeId.length + 1;      // 2nd full name w/o ptr

  verifyList(test, null, nameList, function(len) {
    test.equal(len, expectedLength, 'unpacked number of bytes');
    test.done();
  });
};

module.exports.testBufferUnderrun = function(test) {
  test.expect(1);

  var buf = new Buffer(8);

  // Write a length value of 32 bytes which is longer than the buffer.
  buf.writeUInt8(32, 0);

  unpack(buf, 0, function(error) {
    test.notEqual(error, null, 'unpack should return an error via callback');
    test.done();
  });
};

// Functions below will pack and then unpack a list of names.  Each unpacked
// name is then checked against the names originally passed in.  The final
// number of bytes read is passed back via callback.

function verifyList(test, nameMap, nameList, callback) {
  var buf = new Buffer(1024);
  var suffix = 0x20;

  packList(buf, 0, nameMap, nameList.slice(), suffix, function(error) {
    test.equal(error, null, 'packList callback error');

    var namesOut = [];
    var suffixesOut = [];
    unpackList(buf, 0, nameList.length, namesOut, suffixesOut, function(error, uLen) {
      test.equal(error, null, 'unpackList callback error');

      for (var i = 0; i < nameList.length; ++i) {
        test.equal(namesOut[i], nameList[i],
                   'unpacked name at index [' + i + ']');
        test.equal(suffixesOut[i], suffix, 'unpacked suffix');
      }

      callback(uLen);
    });
  });
}

function packList(buf, offset, nameMap, nameList, suffix, callback) {
  var name = nameList.shift();
  if (!name) {
    callback(null);
    return;
  }

  pack(buf, offset, nameMap, name, suffix, function(error, pLen) {
    if (error) {
      callback(error);
      return;
    }

    packList(buf, (offset + pLen), nameMap, nameList, suffix, callback);
  });
}

function unpackList(buf, offset, nameCount, nameList, suffixList, callback) {
  if (nameCount < 1) {
    callback(null, offset);
    return;
  }

  unpack(buf, offset, function(error, uLen, uName, uSuffix) {
    if (error) {
      callback(error);
      return;
    }

    nameList.push(uName);
    suffixList.push(uSuffix);

    unpackList(buf, (offset + uLen), (nameCount - 1), nameList, suffixList, callback);
  });
}
<|endoftext|>


<commit_before>'use strict';

var chai = chai || require('chai');
var should = chai.should();
var expect = chai.expect;
var bitcore = bitcore || require('../bitcore');
var fs = require('fs');

var PayPro = bitcore.PayPro;
var Key = bitcore.Key;

var x509 = {
  priv: fs.readFileSync(__dirname + '/data/x509.key'),
  pub: fs.readFileSync(__dirname + '/data/x509.pub'),
  crt: fs.readFileSync(__dirname + '/data/x509.der'),
  sig: new Buffer(0)
};

describe('PayPro', function() {

  it('should be able to create class', function() {
    should.exist(PayPro);
  });

  describe('#Output', function() {

    it('should not fail', function() {
      var obj = {};
      var output = new PayPro.Output();
      output.$set('amount', 20);
    });

    it('should be able to set the amount of an output', function() {
      var output = new PayPro.Output();
      output.set('amount', 20);
      output.get('amount').toInt().should.equal(20);
    });

  });

  describe('#PaymentDetails', function() {

    it('should not fail', function() {
      var obj = {};
      var pd = new PayPro.PaymentDetails();
    });

    it('should set the memo', function() {
      var obj = {};
      var pd = new PayPro.PaymentDetails();
      pd.set('memo', 'test memo');
      pd.get('memo').should.equal('test memo');
    });

    it('should serialize', function() {
      var obj = {};
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      pd.set('memo', 'test memo');
      var hex = pd.toHex();
      hex.length.should.be.greaterThan(0);
    });

  });

  describe('#PaymentRequest', function() {

    it('should not fail', function() {
      var obj = {};
      var pd = new PayPro.PaymentRequest();
    });

    it('should serialize', function() {
      var obj = {};
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var pr = new PayPro.PaymentRequest();
      pr.set('serialized_payment_details', pdbuf);
      var prhex = pr.toHex();
      prhex.length.should.be.greaterThan(0);
    });

  });

  describe('#Payment', function() {

    it('should not fail', function() {
      var obj = {};
      var pd = new PayPro.Payment();
    });

    it('should serialize', function() {
      var obj = {};
      var p = new PayPro.Payment();
      p.set('memo', 'this is a memo');
      p.get('memo').should.equal('this is a memo');
      var phex = p.toHex();
      phex.length.should.be.greaterThan(0);
    });

  });

  describe('#PaymentACK', function() {

    it('should not fail', function() {
      var obj = {};
      var pd = new PayPro.PaymentACK();
    });

    it('should serialize', function() {
      var obj = {};
      var p = new PayPro.Payment();
      var pa = new PayPro.PaymentACK();
      pa.set('payment', p);
      pa.set('memo', 'this is a memo');
      pa.get('memo').should.equal('this is a memo');
      var pahex = pa.toHex();
      pahex.length.should.be.greaterThan(0);
    });

  });

  describe('#X509Certificates', function() {

    it('should not fail', function() {
      var obj = {};
      var pd = new PayPro.X509Certificates();
    });

    it('should serialize', function() {
      var obj = {};
      var x = new PayPro.X509Certificates();
      var fakecertificate = new Buffer([0, 0, 0, 0]);
      x.set('certificate', [fakecertificate]);
      var xhex = x.toHex();
      xhex.length.should.be.greaterThan(0);
    });

  });

  describe('#isValidSize', function() {

    it('should return true for validly sized payment', function() {
      var paypro = new PayPro();
      paypro.makePayment();
      paypro.set('memo', 'test memo');
      paypro.isValidSize().should.equal(true);
    });

  });

  describe('#getContentType', function() {

    it('should get a content type for payment', function() {
      var paypro = new PayPro();
      paypro.makePayment();
      paypro.set('memo', 'test memo');
      paypro.getContentType().should.equal('application/bitcoin-payment');
    });

  });

  describe('#set', function() {

    it('should set a field', function() {
      var obj = {};
      var paypro = new PayPro();
      paypro.makePaymentDetails();
      paypro.set('memo', 'test memo');
      paypro.get('memo').should.equal('test memo');
    });

  });

  describe('#get', function() {

    it('should get a field', function() {
      var obj = {};
      var paypro = new PayPro();
      paypro.makePaymentDetails();
      paypro.set('memo', 'test memo');
      paypro.get('memo').should.equal('test memo');
    });

  });

  describe('#setObj', function() {

    it('should set properties of paymentdetails', function() {
      var pd = new PayPro.PaymentDetails();
      var paypro = new PayPro();
      paypro.messageType = "PaymentDetails";
      paypro.message = pd;
      paypro.setObj({
        time: 0
      });
      paypro.get('time').should.equal(0);
    });

  });

  describe('#serializeForSig', function() {

    it('should serialize a PaymentRequest and not fail', function() {
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();

      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      var buf = paypro.serializeForSig();
      buf.length.should.be.greaterThan(0);
    });

  });

  describe('#serialize', function() {

    it('should serialize', function() {
      var obj = {};
      var paypro = new PayPro();
      paypro.makePaymentDetails();
      paypro.set('memo', 'test memo');
      paypro.set('time', 0);
      var buf = paypro.serialize();
      buf.length.should.be.greaterThan(0);
      Buffer.isBuffer(buf).should.equal(true);
    });

  });

  describe('#deserialize', function() {

    it('should deserialize a serialized message', function() {
      var obj = {};
      var paypro = new PayPro();
      paypro.makePaymentDetails();
      paypro.set('memo', 'test memo');
      paypro.set('time', 0);
      var buf = paypro.serialize();
      var paypro2 = new PayPro();
      paypro2.deserialize(buf, 'PaymentDetails');
      paypro2.get('memo').should.equal('test memo');
      paypro2.get('time').should.equal(0);
    });

  });

  describe('#sign', function() {

    it('should sign a payment request', function() {
      // SIN
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'SIN');
      var key = new bitcore.Key();
      key.private = bitcore.util.sha256('test key');
      key.regenerateSync();
      paypro.sign(key);
      var sig = paypro.get('signature');
      sig.length.should.be.greaterThan(0);

      // X509
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'x509+sha256');
      paypro.set('pki_data', x509.crt);
      paypro.sign(x509.priv);
      x509.sig = paypro.get('signature');
      x509.sig.length.should.be.greaterThan(0);
    });

  });

  describe('#verify', function() {

    it('should verify a signed payment request', function() {
      // SIN
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'SIN');
      var key = new bitcore.Key();
      key.private = bitcore.util.sha256('test key');
      key.regenerateSync();
      paypro.sign(key);
      var verify = paypro.verify();
      verify.should.equal(true);

      // X509
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'x509+sha256');
      paypro.set('signature', x509.sig); // sig buffer
      paypro.set('pki_data', x509.crt); // contains one or more x509 certs
      var verify = paypro.verify();
      verify.should.equal(true);
    });

  });

  describe('#sinSign', function() {

    it('should sign assuming pki_type is SIN', function() {
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'SIN');
      var key = new bitcore.Key();
      key.private = bitcore.util.sha256('test key');
      key.regenerateSync();
      var sig = paypro.sinSign(key);
      sig.length.should.be.greaterThan(0);
    });

  });

  describe('#sinVerify', function() {

    it('should verify assuming pki_type is SIN', function() {
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'SIN');
      var key = new bitcore.Key();
      key.private = bitcore.util.sha256('test key');
      key.regenerateSync();
      paypro.sign(key);
      var verify = paypro.sinVerify();
      verify.should.equal(true);
    });

  });

});
<commit_msg>paypro: separate tests for x509+sha256 and x509+sha1.<commit_after>'use strict';

var chai = chai || require('chai');
var should = chai.should();
var expect = chai.expect;
var bitcore = bitcore || require('../bitcore');
var fs = require('fs');

var PayPro = bitcore.PayPro;
var Key = bitcore.Key;

var x509 = {
  priv: fs.readFileSync(__dirname + '/data/x509.key'),
  pub: fs.readFileSync(__dirname + '/data/x509.pub'),
  crt: fs.readFileSync(__dirname + '/data/x509.der'),
  sig1: new Buffer(0),
  sig2: new Buffer(0),
  sig3: new Buffer(0)
};

describe('PayPro', function() {

  it('should be able to create class', function() {
    should.exist(PayPro);
  });

  describe('#Output', function() {

    it('should not fail', function() {
      var obj = {};
      var output = new PayPro.Output();
      output.$set('amount', 20);
    });

    it('should be able to set the amount of an output', function() {
      var output = new PayPro.Output();
      output.set('amount', 20);
      output.get('amount').toInt().should.equal(20);
    });

  });

  describe('#PaymentDetails', function() {

    it('should not fail', function() {
      var obj = {};
      var pd = new PayPro.PaymentDetails();
    });

    it('should set the memo', function() {
      var obj = {};
      var pd = new PayPro.PaymentDetails();
      pd.set('memo', 'test memo');
      pd.get('memo').should.equal('test memo');
    });

    it('should serialize', function() {
      var obj = {};
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      pd.set('memo', 'test memo');
      var hex = pd.toHex();
      hex.length.should.be.greaterThan(0);
    });

  });

  describe('#PaymentRequest', function() {

    it('should not fail', function() {
      var obj = {};
      var pd = new PayPro.PaymentRequest();
    });

    it('should serialize', function() {
      var obj = {};
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var pr = new PayPro.PaymentRequest();
      pr.set('serialized_payment_details', pdbuf);
      var prhex = pr.toHex();
      prhex.length.should.be.greaterThan(0);
    });

  });

  describe('#Payment', function() {

    it('should not fail', function() {
      var obj = {};
      var pd = new PayPro.Payment();
    });

    it('should serialize', function() {
      var obj = {};
      var p = new PayPro.Payment();
      p.set('memo', 'this is a memo');
      p.get('memo').should.equal('this is a memo');
      var phex = p.toHex();
      phex.length.should.be.greaterThan(0);
    });

  });

  describe('#PaymentACK', function() {

    it('should not fail', function() {
      var obj = {};
      var pd = new PayPro.PaymentACK();
    });

    it('should serialize', function() {
      var obj = {};
      var p = new PayPro.Payment();
      var pa = new PayPro.PaymentACK();
      pa.set('payment', p);
      pa.set('memo', 'this is a memo');
      pa.get('memo').should.equal('this is a memo');
      var pahex = pa.toHex();
      pahex.length.should.be.greaterThan(0);
    });

  });

  describe('#X509Certificates', function() {

    it('should not fail', function() {
      var obj = {};
      var pd = new PayPro.X509Certificates();
    });

    it('should serialize', function() {
      var obj = {};
      var x = new PayPro.X509Certificates();
      var fakecertificate = new Buffer([0, 0, 0, 0]);
      x.set('certificate', [fakecertificate]);
      var xhex = x.toHex();
      xhex.length.should.be.greaterThan(0);
    });

  });

  describe('#isValidSize', function() {

    it('should return true for validly sized payment', function() {
      var paypro = new PayPro();
      paypro.makePayment();
      paypro.set('memo', 'test memo');
      paypro.isValidSize().should.equal(true);
    });

  });

  describe('#getContentType', function() {

    it('should get a content type for payment', function() {
      var paypro = new PayPro();
      paypro.makePayment();
      paypro.set('memo', 'test memo');
      paypro.getContentType().should.equal('application/bitcoin-payment');
    });

  });

  describe('#set', function() {

    it('should set a field', function() {
      var obj = {};
      var paypro = new PayPro();
      paypro.makePaymentDetails();
      paypro.set('memo', 'test memo');
      paypro.get('memo').should.equal('test memo');
    });

  });

  describe('#get', function() {

    it('should get a field', function() {
      var obj = {};
      var paypro = new PayPro();
      paypro.makePaymentDetails();
      paypro.set('memo', 'test memo');
      paypro.get('memo').should.equal('test memo');
    });

  });

  describe('#setObj', function() {

    it('should set properties of paymentdetails', function() {
      var pd = new PayPro.PaymentDetails();
      var paypro = new PayPro();
      paypro.messageType = "PaymentDetails";
      paypro.message = pd;
      paypro.setObj({
        time: 0
      });
      paypro.get('time').should.equal(0);
    });

  });

  describe('#serializeForSig', function() {

    it('should serialize a PaymentRequest and not fail', function() {
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();

      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      var buf = paypro.serializeForSig();
      buf.length.should.be.greaterThan(0);
    });

  });

  describe('#serialize', function() {

    it('should serialize', function() {
      var obj = {};
      var paypro = new PayPro();
      paypro.makePaymentDetails();
      paypro.set('memo', 'test memo');
      paypro.set('time', 0);
      var buf = paypro.serialize();
      buf.length.should.be.greaterThan(0);
      Buffer.isBuffer(buf).should.equal(true);
    });

  });

  describe('#deserialize', function() {

    it('should deserialize a serialized message', function() {
      var obj = {};
      var paypro = new PayPro();
      paypro.makePaymentDetails();
      paypro.set('memo', 'test memo');
      paypro.set('time', 0);
      var buf = paypro.serialize();
      var paypro2 = new PayPro();
      paypro2.deserialize(buf, 'PaymentDetails');
      paypro2.get('memo').should.equal('test memo');
      paypro2.get('time').should.equal(0);
    });

  });

  describe('#sign', function() {

    it('should sign a payment request', function() {
      // SIN
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'SIN');
      var key = new bitcore.Key();
      key.private = bitcore.util.sha256('test key');
      key.regenerateSync();
      paypro.sign(key);
      var sig = paypro.get('signature');
      sig.length.should.be.greaterThan(0);

      // X509
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'x509+sha256');
      paypro.set('pki_data', x509.crt);
      paypro.sign(x509.priv);
      x509.sig1 = paypro.get('signature');
      x509.sig1.length.should.be.greaterThan(0);
    });

  });

  describe('#verify', function() {

    it('should verify a signed payment request', function() {
      // SIN
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'SIN');
      var key = new bitcore.Key();
      key.private = bitcore.util.sha256('test key');
      key.regenerateSync();
      paypro.sign(key);
      var verify = paypro.verify();
      verify.should.equal(true);

      // X509
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'x509+sha256');
      paypro.set('signature', x509.sig1); // sig buffer
      paypro.set('pki_data', x509.crt); // contains one or more x509 certs
      var verify = paypro.verify();
      verify.should.equal(true);
    });

  });

  describe('#sinSign', function() {

    it('should sign assuming pki_type is SIN', function() {
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'SIN');
      var key = new bitcore.Key();
      key.private = bitcore.util.sha256('test key');
      key.regenerateSync();
      var sig = paypro.sinSign(key);
      sig.length.should.be.greaterThan(0);
    });

  });

  describe('#sinVerify', function() {

    it('should verify assuming pki_type is SIN', function() {
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);
      var pdbuf = pd.toBuffer();
      var paypro = new PayPro();
      paypro.makePaymentRequest();
      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'SIN');
      var key = new bitcore.Key();
      key.private = bitcore.util.sha256('test key');
      key.regenerateSync();
      paypro.sign(key);
      var verify = paypro.sinVerify();
      verify.should.equal(true);
    });

  });

  describe('#x509+sha256Sign', function() {
    it('should sign assuming pki_type is x509+sha256', function() {
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);

      var pdbuf = pd.toBuffer();

      var paypro = new PayPro();
      paypro.makePaymentRequest();

      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'x509+sha256');
      paypro.set('pki_data', x509.crt);

      var sig = paypro.x509Sign(x509.priv);
      paypro.set('signature', sig);

      x509.sig2 = paypro.get('signature');
      x509.sig2.length.should.be.greaterThan(0);
    });
  });

  describe('#x509+sha256Verify', function() {
    it('should verify assuming pki_type is x509+sha256', function() {
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);

      var pdbuf = pd.toBuffer();

      var paypro = new PayPro();
      paypro.makePaymentRequest();

      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'x509+sha256');

      paypro.set('signature', x509.sig2); // sig buffer
      paypro.set('pki_data', x509.crt); // contains one or more x509 certs

      var verify = paypro.x509Verify();
      verify.should.equal(true);
    });
  });

  describe('#x509+sha1Sign', function() {
    it('should sign assuming pki_type is x509+sha1', function() {
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);

      var pdbuf = pd.toBuffer();

      var paypro = new PayPro();
      paypro.makePaymentRequest();

      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'x509+sha1');
      paypro.set('pki_data', x509.crt);

      var sig = paypro.x509Sign(x509.priv);
      paypro.set('signature', sig);

      x509.sig3 = paypro.get('signature');
      x509.sig3.length.should.be.greaterThan(0);
    });
  });

  describe('#x509+sha1Verify', function() {
    it('should verify assuming pki_type is x509+sha1', function() {
      var pd = new PayPro.PaymentDetails();
      pd.set('time', 0);

      var pdbuf = pd.toBuffer();

      var paypro = new PayPro();
      paypro.makePaymentRequest();

      paypro.set('serialized_payment_details', pdbuf);
      paypro.set('pki_type', 'x509+sha1');

      paypro.set('signature', x509.sig3); // sig buffer
      paypro.set('pki_data', x509.crt); // contains one or more x509 certs

      var verify = paypro.x509Verify();
      verify.should.equal(true);
    });
  });

});
<|endoftext|>


<commit_before>import jsdom from 'jsdom';
import jquery from 'jquery';
import TestUtils from 'react-addons-test-utils';
import ReactDOM from 'react-dom';
import { expect } from 'chai';
import React from 'react';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import reducers from '../src/reducers';

// Setup testing environment to run like a browser in the command line
global.document = jsdom.jsdom('<!doctype html>');
global.window = global.document.defaultView;
const $ = jquery(global.window);

// build 'renderComponent' helper that should render a given react class
function renderComponent(ComponentClass, props, state) {
    const componentInstance = TestUtils.renderIntoDocument(
        <Provider store={createStore(reducers, state)}>
            <ComponentClass {...props} />
        </Provider>
    );

    return $(ReactDOM.findDOMNode(componentInstance)); // produces html
}

// Build helper for simulating events

// Set up chai-jquery
export  { renderComponent, expect };<commit_msg>Finishing Section 3, rebuilding test helper<commit_after>import jsdom from 'jsdom';
import jquery from 'jquery';
import TestUtils from 'react-addons-test-utils';
import ReactDOM from 'react-dom';
import chai, { expect } from 'chai';
import React from 'react';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import reducers from '../src/reducers';
import chaiJquery from 'chai-jquery';

// Setup testing environment to run like a browser in the command line
global.document = jsdom.jsdom('<!doctype html>');
global.window = global.document.defaultView;
const $ = jquery(global.window);

// build 'renderComponent' helper that should render a given react class
function renderComponent(ComponentClass, props, state) {
    const componentInstance = TestUtils.renderIntoDocument(
        <Provider store={createStore(reducers, state)}>
            <ComponentClass {...props} />
        </Provider>
    );

    return $(ReactDOM.findDOMNode(componentInstance)); // produces html
}

// Build helper for simulating events
$.fn.simulate = function(eventName, value) {
    if(value) {
        this.val(value);
    }
    TestUtils.Simulate[eventName](this[0]);
}

// Set up chai-jquery
chaiJquery(chai, chai.util, $);

export  { renderComponent, expect };<|endoftext|>


<commit_before>var path = require("path");
var assert = require("assert");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var local = path.join.bind(path, __dirname);

describe("Clone", function() {
  var Repository = require(local("../../lib/repository"));
  var Clone = require(local("../../lib/clone"));
  var NodeGit = require(local("../../"));

  var clonePath = local("../repos/clone");

  var sshPublicKey = local("../id_rsa.pub");
  var sshPrivateKey = local("../id_rsa");

  // Set a reasonable timeout here now that our repository has grown.
  this.timeout(30000);

  beforeEach(function() {
    return fse.remove(clonePath).catch(function(err) {
      console.log(err);

      throw err;
    });
  });

  it.skip("can clone with http", function() {
    var test = this;
    var url = "http://github.com/nodegit/test.git";
    var opts = {
      remoteCallbacks: {
        certificateCheck: function() {
          return 1;
        }
      }
    };

    return Clone.clone(url, clonePath, opts).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can clone with https", function() {
    var test = this;
    var url = "https://github.com/nodegit/test.git";
    var opts = {
      remoteCallbacks: {
        certificateCheck: function() {
          return 1;
        }
      }
    };

    return Clone.clone(url, clonePath, opts).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can clone with ssh", function() {
    var test = this;
    var url = "git@github.com:nodegit/test.git";
    var opts = {
      remoteCallbacks: {
        certificateCheck: function() {
          return 1;
        },
        credentials: function(url, userName) {
          return NodeGit.Cred.sshKeyFromAgent(userName);
        }
      }
    };

    return Clone.clone(url, clonePath, opts).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can clone with ssh while manually loading a key", function() {
    var test = this;
    var url = "git@github.com:nodegit/test.git";
    var opts = {
      remoteCallbacks: {
        certificateCheck: function() {
          return 1;
        },
        credentials: function(url, userName) {
          return NodeGit.Cred.sshKeyNew(
            userName,
            sshPublicKey,
            sshPrivateKey,
            "");
        }
      }
    };

    return Clone.clone(url, clonePath, opts).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can clone with git", function() {
    var test = this;
    var url = "git://github.com/nodegit/test.git";
    var opts = {
      remoteCallbacks: {
        certificateCheck: function() {
          return 1;
        }
      }
    };

    return Clone.clone(url, clonePath, opts).then(function(repo) {
      test.repository = repo;
      assert.ok(repo instanceof Repository);
    });
  });

  it("can clone with filesystem", function() {
    var test = this;
    var prefix = process.platform === "win32" ? "" : "file://";
    var url = prefix + local("../repos/empty");

    return Clone.clone(url, clonePath).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("will not segfault when accessing a url without username", function() {
    var url = "https://github.com/nodegit/private";

    return Clone.clone(url, clonePath, {
      remoteCallbacks: {
        certificateCheck: function() {
          return 1;
        },
        credentials: function() {
          return NodeGit.Cred.userpassPlaintextNew("fake-token",
            "x-oauth-basic");
        }
      }
    }).catch(function unhandledError() { });
  });
});
<commit_msg>Added in an HTTP url for test<commit_after>var path = require("path");
var assert = require("assert");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var local = path.join.bind(path, __dirname);

describe("Clone", function() {
  var Repository = require(local("../../lib/repository"));
  var Clone = require(local("../../lib/clone"));
  var NodeGit = require(local("../../"));

  var clonePath = local("../repos/clone");

  var sshPublicKey = local("../id_rsa.pub");
  var sshPrivateKey = local("../id_rsa");

  // Set a reasonable timeout here now that our repository has grown.
  this.timeout(30000);

  beforeEach(function() {
    return fse.remove(clonePath).catch(function(err) {
      console.log(err);

      throw err;
    });
  });

  it("can clone with http", function() {
    var test = this;
    var url = "http://git.tbranyen.com/smart/site-content";

    return Clone.clone(url, clonePath).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can clone with https", function() {
    var test = this;
    var url = "https://github.com/nodegit/test.git";
    var opts = {
      remoteCallbacks: {
        certificateCheck: function() {
          return 1;
        }
      }
    };

    return Clone.clone(url, clonePath, opts).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can clone with ssh", function() {
    var test = this;
    var url = "git@github.com:nodegit/test.git";
    var opts = {
      remoteCallbacks: {
        certificateCheck: function() {
          return 1;
        },
        credentials: function(url, userName) {
          return NodeGit.Cred.sshKeyFromAgent(userName);
        }
      }
    };

    return Clone.clone(url, clonePath, opts).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can clone with ssh while manually loading a key", function() {
    var test = this;
    var url = "git@github.com:nodegit/test.git";
    var opts = {
      remoteCallbacks: {
        certificateCheck: function() {
          return 1;
        },
        credentials: function(url, userName) {
          return NodeGit.Cred.sshKeyNew(
            userName,
            sshPublicKey,
            sshPrivateKey,
            "");
        }
      }
    };

    return Clone.clone(url, clonePath, opts).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can clone with git", function() {
    var test = this;
    var url = "git://github.com/nodegit/test.git";
    var opts = {
      remoteCallbacks: {
        certificateCheck: function() {
          return 1;
        }
      }
    };

    return Clone.clone(url, clonePath, opts).then(function(repo) {
      test.repository = repo;
      assert.ok(repo instanceof Repository);
    });
  });

  it("can clone with filesystem", function() {
    var test = this;
    var prefix = process.platform === "win32" ? "" : "file://";
    var url = prefix + local("../repos/empty");

    return Clone.clone(url, clonePath).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("will not segfault when accessing a url without username", function() {
    var url = "https://github.com/nodegit/private";

    return Clone.clone(url, clonePath, {
      remoteCallbacks: {
        certificateCheck: function() {
          return 1;
        },
        credentials: function() {
          return NodeGit.Cred.userpassPlaintextNew("fake-token",
            "x-oauth-basic");
        }
      }
    }).catch(function unhandledError() { });
  });
});
<|endoftext|>


<commit_before>var assert = require("assert");
var path = require("path");
var Promise = require("promise");
var promisify = require("promisify-node");
var rimraf = promisify("rimraf");

describe("Clone", function() {
  var http = path.resolve("test/repos/http");
  var https = path.resolve("test/repos/https");
  var ssh = path.resolve("test/repos/ssh");
  var file = path.resolve("test/repos/file");

  var Repository = require("../../lib/repository");
  var Clone = require("../../lib/clone");
  var NodeGit = require("../../");

  before(function() {
    return Promise.all([
      rimraf(http),
      rimraf(https),
      rimraf(ssh),
      rimraf(file),
    ]);
  });

  it("can clone with http", function() {
    var url = "http://github.com/nodegit/test.git";
    var opts = new NodeGit.CloneOptions();

    opts.ignoreCertErrors = 1;

    return Clone.clone(url, http, opts).then(function(repository) {
      assert.ok(repository instanceof Repository);
    });
  });

  it("can clone with https", function() {
    var url = "https://github.com/nodegit/test.git";
    var opts = new NodeGit.CloneOptions();

    opts.ignoreCertErrors = 1;

    return Clone.clone(url, https, opts).then(function(repository) {
      assert.ok(repository instanceof Repository);
    });
  });

  it("can clone with ssh", function() {
    var url = "git@github.com:nodegit/test.git";
    var opts = new NodeGit.CloneOptions();

    opts.ignoreCertErrors = 1;

    return Clone.clone(url, ssh, opts).then(function(repository) {
      assert.ok(repository instanceof Repository);
    });
  });

  it("can clone with filesystem", function() {
    var url = "file://" + path.resolve("test/repos/empty");

    return Clone.clone(url, file, null).then(function(repository) {
      assert.ok(repository instanceof Repository);
    });
  });
});
<commit_msg>Added git protocol<commit_after>var assert = require("assert");
var path = require("path");
var Promise = require("promise");
var promisify = require("promisify-node");
var rimraf = promisify("rimraf");

describe("Clone", function() {
  var http = path.resolve("test/repos/http");
  var https = path.resolve("test/repos/https");
  var ssh = path.resolve("test/repos/ssh");
  var git = path.resolve("test/repos/git");
  var file = path.resolve("test/repos/file");

  var Repository = require("../../lib/repository");
  var Clone = require("../../lib/clone");
  var NodeGit = require("../../");

  before(function() {
    return Promise.all([
      rimraf(http),
      rimraf(https),
      rimraf(ssh),
      rimraf(git),
      rimraf(file),
    ]);
  });

  it("can clone with http", function() {
    var url = "http://github.com/nodegit/test.git";
    var opts = new NodeGit.CloneOptions();

    opts.ignoreCertErrors = 1;

    return Clone.clone(url, http, opts).then(function(repository) {
      assert.ok(repository instanceof Repository);
    });
  });

  it("can clone with https", function() {
    var url = "https://github.com/nodegit/test.git";
    var opts = new NodeGit.CloneOptions();

    opts.ignoreCertErrors = 1;

    return Clone.clone(url, https, opts).then(function(repository) {
      assert.ok(repository instanceof Repository);
    });
  });

  it("can clone with ssh", function() {
    var url = "git@github.com:nodegit/test.git";
    var opts = new NodeGit.CloneOptions();

    opts.ignoreCertErrors = 1;

    return Clone.clone(url, ssh, opts).then(function(repository) {
      assert.ok(repository instanceof Repository);
    });
  });

  it("can clone with git", function() {
    var url = "git://github.com/nodegit/test.git";
    var opts = new NodeGit.CloneOptions();

    opts.ignoreCertErrors = 1;

    return Clone.clone(url, git, opts).then(function(repository) {
      assert.ok(repository instanceof Repository);
    });
  });

  it("can clone with filesystem", function() {
    var url = "file://" + path.resolve("test/repos/empty");

    return Clone.clone(url, file, null).then(function(repository) {
      assert.ok(repository instanceof Repository);
    });
  });
});
<|endoftext|>


<commit_before>'use strict'

const chai = require('chai')

const log = require('../../src/logger')

const assert = chai.assert

describe('logger', () => {
  it('should use return one stream by default', () => {
    const streams = log._getStreams()
    assert.lengthOf(streams, 1)
    assert.equal(streams[0].stream, process.stdout)
  })
})
<commit_msg>add unit test for default info level<commit_after>'use strict'

const chai = require('chai')

const log = require('../../src/logger')

const assert = chai.assert

describe('logger', () => {
  it('should use return one stream by default', () => {
    const streams = log._getStreams()
    assert.lengthOf(streams, 1)
    assert.equal(streams[0].stream, process.stdout)
  })

  describe('when LOG_LEVEL is not defined', () => {
    let prevLevel

    beforeEach(() => {
      prevLevel = process.env.LOG_LEVEL
      process.env.LOG_LEVEL = undefined
    })

    afterEach(() => {
      process.env.LOG_LEVEL = prevLevel
    })

    it('should default info level', () => {
      const streams = log._getStreams()
      assert.equal(streams[0].level, 'info')
    })
  })
})
<|endoftext|>


<commit_before>// RENDERING TESTS
// ===============
//
// This loads in the render.json sample file and checks that each compiled
// template, in combination with the sample data, produces the expected
// HTML.
//
// TODO: add moar samples

QUnit.config.reorder = false;

var fixture = document.getElementById( 'qunit-fixture' ), tests;

tests = [
	{
		name: "Empty model",
		template: "",
		result: ""
	},
	{
		name: "Plain text",
		template: "a string",
		result: "a string"
	},
	{
		name: "Single interpolator",
		template: "{{mustache}}",
		data: { mustache: "hello world" },
		result: "hello world"
	},
	{
		name: "Element containing single interpolator",
		template: "
{{mustache}}
",
		data: { mustache: "hello world" },
		result: "
hello world
"
	},
	{
		name: "Element containing interpolator surrounded by text",
		template: "
Hello {{mustache}}!
",
		data: { mustache: "world" },
		result: "
Hello world!
"
	},
	{
		name: "Section with index refs",
		template: "
{{#items:i}}
{{i}}: {{name}}
{{/items}}
",
		data: {
			items: [{name:"zero"},{name:"one"},{name:"two"}]
		},
		result: "

0: zero

1: one

2: two

"
	},
	{
		name: "Section with index refs in attributes",
		template: "
{{#items:i}}
{{name}}
{{/items}}
",
		data: {
			items: [{name:"zero"},{name:"one"},{name:"two"}]
		},
		result: "

zero

one

two

"
	},
	{
		name: "Element with attributes",
		template: "
text
",
		data: {
			"class_name": "it_works"
		},
		result: "
text
"
	},
	{
		name: "Section with descendant attributes",
		template: "{{#todos}}
{{todo}}{{todo}}
{{/todos}}",
		data: {
			todos: [{todo:"debug Ractive",status:"complete"},{todo:"release Ractive",status:"incomplete"}]
		},
		result: "
debug Ractivedebug Ractive

release Ractiverelease Ractive
"
	},
	{
		name: "Section with descendant value attributes",
		template: "{{#todos}}
{{todo}}<input value='{{todo}}'>
{{/todos}}",
		data: {
			todos: [{todo:"debug Ractive"},{todo:"release Ractive"}]
		},
		result: "
debug Ractive<input>

release Ractive<input>
"
	},
	{
		name: "Partials",
		template: "{{#items}}{{>item}}{{/items}}",
		data: {
			items: [{description:"Item the first"},{description:"Item the second"},{description:"Item the third"}]
		},
		partials: {
			item: "
{{description}}
"
		},
		result: "
Item the first

Item the second

Item the third
"
	},
	{
		name: 'Partials that compile as HTML',
		template: '
{{>partial}}
',
		data: { content: 'some text' },
		partials: { partial: '
{{content}}
' },
		result: '

some text

'
	},
	{
		name: 'Partials inherit index references',
		template: '
{{#items:i}}{{>item}}{{/items}}
',
		data: { items: [ 'zero', 'one', 'two', 'three' ] },
		partials: { item: '
{{i}}: {{.}}
' },
		result: '

0: zero

1: one

2: two

3: three

'
	},
	{
		name: "Empty string attributes",
		template: "
test
",
		result: "
test
"
	},
	{
		name: 'Attribute with sections',
		template: '
{{#todos:i}}
{{desc}}
{{/todos}}
',
		data: { todos: [{ desc: 'debug Ractive', completed: false }, { desc: 'release Ractive', completed: false }, { desc: 'make cup of tea', completed: true }]},
		result: '

debug Ractive

release Ractive

make cup of tea

'
	},
	{
		name: 'Conditional section with true condition',
		template: '{{#condition}}The condition is truthy{{/condition}}',
		data: { condition: true },
		result: 'The condition is truthy'
	},
	{
		name: 'Conditional section with false condition',
		template: '{{#condition}}The condition is truthy{{/condition}}',
		data: { condition: false },
		result: ''
	},
	{
		name: 'Inverted section with true condition',
		template: '{{^condition}}The condition is falsy{{/condition}}',
		data: { condition: true },
		result: ''
	},
	{
		name: 'Inverted section with false condition',
		template: '{{^condition}}The condition is falsy{{/condition}}',
		data: { condition: false },
		result: 'The condition is falsy'
	},
	{
		name: 'Triple',
		template: '
before {{{triple}}} after
',
		data: { triple: 'bold italic' },
		result: '
before bold italic after
',
		new_data: { triple: 'italic bold' },
		new_result: '
before italic bold after
'
	},
	{
		name: 'SVG',
		template: '<svg xmlns="http://www.w3.org/2000/svg"><circle cx="{{x}}" cy="{{y}}" r="{{r}}"/></svg>',
		data: { x: 50, y: 50, r: 50 },
		result: '<svg xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="50"></circle></svg>'
	},
	{
		name: 'SVG with non-mustache text',
		template: '<svg xmlns="http://www.w3.org/2000/svg"><text>some text</text></svg>',
		data: {},
		result: '<svg xmlns="http://www.w3.org/2000/svg"><text>some text</text></svg>'
	},
	{
		name: 'SVG with interpolator',
		template: '<svg xmlns="http://www.w3.org/2000/svg"><text>{{hello}}</text></svg>',
		data: { hello: 'Hello world!' },
		result: '<svg xmlns="http://www.w3.org/2000/svg"><text>Hello world!</text></svg>'
	},
	{
		name: 'SVG with interpolator and static text',
		template: '<svg xmlns="http://www.w3.org/2000/svg"><text>Hello {{thing}}!</text></svg>',
		data: { thing: 'world' },
		result: '<svg xmlns="http://www.w3.org/2000/svg"><text>Hello world!</text></svg>'
	},
	{
		name: 'Basic expression',
		template: '{{( "test".toUpperCase() )}}',
		result: 'TEST'
	},
	{
		name: 'Expression with a single reference',
		template: '{{( ref )}}',
		data: { ref: 'success' },
		result: 'success'
	},
	{
		name: 'Arithmetic expression',
		template: '{{( number * 2 )}}',
		data: { number: 10 },
		result: '20'
	},
	{
		name: 'Arithmetic expression with update',
		template: '{{( number * 2 )}}',
		data: { number: 10 },
		new_data: { number: 20 },
		result: '20',
		new_result: '40'
	},
	{
		name: 'Arithmetic expression with missing data',
		template: '{{( number * 2 )}}',
		result: ''
	},
	{
		name: 'Arithmetic expression with missing data and update',
		template: '{{( number * 2 )}}',
		new_data: { number: 20 },
		result: '',
		new_result: '40'
	},
	{
		name: 'Arithmetic expression with index reference',
		template: '
{{#items:i}}
{{( i + 1 )}}: {{.}}
{{/items}}
',
		data: { items: [ 'a', 'b', 'c' ] },
		result: '

1: a

2: b

3: c

'
	},
	{
		name: 'Conditional expression',
		template: '
{{desc}}{{( done ? "" : " (pending)" )}}
',
		data: { desc: 'Write more tests', done: true },
		result: '
Write more tests
',
		new_data: { done: false },
		new_result: '
Write more tests (pending)
'
	},
	{
		name: 'Invocation expression',
		template: '
The population of {{country}} is {{( format(population) )}}.
',
		data: {
			country: 'the UK',
			population: 62641000,
			format: function ( num ) {
				if ( num > 1000000000 ) return ( num / 1000000000 ).toFixed( 1 ) + ' billion';
				if ( num > 1000000 ) return ( num / 1000000 ).toFixed( 1 ) + ' million';
				if ( num > 1000 ) return ( Math.floor( num / 1000 ) ) + ',' + ( num % 1000 );
				return num;
			}
		},
		result: '
The population of the UK is 62.6 million.
'
	},
	{
		name: 'Responding to downstream changes',
		template: '
Total: {{( total( numbers ) )}}
',
		data: {
			numbers: [ 1, 2, 3, 4 ],
			total: function ( numbers ) {
				return numbers.reduce( function ( prev, curr ) {
					return prev + curr;
				});
			}
		},
		result: '
Total: 10
',
		new_data: {
			'numbers[4]': 5
		},
		new_result: '
Total: 15
'
	}
];

_.each( tests, function ( t, i ) {
	test( t.name, function () {
		console.group(i+1);

		var view;

		window.view = view = new Ractive({
			el: fixture,
			data: t.data,
			template: t.template,
			partials: t.partials
		});

		equal( fixture.innerHTML, t.result );

		if ( t.new_data ) {
			view.set( t.new_data );
			equal( fixture.innerHTML, t.new_result );
		}

		console.groupEnd();
	});
});<commit_msg>added some tests<commit_after>// RENDERING TESTS
// ===============
//
// This loads in the render.json sample file and checks that each compiled
// template, in combination with the sample data, produces the expected
// HTML.
//
// TODO: add moar samples

QUnit.config.reorder = false;

var fixture = document.getElementById( 'qunit-fixture' ), tests;

tests = [
	{
		name: "Empty model",
		template: "",
		result: ""
	},
	{
		name: "Plain text",
		template: "a string",
		result: "a string"
	},
	{
		name: "Single interpolator",
		template: "{{mustache}}",
		data: { mustache: "hello world" },
		result: "hello world"
	},
	{
		name: "Element containing single interpolator",
		template: "
{{mustache}}
",
		data: { mustache: "hello world" },
		result: "
hello world
"
	},
	{
		name: "Element containing interpolator surrounded by text",
		template: "
Hello {{mustache}}!
",
		data: { mustache: "world" },
		result: "
Hello world!
"
	},
	{
		name: "Section with index refs",
		template: "
{{#items:i}}
{{i}}: {{name}}
{{/items}}
",
		data: {
			items: [{name:"zero"},{name:"one"},{name:"two"}]
		},
		result: "

0: zero

1: one

2: two

"
	},
	{
		name: "Section with index refs in attributes",
		template: "
{{#items:i}}
{{name}}
{{/items}}
",
		data: {
			items: [{name:"zero"},{name:"one"},{name:"two"}]
		},
		result: "

zero

one

two

"
	},
	{
		name: "Element with attributes",
		template: "
text
",
		data: {
			"class_name": "it_works"
		},
		result: "
text
"
	},
	{
		name: "Section with descendant attributes",
		template: "{{#todos}}
{{todo}}{{todo}}
{{/todos}}",
		data: {
			todos: [{todo:"debug Ractive",status:"complete"},{todo:"release Ractive",status:"incomplete"}]
		},
		result: "
debug Ractivedebug Ractive

release Ractiverelease Ractive
"
	},
	{
		name: "Section with descendant value attributes",
		template: "{{#todos}}
{{todo}}<input value='{{todo}}'>
{{/todos}}",
		data: {
			todos: [{todo:"debug Ractive"},{todo:"release Ractive"}]
		},
		result: "
debug Ractive<input>

release Ractive<input>
"
	},
	{
		name: "Partials",
		template: "{{#items}}{{>item}}{{/items}}",
		data: {
			items: [{description:"Item the first"},{description:"Item the second"},{description:"Item the third"}]
		},
		partials: {
			item: "
{{description}}
"
		},
		result: "
Item the first

Item the second

Item the third
"
	},
	{
		name: 'Partials that compile as HTML',
		template: '
{{>partial}}
',
		data: { content: 'some text' },
		partials: { partial: '
{{content}}
' },
		result: '

some text

'
	},
	{
		name: 'Partials inherit index references',
		template: '
{{#items:i}}{{>item}}{{/items}}
',
		data: { items: [ 'zero', 'one', 'two', 'three' ] },
		partials: { item: '
{{i}}: {{.}}
' },
		result: '

0: zero

1: one

2: two

3: three

'
	},
	{
		name: "Empty string attributes",
		template: "
test
",
		result: "
test
"
	},
	{
		name: 'Attribute with sections',
		template: '
{{#todos:i}}
{{desc}}
{{/todos}}
',
		data: { todos: [{ desc: 'debug Ractive', completed: false }, { desc: 'release Ractive', completed: false }, { desc: 'make cup of tea', completed: true }]},
		result: '

debug Ractive

release Ractive

make cup of tea

'
	},
	{
		name: 'Conditional section with true condition',
		template: '{{#condition}}The condition is truthy{{/condition}}',
		data: { condition: true },
		result: 'The condition is truthy'
	},
	{
		name: 'Conditional section with false condition',
		template: '{{#condition}}The condition is truthy{{/condition}}',
		data: { condition: false },
		result: ''
	},
	{
		name: 'Inverted section with true condition',
		template: '{{^condition}}The condition is falsy{{/condition}}',
		data: { condition: true },
		result: ''
	},
	{
		name: 'Inverted section with false condition',
		template: '{{^condition}}The condition is falsy{{/condition}}',
		data: { condition: false },
		result: 'The condition is falsy'
	},
	{
		name: 'Triple',
		template: '
before {{{triple}}} after
',
		data: { triple: 'bold italic' },
		result: '
before bold italic after
',
		new_data: { triple: 'italic bold' },
		new_result: '
before italic bold after
'
	},
	{
		name: 'SVG',
		template: '<svg xmlns="http://www.w3.org/2000/svg"><circle cx="{{x}}" cy="{{y}}" r="{{r}}"/></svg>',
		data: { x: 50, y: 50, r: 50 },
		result: '<svg xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="50"></circle></svg>'
	},
	{
		name: 'SVG with non-mustache text',
		template: '<svg xmlns="http://www.w3.org/2000/svg"><text>some text</text></svg>',
		data: {},
		result: '<svg xmlns="http://www.w3.org/2000/svg"><text>some text</text></svg>'
	},
	{
		name: 'SVG with interpolator',
		template: '<svg xmlns="http://www.w3.org/2000/svg"><text>{{hello}}</text></svg>',
		data: { hello: 'Hello world!' },
		result: '<svg xmlns="http://www.w3.org/2000/svg"><text>Hello world!</text></svg>'
	},
	{
		name: 'SVG with interpolator and static text',
		template: '<svg xmlns="http://www.w3.org/2000/svg"><text>Hello {{thing}}!</text></svg>',
		data: { thing: 'world' },
		result: '<svg xmlns="http://www.w3.org/2000/svg"><text>Hello world!</text></svg>'
	},
	{
		name: 'Basic expression',
		template: '{{( "test".toUpperCase() )}}',
		result: 'TEST'
	},
	{
		name: 'Expression with a single reference',
		template: '{{( ref )}}',
		data: { ref: 'success' },
		result: 'success'
	},
	{
		name: 'Arithmetic expression',
		template: '{{( number * 2 )}}',
		data: { number: 10 },
		result: '20'
	},
	{
		name: 'Arithmetic expression with update',
		template: '{{( number * 2 )}}',
		data: { number: 10 },
		new_data: { number: 20 },
		result: '20',
		new_result: '40'
	},
	{
		name: 'Arithmetic expression with missing data',
		template: '{{( number * 2 )}}',
		result: ''
	},
	{
		name: 'Arithmetic expression with missing data and update',
		template: '{{( number * 2 )}}',
		new_data: { number: 20 },
		result: '',
		new_result: '40'
	},
	{
		name: 'Arithmetic expression with index reference',
		template: '
{{#items:i}}
{{( i + 1 )}}: {{.}}
{{/items}}
',
		data: { items: [ 'a', 'b', 'c' ] },
		result: '

1: a

2: b

3: c

'
	},
	{
		name: 'Conditional expression',
		template: '
{{desc}}{{( done ? "" : " (pending)" )}}
',
		data: { desc: 'Write more tests', done: true },
		result: '
Write more tests
',
		new_data: { done: false },
		new_result: '
Write more tests (pending)
'
	},
	{
		name: 'Invocation expression',
		template: '
The population of {{country}} is {{( format(population) )}}.
',
		data: {
			country: 'the UK',
			population: 62641000,
			format: function ( num ) {
				if ( num > 1000000000 ) return ( num / 1000000000 ).toFixed( 1 ) + ' billion';
				if ( num > 1000000 ) return ( num / 1000000 ).toFixed( 1 ) + ' million';
				if ( num > 1000 ) return ( Math.floor( num / 1000 ) ) + ',' + ( num % 1000 );
				return num;
			}
		},
		result: '
The population of the UK is 62.6 million.
'
	},
	{
		name: 'Responding to downstream changes',
		template: '
Total: {{( total( numbers ) )}}
',
		data: {
			numbers: [ 1, 2, 3, 4 ],
			total: function ( numbers ) {
				return numbers.reduce( function ( prev, curr ) {
					return prev + curr;
				});
			}
		},
		result: '
Total: 10
',
		new_data: {
			'numbers[4]': 5
		},
		new_result: '
Total: 15
'
	},
	{
		name: 'Attribute with nested mustaches',
		template: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="{{#viewBox}}{{x}} {{y}} {{width}} {{height}}{{/viewBox}}">{{#rect}}<rect x="{{x}}" y="{{y}}" width="{{width}}" height="{{height}}"/>{{/rect}}</svg>',
		data: {
			viewBox: { x: 0,  y: 0,  width: 100, height: 100 },
			rect:    { x: 10, y: 10, width: 80,  height: 80  }
		},
		result: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="10" y="10" width="80" height="80"></rect></svg>',
		new_data: {
			viewBox: { x: 50,  y: 50,  width: 350, height: 350 },
			rect:    { x: 20,  y: 20,  width: 200, height: 100 }
		},
		new_result: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="50 50 350 350"><rect x="20" y="20" width="200" height="100"></rect></svg>'
	},
	{
		name: 'List section with non-self-updating attributes',
		template: '
{{#items}}

{{/items}}
',
		data: {
			items: [{ info: { a: 1, b: 2, c: 3 } }]
		},
		result: '

',
		new_data: {
			items: [{ info: { a: 1, b: 2, c: 3 } }, { info: { a: 4, b: 5, c: 6 } }]
		},
		new_result: '

'
	},
	{
		name: 'Section with non-explicitly-closed element',
		template: '
{{#items}}
{{.}}{{/items}}
',
		data: { items: [ 'a', 'b', 'c' ]},
		result: '

a

b

c

',
		new_data: { items: [ 'd', 'e', 'f' ]},
		new_result: '

d

e

f

'
	},
	{
		name: 'Whitespace is stripped from start and end of templates',
		template: '
{{content}}
      ',
		data: { content: 'test' },
		result: '
test
'
	},
	{
		name: 'Whitespace is stripped from start and end of templates without mustaches',
		template: '
test
      ',
		result: '
test
'
	}
];

_.each( tests, function ( t, i ) {
	test( t.name, function () {
		console.group(i+1);

		var view;

		window.view = view = new Ractive({
			el: fixture,
			data: t.data,
			template: t.template,
			partials: t.partials
		});

		equal( fixture.innerHTML, t.result );

		if ( t.new_data ) {
			view.set( t.new_data );
			equal( fixture.innerHTML, t.new_result );
		}

		console.groupEnd();
	});
});<|endoftext|>


<commit_before>const testUtils = require('./testUtils');
const matTestUtils = require('./matTestUtils');
const defaultTests = require('./defaultTests');

const getNodeMajorVersion = () => parseInt(process.version.split('.')[0].slice(1))

module.exports = Object.assign(
  {},
  testUtils,
  matTestUtils,
  defaultTests,
  getNodeMajorVersion
);
<commit_msg>export utils.getMajorNodeVersion properly<commit_after>const testUtils = require('./testUtils');
const matTestUtils = require('./matTestUtils');
const defaultTests = require('./defaultTests');

const getNodeMajorVersion = () => parseInt(process.version.split('.')[0].slice(1))

module.exports = Object.assign(
  {},
  testUtils,
  matTestUtils,
  defaultTests,
  { getNodeMajorVersion }
);
<|endoftext|>


<commit_before>var assert = require('assert');
var toBase64 = require('..');

describe('UUID to Base64', function () {
  it ('should compress UUID to 22 characters', function () {
    var id = toBase64('0e8c72e5-463f-446e-bcf2-695274d55940');
    assert(id.length == 22);
  });
});<commit_msg>Release 0.0.2<commit_after>var assert = require('assert');
var toBase64 = require('..');

describe('UUID to Base64', function () {
  it ('should compress UUID to 22 characters', function () {
    var id = toBase64('38cb87b5-b23a-481e-8373-b238e5e864c4');
    assert(id.length == 22);
  });
});<|endoftext|>