<commit_before>'use strict'

const test = require('tap').test
const hashring = require('.')
const steed = require('steed')
const baseswim = require('baseswim')
const farmhash = require('farmhash')
const maxInt = Math.pow(2, 32) - 1

function boot (t, root, cb) {
  if (typeof root === 'function') {
    cb = root
    root = null
  }
  const opts = {
    joinTimeout: 1000
  }
  if (root) {
    opts.base = [root.whoami()]
  }
  const peer = hashring(opts)
  t.setMaxListeners(100)
  t.tearDown(peer.close.bind(peer))
  peer.on('error', t.fail.bind(t))
  peer.on('up', () => {
    t.pass('peer up')
    cb(peer)
  })
  return peer
}

function bootN (t, num, cb) {
  num = num - 1
  boot(t, (root) => {
    const peers = new Array(num)
    steed.map(peers, (peer, cb) => {
      boot(t, root, (peer) => cb(null, peer))
    }, (err, peers) => {
      t.error(err)
      if (err) {
        return
      }
      peers.unshift(root)
      cb(peers)
    })
  })
}

test('two peer lookup', (t) => {
  t.plan(10)

  const key = 'hello'
  boot(t, (i1) => {
    boot(t, i1, (i2) => {
      let v1 = i1.lookup(key)
      let v2 = i2.lookup(key)
      t.deepEqual(v1, v2, 'both instances look up correctly')

      t.ok(v1, 'value is not null')
      t.ok(i1.mymeta(), 'i1 metadata is not null')
      t.ok(i2.mymeta(), 'i2 metadata is not null')
      t.deepEqual(i1.lookup(key), i1.lookup(i1.hash(key)), 'lookup by hash')

      if (v1.id === i1.whoami()) {
        t.deepEqual(v1, i1.mymeta(), 'hello is matched by i1')
        t.ok(i1.allocatedToMe(key), 'key is allocated to i1')
        t.notOk(i2.allocatedToMe(key), 'key is not allocated to i2')
      } else if (v1.id === i2.whoami()) {
        t.deepEqual(v1, i2.mymeta(), 'hello is matched by i2')
        t.ok(i2.allocatedToMe(key), 'key is allocated to i2')
        t.notOk(i1.allocatedToMe(key), 'key is not allocated to i1')
      } else {
        t.fail('value does not match any known peer')
      }
    })
  })
})

test('peers()', (t) => {
  t.plan(4)

  boot(t, (i1) => {
    boot(t, i1, (i2) => {
      t.deepEqual(i1.peers(), [i2.mymeta()], 'peers matches')
      t.deepEqual(i1.peers(true), [i2.mymeta(), i1.mymeta()], 'peers with myself matches')
    })
  })
})

test('10 peers', (t) => {
  t.plan(23)

  const key = 'hello'
  bootN(t, 10, (peers) => {
    const root = peers[0]
    let value = root.lookup(key)
    for (let i = 0; i < peers.length; i++) {
      let current = peers[i].lookup(key)
      t.deepEqual(value.id, current.id, 'both instances look up correctly')
    }
    let computedPeers = root.peers()
    t.equal(computedPeers.length, peers.length - 1, 'all peers minus one')
    computedPeers = computedPeers.filter((peer) => {
      return !peers.reduce((acc, p) => acc || p.whoami() === peer.id, false)
    })
    t.equal(computedPeers.length, 0, 'all peers accounted for')
  })
})

test('is compatible with swim', (t) => {
  t.plan(11)
  boot(t, (root) => {
    const peer = baseswim({
      joinTimeout: 200,
      base: [root.whoami()]
    })

    t.tearDown(peer.leave.bind(peer))
    peer.on('up', () => {
      let key = 'hello'
      for (let i = 0; i < 10; i++) {
        t.deepEqual(root.lookup(key), root.mymeta(), 'key is matched by root')
        key += farmhash.hash32(key)
      }
    })
  })
})

test('move event', { timeout: 5000 }, (t) => {
  let events = 0
  let moved = 0
  boot(t, (i1) => {
    const i1id = i1.whoami()
    let receivedPeer
    i1.on('move', (moveEvent) => {
      t.ok(Number.isInteger(moveEvent.start), 'start exists')
      t.ok(Number.isInteger(moveEvent.end), 'end exists')
      t.ok(moveEvent.start < moveEvent.end, 'start < end')
      t.ok(moveEvent.to, 'peer exists')
      const key = moveEvent.end - 1
      t.notOk(i1.allocatedToMe(key), 'not allocated to me')
      receivedPeer = moveEvent.to
      t.notEqual(moveEvent.to.id, i1id, 'id of the other peer')
      moved += moveEvent.end - moveEvent.start
      events++
    })
    boot(t, i1, (i2) => {
      t.deepEqual(receivedPeer, i2.mymeta(), 'peer matches')
    })

    i1.on('peerUp', () => {
      setTimeout(() => {
        t.pass('got ' + events + ' moves')
        t.ok(events > 10, 'some overlap')
        let movedPercent = Math.round(moved / maxInt * 1000) / 1000
        t.ok(movedPercent >= 0.40, 'at least 40% is reallocated, got: ' + movedPercent)
        t.ok(movedPercent <= 1, 'we reallocate at most 100%, got: ' + movedPercent)
        t.end()
      }, 1000)
    })
  })
})

test('client', (t) => {
  t.plan(4)

  boot(t, (i1) => {
    boot(t, i1, (i2) => {
      const client = hashring({
        client: true,
        joinTimeout: 1000,
        base: [i1.whoami(), i2.whoami()]
      })
      t.tearDown(client.close.bind(client))
      client.on('error', t.fail.bind(t))
      client.on('up', () => {
        t.pass('client up')
        for (var i = 0; i < maxInt; i += 1000) {
          if (client.allocatedToMe(i) || i1.lookup(i).id === client.whoami()) {
            t.fail('data allocated to a client')
            return
          }
        }
        t.pass('no errors')
      })
    })
  })
})

test('steal event', { timeout: 5000 }, (t) => {
  let stolen = 0
  let moved = 0
  boot(t, (i1) => {
    i1.on('move', (moveEvent) => {
      moved += moveEvent.end - moveEvent.start
    })
    boot(t, i1, (i2) => {
      i1.on('steal', (stealEvent) => {
        t.ok(Number.isInteger(stealEvent.start), 'start exists')
        t.ok(Number.isInteger(stealEvent.end), 'end exists')
        t.ok(stealEvent.start < stealEvent.end, 'start < end')
        t.ok(stealEvent.from, 'peer exists')
        t.deepEqual(i2.mymeta(), stealEvent.from, 'peer matches')
        stolen += stealEvent.end - stealEvent.start
      })
      i1.on('peerDown', () => {
        let stolenPercent = Math.round(stolen / maxInt * 1000) / 1000
        t.ok(stolenPercent >= 0.40, 'at least 40% is reallocated, got: ' + stolenPercent)
        t.ok(stolenPercent <= 1, 'we reallocate at most 100%, got: ' + stolenPercent)
        const difference = stolen - moved
        t.equal(difference, 0, 'the difference between stolen and moved')
        t.equal(stolen, moved, 'same amount of the ring is stolen and moved')
        t.end()
      })
      i2.close()
    })
  })
})

test('next peer lookup', (t) => {
  t.plan(7)

  const key = 'hello'
  boot(t, (i1) => {
    boot(t, i1, (i2) => {
      let v1 = i1.lookup(key)
      let next = i1.next(key)
      t.ok(v1, 'value is not null')
      t.ok(next, 'value is not null')

      t.notEqual(v1.id, next.id, 'ids does not match')

      if (v1.id === i1.whoami()) {
        t.deepEqual(next, i2.mymeta(), 'hello.next is matched by i2')
      } else if (v1.id === i2.whoami()) {
        t.deepEqual(next, i1.mymeta(), 'hello.next is matched by i1')
      } else {
        t.fail('value does not match any known peer')
      }

      next = i1.next(key, [next.id])
      t.notOk(next, 'no next for circuit breaking support')
    })
  })
})
<commit_msg>Removed useless setTimeout.<commit_after>'use strict'

const test = require('tap').test
const hashring = require('.')
const steed = require('steed')
const baseswim = require('baseswim')
const farmhash = require('farmhash')
const maxInt = Math.pow(2, 32) - 1

function boot (t, root, cb) {
  if (typeof root === 'function') {
    cb = root
    root = null
  }
  const opts = {
    joinTimeout: 1000
  }
  if (root) {
    opts.base = [root.whoami()]
  }
  const peer = hashring(opts)
  t.setMaxListeners(100)
  t.tearDown(peer.close.bind(peer))
  peer.on('error', t.fail.bind(t))
  peer.on('up', () => {
    t.pass('peer up')
    cb(peer)
  })
  return peer
}

function bootN (t, num, cb) {
  num = num - 1
  boot(t, (root) => {
    const peers = new Array(num)
    steed.map(peers, (peer, cb) => {
      boot(t, root, (peer) => cb(null, peer))
    }, (err, peers) => {
      t.error(err)
      if (err) {
        return
      }
      peers.unshift(root)
      cb(peers)
    })
  })
}

test('two peer lookup', (t) => {
  t.plan(10)

  const key = 'hello'
  boot(t, (i1) => {
    boot(t, i1, (i2) => {
      let v1 = i1.lookup(key)
      let v2 = i2.lookup(key)
      t.deepEqual(v1, v2, 'both instances look up correctly')

      t.ok(v1, 'value is not null')
      t.ok(i1.mymeta(), 'i1 metadata is not null')
      t.ok(i2.mymeta(), 'i2 metadata is not null')
      t.deepEqual(i1.lookup(key), i1.lookup(i1.hash(key)), 'lookup by hash')

      if (v1.id === i1.whoami()) {
        t.deepEqual(v1, i1.mymeta(), 'hello is matched by i1')
        t.ok(i1.allocatedToMe(key), 'key is allocated to i1')
        t.notOk(i2.allocatedToMe(key), 'key is not allocated to i2')
      } else if (v1.id === i2.whoami()) {
        t.deepEqual(v1, i2.mymeta(), 'hello is matched by i2')
        t.ok(i2.allocatedToMe(key), 'key is allocated to i2')
        t.notOk(i1.allocatedToMe(key), 'key is not allocated to i1')
      } else {
        t.fail('value does not match any known peer')
      }
    })
  })
})

