1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.millscript.syntax;
22
23 import org.millscript.commons.alert.Alert;
24 import org.millscript.millscript.expr.Expr;
25
26 /**
27 * Tests for function header parsing.
28 */
29 public class FunctionHeaderTest extends AbstractSyntaxTestCase {
30
31 /**
32 * Constructor for FunctionHeaderTest.
33 * @param arg0
34 */
35 public FunctionHeaderTest(String arg0) {
36 super(arg0);
37 }
38
39 /**
40 * Tests function header parsing with no function name.
41 */
42 public void testFunctionNoName() {
43 final Parser p = getStringParser( "( x ) =>" );
44 final Expr e = p.readExprTo( "=>" );
45
46 new FunctionHeader().flatten( e, false );
47 try {
48
49 new FunctionHeader().flatten( e, true );
50 } catch ( Alert ex ) {
51 assertEquals( "Invalid procedure definition", ex.getComplaint() );
52 }
53 }
54
55 /**
56 * Tests function header parsing with an invalid function name.
57 */
58 public void testFunctionWithInvalidArgument() {
59 final Parser p = getStringParser( "f( x, `not an arg` ) =>" );
60 final Expr e = p.readExprTo( "=>" );
61 try {
62
63 new FunctionHeader().flatten( e, true );
64 } catch ( Alert ex ) {
65 assertEquals( "Invalid procedure definition", ex.getComplaint() );
66 }
67 }
68
69 /**
70 * Tests function header parsing with an invalid function name.
71 */
72 public void testFunctionWithInvalidName() {
73 final Parser p = getStringParser( "`not a function`( x ) =>" );
74 final Expr e = p.readExprTo( "=>" );
75 try {
76
77 new FunctionHeader().flatten( e, true );
78 } catch ( Alert ex ) {
79 assertEquals( "Invalid procedure definition", ex.getComplaint() );
80 }
81 }
82
83 /**
84 * Tests function header parsing with a function name.
85 */
86 public void testFunctionWithName() {
87 final Parser p = getStringParser( "f( x ) =>" );
88 final Expr e = p.readExprTo( "=>" );
89
90 new FunctionHeader().flatten( e, true );
91
92 new FunctionHeader().flatten( e, false );
93 }
94
95 }