@@ -87,39 +87,35 @@ 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 . getLiteralType ( "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 . getLiteralType ( 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 . getLiteralType ( "" ) . value , "" ) ;
99
+ assert . throws ( ( ) => checker . getLiteralType ( /*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 . getLiteralType ( /*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 . getLiteralType ( 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 . getLiteralType ( 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 . getLiteralType ( num ) . value , num , `${ JSON . stringify ( num ) } should be ${ num } ` ) ;
121
115
} ) ;
122
116
117
+ assert . isNaN ( checker . getLiteralType ( 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
121
assert . throws ( ( ) => checker . getLiteralType ( bad as any ) ) ;
0 commit comments