|
| 1 | +import { expect } from 'chai'; |
| 2 | +import comment from '../src/comment'; |
| 3 | +import Vorpal from 'vorpal'; |
| 4 | +import { stdout } from 'test-console'; |
| 5 | + |
| 6 | +describe('vorpal-comment', function() { |
| 7 | + |
| 8 | + it('should be properly imported as a function', () => { |
| 9 | + expect(comment).to.be.instanceof(Function); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should be imported by Vorpal', () => { |
| 13 | + expect(() => { |
| 14 | + new Vorpal().use(comment); |
| 15 | + new Vorpal().use(comment, { command: '!' }); |
| 16 | + new Vorpal().use(comment, { alias: '//' }); |
| 17 | + new Vorpal().use(comment, { command: '!', alias: '//' }); |
| 18 | + new Vorpal().use(comment, { command: '!', alias: [ '//', '--', '<<' ] }); |
| 19 | + }).to.not.throw(); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should allow comments starting with #', () => { |
| 23 | + const output = stdout.inspectSync(() => { |
| 24 | + const vorpal = new Vorpal(); |
| 25 | + vorpal.use(comment); |
| 26 | + vorpal.exec('# a comment line'); |
| 27 | + }); |
| 28 | + // no output |
| 29 | + expect(output).to.have.length(0); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should allow comments starting with ? instead of #', () => { |
| 33 | + const output = stdout.inspectSync(() => { |
| 34 | + const vorpal = new Vorpal(); |
| 35 | + vorpal.use(comment, { command: '?' }); |
| 36 | + vorpal.exec('? a comment line'); |
| 37 | + }); |
| 38 | + // no output |
| 39 | + expect(output).to.have.length(0); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should allow comments starting with an alias of //', () => { |
| 43 | + const output = stdout.inspectSync(() => { |
| 44 | + const vorpal = new Vorpal(); |
| 45 | + vorpal.use(comment, { alias: '//' }); |
| 46 | + vorpal.exec('// a comment line'); |
| 47 | + }); |
| 48 | + // no output |
| 49 | + expect(output).to.have.length(0); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should allow comments starting with aliases of // -- <<', () => { |
| 53 | + const output = stdout.inspectSync(() => { |
| 54 | + const vorpal = new Vorpal(); |
| 55 | + vorpal.use(comment, { alias: [ '//', '--', '<<' ] }); |
| 56 | + vorpal.exec('// a comment line'); |
| 57 | + vorpal.exec('-- a comment line'); |
| 58 | + vorpal.exec('<< a comment line'); |
| 59 | + }); |
| 60 | + // no output |
| 61 | + expect(output).to.have.length(0); |
| 62 | + }); |
| 63 | +}); |
0 commit comments