<commit_before>/**!
 *
 * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.
 * @private
 */

import {assert} from '@ciscospark/test-helper-chai';

export default function runAbstractStorageAdapterSpec(adapter) {
  const key = `key`;
  const namespace = `namespace`;
  const obj = {a: 1};
  const primitive = 1;
  const options = {
    logger: console
  };

  describe(`#bind()`, () => {
    // namespace and options.logger are required more to make sure we always
    // call bind correctly rather than to make sure the adapter uses them.
    it(`requires a namespace`, () => assert.isRejected(adapter.bind(), /`namespace` is required/));

    it(`requires a logger option`, () => assert.isRejected(adapter.bind(namespace), /`options.logger` is required/));

    it(`returns a db interface`, () => assert.isFulfilled(adapter.bind(namespace, options)));

    describe(`bound`, () => {
      let bound;
      before(() => adapter.bind(namespace, options)
        .then((b) => {
          bound = b;
        }));

      describe(`#put()`, () => {
        it(`puts a primitive into the store`, () => bound.put(key, primitive)
          .then(() => assert.becomes(bound.get(key), primitive)));

        [0, false, null].forEach((falsey) => {
          it(`puts falsey primitive \`${falsey}\` into the store`, () => bound.put(key, falsey)
            .then(() => assert.becomes(bound.get(key), falsey)));
        });

        it(`puts an object into the store`, () => bound.put(key, obj)
          .then(() => assert.becomes(bound.get(key), obj)));

        it(`handles concurrency`, () => Promise.all([
          bound.put(key, 1),
          bound.put(key, 2),
          bound.put(key, 3)<commit_msg>test(storage-adapter-spec): prove the storage adapter doesn't duplicate array contents when loaded/saved/loaded again<commit_after>/**!
 *
 * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.
 * @private
 */

import {assert} from '@ciscospark/test-helper-chai';

export default function runAbstractStorageAdapterSpec(adapter) {
  const key = `key`;
  const namespace = `namespace`;
  const obj = {a: 1};
  const primitive = 1;
  const options = {
    logger: console
  };

  describe(`#bind()`, () => {
    // namespace and options.logger are required more to make sure we always
    // call bind correctly rather than to make sure the adapter uses them.
    it(`requires a namespace`, () => assert.isRejected(adapter.bind(), /`namespace` is required/));

    it(`requires a logger option`, () => assert.isRejected(adapter.bind(namespace), /`options.logger` is required/));

    it(`returns a db interface`, () => assert.isFulfilled(adapter.bind(namespace, options)));

    describe(`bound`, () => {
      let bound;
      before(() => adapter.bind(namespace, options)
        .then((b) => {
          bound = b;
        }));

      describe(`#put()`, () => {
        it(`puts a primitive into the store`, () => bound.put(key, primitive)
          .then(() => assert.becomes(bound.get(key), primitive)));

        [0, false, null].forEach((falsey) => {
          it(`puts falsey primitive \`${falsey}\` into the store`, () => bound.put(key, falsey)
            .then(() => assert.becomes(bound.get(key), falsey)));
        });

        it(`puts an object into the store`, () => bound.put(key, obj)
          .then(() => assert.becomes(bound.get(key), obj)));

        it(`puts an array into the store`, () => bound.put(key, [1, 2])
          .then(() => assert.becomes(bound.get(key), [1, 2])));

        it(`puts an array back into the store`, () => bound.put(key, [1, 2])
          .then(() => assert.becomes(bound.get(key), [1, 2]))
          .then(() => bound.put(key, [1, 2, 3]))
          .then(() => assert.becomes(bound.get(key), [1, 2, 3])));

        it(`handles concurrency`, () => Promise.all([
          bound.put(key, 1),
          bound.put(key, 2),
          bound.put(key, 3)
{'fraction_non_alphanumeric': 0.18277364778261984, 'fraction_numerical': 0.008715713919507819, 'mean_word_length': 2.8481262327416172, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2355421', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1164, 'n_words': 321}