test('peers()', (t) => {
  t.plan(4)

  boot(t, (i1) => {
    boot(t, i1, (i2) => {
      t.deepEqual(i1.peers(), [i2.mymeta()], 'peers matches')
      t.deepEqual(i1.peers(true), [i2.mymeta(), i1.mymeta()], 'peers with myself matches')
    })
  })
})

test('10 peers', (t) => {
  t.plan(23)

  const key = 'hello'
  bootN(t, 10, (peers) => {
    const root = peers[0]
    let value = root.lookup(key)
    for (let i = 0; i < peers.length; i++) {
      let current = peers[i].lookup(key)
      t.deepEqual(value.id, current.id, 'both instances look up correctly')
    }
    let computedPeers = root.peers()
    t.equal(computedPeers.length, peers.length - 1, 'all peers minus one')
    computedPeers = computedPeers.filter((peer) => {
      return !peers.reduce((acc, p) => acc || p.whoami() === peer.id, false)
    })
    t.equal(computedPeers.length, 0, 'all peers accounted for')
  })
})

test('is compatible with swim', (t) => {
  t.plan(11)
  boot(t, (root) => {
    const peer = baseswim({
      joinTimeout: 200,
      base: [root.whoami()]
    })

    t.tearDown(peer.leave.bind(peer))
    peer.on('up', () => {
      let key = 'hello'
      for (let i = 0; i < 10; i++) {
        t.deepEqual(root.lookup(key), root.mymeta(), 'key is matched by root')
        key += farmhash.hash32(key)
      }
    })
  })
})

test('move event', { timeout: 5000 }, (t) => {
  let events = 0
  let moved = 0
  boot(t, (i1) => {
    const i1id = i1.whoami()
    let receivedPeer
    i1.on('move', (moveEvent) => {
      t.ok(Number.isInteger(moveEvent.start), 'start exists')
      t.ok(Number.isInteger(moveEvent.end), 'end exists')
      t.ok(moveEvent.start < moveEvent.end, 'start < end')
      t.ok(moveEvent.to, 'peer exists')
      const key = moveEvent.end - 1
      t.notOk(i1.allocatedToMe(key), 'not allocated to me')
      receivedPeer = moveEvent.to
      t.notEqual(moveEvent.to.id, i1id, 'id of the other peer')
      moved += moveEvent.end - moveEvent.start
      events++
    })
    boot(t, i1, (i2) => {
      t.deepEqual(receivedPeer, i2.mymeta(), 'peer matches')
      t.pass('got ' + events + ' moves')
      t.ok(events > 10, 'some overlap')
      let movedPercent = Math.round(moved / maxInt * 1000) / 1000
      t.ok(movedPercent >= 0.40, 'at least 40% is reallocated, got: ' + movedPercent)
      t.ok(movedPercent <= 1, 'we reallocate at most 100%, got: ' + movedPercent)
      t.end()
    })
  })
})

test('client', (t) => {
  t.plan(4)

  boot(t, (i1) => {
    boot(t, i1, (i2) => {
      const client = hashring({
        client: true,
        joinTimeout: 1000,
        base: [i1.whoami(), i2.whoami()]
      })
      t.tearDown(client.close.bind(client))
      client.on('error', t.fail.bind(t))
      client.on('up', () => {
        t.pass('client up')
        for (var i = 0; i < maxInt; i += 1000) {
          if (client.allocatedToMe(i) || i1.lookup(i).id === client.whoami()) {
            t.fail('data allocated to a client')
            return
          }
        }
        t.pass('no errors')
      })
    })
  })
})

test('steal event', { timeout: 5000 }, (t) => {
  let stolen = 0
  let moved = 0
  boot(t, (i1) => {
    i1.on('move', (moveEvent) => {
      moved += moveEvent.end - moveEvent.start
    })
    boot(t, i1, (i2) => {
      i1.on('steal', (stealEvent) => {
        t.ok(Number.isInteger(stealEvent.start), 'start exists')
        t.ok(Number.isInteger(stealEvent.end), 'end exists')
        t.ok(stealEvent.start < stealEvent.end, 'start < end')
        t.ok(stealEvent.from, 'peer exists')
        t.deepEqual(i2.mymeta(), stealEvent.from, 'peer matches')
        stolen += stealEvent.end - stealEvent.start
      })
      i1.on('peerDown', () => {
        let stolenPercent = Math.round(stolen / maxInt * 1000) / 1000
        t.ok(stolenPercent >= 0.40, 'at least 40% is reallocated, got: ' + stolenPercent)
        t.ok(stolenPercent <= 1, 'we reallocate at most 100%, got: ' + stolenPercent)
        const difference = stolen - moved
        t.equal(difference, 0, 'the difference between stolen and moved')
        t.equal(stolen, moved, 'same amount of the ring is stolen and moved')
        t.end()
      })
      i2.close()
    })
  })
})

test('next peer lookup', (t) => {
  t.plan(7)

  const key = 'hello'
  boot(t, (i1) => {
    boot(t, i1, (i2) => {
      let v1 = i1.lookup(key)
      let next = i1.next(key)
      t.ok(v1, 'value is not null')
      t.ok(next, 'value is not null')

      t.notEqual(v1.id, next.id, 'ids does not match')

      if (v1.id === i1.whoami()) {
        t.deepEqual(next, i2.mymeta(), 'hello.next is matched by i2')
      } else if (v1.id === i2.whoami()) {
        t.deepEqual(next, i1.mymeta(), 'hello.next is matched by i1')
      } else {
        t.fail('value does not match any known peer')
      }

      next = i1.next(key, [next.id])
      t.notOk(next, 'no next for circuit breaking support')
    })
  })
})
<|endoftext|>


<commit_before>import test from 'ava'

import identifierfy from './'

test('prefixes reserved words with an underscore', t => {
  t.is(identifierfy('class'), '_class')
  t.is(identifierfy('class', { prefixInvalidIdentifiers: false }), '_class')
})

test('does not prefix reserved words with an underscore, if directed', t => {
  t.is(identifierfy('class', { prefixReservedWords: false }), 'class')
})

test('prefixes characters that cannot start as an identifier with an underscore', t => {
  t.is(identifierfy('42'), '_42')
  t.is(identifierfy('42', { prefixReservedWords: false }), '_42')
})

test('does not prefix characters that cannot start as an identifier with an underscore, if directed', t => {
  t.is(identifierfy('42', { prefixInvalidIdentifiers: false }), '42')
})

test('leaves good names as-is', t => {
  t.is(identifierfy('good'), 'good')
})

test('drops illegal characters at the front of the name, without uppercasing', t => {
  t.is(identifierfy('-foo'), 'foo')
})

test('drops illegal characters, uppercasing the character that follows', t => {
  t.is(identifierfy('foo-bar🙊baz'), 'fooBarBaz')
})

test('not all characters can be upper cased', t => {
  t.is(identifierfy('foo-9'), 'foo9')
})

test('returns null if no characters from the original name could be used', t => {
  t.is(identifierfy('💩'), null)
})
<commit_msg>fix standard violations<commit_after>import test from 'ava'

import identifierfy from './'

test('prefixes reserved words with an underscore', (t) => {
  t.is(identifierfy('class'), '_class')
  t.is(identifierfy('class', { prefixInvalidIdentifiers: false }), '_class')
})

test('does not prefix reserved words with an underscore, if directed', (t) => {
  t.is(identifierfy('class', { prefixReservedWords: false }), 'class')
})

test('prefixes characters that cannot start as an identifier with an underscore', (t) => {
  t.is(identifierfy('42'), '_42')
  t.is(identifierfy('42', { prefixReservedWords: false }), '_42')
})

test('does not prefix characters that cannot start as an identifier with an underscore, if directed', (t) => {
  t.is(identifierfy('42', { prefixInvalidIdentifiers: false }), '42')
})

test('leaves good names as-is', (t) => {
  t.is(identifierfy('good'), 'good')
})

test('drops illegal characters at the front of the name, without uppercasing', (t) => {
  t.is(identifierfy('-foo'), 'foo')
})

test('drops illegal characters, uppercasing the character that follows', (t) => {
  t.is(identifierfy('foo-bar🙊baz'), 'fooBarBaz')
})

test('not all characters can be upper cased', (t) => {
  t.is(identifierfy('foo-9'), 'foo9')
})

test('returns null if no characters from the original name could be used', (t) => {
  t.is(identifierfy('💩'), null)
})
<|endoftext|>


<commit_before>var Crawler = require("./lib/crawler");
var url = require('url');

var c = new Crawler({
    maxConnections : 10,
    //This will be called for each crawled page
    callback : function (error, result, $) {
        //$ is Cheerio by default
        //a lean implementation of core jQuery designed specifically for the server
        $('a').each(function(index, a) {
            var toQueueUrl = $(a).attr('href');
            console.log(toQueueUrl);
        });
    }
});

//Queue just one URL, with default callback
c.queue('http://google.com');

//Queue a list of URLs
c.queue(['http://youtube.com/','http://google.com']);
console.log("got passed second.");

//Queue URLs with custom callbacks & parameters
c.queue([{
    uri: 'http://parishackers.org/',
    jQuery: false,

    // The global callback won't be called
    callback: function (error, result) {
        console.log('Grabbed', result.body.length, 'bytes');
    }
}]);
console.log("got passed third.");

//Queue using a function
var googleSearch = function(search) {
    return 'http://www.google.fr/search?q=' + search;
};
c.queue({
    uri: googleSearch('cheese')
});
console.log("got passed fourth.");

//Queue some HTML code directly without grabbing (mostly for tests)
c.queue([{
    html: '
This is a test
'
}]);
<commit_msg>Completed changes to push to contribute.<commit_after><|endoftext|>


<commit_before>var test_cases = [
    0, "127.0.0.1",
    0, "qq.com",
    0, "im.qq.com",
    0, "www.imqq.com",
    1, "qqq.com",
    1, "google.com",
    1, "www.google.com"
];

function isPlainHostName(host) {
    return false;
}
function test(url, host) {
    ret = FindProxyForURL(url, host);
    if ( ret === direct )
        return 0;
    else
        return 1;
}

