NodeGuards.spec.ts 30 KB

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