Optimize only simpleLoopTest... method and first check the generated code before compiling it as JavaScript
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.flow;
20 import org.apidesign.vm4brwsr.Bck2Brwsr.Flow;
21 import static org.testng.Assert.*;
22 import org.testng.annotations.AfterClass;
23 import org.testng.annotations.AfterMethod;
24 import org.testng.annotations.BeforeClass;
25 import org.testng.annotations.BeforeMethod;
26 import org.testng.annotations.Test;
30 * @author Jaroslav Tulach
32 public class LoopControlTest {
33 private static TestVM vm;
35 public LoopControlTest() {
39 public static void setUpClass() throws Exception {
40 class MyFlow implements Flow.Analyzer {
43 public boolean analyze(Flow request) {
44 if (request.getMethodName().equals("simpleLoopTestWithExit")) {
46 return GraalFlowAnalyzer.getDefault().analyze(request);
52 MyFlow flow = new MyFlow();
53 vm = TestVM.compileClass(null, flow, LoopControl.class.getName().replace('.', '/'));
54 assertTrue(flow.called, "We have been consuted about at least one method");
58 public static void tearDownClass() throws Exception {
63 public void setUpMethod() throws Exception {
67 public void tearDownMethod() throws Exception {
71 public void testExecute() throws Exception {
72 String code = vm.codeSeq().toString();
73 int begin = code.indexOf("simpleLoopTestWithExit__II = function");
74 assertNotEquals(begin, -1, "Control loop defined" + code);
75 int end = code.indexOf("m.access = ", begin);
76 assertNotEquals(end, -1, "Control loop end defined" + code);
77 final String body = code.substring(begin, end);
78 assertFalse(body.contains("gt"), "No gt control flow used: " + body);
80 int exp = LoopControl.simpleLoopTestWithExit(123);
81 vm.assertExec("Is the code compilable?", LoopControl.class, "simpleLoopTestWithExit__II", exp, 123);