function output_result(out_obj) {
    output.value = "";
    for (var j = 0; j < test_cases.length; j+=2) {
        var test_case = test_cases[j+1];
        var test_result = test(test_case, test_case);
        var out_line = "" + test_result + " " + test_case + " ";
        if ( test_result === test_cases[j] ) {
            out_line = out_line + "Pass";
        } else {
            out_line = out_line + "NOT Pass";
        }
        out_obj.value = out_obj.value + out_line + "\n";
    }
}

function begin_test() {
    var output = document.getElementById("output");
    output_result( output );
}

<commit_msg>add localhost testcase<commit_after>var test_cases = [
    0, "127.0.0.1",
    0, "qq.com",
    0, "im.qq.com",
    0, "www.imqq.com",
    1, "qqq.com",
    1, "google.com",
    1, "www.google.com",
    0, "localhost"
];

function isPlainHostName(host) {
    if ( host.toLowerCase() == 'localhost' )
        return true;
    return false;
}
function test(url, host) {
    ret = FindProxyForURL(url, host);
    if ( ret === direct )
        return 0;
    else
        return 1;
}

function output_result(out_obj) {
    output.value = "";
    for (var j = 0; j < test_cases.length; j+=2) {
        var test_case = test_cases[j+1];
        var test_result = test(test_case, test_case);
        var out_line = "" + test_result + " " + test_case + " ";
        if ( test_result === test_cases[j] ) {
            out_line = out_line + "Pass";
        } else {
            out_line = out_line + "NOT Pass";
        }
        out_obj.value = out_obj.value + out_line + "\n";
    }
}

function begin_test() {
    var output = document.getElementById("output");
    output_result( output );
}

<|endoftext|>


<commit_before>/*!
 * filename-regex <https://github.com/regexps/filename-regex>
 *
 * Copyright (c) 2014-2015, Jon Schlinkert
 * Licensed under the MIT License
 */

'use strict';

var assert = require('assert');
var re = require('./');

function match(str) {
  return str.match(re());
}

it('should match the last part of a file path:', function () {
  assert.equal(match('')[0], '');
  assert.equal(match('a')[0], 'a');
  assert.equal(match('a/b')[0], 'b');
  assert.equal(match('a/b/c/d')[0], 'd');
  assert.equal(match('a/b/c/d')[1], 'd');
  assert.equal(match('a/b/c/d')[2], '');
  assert.equal(match('a/b/c/d')[3], null);
  assert.equal(match('a/b/c/d')[4], null);
});

it('should match the parts in a filename:', function () {
  assert.equal(match('abc/xyz.md')[0], 'xyz.md');
  assert.equal(match('abc/xyz.md')[1], 'xyz');
  assert.equal(match('abc/xyz.md')[2], '.md');
  assert.equal(match('abc/xyz.md')[3], '.md');
  assert.equal(match('abc/xyz.md')[4], 'md');
});

it('should match a file extension:', function () {
  assert.equal(match('.md')[0], '.md');
  assert.equal(match('.md')[1], '');
  assert.equal(match('.md')[2], '.md');
  assert.equal(match('.md')[3], '.md');
  assert.equal(match('.md')[4], 'md');
});

it('should match a dotfile:', function () {
  assert.equal(match('abc/.gitignore')[0], '.gitignore');
  assert.equal(match('abc/.gitignore')[1], '');
  assert.equal(match('abc/.gitignore')[2], '.gitignore');
  assert.equal(match('abc/.gitignore')[3], '.gitignore');
  assert.equal(match('abc/.gitignore')[4], 'gitignore');
});

it('should match a path with dots in the dirname:', function () {
  assert.equal(match('a/.b/abc.foo.min.js')[0], 'abc.foo.min.js');
  assert.equal(match('a/.b/abc.foo.min.js')[1], 'abc');
  assert.equal(match('a/.b/abc.foo.min.js')[2], '.foo.min.js');
  assert.equal(match('a/.b/abc.foo.min.js')[3], '.js');
  assert.equal(match('a/.b/abc.foo.min.js')[4], 'js');
});
<commit_msg>update tests<commit_after>/*!
 * filename-regex <https://github.com/regexps/filename-regex>
 *
 * Copyright (c) 2014-2015, Jon Schlinkert
 * Licensed under the MIT License
 */

'use strict';

var assert = require('assert');
var re = require('./');

function match(str) {
  var res = str.match(re())
  return res && res[0];
}

it('should match the last part of a file path:', function () {
  assert.equal(match(''), null);
  assert.equal(match('a'), 'a');
  assert.equal(match('a/b'), 'b');
  assert.equal(match('a/b/c/d'), 'd');
  assert.equal(match('a\\b\\c\\d'), 'd');
});

it('should match a filename with an extension:', function () {
  assert.equal(match('abc/xyz.md'), 'xyz.md');
  assert.equal(match('abc\\xyz.md'), 'xyz.md');
  assert.equal(match('b.md'), 'b.md');
});

it('should match a file name that is only a dotfile or file extension:', function () {
  assert.equal(match('.md'), '.md');
  assert.equal(match('.dotfile'), '.dotfile');
  assert.equal(match('abc\\.gitignore'), '.gitignore');
  assert.equal(match('abc/.gitignore'), '.gitignore');
});

it('should match the filename when there are dots in the dirname:', function () {
  assert.equal(match('a/.b/abc.foo.min.js'), 'abc.foo.min.js');
  assert.equal(match('a/b.c.d/foo.js'), 'foo.js');
});
<|endoftext|>


<commit_before>var fs = require('fs');
var expect = require('chai').expect;
var RandStream = require('randstream');
var TruncateStream = require('truncate-stream');
var DevNullStream = require('dev-null-stream');
var concat = require('concat-stream');

var peek = require('./buffer-peek-stream');

function make(size, mode) {
  return (new RandStream({mode: mode || 'pseudo'})).pipe(new TruncateStream({maxBytes: size}));
}

describe('peek', function() {
  this.timeout(250);

  it('should callback with a buffer', function (done) {
    var source = make(50000);
    peek(source, 50000, function (err, buffer) {
      if (err) return done(err);
      expect(buffer).to.be.an.instanceof(Buffer);
      done();
    }).pipe(new DevNullStream());
  });

  it('should callback with exactly the number of bytes requested', function (done) {
    peek(make(50000), 1000, function (err, buffer) {
      if (err) return done(err);
      expect(buffer).to.have.lengthOf(1000);
      done();
    });
  });

  it('should callback with all bytes when peeking more than is available', function (done) {
    peek(make(1000), 5000, function (err, buffer) {
      if (err) return done(err);
      expect(buffer).to.have.lengthOf(1000);
      done();
    });
  });

  it('should callback with a stream which receives all bytes', function (done) {
    var source = make(50000);
    peek(source, 1000, function (err, buffer, stream) {
      if (err) return done(err);
      stream.pipe(concat(function (data) {
        expect(data).to.have.lengthOf(50000);
        done();
      }));
    });
  });

  it('should return a stream which receives all bytes', function (done) {
    peek(make(5000), 1000, function () {}).pipe(concat(function (data) {
      expect(data).to.have.lengthOf(5000);
      done();
    }));
  });

  it('should return the same stream as it calls back', function (done) {
    var res = peek(make(5000), 1000, function (err, buffer, stream) {
      if (err) return done(err);
      expect(stream).to.equal(res);
      done();
    });
  });

  it('should peek 65536 bytes by default', function (done) {
    peek(make(100000), function (err, buffer) {
      if (err) return done(err);
      expect(buffer).to.have.lengthOf(65536);
      done();
    });
  });

  it('should work when peeked more once in a pipeline', function (done) {
    peek(make(100000), 50000, function (err, first, stream) {
      if (err) return done(err);
      expect(first).to.have.lengthOf(50000);
      peek(stream, 40000, function (err, second, stream) {
        if (err) return done(err);
        expect(second).to.have.lengthOf(40000);
        expect(second).to.eql(first.slice(0, 40000));
        stream.pipe(concat(function (data) {
          expect(data).to.have.lengthOf(100000);
          expect(first).to.eql(data.slice(0, 50000));
          expect(second).to.eql(data.slice(0, 40000));
          done();
        }));
      });
    });
  });

  //TODO: peeking inside gzip data (transform)

  //TODO: peeking a http response
});<commit_msg>add http stream test<commit_after>var fs = require('fs');
var expect = require('chai').expect;
var RandStream = require('randstream');
var TruncateStream = require('truncate-stream');
var DevNullStream = require('dev-null-stream');
var concat = require('concat-stream');
var http = require('http');

var peek = require('./buffer-peek-stream');

function make(size, mode) {
  return (new RandStream({mode: mode || 'pseudo'})).pipe(new TruncateStream({maxBytes: size}));
}

describe('peek', function() {
  this.timeout(250);

  it('should callback with a buffer', function (done) {
    var source = make(50000);
    peek(source, 50000, function (err, buffer) {
      if (err) return done(err);
      expect(buffer).to.be.an.instanceof(Buffer);
      done();
    }).pipe(new DevNullStream());
  });

  it('should callback with exactly the number of bytes requested', function (done) {
    peek(make(50000), 1000, function (err, buffer) {
      if (err) return done(err);
      expect(buffer).to.have.lengthOf(1000);
      done();
    });
  });

  it('should callback with all bytes when peeking more than is available', function (done) {
    peek(make(1000), 5000, function (err, buffer) {
      if (err) return done(err);
      expect(buffer).to.have.lengthOf(1000);
      done();
    });
  });

  it('should callback with a stream which receives all bytes', function (done) {
    var source = make(50000);
    peek(source, 1000, function (err, buffer, stream) {
      if (err) return done(err);
      stream.pipe(concat(function (data) {
        expect(data).to.have.lengthOf(50000);
        done();
      }));
    });
  });

  it('should return a stream which receives all bytes', function (done) {
    peek(make(5000), 1000, function () {}).pipe(concat(function (data) {
      expect(data).to.have.lengthOf(5000);
      done();
    }));
  });

  it('should return the same stream as it calls back', function (done) {
    var res = peek(make(5000), 1000, function (err, buffer, stream) {
      if (err) return done(err);
      expect(stream).to.equal(res);
      done();
    });
  });

  it('should peek 65536 bytes by default', function (done) {
    peek(make(100000), function (err, buffer) {
      if (err) return done(err);
      expect(buffer).to.have.lengthOf(65536);
      done();
    });
  });

  it('should work when peeked more once in a pipeline', function (done) {
    peek(make(100000), 50000, function (err, first, stream) {
      if (err) return done(err);
      expect(first).to.have.lengthOf(50000);
      peek(stream, 40000, function (err, second, stream) {
        if (err) return done(err);
        expect(second).to.have.lengthOf(40000);
        expect(second).to.eql(first.slice(0, 40000));
        stream.pipe(concat(function (data) {
          expect(data).to.have.lengthOf(100000);
          expect(first).to.eql(data.slice(0, 50000));
          expect(second).to.eql(data.slice(0, 40000));
          done();
        }));
      });
    });
  });

  //TODO: peeking inside gzip data (transform)

  this.timeout(10000);
  it('should peek an IncomingMessage stream', (done) => {

    http.get('http://nodejs.org/dist/index.json', (res) => {
      const statusCode = res.statusCode;

      if (statusCode !== 200) {
        return done(new Error(`Request Failed [${statusCode}]`));
      }

      peek(res, 1000, function (err, data, stream) {
        if (err) return done(err);
        const index_json = data.toString();
        expect(index_json).to.have.string('"version"');
        stream.resume();
        done();
      });

    });
  });
});
<|endoftext|>


