/**
 * Copyright (c) 2016-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */ import * as CommandLine from '../commandline' ; import * as List from '../list' ; import * as Logging from '../logging' ; import * as Maybe from '../maybe' ; describe ( 'CommandLine' , function ( ) { describe ( '#parseArgs' , function ( ) { it ( 'returns an error when no arguments are passed in' , function ( ) { const args = [ ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = null ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'gives the default levels for everything when only a path is provided' , function ( ) { const args = [ 'project/to/generate' ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = { givenPaths : [ 'project/to/generate' ] , adtConfigPath : undefined , valueObjectConfigPath : undefined , objectConfigPath : undefined , interestedLoggingTypes : List . of ( Logging . LoggingType . info , Logging . LoggingType . error ) , minimalLevel : 10 , dryRun : false , outputPath : undefined , includes : [ ] , excludes : [ ] , outputFlags : { emitHeaders : true , emitImplementations : true , outputList : [ ] , singleFile : false } } ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'decreases the minimal level to one when --verbose is provided' , function ( ) { const args = [ '--verbose' , 'project/to/generate' ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = { givenPaths : [ 'project/to/generate' ] , adtConfigPath : undefined , valueObjectConfigPath : undefined , objectConfigPath : undefined , interestedLoggingTypes : List . of ( Logging . LoggingType . info , Logging . LoggingType . error ) , minimalLevel : 1 , dryRun : false , outputPath : undefined , includes : [ ] , excludes : [ ] , outputFlags : { emitHeaders : true , emitImplementations : true , outputList : [ ] , singleFile : false } } ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'includes perf logging when --perf-log is provided' , function ( ) { const args = [ '--perf-log' , 'project/to/generate' ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = { givenPaths : [ 'project/to/generate' ] , adtConfigPath : undefined , valueObjectConfigPath : undefined , objectConfigPath : undefined , interestedLoggingTypes : List . of ( Logging . LoggingType . info , Logging . LoggingType . error , Logging . LoggingType . performance ) , minimalLevel : 10 , dryRun : false , outputPath : undefined , includes : [ ] , excludes : [ ] , outputFlags : { emitHeaders : true , emitImplementations : true , outputList : [ ] , singleFile : false } } ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'includes debug logging when --debug is provided' , function ( ) { const args = [ '--debug' , 'project/to/generate' ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = { givenPaths : [ 'project/to/generate' ] , adtConfigPath : undefined , valueObjectConfigPath : undefined , objectConfigPath : undefined , interestedLoggingTypes : List . of ( Logging . LoggingType . info , Logging . LoggingType . error , Logging . LoggingType . debug ) , minimalLevel : 10 , dryRun : false , outputPath : undefined , includes : [ ] , excludes : [ ] , outputFlags : { emitHeaders : true , emitImplementations : true , outputList : [ ] , singleFile : false } } ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'includes dry run when --dry-run is provided' , function ( ) { const args = [ '--dry-run' , 'project/to/generate' ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = { givenPaths : [ 'project/to/generate' ] , adtConfigPath : undefined , valueObjectConfigPath : undefined , objectConfigPath : undefined , interestedLoggingTypes : List . of ( Logging . LoggingType . info , Logging . LoggingType . error ) , minimalLevel : 10 , dryRun : true , outputPath : undefined , includes : [ ] , excludes : [ ] , outputFlags : { emitHeaders : true , emitImplementations : true , outputList : [ ] , singleFile : false } } ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'includes no logging info when --silent is provided' , function ( ) { const args = [ '--debug' , '--perf-log' , '--silent' , 'project/to/generate' , ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = { givenPaths : [ 'project/to/generate' ] , adtConfigPath : undefined , valueObjectConfigPath : undefined , objectConfigPath : undefined , interestedLoggingTypes : List . of < Logging . LoggingType > ( ) , minimalLevel : 10 , dryRun : false , outputPath : undefined , includes : [ ] , excludes : [ ] , outputFlags : { emitHeaders : true , emitImplementations : true , outputList : [ ] , singleFile : false } } ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'includes valueObjectConfigPath' , function ( ) { const args = [ 'project/to/generate' , '--value-object-config-path' , 'path/to/valueObjectConfig' , ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = { givenPaths : [ 'project/to/generate' ] , adtConfigPath : undefined , valueObjectConfigPath : 'path/to/valueObjectConfig' , objectConfigPath : undefined , interestedLoggingTypes : List . of ( Logging . LoggingType . info , Logging . LoggingType . error ) , minimalLevel : 10 , dryRun : false , outputPath : undefined , includes : [ ] , excludes : [ ] , outputFlags : { emitHeaders : true , emitImplementations : true , outputList : [ ] , singleFile : false } } ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'includes objectConfigPath' , function ( ) { const args = [ 'project/to/generate' , '--object-config-path' , 'path/to/objectConfig' , ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = { givenPaths : [ 'project/to/generate' ] , adtConfigPath : undefined , valueObjectConfigPath : undefined , objectConfigPath : 'path/to/objectConfig' , interestedLoggingTypes : List . of ( Logging . LoggingType . info , Logging . LoggingType . error ) , minimalLevel : 10 , dryRun : false , outputPath : undefined , includes : [ ] , excludes : [ ] , outputFlags : { emitHeaders : true , emitImplementations : true , outputList : [ ] , singleFile : false } } ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'includes an output directory when --output-path is passed' , function ( ) { const args = [ '--output-path=path/to/output' , 'project/to/generate' , ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = { givenPaths : [ 'project/to/generate' ] , adtConfigPath : undefined , valueObjectConfigPath : undefined , objectConfigPath : undefined , interestedLoggingTypes : List . of ( Logging . LoggingType . info , Logging . LoggingType . error ) , minimalLevel : 10 , dryRun : false , outputPath : 'path/to/output' , includes : [ ] , excludes : [ ] , outputFlags : { emitHeaders : true , emitImplementations : true , outputList : [ ] , singleFile : false } } ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'includes a list of includes and excludes if specified' , function ( ) { const args = [ 'project/to/generate' , '--include=PluginOne' , '--include=PluginTwo' , '--exclude=PluginThree' , ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = { givenPaths : [ 'project/to/generate' ] , adtConfigPath : undefined , valueObjectConfigPath : undefined , objectConfigPath : undefined , interestedLoggingTypes : List . of ( Logging . LoggingType . info , Logging . LoggingType . error ) , minimalLevel : 10 , dryRun : false , outputPath : undefined , includes : [ 'PluginOne' , 'PluginTwo' ] , excludes : [ 'PluginThree' ] , outputFlags : { emitHeaders : true , emitImplementations : true , outputList : [ ] , singleFile : false } } ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'returns nothing when both --headers-only and implementation-only are passed' , function ( ) { const args = [ '--headers-only' , '--implementation-only' ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = null ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'includes a list of things to emit' , function ( ) { const args = [ 'project/to/generate' , '--include=PluginOne' , '--include=PluginTwo' , '--emit=PluginOne' , '--emit=object' , ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = { givenPaths : [ 'project/to/generate' ] , adtConfigPath : undefined , valueObjectConfigPath : undefined , objectConfigPath : undefined , interestedLoggingTypes : List . of ( Logging . LoggingType . info , Logging . LoggingType . error ) , minimalLevel : 10 , dryRun : false , outputPath : undefined , includes : [ 'PluginOne' , 'PluginTwo' ] , excludes : [ ] , outputFlags : { emitHeaders : true , emitImplementations : true , outputList : [ 'PluginOne' , 'object' ] , singleFile : false } } ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'emitting "all" ensures empty output list, even if other emit options are present' , function ( ) { const args = [ 'project/to/generate' , '--include=PluginOne' , '--include=PluginTwo' , '--emit=all' , '--emit=foo' , ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = { givenPaths : [ 'project/to/generate' ] , adtConfigPath : undefined , valueObjectConfigPath : undefined , objectConfigPath : undefined , interestedLoggingTypes : List . of ( Logging . LoggingType . info , Logging . LoggingType . error ) , minimalLevel : 10 , dryRun : false , outputPath : undefined , includes : [ 'PluginOne' , 'PluginTwo' ] , excludes : [ ] , outputFlags : { emitHeaders : true , emitImplementations : true , outputList : [ ] , singleFile : false } } ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; it ( 'returns nothing when only --verbose is provided' , function ( ) { const args = [ '--verbose' ] ; const parsedArgs = CommandLine . parseArgs ( args ) ; const expectedResult = null ; expect ( parsedArgs ) . toEqualJSON ( expectedResult ) ; } ) ; } ) ; } ) ;