| 
									
										
										
										
											2018-03-01 10:41:35 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08:00
										 |  |  | import chai = require('chai'); | 
					
						
							| 
									
										
										
										
											2018-10-29 21:25:00 +01:00
										 |  |  | import {parseArguments} from '../lib/cli'; | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('cli: parseArguments', () => { | 
					
						
							|  |  |  |   it('should show usage with error when supplied with no arguments', () => { | 
					
						
							| 
									
										
										
										
											2018-10-29 21:25:00 +01:00
										 |  |  |     const {mode, errors} = parseArguments([]); | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08:00
										 |  |  |     chai.assert.equal(mode, 'help'); | 
					
						
							|  |  |  |     chai.assert.deepEqual(errors, ['No input file specified.']); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should show usage without error when supplied with --help', () => { | 
					
						
							| 
									
										
										
										
											2018-10-29 21:25:00 +01:00
										 |  |  |     const {mode, errors} = parseArguments(['--help']); | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08:00
										 |  |  |     chai.assert.equal(mode, 'help'); | 
					
						
							|  |  |  |     chai.assert.deepEqual(errors, []); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should show usage with error when supplied with none of --out/verify[Dir]', () => { | 
					
						
							| 
									
										
										
										
											2018-10-29 21:25:00 +01:00
										 |  |  |     const {mode, errors} = parseArguments(['input.d.ts']); | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08:00
										 |  |  |     chai.assert.equal(mode, 'help'); | 
					
						
							|  |  |  |     chai.assert.deepEqual(errors, ['Specify either --out[Dir] or --verify[Dir]']); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should show usage with error when supplied with both of --out/verify[Dir]', () => { | 
					
						
							| 
									
										
										
										
											2018-10-29 21:25:00 +01:00
										 |  |  |     const {mode, errors} = | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08:00
										 |  |  |         parseArguments(['--out', 'out.d.ts', '--verifyDir', 'golden.d.ts', 'input.d.ts']); | 
					
						
							|  |  |  |     chai.assert.equal(mode, 'help'); | 
					
						
							|  |  |  |     chai.assert.deepEqual(errors, ['Specify either --out[Dir] or --verify[Dir]']); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should show usage with error when supplied without input file', () => { | 
					
						
							| 
									
										
										
										
											2018-10-29 21:25:00 +01:00
										 |  |  |     const {mode, errors} = parseArguments(['--out', 'output.d.ts']); | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08:00
										 |  |  |     chai.assert.equal(mode, 'help'); | 
					
						
							|  |  |  |     chai.assert.deepEqual(errors, ['No input file specified.']); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should show usage with error when supplied without input file', () => { | 
					
						
							| 
									
										
										
										
											2018-10-29 21:25:00 +01:00
										 |  |  |     const {mode, errors} = parseArguments(['--out', 'output.d.ts', 'first.d.ts', 'second.d.ts']); | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08:00
										 |  |  |     chai.assert.equal(mode, 'help'); | 
					
						
							|  |  |  |     chai.assert.deepEqual(errors, ['More than one input specified. Use --outDir instead.']); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should use out mode when supplied with --out', () => { | 
					
						
							|  |  |  |     const {argv, mode, errors} = parseArguments(['--out', 'out.d.ts', 'input.d.ts']); | 
					
						
							|  |  |  |     chai.assert.equal(argv['out'], 'out.d.ts'); | 
					
						
							|  |  |  |     chai.assert.deepEqual(argv._, ['input.d.ts']); | 
					
						
							|  |  |  |     chai.assert.equal(mode, 'out'); | 
					
						
							|  |  |  |     chai.assert.deepEqual(errors, []); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should use verify mode when supplied with --verify', () => { | 
					
						
							|  |  |  |     const {argv, mode, errors} = parseArguments(['--verify', 'out.d.ts', 'input.d.ts']); | 
					
						
							|  |  |  |     chai.assert.equal(argv['verify'], 'out.d.ts'); | 
					
						
							|  |  |  |     chai.assert.deepEqual(argv._, ['input.d.ts']); | 
					
						
							|  |  |  |     chai.assert.equal(mode, 'verify'); | 
					
						
							|  |  |  |     chai.assert.deepEqual(errors, []); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |