vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java
branchcanvas
changeset 808 bd8b726902a3
parent 731 e8283f10a127
parent 807 e93506e603ad
child 809 5c61f5e4898e
     1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java	Thu Feb 14 12:06:16 2013 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,216 +0,0 @@
     1.4 -/**
     1.5 - * Back 2 Browser Bytecode Translator
     1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 - *
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, version 2 of the License.
    1.11 - *
    1.12 - * This program is distributed in the hope that it will be useful,
    1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 - * GNU General Public License for more details.
    1.16 - *
    1.17 - * You should have received a copy of the GNU General Public License
    1.18 - * along with this program. Look for COPYING file in the top folder.
    1.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 - */
    1.21 -package org.apidesign.vm4brwsr;
    1.22 -
    1.23 -import javax.script.Invocable;
    1.24 -import org.testng.annotations.Test;
    1.25 -import static org.testng.Assert.*;
    1.26 -import org.testng.annotations.BeforeClass;
    1.27 -
    1.28 -/**
    1.29 - *
    1.30 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.31 - */
    1.32 -public class StringTest {
    1.33 -    @Test public void firstChar() throws Exception {
    1.34 -        assertExec(
    1.35 -            "First char in Hello is H",
    1.36 -            StringSample.class, "sayHello__CI",
    1.37 -            72, 0
    1.38 -        );
    1.39 -    }
    1.40 -
    1.41 -    @Test public void fromChars() throws Exception {
    1.42 -        assertExec(
    1.43 -            "First char in Hello is ABC",
    1.44 -            StringSample.class, "fromChars__Ljava_lang_String_2CCC",
    1.45 -            "ABC", 'A', 'B', 'C'
    1.46 -        );
    1.47 -    }
    1.48 -
    1.49 -    @Test public void concatChars() throws Exception {
    1.50 -        assertExec(
    1.51 -            "Composing yields ABC",
    1.52 -            StringSample.class, "chars__Ljava_lang_String_2CCC",
    1.53 -            "ABC", 'A', 'B', 'C'
    1.54 -        );
    1.55 -    }
    1.56 -
    1.57 -    @Test public void concatCharsFromInts() throws Exception {
    1.58 -        assertExec(
    1.59 -            "Composing yields ABC",
    1.60 -            StringSample.class, "charsFromNumbers__Ljava_lang_String_2",
    1.61 -            "ABC"
    1.62 -        );
    1.63 -    }
    1.64 -
    1.65 -    @Test public void concatCharsFromChars() throws Exception {
    1.66 -        assertExec(
    1.67 -            "Composing yields ABC",
    1.68 -            StringSample.class, "charsFromChars__Ljava_lang_String_2",
    1.69 -            "ABC"
    1.70 -        );
    1.71 -    }
    1.72 -
    1.73 -    @Test public void instanceOfWorks() throws Exception {
    1.74 -        assertExec(
    1.75 -            "It is string",
    1.76 -            StringSample.class, "isStringInstance__Z",
    1.77 -            Double.valueOf(1.0)
    1.78 -        );
    1.79 -    }
    1.80 -
    1.81 -    @Test public void getBytes() throws Exception {
    1.82 -        final String horse = "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148";
    1.83 -        final String expected = StringSample.getBytes(horse);
    1.84 -        assertExec(
    1.85 -            "Bytes look simplar",
    1.86 -            StringSample.class, "getBytes__Ljava_lang_String_2Ljava_lang_String_2",
    1.87 -            expected, horse
    1.88 -        );
    1.89 -    }
    1.90 -
    1.91 -    @Test(timeOut=10000) public void toStringConcatenation() throws Exception {
    1.92 -        assertExec(
    1.93 -            "Five executions should generate 5Hello World!",
    1.94 -            StringSample.class, "toStringTest__Ljava_lang_String_2I",
    1.95 -            "Hello World!5", 5
    1.96 -        );
    1.97 -    }
    1.98 -    @Test public void toStringConcatenationJava() throws Exception {
    1.99 -        assertEquals("Hello World!5", StringSample.toStringTest(5));
   1.100 -    }
   1.101 -    
   1.102 -    @Test(timeOut=10000) public void stringStringConcat() throws Exception {
   1.103 -        assertExec(
   1.104 -            "Composes strings OK",
   1.105 -            StringSample.class, "concatStrings__Ljava_lang_String_2",
   1.106 -            "Hello World!1" + "\\\n\r\t"
   1.107 -        );
   1.108 -    }
   1.109 -
   1.110 -    @Test public void equalsAndSubstring() throws Exception {
   1.111 -        assertExec(
   1.112 -            "Composes are OK",
   1.113 -            StringSample.class, "equalToHello__ZII",
   1.114 -            true, 0, 5
   1.115 -        );
   1.116 -    }
   1.117 -    @Test public void replaceChars() throws Exception {
   1.118 -        assertExec(
   1.119 -            "Can replace slashes by underscores",
   1.120 -            StringSample.class, "replace__Ljava_lang_String_2Ljava_lang_String_2CC",
   1.121 -            "x_y_z", "x/y/z", '/', '_'
   1.122 -        );
   1.123 -    }
   1.124 -    @Test public void replaceIntChars() throws Exception {
   1.125 -        assertExec(
   1.126 -            "Can replace slashes by underscores",
   1.127 -            StringSample.class, "replace__Ljava_lang_String_2Ljava_lang_String_2CC",
   1.128 -            "x_y_z", "x/y/z", (int)'/', (int)'_'
   1.129 -        );
   1.130 -    }
   1.131 -
   1.132 -    @Test public void insertBuilder() throws Exception {
   1.133 -        assertExec(
   1.134 -            "Can insert something into a buffer?",
   1.135 -            StringSample.class, "insertBuffer__Ljava_lang_String_2",
   1.136 -            "Ahojdo!"
   1.137 -        );
   1.138 -    }
   1.139 -    
   1.140 -    @Test public void compareHashCodeHi() throws Exception {
   1.141 -        String j = "Hi";
   1.142 -        int jh = StringSample.hashCode(j);
   1.143 -        assertExec(
   1.144 -            "Hashcode is the same " +jh,
   1.145 -            StringSample.class, "hashCode__ILjava_lang_String_2",
   1.146 -            Double.valueOf(jh), j
   1.147 -        );
   1.148 -    }
   1.149 -    @Test public void compareHashCode1() throws Exception {
   1.150 -        String j = "Hello Java!";
   1.151 -        int jh = StringSample.hashCode(j);
   1.152 -        assertExec(
   1.153 -            "Hashcode is the same " + jh,
   1.154 -            StringSample.class, "hashCode__ILjava_lang_String_2",
   1.155 -            Double.valueOf(jh), j
   1.156 -        );
   1.157 -    }
   1.158 -    @Test public void stringSwitch1() throws Exception {
   1.159 -        assertExec(
   1.160 -            "Get one",
   1.161 -            StringSample.class, "stringSwitch__ILjava_lang_String_2",
   1.162 -            Double.valueOf(1), "jedna"
   1.163 -        );
   1.164 -    }
   1.165 -    @Test public void stringSwitch2() throws Exception {
   1.166 -        assertExec(
   1.167 -            "Get two",
   1.168 -            StringSample.class, "stringSwitch__ILjava_lang_String_2",
   1.169 -            Double.valueOf(2), "dve"
   1.170 -        );
   1.171 -    }
   1.172 -    @Test public void stringSwitchDefault() throws Exception {
   1.173 -        assertExec(
   1.174 -            "Get -1",
   1.175 -            StringSample.class, "stringSwitch__ILjava_lang_String_2",
   1.176 -            Double.valueOf(-1), "none"
   1.177 -        );
   1.178 -    }
   1.179 -    
   1.180 -    @Test public void countAB() throws Exception {
   1.181 -        assertEquals(StringSample.countAB("Ahoj Bedo!"), 3, "Verify Java code is sane");
   1.182 -        assertExec(
   1.183 -            "One A and one B adds to 3",
   1.184 -            StringSample.class, "countAB__ILjava_lang_String_2",
   1.185 -            Double.valueOf(3), "Ahoj Bedo!"
   1.186 -        );
   1.187 -        
   1.188 -    }
   1.189 -
   1.190 -    @Test public void compareStrings() throws Exception {
   1.191 -        int res = StringSample.compare("Saab", "Volvo");
   1.192 -        assertExec(
   1.193 -            "Saab finished sooner than Volvo",
   1.194 -            StringSample.class, "compare__ILjava_lang_String_2Ljava_lang_String_2",
   1.195 -            Double.valueOf(res), "Saab", "Volvo"
   1.196 -        );
   1.197 -        
   1.198 -    }
   1.199 -    
   1.200 -    private static CharSequence codeSeq;
   1.201 -    private static Invocable code;
   1.202 -    
   1.203 -    @BeforeClass 
   1.204 -    public void compileTheCode() throws Exception {
   1.205 -        StringBuilder sb = new StringBuilder();
   1.206 -        code = StaticMethodTest.compileClass(sb, 
   1.207 -            "org/apidesign/vm4brwsr/StringSample",
   1.208 -            "java/lang/String"
   1.209 -        );
   1.210 -        codeSeq = sb;
   1.211 -    }
   1.212 -    
   1.213 -    private static void assertExec(String msg, 
   1.214 -        Class<?> clazz, String method, Object expRes, Object... args
   1.215 -    ) throws Exception {
   1.216 -        StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
   1.217 -    }
   1.218 -    
   1.219 -}