@@ -87,42 +87,38 @@ namespace ts {
87
87
} ) ;
88
88
89
89
it ( "can get string literal types" , ( ) => {
90
- assert ( ( checker . getLiteralType ( "foobar" ) as LiteralType ) . value === "foobar" ) ;
90
+ assert ( checker . getStringLiteralType ( "foobar" ) . value === "foobar" ) ;
91
91
} ) ;
92
92
93
93
it ( "can get numeber literal types" , ( ) => {
94
- assert ( ( checker . getLiteralType ( 42 ) as LiteralType ) . value === "42" ) ;
94
+ assert ( checker . getNumberLiteralType ( 42 ) . value === 42 ) ;
95
95
} ) ;
96
96
97
97
it ( "doesn't choke on exceptional input to literal type getters" , ( ) => {
98
- assert . equal ( ( checker . getLiteralType ( "" ) as LiteralType ) . value , "" ) ;
99
- assert . throws ( ( ) => checker . getLiteralType ( /*content*/ undefined ) , Error , "Debug Failure. False expression: " ) ;
98
+ assert . equal ( checker . getStringLiteralType ( "" ) . value , "" ) ;
99
+ assert . throws ( ( ) => checker . getStringLiteralType ( /*content*/ undefined ) , Error , "Argument to getLiteralType was null or undefined " ) ;
100
100
/* tslint:disable:no-null-keyword */
101
- assert . throws ( ( ) => checker . getLiteralType ( /*content*/ null ) , Error , "Debug Failure. False expression: " ) ;
101
+ assert . throws ( ( ) => checker . getNumberLiteralType ( /*content*/ null ) , Error , "Argument to getLiteralType was null or undefined " ) ;
102
102
/* tslint:enable:no-null-keyword */
103
103
let hugeStringLiteral = map ( new Array ( 2 ** 16 - 1 ) , ( ) => "a" ) . join ( ) ;
104
- assert . equal ( ( checker . getLiteralType ( hugeStringLiteral ) as LiteralType ) . value , hugeStringLiteral ) ;
104
+ assert . equal ( checker . getStringLiteralType ( hugeStringLiteral ) . value , hugeStringLiteral ) ;
105
105
hugeStringLiteral = undefined ;
106
106
107
-
108
- assert . throws ( ( ) => checker . getLiteralType ( /*content*/ undefined ) , Error , "Debug Failure. False expression:" ) ;
109
- /* tslint:disable:no-null-keyword */
110
- assert . throws ( ( ) => checker . getLiteralType ( /*content*/ null ) , Error , "Debug Failure. False expression:" ) ;
111
- /* tslint:enable:no-null-keyword */
112
-
113
107
const sanityChecks = [ "000" , "0b0" , "0x0" , "0.0" , "0e-0" , "-010" , "-0b10" , "-0x10" , "-0o10" , "-10.0" , "-1e-1" , "NaN" , "Infinity" , "-Infinity" ] ;
114
108
forEach ( sanityChecks , num => {
115
- assert . equal ( ( checker . getLiteralType ( num ) as LiteralType ) . value , num , `${ num } did not match.` ) ;
109
+ assert . equal ( checker . getStringLiteralType ( num ) . value , num , `${ num } did not match.` ) ;
116
110
} ) ;
117
111
118
- const insanityChecks = [ [ 0 , "0" ] , [ 0b0 , "0" ] , [ - 10 , "-10" ] , [ NaN , "NaN" ] , [ Infinity , "Infinity" ] , [ - Infinity , "-Infinity" ] ] ;
119
- forEach ( insanityChecks , ( [ num , expected ] ) => {
120
- assert . equal ( ( checker . getLiteralType ( num as any ) as LiteralType ) . value , expected , `${ JSON . stringify ( num ) } should be ${ expected } ` ) ;
112
+ const insanityChecks = [ 0 , 0b0 , - 10 , Infinity , - Infinity ] ;
113
+ forEach ( insanityChecks , ( num ) => {
114
+ assert . equal ( checker . getNumberLiteralType ( num ) . value , num , `${ JSON . stringify ( num ) } should be ${ num } ` ) ;
121
115
} ) ;
122
116
117
+ assert . isNaN ( checker . getNumberLiteralType ( NaN ) . value ) ;
118
+
123
119
const instabilityChecks = [ { foo : 42 } , new Date ( 42 ) , [ 42 ] , new Number ( 42 ) , new String ( "42" ) ] ;
124
120
forEach ( instabilityChecks , ( bad ) => {
125
- assert . throws ( ( ) => checker . getLiteralType ( bad as any ) ) ;
121
+ assert . throws ( ( ) => checker . getStringLiteralType ( bad as any ) ) ;
126
122
} ) ;
127
123
} ) ;
128
124
@@ -152,7 +148,7 @@ namespace ts {
152
148
assert . notEqual ( checker . lookupGlobalType ( "Function" ) , innerFunction , "Inner function type should be different than global" ) ;
153
149
const brandNameType = checker . getTypeOfSymbol ( innerFunction . getProperty ( "myBrand" ) ) ;
154
150
assert . notEqual ( brandNameType , checker . getUnknownType ( ) , "Brand type on inner function should not be unknown" ) ;
155
- assert . equal ( brandNameType , checker . getLiteralType ( 42 ) , "Brand type should be 42" ) ;
151
+ assert . equal ( brandNameType , checker . getNumberLiteralType ( 42 ) , "Brand type should be 42" ) ;
156
152
157
153
let skipped = false ;
158
154
const functionBody2 = forEachChild ( program . getSourceFile ( "test.ts" ) , node => node . kind === SyntaxKind . FunctionDeclaration ? skipped ? ( node as FunctionDeclaration ) : ( skipped = true , undefined ) : undefined ) . body ;
0 commit comments