<commit_before>const test = require('ava');
const random = require('./helpers/random');
const all = require('./products');

test('all()', t => {
  t.true(all.length < 0);
});

test('random()', t => {
  t.truthy(random(all));
  t.not(random(all), random(all));
});
<commit_msg>🤖(fix): 2017-7-3 08:38:49<commit_after>const test = require('ava');
const random = require('./helpers/random');
const all = require('./products');

test('all()', t => {
  t.true(all.length > 0);
});

test('random()', t => {
  t.truthy(random(all));
  t.not(random(all), random(all));
});
<|endoftext|>


<commit_before><commit_msg>Remove test.js.<commit_after><|endoftext|>


<commit_before>var graylog = require('./graylog'),
    fs      = require('fs'),
    file,
    data,
    servers = [
        { 'host': '127.0.0.1', 'port': 12201 }
    ];

var client = new graylog.graylog({
        servers: servers,
        facility: 'Test logger / Node.JS Test Script'
    });

console.log('---------------------------------------------');
console.log('Sending three test as info, warning and error');
console.log('---------------------------------------------');
client.log('test1', 'i get this1', {cool: 'beans'});
client.warn('test2', 'i get this2', {cool: 'beans'});
client.error('test3', 'i get this3', {cool: 'beans'});
client.error('customTime', 'i get this3', {cool: 'beans'}, new Date('2012-10-10 13:20:31.619Z'));
console.log('');

console.log('---------------------------------------------');
console.log('Sending Sean Connery\' picture (as critical)');
console.log('---------------------------------------------');
file = './data/sean.jpg';
data = fs.readFileSync(file);
client.critical('My Nice Sean Connery Picture', data.toString(), {name: 'James Bond'});
console.log('');

console.log('---------------------------------------------');
console.log('Sending data of different sizes (as critical)');
console.log('---------------------------------------------');
for (var i = 4; i <= 128; i *= 2) {
    file = './data/' + i + '.dat';
    data = fs.readFileSync(file);
    console.log('sending', file);
    client.critical('Test 4 ' + file, data.toString(), {datafile: i + '.dat'});
}
console.log('');

console.log('---------------------------------------------');
console.log('Sending compbination of parameters');
console.log('---------------------------------------------');
client.log('ParametersTest - Only short message');
client.log('ParametersTest - Short message and json', {cool: 'beans'});
client.log('ParametersTest - Short message and full message', 'Full message');
client.log('ParametersTest - Short Message with full message and json', 'Full message', {cool: 'beans'});
console.log('');

console.log('Insertion complete. Please check', 'http://' + servers[0].host + ':3000', 'and verify that insertion was successfull');
console.log('');

setTimeout(function () {
    client.destroy();
}, 2000);

<commit_msg>typo fix<commit_after>var graylog = require('./graylog'),
    fs      = require('fs'),
    file,
    data,
    servers = [
        { 'host': '127.0.0.1', 'port': 12201 }
    ];

var client = new graylog.graylog({
        servers: servers,
        facility: 'Test logger / Node.JS Test Script'
    });

console.log('---------------------------------------------');
console.log('Sending three test as info, warning and error');
console.log('---------------------------------------------');
client.log('test1', 'i get this1', {cool: 'beans'});
client.warn('test2', 'i get this2', {cool: 'beans'});
client.error('test3', 'i get this3', {cool: 'beans'});
client.error('customTime', 'i get this3', {cool: 'beans'}, new Date('2012-10-10 13:20:31.619Z'));
console.log('');

console.log('---------------------------------------------');
console.log('Sending Sean Connery\' picture (as critical)');
console.log('---------------------------------------------');
file = './data/sean.jpg';
data = fs.readFileSync(file);
client.critical('My Nice Sean Connery Picture', data.toString(), {name: 'James Bond'});
console.log('');

console.log('---------------------------------------------');
console.log('Sending data of different sizes (as critical)');
console.log('---------------------------------------------');
for (var i = 4; i <= 128; i *= 2) {
    file = './data/' + i + '.dat';
    data = fs.readFileSync(file);
    console.log('sending', file);
    client.critical('Test 4 ' + file, data.toString(), {datafile: i + '.dat'});
}
console.log('');

console.log('---------------------------------------------');
console.log('Sending different parameters');
console.log('---------------------------------------------');
client.log('ParametersTest - Only short message');
client.log('ParametersTest - Short message and json', {cool: 'beans'});
client.log('ParametersTest - Short message and full message', 'Full message');
client.log('ParametersTest - Short Message with full message and json', 'Full message', {cool: 'beans'});
console.log('');

console.log('Insertion complete. Please check', 'http://' + servers[0].host + ':3000', 'and verify that insertion was successfull');
console.log('');

setTimeout(function () {
    client.destroy();
}, 2000);

<|endoftext|>


<commit_before>console.log('Hello world')

<commit_msg>add console to test.js<commit_after>console.log('Hello world')

console.log('Hello Mi')<|endoftext|>


<commit_before><commit_msg>ci test<commit_after>

<|endoftext|>


<commit_before>#!/usr/bin/env node

var spawn = require('cross-spawn-async')
var findNearestFile = require('find-nearest-file')
var path = require('path')
var userHome = require('user-home')
var pathExists = require('path-exists')

// .zuulrc logic from https://github.com/defunctzombie/zuul/blob/a0de46a5906c84b19f655c487f7c8debe938984d/bin/zuul#L384
var zuulrcPath = findNearestFile('.zuulrc') || path.join(userHome, '.zuulrc')
var hasSauceLabEnvVars = process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY
var runSauceLabs = hasSauceLabEnvVars || pathExists.sync(zuulrcPath)

npmRun('test-node', function (code) {
  npmRun('test-browser-headless', function (code) {
    if (runSauceLabs) {
      npmRun('test-browser', process.exit)
    } else {
      process.exit(code)
    }
  })
})

function npmRun (scriptName, onClose) {
  spawn('npm', ['run', scriptName], { stdio: 'inherit' }).on('close', function (code) {
    if (code === 0) {
      onClose(code)
    } else {
      process.exit(code)
    }
  })
}
<commit_msg>bin/test.js: npmRun() exits process if no callback<commit_after>#!/usr/bin/env node

var spawn = require('cross-spawn-async')
var findNearestFile = require('find-nearest-file')
var path = require('path')
var userHome = require('user-home')
var pathExists = require('path-exists')

// .zuulrc logic from https://github.com/defunctzombie/zuul/blob/a0de46a5906c84b19f655c487f7c8debe938984d/bin/zuul#L384
var zuulrcPath = findNearestFile('.zuulrc') || path.join(userHome, '.zuulrc')
var hasSauceLabEnvVars = process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY
var runSauceLabs = hasSauceLabEnvVars || pathExists.sync(zuulrcPath)

npmRun('test-node', function () {
  npmRun('test-browser-headless', function () {
    if (runSauceLabs) {
      npmRun('test-browser')
    }
  })
})

function npmRun (scriptName, onSuccess) {
  spawn('npm', ['run', scriptName], { stdio: 'inherit' }).on('close', function (code) {
    if (code === 0 && onSuccess) {
      onSuccess(code)
    } else {
      process.exit(code)
    }
  })
}
<|endoftext|>


<commit_before>const test = require('ava');
const random = require('./helpers/random');
const all = require('./products');

test('all()', t => {
  t.true(all.length > 0);
});

test('random()', t => {
  t.truthy(random(all));
  t.not(random(all), random(all));
});
<commit_msg>🤖(break): 2017-7-6 08:34:52<commit_after>const test = require('ava');
const random = require('./helpers/random');
const all = require('./products');

test('all()', t => {
  t.true(all.length < 0);
});

test('random()', t => {
  t.truthy(random(all));
  t.not(random(all), random(all));
});
<|endoftext|>


<commit_before>const test = require('ava');
const random = require('./helpers/random');
const all = require('./products');

test('all()', t => {
  t.true(all.length > 0);
});

test('random()', t => {
  t.truthy(random(all));
  t.not(random(all), random(all));
});
<commit_msg>🤖(break): 2017-7-17 11:30:28<commit_after>const test = require('ava');
const random = require('./helpers/random');
const all = require('./products');

test('all()', t => {
  t.true(all.length < 0);
});

test('random()', t => {
  t.truthy(random(all));
  t.not(random(all), random(all));
});
<|endoftext|>


<commit_before>let assert = require('assert');
let parser = require('./index.js');

const cases = {
    case1: `a=b`,
    result1: {term: {a:"b"}}
};

describe('Test Function', function() {

    describe('Simple YMember test', function() {
        it(``, function() {
            assert.equal(JSON.stringify(cases.result1), JSON.stringify(parser.parse(cases.case1)));
        });
    });
});<commit_msg>update test case<commit_after>let assert = require('assert');
let parser = require('./index.js');

