-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #187 - Added TypeGuards.hasExpression.
This can be used to tell if a node has a .getExpression function or not.
- Loading branch information
Showing
3 changed files
with
2,651 additions
and
2,592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as ts from "typescript"; | ||
import {expect} from "chai"; | ||
import {TypeGuards} from "./../../utils"; | ||
import {getInfoFromText} from "./../compiler/testHelpers"; | ||
|
||
describe(nameof(TypeGuards), () => { | ||
// most of the code in TypeGuards is not worth the effort to test... it's auto generated from code so it should be close to correct | ||
|
||
describe(nameof(TypeGuards.hasExpression), () => { | ||
it("should have an expression when it's a function call", () => { | ||
const {firstChild} = getInfoFromText("funcCall()"); | ||
expect(TypeGuards.hasExpression(firstChild)).to.be.true; | ||
if (TypeGuards.hasExpression(firstChild)) | ||
expect(firstChild.getExpression().getText()).to.equal("funcCall()"); | ||
}); | ||
|
||
it("should not have an expression when it doesn't", () => { | ||
const {firstChild} = getInfoFromText("class Test {}"); | ||
expect(TypeGuards.hasExpression(firstChild)).to.be.false; | ||
}); | ||
|
||
it("should have an expression when it's a return statement with a value", () => { | ||
const {firstChild} = getInfoFromText("return 5;"); | ||
expect(TypeGuards.hasExpression(firstChild)).to.be.true; | ||
if (TypeGuards.hasExpression(firstChild)) | ||
expect(firstChild.getExpression().getText()).to.equal("5"); | ||
}); | ||
|
||
it("should not have an expression when it's a return statement without a value", () => { | ||
const {firstChild} = getInfoFromText("return;"); | ||
expect(TypeGuards.hasExpression(firstChild)).to.be.false; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.