NodeGuards.spec.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. import * as ESTree from 'estree';
  2. import { assert } from 'chai';
  3. import { NodeGuards } from '../../../../src/node/NodeGuards';
  4. import { NodeFactory } from '../../../../src/node/NodeFactory';
  5. import { NodeUtils } from '../../../../src/node/NodeUtils';
  6. describe('NodeGuards', () => {
  7. describe('isIfStatementNodeWithSingleStatementBody', () => {
  8. describe('truthful checks', () => {
  9. describe('Variant #1: single statement `consequent`', () => {
  10. const expectedResult: boolean = true;
  11. const node: ESTree.IfStatement = NodeFactory.ifStatementNode(
  12. NodeFactory.literalNode(true),
  13. NodeFactory.expressionStatementNode(
  14. NodeFactory.literalNode(true)
  15. )
  16. );
  17. let result: boolean;
  18. before(() => {
  19. result = NodeGuards.isIfStatementNodeWithSingleStatementBody(node);
  20. });
  21. it('should check if `IfStatement` node has single statement `consequent`', () => {
  22. assert.equal(result, expectedResult);
  23. });
  24. });
  25. describe('Variant #2: single statement `alternate`', () => {
  26. const expectedResult: boolean = true;
  27. const node: ESTree.IfStatement = NodeFactory.ifStatementNode(
  28. NodeFactory.literalNode(true),
  29. NodeFactory.blockStatementNode([
  30. NodeFactory.expressionStatementNode(
  31. NodeFactory.literalNode(true)
  32. )
  33. ]),
  34. NodeFactory.expressionStatementNode(
  35. NodeFactory.literalNode(true)
  36. )
  37. );
  38. let result: boolean;
  39. before(() => {
  40. result = NodeGuards.isIfStatementNodeWithSingleStatementBody(node);
  41. });
  42. it('should check if `IfStatement` node has single statement `alternate`', () => {
  43. assert.equal(result, expectedResult);
  44. });
  45. });
  46. describe('Variant #3: single statement `consequent` and `alternate`', () => {
  47. const expectedResult: boolean = true;
  48. const node: ESTree.IfStatement = NodeFactory.ifStatementNode(
  49. NodeFactory.literalNode(true),
  50. NodeFactory.expressionStatementNode(
  51. NodeFactory.literalNode(true)
  52. ),
  53. NodeFactory.expressionStatementNode(
  54. NodeFactory.literalNode(true)
  55. )
  56. );
  57. let result: boolean;
  58. before(() => {
  59. result = NodeGuards.isIfStatementNodeWithSingleStatementBody(node);
  60. });
  61. it('should check if `IfStatement` node has single statement `consequent` and `alternate`', () => {
  62. assert.equal(result, expectedResult);
  63. });
  64. });
  65. });
  66. describe('false checks', () => {
  67. describe('Variant #1: other node', () => {
  68. const expectedResult: boolean = false;
  69. const node: ESTree.Literal = NodeFactory.literalNode(true);
  70. let result: boolean;
  71. before(() => {
  72. result = NodeGuards.isIfStatementNodeWithSingleStatementBody(node);
  73. });
  74. it('should return `false` for other node', () => {
  75. assert.equal(result, expectedResult);
  76. });
  77. });
  78. describe('Variant #2: multiple statements `consequent` and `alternate`', () => {
  79. const expectedResult: boolean = false;
  80. const node: ESTree.IfStatement = NodeFactory.ifStatementNode(
  81. NodeFactory.literalNode(true),
  82. NodeFactory.blockStatementNode([
  83. NodeFactory.expressionStatementNode(
  84. NodeFactory.literalNode(true)
  85. )
  86. ]),
  87. NodeFactory.blockStatementNode([
  88. NodeFactory.expressionStatementNode(
  89. NodeFactory.literalNode(true)
  90. )
  91. ])
  92. );
  93. let result: boolean;
  94. before(() => {
  95. result = NodeGuards.isIfStatementNodeWithSingleStatementBody(node);
  96. });
  97. it('should check if `IfStatement` node has multiple statements `consequent` and `alternate`', () => {
  98. assert.equal(result, expectedResult);
  99. });
  100. });
  101. });
  102. });
  103. describe('isNodeWithLexicalScopeStatements', () => {
  104. describe('truthful checks', () => {
  105. describe('Variant #1: block statement of function declaration', () => {
  106. const expectedResult: boolean = true;
  107. const node: ESTree.Node = NodeFactory.blockStatementNode();
  108. const parentNode: ESTree.FunctionDeclaration = NodeFactory.functionDeclarationNode(
  109. 'foo',
  110. [],
  111. node
  112. );
  113. let result: boolean;
  114. before(() => {
  115. NodeUtils.parentizeAst(parentNode);
  116. result = NodeGuards.isNodeWithLexicalScopeStatements(node, parentNode);
  117. });
  118. it('should check if node has statements', () => {
  119. assert.equal(result, expectedResult);
  120. });
  121. });
  122. describe('Variant #2: block statement of function expression', () => {
  123. const expectedResult: boolean = true;
  124. const node: ESTree.Node = NodeFactory.blockStatementNode();
  125. const parentNode: ESTree.FunctionExpression = NodeFactory.functionExpressionNode(
  126. [],
  127. node
  128. );
  129. let result: boolean;
  130. before(() => {
  131. NodeUtils.parentizeAst(parentNode);
  132. result = NodeGuards.isNodeWithLexicalScopeStatements(node, parentNode);
  133. });
  134. it('should check if node has statements', () => {
  135. assert.equal(result, expectedResult);
  136. });
  137. });
  138. });
  139. describe('false checks', () => {
  140. describe('Variant #1: switch-case node', () => {
  141. const expectedResult: boolean = false;
  142. const node: ESTree.Node = NodeFactory.switchCaseNode(
  143. NodeFactory.literalNode(1),
  144. []
  145. );
  146. const parentNode: ESTree.FunctionDeclaration = NodeFactory.functionDeclarationNode(
  147. 'foo',
  148. [],
  149. NodeFactory.blockStatementNode([
  150. NodeFactory.switchStatementNode(
  151. NodeFactory.memberExpressionNode(
  152. NodeFactory.identifierNode('bar'),
  153. NodeFactory.updateExpressionNode(
  154. '++',
  155. NodeFactory.identifierNode('baz')
  156. ),
  157. true
  158. ),
  159. [node]
  160. )
  161. ])
  162. );
  163. let result: boolean;
  164. before(() => {
  165. NodeUtils.parentizeAst(parentNode);
  166. result = NodeGuards.isNodeWithLexicalScopeStatements(node, parentNode);
  167. });
  168. it('should check if node has statements', () => {
  169. assert.equal(result, expectedResult);
  170. });
  171. });
  172. describe('Variant #2: literal node', () => {
  173. const expectedResult: boolean = false;
  174. const node: ESTree.Node = NodeFactory.literalNode(1);
  175. const parentNode: ESTree.FunctionDeclaration = NodeFactory.functionDeclarationNode(
  176. 'foo',
  177. [],
  178. NodeFactory.blockStatementNode([
  179. NodeFactory.expressionStatementNode(
  180. NodeFactory.callExpressionNode(
  181. NodeFactory.identifierNode('bar'),
  182. [node]
  183. )
  184. )
  185. ])
  186. );
  187. let result: boolean;
  188. before(() => {
  189. NodeUtils.parentizeAst(parentNode);
  190. result = NodeGuards.isNodeWithLexicalScopeStatements(node, parentNode);
  191. });
  192. it('should check if node has statements', () => {
  193. assert.equal(result, expectedResult);
  194. });
  195. });
  196. describe('Variant #3: block statement of if statement', () => {
  197. const expectedResult: boolean = false;
  198. const node: ESTree.Node = NodeFactory.blockStatementNode();
  199. const parentNode: ESTree.IfStatement = NodeFactory.ifStatementNode(
  200. NodeFactory.identifierNode('foo'),
  201. node
  202. );
  203. let result: boolean;
  204. before(() => {
  205. NodeUtils.parentizeAst(parentNode);
  206. result = NodeGuards.isNodeWithLexicalScopeStatements(node, parentNode);
  207. });
  208. it('should check if node has statements', () => {
  209. assert.equal(result, expectedResult);
  210. });
  211. });
  212. });
  213. });
  214. describe('isNodeWithSingleStatementBody', () => {
  215. describe('truthful checks', () => {
  216. describe('Variant #1: `IfStatement` node', () => {
  217. describe('Variant #1: single statement `consequent`', () => {
  218. const expectedResult: boolean = true;
  219. const node: ESTree.IfStatement = NodeFactory.ifStatementNode(
  220. NodeFactory.literalNode(true),
  221. NodeFactory.expressionStatementNode(
  222. NodeFactory.literalNode(true)
  223. )
  224. );
  225. let result: boolean;
  226. before(() => {
  227. result = NodeGuards.isNodeWithSingleStatementBody(node);
  228. });
  229. it('should check if `IfStatement` node has single statement `consequent`', () => {
  230. assert.equal(result, expectedResult);
  231. });
  232. });
  233. describe('Variant #2: single statement `alternate`', () => {
  234. const expectedResult: boolean = true;
  235. const node: ESTree.IfStatement = NodeFactory.ifStatementNode(
  236. NodeFactory.literalNode(true),
  237. NodeFactory.blockStatementNode([
  238. NodeFactory.expressionStatementNode(
  239. NodeFactory.literalNode(true)
  240. )
  241. ]),
  242. NodeFactory.expressionStatementNode(
  243. NodeFactory.literalNode(true)
  244. )
  245. );
  246. let result: boolean;
  247. before(() => {
  248. result = NodeGuards.isNodeWithSingleStatementBody(node);
  249. });
  250. it('should check if `IfStatement` node has single statement `alternate`', () => {
  251. assert.equal(result, expectedResult);
  252. });
  253. });
  254. describe('Variant #3: single statement `consequent` and `alternate`', () => {
  255. const expectedResult: boolean = true;
  256. const node: ESTree.IfStatement = NodeFactory.ifStatementNode(
  257. NodeFactory.literalNode(true),
  258. NodeFactory.expressionStatementNode(
  259. NodeFactory.literalNode(true)
  260. ),
  261. NodeFactory.expressionStatementNode(
  262. NodeFactory.literalNode(true)
  263. )
  264. );
  265. let result: boolean;
  266. before(() => {
  267. result = NodeGuards.isNodeWithSingleStatementBody(node);
  268. });
  269. it('should check if `IfStatement` node has single statement `consequent` and `alternate`', () => {
  270. assert.equal(result, expectedResult);
  271. });
  272. });
  273. });
  274. describe('Variant #2: `ForStatement` node', () => {
  275. const expectedResult: boolean = true;
  276. const node: ESTree.ForStatement = NodeFactory.forStatementNode(
  277. NodeFactory.variableDeclarationNode([
  278. NodeFactory.variableDeclaratorNode(
  279. NodeFactory.identifierNode('i'),
  280. NodeFactory.literalNode(0)
  281. )
  282. ]),
  283. NodeFactory.binaryExpressionNode(
  284. '<',
  285. NodeFactory.identifierNode('i'),
  286. NodeFactory.literalNode(10)
  287. ),
  288. NodeFactory.updateExpressionNode(
  289. '++',
  290. NodeFactory.identifierNode('i')
  291. ),
  292. NodeFactory.expressionStatementNode(
  293. NodeFactory.literalNode(true)
  294. )
  295. );
  296. let result: boolean;
  297. before(() => {
  298. result = NodeGuards.isNodeWithSingleStatementBody(node);
  299. });
  300. it('should check if `ForStatement` node has single statement `body`', () => {
  301. assert.equal(result, expectedResult);
  302. });
  303. });
  304. describe('Variant #3: `ForInStatement` node', () => {
  305. const expectedResult: boolean = true;
  306. const node: ESTree.ForInStatement = NodeFactory.forInStatementNode(
  307. NodeFactory.variableDeclarationNode([
  308. NodeFactory.variableDeclaratorNode(
  309. NodeFactory.identifierNode('key'),
  310. null
  311. )
  312. ]),
  313. NodeFactory.objectExpressionNode(
  314. []
  315. ),
  316. NodeFactory.expressionStatementNode(
  317. NodeFactory.literalNode(true)
  318. )
  319. );
  320. let result: boolean;
  321. before(() => {
  322. result = NodeGuards.isNodeWithSingleStatementBody(node);
  323. });
  324. it('should check if `ForInStatement` node has single statement `body`', () => {
  325. assert.equal(result, expectedResult);
  326. });
  327. });
  328. describe('Variant #4: `ForOfStatement` node', () => {
  329. const expectedResult: boolean = true;
  330. const node: ESTree.ForOfStatement = NodeFactory.forOfStatementNode(
  331. false,
  332. NodeFactory.variableDeclarationNode([
  333. NodeFactory.variableDeclaratorNode(
  334. NodeFactory.identifierNode('key'),
  335. null
  336. )
  337. ]),
  338. NodeFactory.objectExpressionNode(
  339. []
  340. ),
  341. NodeFactory.expressionStatementNode(
  342. NodeFactory.literalNode(true)
  343. )
  344. );
  345. let result: boolean;
  346. before(() => {
  347. result = NodeGuards.isNodeWithSingleStatementBody(node);
  348. });
  349. it('should check if `ForOfStatement` node has single statement `body`', () => {
  350. assert.equal(result, expectedResult);
  351. });
  352. });
  353. describe('Variant #5: `WhileStatement` node', () => {
  354. const expectedResult: boolean = true;
  355. const node: ESTree.WhileStatement = NodeFactory.whileStatementNode(
  356. NodeFactory.literalNode(true),
  357. NodeFactory.expressionStatementNode(
  358. NodeFactory.literalNode(true)
  359. )
  360. );
  361. let result: boolean;
  362. before(() => {
  363. result = NodeGuards.isNodeWithSingleStatementBody(node);
  364. });
  365. it('should check if `WhileStatement` node has single statement `body`', () => {
  366. assert.equal(result, expectedResult);
  367. });
  368. });
  369. describe('Variant #6: `DoWhileStatement` node', () => {
  370. const expectedResult: boolean = true;
  371. const node: ESTree.DoWhileStatement = NodeFactory.doWhileStatementNode(
  372. NodeFactory.expressionStatementNode(
  373. NodeFactory.literalNode(true)
  374. ),
  375. NodeFactory.literalNode(true)
  376. );
  377. let result: boolean;
  378. before(() => {
  379. result = NodeGuards.isNodeWithSingleStatementBody(node);
  380. });
  381. it('should check if `DoWhileStatement` node has single statement `body`', () => {
  382. assert.equal(result, expectedResult);
  383. });
  384. });
  385. describe('Variant #7: `LabeledStatement` node', () => {
  386. const expectedResult: boolean = true;
  387. const node: ESTree.LabeledStatement = NodeFactory.labeledStatementNode(
  388. NodeFactory.identifierNode('label'),
  389. NodeFactory.expressionStatementNode(
  390. NodeFactory.literalNode(true)
  391. )
  392. );
  393. let result: boolean;
  394. before(() => {
  395. result = NodeGuards.isNodeWithSingleStatementBody(node);
  396. });
  397. it('should check if `LabeledStatement` node has single statement `body`', () => {
  398. assert.equal(result, expectedResult);
  399. });
  400. });
  401. });
  402. describe('false checks', () => {
  403. describe('Variant #1: `IfStatement` node', () => {
  404. describe('Variant #1: multiple statements `consequent` and `alternate`', () => {
  405. const expectedResult: boolean = false;
  406. const node: ESTree.IfStatement = NodeFactory.ifStatementNode(
  407. NodeFactory.literalNode(true),
  408. NodeFactory.blockStatementNode([
  409. NodeFactory.expressionStatementNode(
  410. NodeFactory.literalNode(true)
  411. )
  412. ]),
  413. NodeFactory.blockStatementNode([
  414. NodeFactory.expressionStatementNode(
  415. NodeFactory.literalNode(true)
  416. )
  417. ])
  418. );
  419. let result: boolean;
  420. before(() => {
  421. result = NodeGuards.isNodeWithSingleStatementBody(node);
  422. });
  423. it('should check if `IfStatement` node has multiple statements `consequent` and `alternate`', () => {
  424. assert.equal(result, expectedResult);
  425. });
  426. });
  427. });
  428. describe('Variant #2: `ForStatement` node', () => {
  429. const expectedResult: boolean = false;
  430. const node: ESTree.ForStatement = NodeFactory.forStatementNode(
  431. NodeFactory.variableDeclarationNode([
  432. NodeFactory.variableDeclaratorNode(
  433. NodeFactory.identifierNode('i'),
  434. NodeFactory.literalNode(0)
  435. )
  436. ]),
  437. NodeFactory.binaryExpressionNode(
  438. '<',
  439. NodeFactory.identifierNode('i'),
  440. NodeFactory.literalNode(10)
  441. ),
  442. NodeFactory.updateExpressionNode(
  443. '++',
  444. NodeFactory.identifierNode('i')
  445. ),
  446. NodeFactory.blockStatementNode([
  447. NodeFactory.expressionStatementNode(
  448. NodeFactory.literalNode(true)
  449. )
  450. ])
  451. );
  452. let result: boolean;
  453. before(() => {
  454. result = NodeGuards.isNodeWithSingleStatementBody(node);
  455. });
  456. it('should check if `ForStatement` node has multiple statements `body`', () => {
  457. assert.equal(result, expectedResult);
  458. });
  459. });
  460. describe('Variant #3: `ForInStatement` node', () => {
  461. const expectedResult: boolean = false;
  462. const node: ESTree.ForInStatement = NodeFactory.forInStatementNode(
  463. NodeFactory.variableDeclarationNode([
  464. NodeFactory.variableDeclaratorNode(
  465. NodeFactory.identifierNode('key'),
  466. null
  467. )
  468. ]),
  469. NodeFactory.objectExpressionNode(
  470. []
  471. ),
  472. NodeFactory.blockStatementNode([
  473. NodeFactory.expressionStatementNode(
  474. NodeFactory.literalNode(true)
  475. )
  476. ])
  477. );
  478. let result: boolean;
  479. before(() => {
  480. result = NodeGuards.isNodeWithSingleStatementBody(node);
  481. });
  482. it('should check if `ForInStatement` node has multiple statements `body`', () => {
  483. assert.equal(result, expectedResult);
  484. });
  485. });
  486. describe('Variant #4: `ForOfStatement` node', () => {
  487. const expectedResult: boolean = false;
  488. const node: ESTree.ForOfStatement = NodeFactory.forOfStatementNode(
  489. false,
  490. NodeFactory.variableDeclarationNode([
  491. NodeFactory.variableDeclaratorNode(
  492. NodeFactory.identifierNode('key'),
  493. null
  494. )
  495. ]),
  496. NodeFactory.objectExpressionNode(
  497. []
  498. ),
  499. NodeFactory.blockStatementNode([
  500. NodeFactory.expressionStatementNode(
  501. NodeFactory.literalNode(true)
  502. )
  503. ])
  504. );
  505. let result: boolean;
  506. before(() => {
  507. result = NodeGuards.isNodeWithSingleStatementBody(node);
  508. });
  509. it('should check if `ForOfStatement` node has multiple statements `body`', () => {
  510. assert.equal(result, expectedResult);
  511. });
  512. });
  513. describe('Variant #5: `WhileStatement` node', () => {
  514. const expectedResult: boolean = false;
  515. const node: ESTree.WhileStatement = NodeFactory.whileStatementNode(
  516. NodeFactory.literalNode(true),
  517. NodeFactory.blockStatementNode([
  518. NodeFactory.expressionStatementNode(
  519. NodeFactory.literalNode(true)
  520. )
  521. ])
  522. );
  523. let result: boolean;
  524. before(() => {
  525. result = NodeGuards.isNodeWithSingleStatementBody(node);
  526. });
  527. it('should check if `WhileStatement` node has multiple statements `body`', () => {
  528. assert.equal(result, expectedResult);
  529. });
  530. });
  531. describe('Variant #6: `DoWhileStatement` node', () => {
  532. const expectedResult: boolean = false;
  533. const node: ESTree.DoWhileStatement = NodeFactory.doWhileStatementNode(
  534. NodeFactory.blockStatementNode([
  535. NodeFactory.expressionStatementNode(
  536. NodeFactory.literalNode(true)
  537. )
  538. ]),
  539. NodeFactory.literalNode(true)
  540. );
  541. let result: boolean;
  542. before(() => {
  543. result = NodeGuards.isNodeWithSingleStatementBody(node);
  544. });
  545. it('should check if `DoWhileStatement` node has multiple statements `body`', () => {
  546. assert.equal(result, expectedResult);
  547. });
  548. });
  549. describe('Variant #7: `LabeledStatement` node', () => {
  550. const expectedResult: boolean = false;
  551. const node: ESTree.LabeledStatement = NodeFactory.labeledStatementNode(
  552. NodeFactory.identifierNode('label'),
  553. NodeFactory.blockStatementNode([
  554. NodeFactory.expressionStatementNode(
  555. NodeFactory.literalNode(true)
  556. )
  557. ])
  558. );
  559. let result: boolean;
  560. before(() => {
  561. result = NodeGuards.isNodeWithSingleStatementBody(node);
  562. });
  563. it('should check if `LabeledStatement` node has multiple statements `body`', () => {
  564. assert.equal(result, expectedResult);
  565. });
  566. });
  567. });
  568. });
  569. describe('isNodeWithStatements', () => {
  570. describe('truthful checks', () => {
  571. describe('Variant #1: program node', () => {
  572. const expectedResult: boolean = true;
  573. const node: ESTree.Node = NodeFactory.programNode();
  574. let result: boolean;
  575. before(() => {
  576. result = NodeGuards.isNodeWithStatements(node);
  577. });
  578. it('should check if node has statements', () => {
  579. assert.equal(result, expectedResult);
  580. });
  581. });
  582. describe('Variant #2: block statement node', () => {
  583. const expectedResult: boolean = true;
  584. const node: ESTree.Node = NodeFactory.blockStatementNode();
  585. let result: boolean;
  586. before(() => {
  587. result = NodeGuards.isNodeWithStatements(node);
  588. });
  589. it('should check if node has statements', () => {
  590. assert.equal(result, expectedResult);
  591. });
  592. });
  593. describe('Variant #3: switch case node', () => {
  594. const expectedResult: boolean = true;
  595. const node: ESTree.Node = NodeFactory.switchCaseNode(
  596. NodeFactory.literalNode(1),
  597. []
  598. );
  599. let result: boolean;
  600. before(() => {
  601. result = NodeGuards.isNodeWithStatements(node);
  602. });
  603. it('should check if node has statements', () => {
  604. assert.equal(result, expectedResult);
  605. });
  606. });
  607. });
  608. describe('false checks', () => {
  609. describe('Variant #1: literal node', () => {
  610. const expectedResult: boolean = false;
  611. const node: ESTree.Node = NodeFactory.literalNode(1);
  612. let result: boolean;
  613. before(() => {
  614. result = NodeGuards.isNodeWithStatements(node);
  615. });
  616. it('should check if node has statements', () => {
  617. assert.equal(result, expectedResult);
  618. });
  619. });
  620. describe('Variant #2: identifier node', () => {
  621. const expectedResult: boolean = false;
  622. const node: ESTree.Node = NodeFactory.identifierNode('foo');
  623. let result: boolean;
  624. before(() => {
  625. result = NodeGuards.isNodeWithStatements(node);
  626. });
  627. it('should check if node has statements', () => {
  628. assert.equal(result, expectedResult);
  629. });
  630. });
  631. describe('Variant #3: if-statement node', () => {
  632. const expectedResult: boolean = false;
  633. const node: ESTree.Node = NodeFactory.ifStatementNode(
  634. NodeFactory.identifierNode('foo'),
  635. NodeFactory.blockStatementNode()
  636. );
  637. let result: boolean;
  638. before(() => {
  639. result = NodeGuards.isNodeWithStatements(node);
  640. });
  641. it('should check if node has statements', () => {
  642. assert.equal(result, expectedResult);
  643. });
  644. });
  645. describe('Variant #4: switch-statement node', () => {
  646. const expectedResult: boolean = false;
  647. const node: ESTree.Node = NodeFactory.switchStatementNode(
  648. NodeFactory.identifierNode('foo'),
  649. []
  650. );
  651. let result: boolean;
  652. before(() => {
  653. result = NodeGuards.isNodeWithStatements(node);
  654. });
  655. it('should check if node has statements', () => {
  656. assert.equal(result, expectedResult);
  657. });
  658. });
  659. });
  660. });
  661. });