1   package delight.nashornsandbox.tests;
2   
3   import delight.nashornsandbox.NashornSandbox;
4   import delight.nashornsandbox.NashornSandboxes;
5   import java.util.concurrent.Executors;
6   import org.eclipse.xtend2.lib.StringConcatenation;
7   import org.junit.Test;
8   
9   @SuppressWarnings("all")
10  public class TestSwitch {
11    @Test
12    public void test() {
13      final NashornSandbox sandbox = NashornSandboxes.create();
14      try {
15        sandbox.allowPrintFunctions(true);
16        sandbox.setMaxCPUTime(50);
17        sandbox.setExecutor(Executors.newSingleThreadExecutor());
18        StringConcatenation _builder = new StringConcatenation();
19        _builder.append("var expr = \"one\";");
20        _builder.newLine();
21        _builder.newLine();
22        _builder.append("switch (expr) {");
23        _builder.newLine();
24        _builder.append("  ");
25        _builder.append("case \"one\":");
26        _builder.newLine();
27        _builder.append("    ");
28        _builder.append("// ok");
29        _builder.newLine();
30        _builder.append("    ");
31        _builder.append("break;");
32        _builder.newLine();
33        _builder.append("  ");
34        _builder.append("case \"two\":");
35        _builder.newLine();
36        _builder.append("    ");
37        _builder.append("// ok");
38        _builder.newLine();
39        _builder.append("    ");
40        _builder.append("break;");
41        _builder.newLine();
42        _builder.append("  ");
43        _builder.append("default:");
44        _builder.newLine();
45        _builder.append("    ");
46        _builder.append("print(\"Unknown expression\");");
47        _builder.newLine();
48        _builder.append("}");
49        _builder.newLine();
50        _builder.newLine();
51        sandbox.eval(_builder.toString());
52      } finally {
53        sandbox.getExecutor().shutdown();
54      }
55    }
56  }