1 package groovy.lang;
2
3 import org.codehaus.groovy.classgen.TestSupport;
4 import org.codehaus.groovy.control.CompilationFailedException;
5
6
7 /***
8 * @author Steve Goetze
9 */
10 public class ScriptIntegerDivideTest extends TestSupport {
11
12 /***
13 * If a script that invokes integer division is specified as a literal string, the
14 * division token "\" needs to be escaped.
15 */
16 public void testIntegerDivide() throws Exception {
17 assertScript( "assert 4//3 == 1" );
18 }
19
20 /***
21 * If a groovy script is spec'd in a literal string, any intended Integer
22 * divisions need to be escaped. In cases where the integer division token "\"
23 * is surrounded by whitespace the literal cannot be constructed, which is OK.
24 * In the case where the second operand immediately follows the token, the literal
25 * can be specified, but will result in a compilation error as the token immediately
26 * following the backslash will be taken as the escape sequence.
27 */
28 public void testIntegerDivideWithBadEscape() throws Exception {
29 try {
30 assertScript( "assert 4\3 == 1" );
31 } catch (CompilationFailedException e) {
32 return;
33 }
34 fail("Should catch a CompilationFailedException");
35 }
36 }