1
2
3
4 package net.sourceforge.pmd.lang.ecmascript.ast;
5
6 import org.junit.Assert;
7 import org.junit.Test;
8
9 public class ASTFunctionNodeTest extends EcmascriptParserTestBase {
10
11 @Test
12 public void testGetBody() {
13 ASTAstRoot node = parse("function foo() { var a = 'a'; }");
14 ASTFunctionNode fn = node.getFirstDescendantOfType(ASTFunctionNode.class);
15 Assert.assertFalse(fn.isClosure());
16 EcmascriptNode<?> body = fn.getBody();
17 Assert.assertTrue(body instanceof ASTBlock);
18 }
19
20 @Test
21 public void testGetBodyFunctionClosureExpression() {
22 ASTAstRoot node = parse18("(function(x) x*x)");
23 ASTFunctionNode fn = node.getFirstDescendantOfType(ASTFunctionNode.class);
24 Assert.assertTrue(fn.isClosure());
25 EcmascriptNode<?> body = fn.getBody();
26 Assert.assertTrue(body instanceof ASTBlock);
27 Assert.assertTrue(body.jjtGetChild(0) instanceof ASTReturnStatement);
28 }
29 }