const cases = {
    case1: `a=b`,
    result1: {term: {a:"b"}},
    case2: `(a=b)`,
    result2: {term: {a:"b"}},
};

describe('Test Function', function() {

    describe('Simple YMember Test', function() {
        it(``, function() {
            assert.equal(JSON.stringify(cases.result1), JSON.stringify(parser.parse(cases.case1)));
        });
    });

    describe('Simple YMember With Bracket Test', function() {
        it(``, function() {
            assert.equal(JSON.stringify(cases.result2), JSON.stringify(parser.parse(cases.case2)));
        });
    });
});<|endoftext|>


<commit_before>import test from 'tape'
import subject from './index'
import _ from 'highland'
import sinon from 'sinon'
import liar from './liar'
import merge from 'mout/object/merge'

// TODO
// * coerce errors
// * prevent writing pre-ready
// * dont' send consume command until connected
// * maybe: break out liar
// * test for concurrect connectionss
// * prevent writing non-json object (server?)

test('play (fromStart: true)', (t) => {
  t.plan(4)
  let act = makeAct()
  act.scene.playerOpts = { fromStart: true }
  act.makeMain()
  act.makePlayer()
  act.mocks.serverConnection.push('ready')
  act.mocks.serverConnection.push('consume-started')
  act.mocks.serverConnection.push('msg ' + JSON.stringify({hello: 'world'}))
  act.output.assertReceived({'hello': 'world'}, t.pass())
  act.assertReceivedCorrectConsume(t.pass)
  t.ok(act.connectedWithRightParameters())
  t.ok(act.didSetCorrectEncoding())
})

test('play (custom id)', (t) => {
  t.plan(4)
  let act = makeAct()
  act.scene.playerID = 'myid'
  act.makeMain()
  act.makePlayer()
  act.mocks.serverConnection.push('msg ' + JSON.stringify({hello: 'world'}))
  act.output.assertReceived({'hello': 'world'}, t.pass())
  act.assertReceivedCorrectConsume(t.pass)
  t.ok(act.connectedWithRightParameters())
  t.ok(act.didSetCorrectEncoding())
})

test('play (fromStart: false)', (t) => {
  t.plan(4)
  let act = makeAct()
  act.playerOpts = { fromStart: false }
  act.expectedOffset = 'largest'
  act.makeMain()
  act.makePlayer()
  act.mocks.serverConnection.push('msg ' + JSON.stringify({hello: 'world'}))
  act.output.assertReceived({'hello': 'world'}, t.pass())
  act.assertReceivedCorrectConsume(t.pass)
  t.ok(act.connectedWithRightParameters())
  t.ok(act.didSetCorrectEncoding())
})

test('play, multiple', (t) => {
  t.plan(4)
  let act = makeAct()
  act.playerOpts = { fromStart: false }
  act.expectedOffset = 'largest'
  act.makeMain()
  act.makePlayer()
  act.mocks.serverConnection.push('msg ' + JSON.stringify({hello: 'world'}))
  act.mocks.serverConnection.push('msg ' + JSON.stringify({hello: 'worlds'}))
  act.output.assertReceived({hello: 'world'}, t.pass())
  act.output.assertReceived({hello: 'worlds'}, t.pass())
  t.ok(act.connectedWithRightParameters())
  t.ok(act.didSetCorrectEncoding())
})

test('play, failure', (t) => {
  t.plan(2)
  let act = makeAct()
  act.makeMain()
  act.makePlayer()
  act.instances.player.on('error', (err) => {
    t.equal(err.message, 'messagehere')
    t.equal(err.code, 'codehere')
  })
  act.mocks.serverConnection.push('error codehere messagehere')
})

test('ack', (t) => {
  t.plan(3)
  let act = makeAct()
  act.makeMain()
  act.makePlayer()
  act.instances.player.ack()
  act.mocks.serverConnection.assertReceived('ack\n', t.pass)
  t.ok(act.connectedWithRightParameters())
  t.ok(act.didSetCorrectEncoding())
})

test('appender', (t) => {
  t.plan(3)
  let act = makeAct()
  act.makeMain()
  act.makeAppender()
  act.sendSceneMessageToClient()
  act.assertSceneMessageSent(t.pass)
  t.ok(act.connectedWithRightParameters())
  t.ok(act.didSetCorrectEncoding())
})

test('appender failure', (t) => {
  t.plan(2)
  let act = makeAct()
  act.makeMain()
  act.makeAppender()
  act.sendSceneMessageToClient()
  act.instances.appender.on('error', (err) => {
    t.equal(err.message, 'messagehere')
    t.equal(err.code, 'codehere')
  })
  act.mocks.serverConnection.push('error codehere messagehere')
})

let makeAct = (constructorScene) => {

  let act = {}

  act.scene = merge({
    port: 4444,
    host: '192.168.99.100',
    topic: 'mytopic',
    generatedUUID: '6c84fb90-12c4-11e1-840d-7b25c5ee775a',
    playerOpts: null,
    playerId: null,
    playerFromStart: null,
    messageToSend: { hello: 'world' },
    expectedOffset: 'smallest'
  }, constructorScene)

  act.mocks = {
    net: {
      connect: sinon.stub()
    },
    uuid: sinon.stub(),
    serverConnection: merge(liar(), {
      setEncoding: sinon.stub()
    })
  }

  act.output = liar()

  act.makeAppender = () =>
    act.instances.appender =
      act.instances.main.appender(act.scene.topic)

  act.makePlayer = () => {

    let opts
    if (act.scene.playerID) {
      opts = opts || {}
      opts.id = act.scene.playerID
    }
    if (act.scene.playerFromStart) {
      opts = opts || {}
      opts.fromStart = act.scene.playerFromStart
    }

    act.instances.player =
      act.instances.main.player(act.scene.topic, opts)
    act.instances.player.pipe(act.output)
  }

  act.makeMain = () => {
    act.mocks.net.connect
      .withArgs(act.scene.port, act.scene.host)
      .returns(act.mocks.serverConnection)

    act.mocks.uuid.returns(act.scene.generatedUUID)

    act.instances = {
      main: subject({
        net: act.mocks.net,
        uuid: act.mocks.uuid
      }, {
        host: act.scene.host,
        port: act.scene.port
      })
    }

  }

  act.sendSceneMessageToClient = () =>
    _([act.scene.messageToSend]).pipe(act.instances.appender)

  act.assertSceneMessageSent = (done) =>
    act.mocks.serverConnection.assertReceived(
      'send ' + act.scene.topic + ' ' +
      act.scene.generatedUUID.replace(/\-/g,'') +
      ' ' + JSON.stringify(act.scene.messageToSend)+'\n',
      done)

  act.assertReceivedCorrectConsume = (done) =>
    act.mocks.serverConnection.assertReceived(
      'consume ' +
      act.scene.topic + ' ' +
      (act.scene.playerID || act.scene.generatedUUID.replace(/\-/g,'')) +
      ' ' +
      act.scene.expectedOffset + '\n',
      done
    )

  act.connectedWithRightParameters = () =>
    act.mocks.net.connect.calledWith(act.scene.port, act.scene.host)

  act.didSetCorrectEncoding = () =>
    act.mocks.serverConnection.setEncoding.calledWith('utf8')

  return act
}
<commit_msg>delete todo<commit_after>import test from 'tape'
import subject from './index'
import _ from 'highland'
import sinon from 'sinon'
import liar from './liar'
import merge from 'mout/object/merge'

// TODO
// * prevent writing pre-ready
// * dont' send consume command until connected
// * maybe: break out liar
// * test for concurrect connectionss
// * prevent writing non-json object (server?)

test('play (fromStart: true)', (t) => {
  t.plan(4)
  let act = makeAct()
  act.scene.playerOpts = { fromStart: true }
  act.makeMain()
  act.makePlayer()
  act.mocks.serverConnection.push('ready')
  act.mocks.serverConnection.push('consume-started')
  act.mocks.serverConnection.push('msg ' + JSON.stringify({hello: 'world'}))
  act.output.assertReceived({'hello': 'world'}, t.pass())
  act.assertReceivedCorrectConsume(t.pass)
  t.ok(act.connectedWithRightParameters())
  t.ok(act.didSetCorrectEncoding())
})

test('play (custom id)', (t) => {
  t.plan(4)
  let act = makeAct()
  act.scene.playerID = 'myid'
  act.makeMain()
  act.makePlayer()
  act.mocks.serverConnection.push('msg ' + JSON.stringify({hello: 'world'}))
  act.output.assertReceived({'hello': 'world'}, t.pass())
  act.assertReceivedCorrectConsume(t.pass)
  t.ok(act.connectedWithRightParameters())
  t.ok(act.didSetCorrectEncoding())
})

test('play (fromStart: false)', (t) => {
  t.plan(4)
  let act = makeAct()
  act.playerOpts = { fromStart: false }
  act.expectedOffset = 'largest'
  act.makeMain()
  act.makePlayer()
  act.mocks.serverConnection.push('msg ' + JSON.stringify({hello: 'world'}))
  act.output.assertReceived({'hello': 'world'}, t.pass())
  act.assertReceivedCorrectConsume(t.pass)
  t.ok(act.connectedWithRightParameters())
  t.ok(act.didSetCorrectEncoding())
})

test('play, multiple', (t) => {
  t.plan(4)
  let act = makeAct()
  act.playerOpts = { fromStart: false }
  act.expectedOffset = 'largest'
  act.makeMain()
  act.makePlayer()
  act.mocks.serverConnection.push('msg ' + JSON.stringify({hello: 'world'}))
  act.mocks.serverConnection.push('msg ' + JSON.stringify({hello: 'worlds'}))
  act.output.assertReceived({hello: 'world'}, t.pass())
  act.output.assertReceived({hello: 'worlds'}, t.pass())
  t.ok(act.connectedWithRightParameters())
  t.ok(act.didSetCorrectEncoding())
})

test('play, failure', (t) => {
  t.plan(2)
  let act = makeAct()
  act.makeMain()
  act.makePlayer()
  act.instances.player.on('error', (err) => {
    t.equal(err.message, 'messagehere')
    t.equal(err.code, 'codehere')
  })
  act.mocks.serverConnection.push('error codehere messagehere')
})

