<commit_before>/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2016, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
'use strict';

import expect = require('expect.js');

import {
  ICommandItem
} from '../../lib/commandregistry/index';

import {
  CommandRegistry
} from '../../lib/commandregistry/plugin';

// import {
//   IShortcutItem
// } from '../../lib/shortcutmanager/index';
//
// import {
//   ShortcutManager
// } from '../../lib/shortcutmanager/plugin';



describe('phosphide', () => {
  let reg: CommandRegistry = null;

  describe('CommandRegistry', () => {
    let cmd: (args: any) => void = null;
    let item: ICommandItem = null;
    let count = 0;

    beforeEach(() => {
      count = 0;
      reg = new CommandRegistry();
      cmd = (args: any) => { count += 1; };
      item = {
        id: "cmd:test",
        handler: cmd
      };
    });

    describe('#create()', () => {

      it('should return a new instance', () => {
        expect(CommandRegistry.create()).to.not.be(reg);
      });

    });

    describe('#constructor()', () => {

      it('should accept no arguments', () => {
        expect(reg instanceof CommandRegistry).to.be(true);
      });

    });

    describe('#list()', () => {

      it('should return an empty array by default', () => {
        expect(reg.list().length).to.be(0);
      });

      it('should return an array of keys if commands are registered', () => {
        reg.add([item]);
        expect(reg.list().length).to.be(1);
      });

      it('should return a new array each time', () => {
        expect(reg.list()).to.not.be(reg.list());
      });

    });

    describe('#get()', () => {

      it('should return `undefined` if command is not registered', () => {
        expect(reg.get("cmd:test")).to.be(undefined);
      });

      it('should correctly return a registered command', () => {
        reg.add([item]);
        expect(reg.get("cmd:test")).to.be(cmd);
      });

    });

    describe('#add()', () => {

      it('should return a disposable', () => {
        let disp = reg.add([item]);
        expect(reg.list().length).to.be(1);
        disp.dispose();
        expect(reg.list().length).to.be(0);
      });

      it('should not add a given id more than once', () => {
        let disp = reg.add([item]);
        let item2 = {
          id: "cmd:test",
          handler: cmd
        };
        let disp2 = reg.add([item2]);
        expect(reg.list().length).to.be(1);
        disp2.dispose();
        expect(reg.list().length).to.be(1);
        disp.dispose();
        expect(reg.list().length).to.be(0);
      });

    });

  });

  // describe('ShortcutManager', () => {
  //   let shortcuts: ShortcutManager = null;
  //
  //   beforeEach(() => {
  //     reg = new CommandRegistry();
  //     shortcuts = new ShortcutManager(reg);
  //   });
  //
  //   describe('#create()', () => {
  //
  //     it('should create a new instance', () => {
  //       expect(new ShortcutManager(reg)).to.not.be(shortcuts);
  //     });
  //
  //   });
  //
  //   describe('#constructor()', () => {
  //
  //     it('should take a single argument', () => {
  //       expect(shortcuts instanceof ShortcutManager).to.be(true);
  //     });
  //
  //   });
  //
  // });<commit_msg>Add back shortcut tests<commit_after>/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2016, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
'use strict';

import expect = require('expect.js');

import {
  ICommandItem
} from '../../lib/commandregistry/index';

import {
  CommandRegistry
} from '../../lib/commandregistry/plugin';

import {
  IShortcutItem
} from '../../lib/shortcutmanager/index';

import {
  ShortcutManager
} from '../../lib/shortcutmanager/plugin';



describe('phosphide', () => {
  let reg: CommandRegistry = null;

  describe('CommandRegistry', () => {
    let cmd: (args: any) => void = null;
    let item: ICommandItem = null;
    let count = 0;

    beforeEach(() => {
      count = 0;
      reg = new CommandRegistry();
      cmd = (args: any) => { count += 1; };
      item = {
        id: "cmd:test",
        handler: cmd
      };
    });

    describe('#create()', () => {

      it('should return a new instance', () => {
        expect(CommandRegistry.create()).to.not.be(reg);
      });

    });

    describe('#constructor()', () => {

      it('should accept no arguments', () => {
        expect(reg instanceof CommandRegistry).to.be(true);
      });

    });

    describe('#list()', () => {

      it('should return an empty array by default', () => {
        expect(reg.list().length).to.be(0);
      });

      it('should return an array of keys if commands are registered', () => {
        reg.add([item]);
        expect(reg.list().length).to.be(1);
      });

      it('should return a new array each time', () => {
        expect(reg.list()).to.not.be(reg.list());
      });

    });

    describe('#get()', () => {

      it('should return `undefined` if command is not registered', () => {
        expect(reg.get("cmd:test")).to.be(undefined);
      });

      it('should correctly return a registered command', () => {
        reg.add([item]);
        expect(reg.get("cmd:test")).to.be(cmd);
      });

    });

    describe('#add()', () => {

      it('should return a disposable', () => {
        let disp = reg.add([item]);
        expect(reg.list().length).to.be(1);
        disp.dispose();
        expect(reg.list().length).to.be(0);
      });

      it('should not add a given id more than once', () => {
        let disp = reg.add([item]);
        let item2 = {
          id: "cmd:test",
          handler: cmd
        };
        let disp2 = reg.add([item2]);
        expect(reg.list().length).to.be(1);
        disp2.dispose();
        expect(reg.list().length).to.be(1);
        disp.dispose();
        expect(reg.list().length).to.be(0);
      });

    });

  });

  describe('ShortcutManager', () => {
    let shortcuts: ShortcutManager = null;

    beforeEach(() => {
      reg = new CommandRegistry();
      shortcuts = new ShortcutManager(reg);
    });

    describe('#create()', () => {

      it('should create a new instance', () => {
        expect(new ShortcutManager(reg)).to.not.be(shortcuts);
      });

    });

    describe('#constructor()', () => {

      it('should take a single argument', () => {
        expect(shortcuts instanceof ShortcutManager).to.be(true);
      });

    });

  });
{'fraction_non_alphanumeric': 0.23723419644148705, 'fraction_numerical': 0.006654129900188052, 'mean_word_length': 1.9087084560370216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 53, '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': '2050045', 'n_tokens_mistral': 2092, 'n_tokens_neox': 2004, 'n_words': 425}