Skip to content

Commit 3a9686e

Browse files
committed
fix tests
1 parent ee18f7d commit 3a9686e

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/harness/unittests/checkerPublicRelationships.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,42 +87,38 @@ namespace ts {
8787
});
8888

8989
it("can get string literal types", () => {
90-
assert((checker.getLiteralType("foobar") as LiteralType).value === "foobar");
90+
assert(checker.getStringLiteralType("foobar").value === "foobar");
9191
});
9292

9393
it("can get numeber literal types", () => {
94-
assert((checker.getLiteralType(42) as LiteralType).value === "42");
94+
assert(checker.getNumberLiteralType(42).value === 42);
9595
});
9696

9797
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");
100100
/* 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");
102102
/* tslint:enable:no-null-keyword */
103103
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);
105105
hugeStringLiteral = undefined;
106106

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-
113107
const sanityChecks = ["000", "0b0", "0x0", "0.0", "0e-0", "-010", "-0b10", "-0x10", "-0o10", "-10.0", "-1e-1", "NaN", "Infinity", "-Infinity"];
114108
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.`);
116110
});
117111

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}`);
121115
});
122116

117+
assert.isNaN(checker.getNumberLiteralType(NaN).value);
118+
123119
const instabilityChecks = [{ foo: 42 }, new Date(42), [42], new Number(42), new String("42")];
124120
forEach(instabilityChecks, (bad) => {
125-
assert.throws(() => checker.getLiteralType(bad as any));
121+
assert.throws(() => checker.getStringLiteralType(bad as any));
126122
});
127123
});
128124

@@ -152,7 +148,7 @@ namespace ts {
152148
assert.notEqual(checker.lookupGlobalType("Function"), innerFunction, "Inner function type should be different than global");
153149
const brandNameType = checker.getTypeOfSymbol(innerFunction.getProperty("myBrand"));
154150
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");
156152

157153
let skipped = false;
158154
const functionBody2 = forEachChild(program.getSourceFile("test.ts"), node => node.kind === SyntaxKind.FunctionDeclaration ? skipped ? (node as FunctionDeclaration) : (skipped = true, undefined) : undefined).body;

0 commit comments

Comments
 (0)