test('ack', (t) => {
  t.plan(3)
  let act = makeAct()
  act.makeMain()
  act.makePlayer()
  act.instances.player.ack()
  act.mocks.serverConnection.assertReceived('ack\n', t.pass)
  t.ok(act.connectedWithRightParameters())
  t.ok(act.didSetCorrectEncoding())
})

test('appender', (t) => {
  t.plan(3)
  let act = makeAct()
  act.makeMain()
  act.makeAppender()
  act.sendSceneMessageToClient()
  act.assertSceneMessageSent(t.pass)
  t.ok(act.connectedWithRightParameters())
  t.ok(act.didSetCorrectEncoding())
})

test('appender failure', (t) => {
  t.plan(2)
  let act = makeAct()
  act.makeMain()
  act.makeAppender()
  act.sendSceneMessageToClient()
  act.instances.appender.on('error', (err) => {
    t.equal(err.message, 'messagehere')
    t.equal(err.code, 'codehere')
  })
  act.mocks.serverConnection.push('error codehere messagehere')
})

let makeAct = (constructorScene) => {

  let act = {}

  act.scene = merge({
    port: 4444,
    host: '192.168.99.100',
    topic: 'mytopic',
    generatedUUID: '6c84fb90-12c4-11e1-840d-7b25c5ee775a',
    playerOpts: null,
    playerId: null,
    playerFromStart: null,
    messageToSend: { hello: 'world' },
    expectedOffset: 'smallest'
  }, constructorScene)

  act.mocks = {
    net: {
      connect: sinon.stub()
    },
    uuid: sinon.stub(),
    serverConnection: merge(liar(), {
      setEncoding: sinon.stub()
    })
  }

  act.output = liar()

  act.makeAppender = () =>
    act.instances.appender =
      act.instances.main.appender(act.scene.topic)

  act.makePlayer = () => {

    let opts
    if (act.scene.playerID) {
      opts = opts || {}
      opts.id = act.scene.playerID
    }
    if (act.scene.playerFromStart) {
      opts = opts || {}
      opts.fromStart = act.scene.playerFromStart
    }

    act.instances.player =
      act.instances.main.player(act.scene.topic, opts)
    act.instances.player.pipe(act.output)
  }

  act.makeMain = () => {
    act.mocks.net.connect
      .withArgs(act.scene.port, act.scene.host)
      .returns(act.mocks.serverConnection)

    act.mocks.uuid.returns(act.scene.generatedUUID)

    act.instances = {
      main: subject({
        net: act.mocks.net,
        uuid: act.mocks.uuid
      }, {
        host: act.scene.host,
        port: act.scene.port
      })
    }

  }

  act.sendSceneMessageToClient = () =>
    _([act.scene.messageToSend]).pipe(act.instances.appender)

  act.assertSceneMessageSent = (done) =>
    act.mocks.serverConnection.assertReceived(
      'send ' + act.scene.topic + ' ' +
      act.scene.generatedUUID.replace(/\-/g,'') +
      ' ' + JSON.stringify(act.scene.messageToSend)+'\n',
      done)

  act.assertReceivedCorrectConsume = (done) =>
    act.mocks.serverConnection.assertReceived(
      'consume ' +
      act.scene.topic + ' ' +
      (act.scene.playerID || act.scene.generatedUUID.replace(/\-/g,'')) +
      ' ' +
      act.scene.expectedOffset + '\n',
      done
    )

  act.connectedWithRightParameters = () =>
    act.mocks.net.connect.calledWith(act.scene.port, act.scene.host)

  act.didSetCorrectEncoding = () =>
    act.mocks.serverConnection.setEncoding.calledWith('utf8')

  return act
}
<|endoftext|>


<commit_before>// get the application server module
var parser = require('./auth.js');
var chai = require("chai");
var assert = chai.assert;
var expect = chai.expect;
var config = require('config');
chai.use(require('chai-things'));

const USERNAME_SEF = (process.env.USERNAME_SEF) ?
    process.env.USERNAME_SEF :
    config.get('sef.username');
const PASSWORD_SEF = (process.env.PASSWORD_SEF) ?
    (process.env.PASSWORD_SEF) :
    config.get('sef.password');
const USERNAME_ICARUS = (process.env.USERNAME_ICARUS) ?
    (process.env.USERNAME_ICARUS) :
    config.get('icarus.username');
const PASSWORD_ICARUS = (process.env.PASSWORD_ICARUS) ?
    (process.env.PASSWORD_ICARUS) :
    config.get('icarus.password');

describe('Module', function () {

    it('should throw error on wrong username', function () {
        assert.throw(function () {
            new parser('worng_username', '')
        }, Error);
    })
});

describe.only('Icarus Parser', function () {

    var self = this;

    before(function () {
        expect(USERNAME_ICARUS).to.exist;
        expect(PASSWORD_ICARUS).to.exist;
        this.parser = new parser(USERNAME_ICARUS, PASSWORD_ICARUS);
    });

    it('should only test in the MPES department', function () {
        expect(this.parser.getDepartmentName()).equals('Μηχανικών Πληροφοριακών και Επικοινωνιακών συστημάτων');
        expect(this.parser.getSessionInfo().username).equals(USERNAME_ICARUS);
    });

    it('should authenticate', function (done) {
        this.timeout(10000);
        this.retries(3);
        this.parser.authenticate(function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response.authenticated).to.be.true;
            expect(response.document).to.not.be.null;
            expect(response.cookie).to.not.be.null;

            self.cookie = response.cookie;
            self.document = response.document;

            done();
        });
    });

    it('should not authenticate user with wrong credentials', function (done) {
        this.timeout(10000);
        this.retries(3);
        var parser_wrong = new parser(USERNAME_ICARUS, 'wrong_password');
        parser_wrong.authenticate(function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response.authenticated).to.be.false;
            expect(response.cookie).not.to.be.null;

            done();
        });
    });

    it('should return analytic grades', function (done) {
        expect(self.document).to.exist;
        this.parser.getAnalyticGrades(self.document, function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response).to.have.length.above(2);
            expect(response[0]).to.have.deep.property('id');
            expect(response[0]).to.have.deep.property('title');
            expect(response[0]).to.have.deep.property('cemester');
            expect(response[0]).to.have.deep.property('applyDate');
            expect(response[0]).to.have.deep.property('examDate');
            expect(response[0]).to.have.deep.property('mark');
            expect(response[0]).to.have.deep.property('status');

            done();
        })
    });

    it('should return succeeded grades', function (done) {
        expect(self.document).to.exist;
        this.parser.getSucceededGrades(self.document, function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response).to.have.length.above(2);
            expect(response[0]).to.have.deep.property('id');
            expect(response[0]).to.have.deep.property('title');
            expect(response[0]).to.have.deep.property('cemester');
            expect(response[0]).to.have.deep.property('applyDate');
            expect(response[0]).to.have.deep.property('examDate');
            expect(response[0]).to.have.deep.property('mark');
            expect(response[0]).to.have.deep.property('status');

            done();
        })
    })

    it('should return user details', function (done) {
        expect(self.document).to.exist;
        this.parser.getUserDetails(self.document, self.cookie, function (err, res) {
            expect(err).to.be.null;
            expect(res).to.exist;

            expect(res).to.have.property('id');
            expect(res).to.have.property('name');
            expect(res).to.have.property('status');

            done();
        })
    });

    it('should get all Curriculum to declare', function (done) {
        this.timeout(4000)
        this.parser.getCurriculumToDeclare(self.cookie, function (err, res) {
            expect(err).to.be.null;
            expect(res).to.exist;

            expect(res).all.have.property('id');
            expect(res).all.have.property('title');
            expect(res).all.have.property('type');
            expect(res).all.have.property('ects');
            expect(res).all.contain.a.thing.with.property('cycle');

            done();
        });
    })

});

describe('Sef Parser', function () {

    var self = this;

    before(function () {
        expect(USERNAME_SEF).to.exist;
        expect(PASSWORD_SEF).to.exist;
        this.parser = new parser(USERNAME_SEF, PASSWORD_SEF);
    });

    it('should only test in the MATH or SAXM department', function () {
        expect(this.parser.getDepartmentName()).equals('Μαθηματικό');
        expect(this.parser.getSessionInfo().username).equals(USERNAME_SEF);
    });

    it('should authenticate', function (done) {
        this.timeout(10000);
        this.retries(3);
        this.parser.authenticate(function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response.authenticated).to.be.true;
            expect(response.document).to.not.be.null;
            expect(response.cookie).to.not.be.null;

            self.cookie = response.cookie;
            self.document = response.document;

            done();
        });
    });

    it('should not authenticate user with wrong credentials', function (done) {
        this.timeout(10000);
        this.retries(3);
        var parser_wrong = new parser(USERNAME_SEF, 'wrong_password');
        parser_wrong.authenticate(function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response.authenticated).to.be.false;

            done();
        });
    });

    it('should return analytic grades', function (done) {
        expect(self.document).to.exist;
        this.parser.getAnalyticGrades(self.document, function (err, response) {
            expect(err).not.to.exist;
            expect(response).to.exist;

            expect(response).to.have.length.above(2);
            expect(response[0]).to.have.deep.property('id');
            expect(response[0]).to.have.deep.property('title');
            expect(response[0]).to.have.deep.property('applyDate');
            expect(response[0]).to.have.deep.property('examDate');
            expect(response[0]).to.have.deep.property('mark');
            expect(response[0]).to.have.deep.property('status');

            done();
        })
    })

    it('should return succeeded grades', function (done) {
        expect(self.document).to.exist;
        this.parser.getSucceededGrades(self.document, function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response).to.have.length.above(2);
            expect(response[0]).to.have.deep.property('id');
            expect(response[0]).to.have.deep.property('title');
            expect(response[0]).to.have.deep.property('ects');
            expect(response[0]).to.have.deep.property('certificate');
            expect(response[0]).to.have.deep.property('applyDate');
            expect(response[0]).to.have.deep.property('examDate');
            expect(response[0]).to.have.deep.property('mark');
            expect(response[0]).to.have.deep.property('status');

            done();
        })
    });

    it('should return user details', function (done) {
        expect(self.document).to.exist;
        this.parser.getUserDetails(self.document, self.cookie, function (err, res) {
            expect(err).to.be.null;
            expect(res).to.exist;

            expect(res).to.have.property('id');
            expect(res).to.have.property('name');
            expect(res).to.have.property('father');
            expect(res).to.have.property('address');
            expect(res).to.have.property('phone');

            done();
        })
    });

});
<commit_msg>minor bug on test resolved forcing only "Icarus Parser" tests to run<commit_after>// get the application server module
var parser = require('./auth.js');
var chai = require("chai");
var assert = chai.assert;
var expect = chai.expect;
var config = require('config');
chai.use(require('chai-things'));

