{"size": 4145, "ext": "js", "max_stars_repo_path": "test/index.js", "max_stars_repo_name": "bestchu/sharedArrayBufferStore", "max_stars_repo_stars_event_min_datetime": "2018-07-27T23:01:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-20T18:34:13.000Z", "max_issues_repo_path": "test/index.js", "max_issues_repo_name": "bestchu/sharedArrayBufferStore", "max_issues_repo_issues_event_min_datetime": "2019-01-24T22:21:16.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-24T22:21:16.000Z", "max_forks_repo_path": "test/index.js", "max_forks_repo_name": "bestchu/sharedArrayBufferStore", "max_forks_repo_forks_event_min_datetime": "2018-10-14T17:14:03.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-19T08:30:29.000Z"}
{"max_stars_count": 9, "max_issues_count": 1, "max_forks_count": 2, "avg_line_length": 23.9595375723, "max_line_length": 57, "alphanum_fraction": 0.6376357057}
const test = require('ava');
const SharedArrayBufferStore = require('../lib/index');

test('init', t => {
  const instance = new SharedArrayBufferStore();
  t.is(instance.keyArray instanceof Uint32Array, true);
  t.is(instance.valueArray instanceof Uint32Array, true);
});

test('change length', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 10,
    valueBufferLength: 20
  });
  t.is(instance.keyArray.length, 10);
  t.is(instance.valueArray.length, 20);
});

test('get, key is undefined', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 10,
    valueBufferLength: 20
  });
  t.is(instance.get('test'), undefined);
});

test('get and set', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 200
  });
  instance.set('name', 'test');
  t.is(instance.get('name'), 'test');
});

test('get and set, length not enough', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 10,
    valueBufferLength: 20
  });
  try {
    instance.set('name', 'test');
    t.is(1, 2);
  } catch (e) {
    t.is(e instanceof Error, true);
  }
});

test('get and set, reset', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 200
  });
  instance.set('name', 'test');
  instance.set('name', 'test2');
  t.is(instance.get('name'), 'test2');
});

test('get and set, reset2', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 200
  });
  instance.set('name', 'test');
  instance.set('name', 't');
  t.is(instance.get('name'), 't');
});

test('get and set, reset4', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 200
  });
  instance.set('name', 'test');
  instance.set('name', 'wwww');
  t.is(instance.get('name'), 'wwww');
});

test('get, buffer', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 200
  });
  instance.set('name', 'test');
  instance.set('name', 't');
  const data = instance.get('name', null);
  t.is(data instanceof Buffer, true);
  t.is(data[0], 116);
});

test('delete', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 200
  });
  instance.delete('name');
  // console.log(instance.keyArray)
  t.is(instance.get('name'), undefined);
});

test('delete 2', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 200
  });
  instance.set('name', 'test');
  instance.delete('name');
  t.is(instance.get('name'), undefined);
});

test('delete 3', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 200
  });
  instance.set('name', 'test');
  instance.delete('name2');
  t.is(instance.get('name'), 'test');
});

test('delete 4', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 200
  });
  instance.set('name', 'test');
  instance.set('name1', 'test');
  instance.delete('name');
  t.is(instance.get('name1'), 'test');
});

test('get keys', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 200
  });
  instance.set('name', 'test');
  instance.set('name1', 'test');
  instance.delete('name');
  t.deepEqual(instance.keys(), ['name1']);
});

test('get keys 2', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 200
  });
  instance.set('name', 'test');
  instance.set('name1', 'test');
  t.deepEqual(instance.keys(), ['name', 'name1']);
});

test('get keys 3', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 200
  });
  t.deepEqual(instance.keys(), []);
});

test('set error', t => {
  const instance = new SharedArrayBufferStore({
    keyBufferLength: 100,
    valueBufferLength: 20
  });
  try {
    instance.set('value', 'fasdfafasdfasdfasdfafd');
    t.is(1, 2);
  } catch (e) {
    t.is(e instanceof Error, true);
  }
});
