/**
 * 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 AlgebraicType from '../../algebraic-type' ; import * as InitNewUnavailable from '../../plugins/init-new-unavailable' ; import * as ObjC from '../../objc' ; import * as ObjectSpec from '../../object-spec' ; import * as ObjectSpecHelpers from '../../object-spec-helpers' ; const ObjectSpecPlugin = InitNewUnavailable . createPlugin ( ) ; const AlgebraicTypePlugin = InitNewUnavailable . createAlgebraicTypePlugin ( ) ; describe ( 'ObjectSpecPlugins.InitNewUnavailable' , function ( ) { describe ( '#instanceMethods' , function ( ) { it ( 'generates no instance or class methods, if no attributes are given' , function ( ) { const objectType = { annotations : { } , attributes : [ ] , comments : [ ] , typeLookups : [ ] , excludes : [ ] , includes : [ 'RMInitNewUnavailable' ] , libraryName : null , typeName : 'Foo' } ; const instanceMethods = ObjectSpecPlugin . instanceMethods ( objectType ) ; const expectedInstanceMethods = [ ] ; expect ( instanceMethods ) . toEqualJSON ( expectedInstanceMethods ) ; const classMethods = ObjectSpecPlugin . classMethods ( objectType ) ; const expectedClassMethods = [ ] ; expect ( classMethods ) . toEqualJSON ( expectedClassMethods ) ; } ) ; it ( 'generates unavailable init/new instance methods, if at least one attribute is given' , function ( ) { const objectType = { annotations : { } , attributes : [ new ObjectSpecHelpers . AttributeBuilder ( 'value' , new ObjectSpecHelpers . AttributeTypeBuilder ( 'NSString' , 'NSString *' , 'NSObject' ) ) . asObject ( ) , ] , comments : [ ] , typeLookups : [ ] , excludes : [ ] , includes : [ 'RMInitNewUnavailable' ] , libraryName : null , typeName : 'Foo' } ; const instanceMethods = ObjectSpecPlugin . instanceMethods ( objectType ) ; const expectedInstanceMethods = [ { preprocessors : [ ] , belongsToProtocol : 'NSObject' , code : [ ] , comments : [ ] , compilerAttributes : [ 'NS_UNAVAILABLE' ] , keywords : [ { name : 'init' , argument : null } , ] , returnType : { type : { name : 'instancetype' , reference : 'instancetype' } , modifiers : [ ] } } , ] ; expect ( instanceMethods ) . toEqualJSON ( expectedInstanceMethods ) ; const classMethods = ObjectSpecPlugin . classMethods ( objectType ) ; const expectedClassMethods = [ { preprocessors : [ ] , belongsToProtocol : 'NSObject' , code : [ ] , comments : [ ] , compilerAttributes : [ 'NS_UNAVAILABLE' ] , keywords : [ { name : 'new' , argument : null } , ] , returnType : { type : { name : 'instancetype' , reference : 'instancetype' } , modifiers : [ ] } } , ] ; expect ( classMethods ) . toEqualJSON ( expectedClassMethods ) ; } ) ; } ) ; } ) ; describe ( 'AlgebraicTypePlugins.InitNewUnavailable' , function ( ) { describe ( '#instanceMethods' , function ( ) { it ( 'always generates unavailable init/new methods for ADTs' , function ( ) { const algebraicType = { annotations : { } , name : 'Foo' , includes : [ 'RMInitNewUnavailable' ] , typeLookups : [ ] , excludes : [ ] , libraryName : null , comments : [ ] , subtypes : [ AlgebraicType . Subtype . NamedAttributeCollectionDefinition ( { name : 'subtypeOne' , comments : [ ] , attributes : [ ] , annotations : { } } ) , ] } ; const instanceMethods = AlgebraicTypePlugin . instanceMethods ( algebraicType ) ; const expectedInstanceMethods = [ { preprocessors : [ ] , belongsToProtocol : 'NSObject' , code : [ ] , comments : [ ] , compilerAttributes : [ 'NS_UNAVAILABLE' ] , keywords : [ { name : 'init' , argument : null } , ] , returnType : { type : { name : 'instancetype' , reference : 'instancetype' } , modifiers : [ ] } } , ] ; expect ( instanceMethods ) . toEqualJSON ( expectedInstanceMethods ) ; const classMethods = AlgebraicTypePlugin . classMethods ( algebraicType ) ; const expectedClassMethods = [ { preprocessors : [ ] , belongsToProtocol : 'NSObject' , code : [ ] , comments : [ ] , compilerAttributes : [ 'NS_UNAVAILABLE' ] , keywords : [ { name : 'new' , argument : null } , ] , returnType : { type : { name : 'instancetype' , reference : 'instancetype' } , modifiers : [ ] } } , ] ; expect ( classMethods ) . toEqualJSON ( expectedClassMethods ) ; } ) ; } ) ; } ) ;