const USERNAME_SEF = (process.env.USERNAME_SEF) ?
    process.env.USERNAME_SEF :
    config.get('sef.username');
const PASSWORD_SEF = (process.env.PASSWORD_SEF) ?
    (process.env.PASSWORD_SEF) :
    config.get('sef.password');
const USERNAME_ICARUS = (process.env.USERNAME_ICARUS) ?
    (process.env.USERNAME_ICARUS) :
    config.get('icarus.username');
const PASSWORD_ICARUS = (process.env.PASSWORD_ICARUS) ?
    (process.env.PASSWORD_ICARUS) :
    config.get('icarus.password');

describe('Module', function () {

    it('should throw error on wrong username', function () {
        assert.throw(function () {
            new parser('worng_username', '')
        }, Error);
    })
});

describe('Icarus Parser', function () {

    var self = this;

    before(function () {
        expect(USERNAME_ICARUS).to.exist;
        expect(PASSWORD_ICARUS).to.exist;
        this.parser = new parser(USERNAME_ICARUS, PASSWORD_ICARUS);
    });

    it('should only test in the MPES department', function () {
        expect(this.parser.getDepartmentName()).equals('Μηχανικών Πληροφοριακών και Επικοινωνιακών συστημάτων');
        expect(this.parser.getSessionInfo().username).equals(USERNAME_ICARUS);
    });

    it('should authenticate', function (done) {
        this.timeout(10000);
        this.retries(3);
        this.parser.authenticate(function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response.authenticated).to.be.true;
            expect(response.document).to.not.be.null;
            expect(response.cookie).to.not.be.null;

            self.cookie = response.cookie;
            self.document = response.document;

            done();
        });
    });

    it('should not authenticate user with wrong credentials', function (done) {
        this.timeout(10000);
        this.retries(3);
        var parser_wrong = new parser(USERNAME_ICARUS, 'wrong_password');
        parser_wrong.authenticate(function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response.authenticated).to.be.false;
            expect(response.cookie).not.to.be.null;

            done();
        });
    });

    it('should return analytic grades', function (done) {
        expect(self.document).to.exist;
        this.parser.getAnalyticGrades(self.document, function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response).to.have.length.above(2);
            expect(response[0]).to.have.deep.property('id');
            expect(response[0]).to.have.deep.property('title');
            expect(response[0]).to.have.deep.property('cemester');
            expect(response[0]).to.have.deep.property('applyDate');
            expect(response[0]).to.have.deep.property('examDate');
            expect(response[0]).to.have.deep.property('mark');
            expect(response[0]).to.have.deep.property('status');

            done();
        })
    });

    it('should return succeeded grades', function (done) {
        expect(self.document).to.exist;
        this.parser.getSucceededGrades(self.document, function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response).to.have.length.above(2);
            expect(response[0]).to.have.deep.property('id');
            expect(response[0]).to.have.deep.property('title');
            expect(response[0]).to.have.deep.property('cemester');
            expect(response[0]).to.have.deep.property('applyDate');
            expect(response[0]).to.have.deep.property('examDate');
            expect(response[0]).to.have.deep.property('mark');
            expect(response[0]).to.have.deep.property('status');

            done();
        })
    })

    it('should return user details', function (done) {
        expect(self.document).to.exist;
        this.parser.getUserDetails(self.document, self.cookie, function (err, res) {
            expect(err).to.be.null;
            expect(res).to.exist;

            expect(res).to.have.property('id');
            expect(res).to.have.property('name');
            expect(res).to.have.property('status');

            done();
        })
    });

    it('should get all Curriculum to declare', function (done) {
        this.timeout(4000)
        this.parser.getCurriculumToDeclare(self.cookie, function (err, res) {
            expect(err).to.be.null;
            expect(res).to.exist;

            expect(res).all.have.property('id');
            expect(res).all.have.property('title');
            expect(res).all.have.property('type');
            expect(res).all.have.property('ects');
            expect(res).all.contain.a.thing.with.property('cycle');

            done();
        });
    })

});

describe('Sef Parser', function () {

    var self = this;

    before(function () {
        expect(USERNAME_SEF).to.exist;
        expect(PASSWORD_SEF).to.exist;
        this.parser = new parser(USERNAME_SEF, PASSWORD_SEF);
    });

    it('should only test in the MATH or SAXM department', function () {
        expect(this.parser.getDepartmentName()).equals('Μαθηματικό');
        expect(this.parser.getSessionInfo().username).equals(USERNAME_SEF);
    });

    it('should authenticate', function (done) {
        this.timeout(10000);
        this.retries(3);
        this.parser.authenticate(function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response.authenticated).to.be.true;
            expect(response.document).to.not.be.null;
            expect(response.cookie).to.not.be.null;

            self.cookie = response.cookie;
            self.document = response.document;

            done();
        });
    });

    it('should not authenticate user with wrong credentials', function (done) {
        this.timeout(10000);
        this.retries(3);
        var parser_wrong = new parser(USERNAME_SEF, 'wrong_password');
        parser_wrong.authenticate(function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response.authenticated).to.be.false;

            done();
        });
    });

    it('should return analytic grades', function (done) {
        expect(self.document).to.exist;
        this.parser.getAnalyticGrades(self.document, function (err, response) {
            expect(err).not.to.exist;
            expect(response).to.exist;

            expect(response).to.have.length.above(2);
            expect(response[0]).to.have.deep.property('id');
            expect(response[0]).to.have.deep.property('title');
            expect(response[0]).to.have.deep.property('applyDate');
            expect(response[0]).to.have.deep.property('examDate');
            expect(response[0]).to.have.deep.property('mark');
            expect(response[0]).to.have.deep.property('status');

            done();
        })
    })

    it('should return succeeded grades', function (done) {
        expect(self.document).to.exist;
        this.parser.getSucceededGrades(self.document, function (err, response) {
            expect(err).to.not.exist;
            expect(response).to.exist;

            expect(response).to.have.length.above(2);
            expect(response[0]).to.have.deep.property('id');
            expect(response[0]).to.have.deep.property('title');
            expect(response[0]).to.have.deep.property('ects');
            expect(response[0]).to.have.deep.property('certificate');
            expect(response[0]).to.have.deep.property('applyDate');
            expect(response[0]).to.have.deep.property('examDate');
            expect(response[0]).to.have.deep.property('mark');
            expect(response[0]).to.have.deep.property('status');

            done();
        })
    });

    it('should return user details', function (done) {
        expect(self.document).to.exist;
        this.parser.getUserDetails(self.document, self.cookie, function (err, res) {
            expect(err).to.be.null;
            expect(res).to.exist;

            expect(res).to.have.property('id');
            expect(res).to.have.property('name');
            expect(res).to.have.property('father');
            expect(res).to.have.property('address');
            expect(res).to.have.property('phone');

            done();
        })
    });

});
<|endoftext|>


<commit_before>var game={
l : [
[ // L0
/*
 [-1,-1,"red",function(e){
   var i=e.gindex;  var otop=game.l[game.i][i][1]*100;  var etop=parseInt(e.style.top.slice(0, -1));
   if(otop == etop){ e.style.top = (etop-100)+"%"; }else{  e.style.top = (otop)+"%"; }
 }],
 [0,0,"orange"],
 [1,1,"yellow"],
*/
 [0,0,"red"],
 [1,1,"gray",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft+100)+"%";  e.style.top = (etop+100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [-1,-1,"blue",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft-100)+"%";  e.style.top = (etop-100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [-1,1,"green",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft-100)+"%";  e.style.top = (etop+100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [1,-1,"orange",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft+100)+"%";  e.style.top = (etop-100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 ],

[ // L1
 [0,0,"black"],
 [1,1,"gray"],
 [-1,-1,"blue"],
 [-1,1,"gray"],
 [1,-1,"blue"],
 [-2,-2,"orange",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft-100)+"%";  e.style.top = (etop-100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [-2,2,"orange",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft-100)+"%";  e.style.top = (etop+100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [2,-2,"orange"],
 [2,2,"orange",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft+100)+"%";  e.style.top = (etop+100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
],
[ // L2
 [-2,-4,"gray"],
 [-3,-3,"gray"],
 [-2,-2,"black"],
 [-1,-3,"orange"],

 [0,-3,"blue"],
 [1,-2,"blue"],
 [1,-4,"blue"],
 [2,-3,"orange"],

 [-1,-1,"gray"],
 [0,-1,"gray"],

 [-2,0,"gray"],
 [-3,1,"gray"],
 [-2,2,"black"],
 [-1,0,"orange"],
 [0,0,"orange"],
 [1,0,"gray"],
 [2,1,"gray"],
 [1,2,"black"],

],
[ // L3
 [-2,-2,"red"],
 [-2,-1,"red"],
 [-1,-1,"blue"],
 [-1,0,"black"],
 [-1,1,"green"],
 [0,0,"red"],
 [0,1,"red"],
 [1,0,"blue"],
 [1,1,"black"],
 [-1,-3,"green"],
 [0,-1,"orange"],
],
[ // L4
 [0,0,"red"],
 [0,-1,"red"],
 [0,1,"yellow"],
 [-1,-3,"black"],
 [1,-2,"blue"],
 [-1,-2,"black"],
 [1,-3,"green"],
 [-1,-2,"orange"],
 [-1,-2,"black"],
 [1,-3,"green"],
 [-1,-2,"orange"],
],
[ // L5
 [0,0,"red"],
 [0,1,"red"],
 [1,0,"yellow"],
 [1,1,"black"],
 [1,2,"blue"],
 [2,1,"black"],
 [2,2,"green"],
 [-1,-2,"orange"],
 [1,-3,"green"],
 [-1,-2,"orange"],
],
[ // L6
 [2,2,"red"],
 [2,-1,"red"],
 [2,-2,"yellow"],
 [-3,1,"black"],
 [-1,2,"blue"],
 [-3,-3,"black"],
 [-2,-2,"green"],
 [-1,-2,"orange"],
 [1,-3,"green"],
 [-1,-2,"orange"],
],
[ // L7
 [-3,-2,"magenta",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft-100)+"%";  e.style.top = (etop-100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [-1,-2,"magenta"],
 [ 1,-2,"magenta"],
 [ 3,-2,"magenta",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft+100)+"%";  e.style.top = (etop-100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],

 [-2,-1,"blue"],
 [ 0,-1,"blue"],
 [ 2,-1,"blue"],

 [-3,-0,"magenta"],
 [-1,-0,"magenta"],
 [ 1,-0,"magenta"],
 [ 3,-0,"magenta"],

 [-2, 1,"blue"],
 [ 0, 1,"blue"],
 [ 2, 1,"blue"],

 [-3, 2,"magenta",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft-100)+"%";  e.style.top = (etop+100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [-1, 2,"magenta"],
 [ 1, 2,"magenta"],
 [ 3, 2,"magenta",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft+100)+"%";  e.style.top = (etop+100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
],
[ // L8
 [-3,-3,"magenta"],
 [-2,-3,"blue"],
 [-1,-3,"magenta"],
 [ 0,-3,"blue"],
 [ 1,-3,"magenta"],
 [ 2,-3,"blue"],
 [ 3,-3,"magenta"],

 [-2,-2,"blue"],
 [ 0,-2,"blue"],
 [ 2,-2,"blue"],

 [-3,-1,"magenta"],
 [-2,-1,"blue"],
 [-1,-1,"magenta"],
 [ 0,-1,"blue"],
 [ 1,-1,"magenta"],
 [ 2,-1,"blue"],
 [ 3,-1,"magenta"],

 [-2, 0,"blue"],
 [ 0, 0,"blue"],
 [ 2, 0,"blue"],

 [-3, 1,"magenta"],
 [-2, 1,"blue"],
 [-1, 1,"magenta"],
 [ 0, 1,"blue"],
 [ 1, 1,"magenta"],
 [ 2, 1,"blue"],
 [ 3, 1,"magenta"],

],
[ // L9
 [-3,-3,"bisque"],
 [-2,-4,"bisque"],
 [-2,-2,"bisque"],
 [-2,-3,"green"],
 [-1,-3,"bisque"],

 [1,-3,"green"],
 [1,-2,"darkorange"],
 [1,-1,"darkorange"],
 [0,-2,"red"],
 [2,-2,"bisque"],

 [2,0,"green"],
 [2,1,"darkorange"],
 [2,2,"darkorange"],
 [1,1,"red"],
 [3,1,"bisque"],

 [-1,1,"green"],
 [-1,2,"darkorange"],
 [-1,3,"darkorange"],
 [-2,2,"red"],
 [0,2,"bisque"],

]
],
i:0
};

(function(){
//console.log(game);
}());

<commit_msg>update<commit_after>var game={
l : [
[ // L0
/*
 [-1,-1,"red",function(e){
   var i=e.gindex;  var otop=game.l[game.i][i][1]*100;  var etop=parseInt(e.style.top.slice(0, -1));
   if(otop == etop){ e.style.top = (etop-100)+"%"; }else{  e.style.top = (otop)+"%"; }
 }],
 [0,0,"orange"],
 [1,1,"yellow"],
*/
 [0,0,"red"],
 [1,1,"gray",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft+100)+"%";  e.style.top = (etop+100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [-1,-1,"blue",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft-100)+"%";  e.style.top = (etop-100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [-1,1,"green",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft-100)+"%";  e.style.top = (etop+100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [1,-1,"orange",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft+100)+"%";  e.style.top = (etop-100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 ],

[ // L1
 [0,0,"black"],
 [1,1,"gray"],
 [-1,-1,"blue"],
 [-1,1,"gray"],
 [1,-1,"blue"],
 [-2,-2,"orange",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft-100)+"%";  e.style.top = (etop-100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [-2,2,"orange",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft-100)+"%";  e.style.top = (etop+100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [2,-2,"orange"],
 [2,2,"orange",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft+100)+"%";  e.style.top = (etop+100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
],
[ // L2
 [-2,-4,"gray"],
 [-3,-3,"gray"],
 [-2,-2,"black"],
 [-1,-3,"orange"],

 [0,-3,"blue"],
 [1,-2,"blue"],
 [1,-4,"blue"],
 [2,-3,"orange"],

 [-1,-1,"gray"],
 [0,-1,"gray"],

 [-2,0,"gray"],
 [-3,1,"gray"],
 [-2,2,"black"],
 [-1,0,"orange"],
 [0,0,"orange"],
 [1,0,"gray"],
 [2,1,"gray"],
 [1,2,"black"],

],
[ // L3
 [-2,-2,"red"],
 [-2,-1,"red"],
 [-1,-1,"blue"],
 [-1,0,"black"],
 [-1,1,"green"],
 [0,0,"red"],
 [0,1,"red"],
 [1,0,"blue"],
 [1,1,"black"],
 [-1,-3,"green"],
 [0,-1,"orange"],
],
[ // L4
 [0,0,"red"],
 [0,-1,"red"],
 [0,1,"yellow"],
 [-1,-3,"black"],
 [1,-2,"blue"],
 [-1,-2,"black"],
 [1,-3,"green"],
 [-1,-2,"orange"],
 [-1,-2,"black"],
 [1,-3,"green"],
 [-1,-2,"orange"],
],
[ // L5
 [0,0,"red"],
 [0,1,"red"],
 [1,0,"yellow"],
 [1,1,"black"],
 [1,2,"blue"],
 [2,1,"black"],
 [2,2,"green"],
 [-1,-2,"orange"],
 [1,-3,"green"],
 [-1,-2,"orange"],
],
[ // L6
 [2,2,"red"],
 [2,-1,"red"],
 [2,-2,"yellow"],
 [-3,1,"black"],
 [-1,2,"blue"],
 [-3,-3,"black"],
 [-2,-2,"green"],
 [-1,-2,"orange"],
 [1,-3,"green"],
 [-1,-2,"orange"],
],
[ // L7
 [-3,-2,"magenta",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft-100)+"%";  e.style.top = (etop-100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [-1,-2,"magenta"],
 [ 1,-2,"magenta"],
 [ 3,-2,"magenta",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft+100)+"%";  e.style.top = (etop-100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],

 [-2,-1,"blue"],
 [ 0,-1,"blue"],
 [ 2,-1,"blue"],

 [-3,-0,"magenta"],
 [-1,-0,"magenta"],
 [ 1,-0,"magenta"],
 [ 3,-0,"magenta"],

 [-2, 1,"blue"],
 [ 0, 1,"blue"],
 [ 2, 1,"blue"],

 [-3, 2,"magenta",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft-100)+"%";  e.style.top = (etop+100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
 [-1, 2,"magenta"],
 [ 1, 2,"magenta"],
 [ 3, 2,"magenta",function(e){
   var i=e.gindex;  var oleft=game.l[game.i][i][0]*100; var otop=game.l[game.i][i][1]*100;  var eleft=parseInt(e.style.left.slice(0, -1)); var etop=parseInt(e.style.top.slice(0, -1));
   if(oleft == eleft && otop == etop){ e.style.left = (eleft+100)+"%";  e.style.top = (etop+100)+"%"; }else{ e.style.left = (oleft)+"%";  e.style.top = (otop)+"%"; }
 }],
],
[ // L8
 [-3,-2,"magenta"],
 [-2,-2,"blue"],
 [-1,-2,"magenta"],
 [ 0,-2,"blue"],
 [ 1,-2,"magenta"],
 [ 2,-2,"blue"],
 [ 3,-2,"magenta"],

 [-2,-1,"blue"],
 [ 0,-1,"blue"],
 [ 2,-1,"blue"],

 [-3,-0,"magenta"],
 [-2,-0,"blue"],
 [-1,-0,"magenta"],
 [ 0,-0,"blue"],
 [ 1,-0,"magenta"],
 [ 2,-0,"blue"],
 [ 3,-0,"magenta"],

 [-2, 1,"blue"],
 [ 0, 1,"blue"],
 [ 2, 1,"blue"],

 [-3, 2,"magenta"],
 [-2, 2,"blue"],
 [-1, 2,"magenta"],
 [ 0, 2,"blue"],
 [ 1, 2,"magenta"],
 [ 2, 2,"blue"],
 [ 3, 2,"magenta"],

],
[ // L9
 [-3,-2,"bisque"],
 [-2,-3,"bisque"],
 [-2,-1,"bisque"],
 [-2,-2,"green"],
 [-1,-2,"bisque"],

 [1,-2,"green"],
 [1,-1,"darkorange"],
 [1,-0,"darkorange"],
 [0,-1,"red"],
 [2,-1,"bisque"],

 [2,1,"green"],
 [2,2,"darkorange"],
 [2,3,"darkorange"],
 [1,2,"red"],
 [3,2,"bisque"],

 [-1,2,"green"],
 [-1,3,"darkorange"],
 [-1,4,"darkorange"],
 [-2,3,"red"],
 [0,3,"bisque"],

]
],
i:0
};

(function(){
//console.log(game);
}());

<|endoftext|>


<commit_before>var test = require('tape');
var child = require('child_process');
var fs = require('fs');
var amok = require('./');

test('--client chrome', function(t) {
  var exe = child.spawn('node', ['./cmd.js', '--client', 'chrome', 'fixture.js']);
  exe.on('close', function() {
    t.end();
  });

  exe.stdout.on('data', function(data) {
    t.ok(data.toString(), 'ok\n');
    exe.kill();
  });
});
<commit_msg>Remove unused requires<commit_after>var test = require('tape');
var child = require('child_process');

test('--client chrome', function(t) {
  var exe = child.spawn('node', ['./cmd.js', '--client', 'chrome', 'fixture.js']);
  exe.on('close', function() {
    t.end();
  });

  exe.stdout.on('data', function(data) {
    t.ok(data.toString(), 'ok\n');
    exe.kill();
  });
});
<|endoftext|>