1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Tue Dec 04 09:16:53 2012 +0100
1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Thu Jan 03 11:20:40 2013 +0100
1.3 @@ -38,7 +38,7 @@
1.4 @Test public void fromChars() throws Exception {
1.5 assertExec(
1.6 "First char in Hello is ABC",
1.7 - StringSample.class, "fromChars__Ljava_lang_String_2CCC",
1.8 + StringSample.class, "fromChars__sCCC",
1.9 "ABC", 'A', 'B', 'C'
1.10 );
1.11 }
1.12 @@ -46,7 +46,7 @@
1.13 @Test public void concatChars() throws Exception {
1.14 assertExec(
1.15 "Composing yields ABC",
1.16 - StringSample.class, "chars__Ljava_lang_String_2CCC",
1.17 + StringSample.class, "chars__sCCC",
1.18 "ABC", 'A', 'B', 'C'
1.19 );
1.20 }
1.21 @@ -54,7 +54,7 @@
1.22 @Test public void concatCharsFromInts() throws Exception {
1.23 assertExec(
1.24 "Composing yields ABC",
1.25 - StringSample.class, "charsFromNumbers__Ljava_lang_String_2",
1.26 + StringSample.class, "charsFromNumbers__s",
1.27 "ABC"
1.28 );
1.29 }
1.30 @@ -62,7 +62,7 @@
1.31 @Test public void concatCharsFromChars() throws Exception {
1.32 assertExec(
1.33 "Composing yields ABC",
1.34 - StringSample.class, "charsFromChars__Ljava_lang_String_2",
1.35 + StringSample.class, "charsFromChars__s",
1.36 "ABC"
1.37 );
1.38 }
1.39 @@ -78,7 +78,7 @@
1.40 @Test(timeOut=10000) public void toStringConcatenation() throws Exception {
1.41 assertExec(
1.42 "Five executions should generate 5Hello World!",
1.43 - StringSample.class, "toStringTest__Ljava_lang_String_2I",
1.44 + StringSample.class, "toStringTest__sI",
1.45 "Hello World!5", 5
1.46 );
1.47 }
1.48 @@ -89,7 +89,7 @@
1.49 @Test(timeOut=10000) public void stringStringConcat() throws Exception {
1.50 assertExec(
1.51 "Composes strings OK",
1.52 - StringSample.class, "concatStrings__Ljava_lang_String_2",
1.53 + StringSample.class, "concatStrings__s",
1.54 "Hello World!1" + "\\\n\r\t"
1.55 );
1.56 }
1.57 @@ -104,14 +104,14 @@
1.58 @Test public void replaceChars() throws Exception {
1.59 assertExec(
1.60 "Can replace slashes by underscores",
1.61 - StringSample.class, "replace__Ljava_lang_String_2Ljava_lang_String_2CC",
1.62 + StringSample.class, "replace__ssCC",
1.63 "x_y_z", "x/y/z", '/', '_'
1.64 );
1.65 }
1.66 @Test public void replaceIntChars() throws Exception {
1.67 assertExec(
1.68 "Can replace slashes by underscores",
1.69 - StringSample.class, "replace__Ljava_lang_String_2Ljava_lang_String_2CC",
1.70 + StringSample.class, "replace__ssCC",
1.71 "x_y_z", "x/y/z", (int)'/', (int)'_'
1.72 );
1.73 }
1.74 @@ -119,7 +119,7 @@
1.75 @Test public void insertBuilder() throws Exception {
1.76 assertExec(
1.77 "Can insert something into a buffer?",
1.78 - StringSample.class, "insertBuffer__Ljava_lang_String_2",
1.79 + StringSample.class, "insertBuffer__s",
1.80 "Ahojdo!"
1.81 );
1.82 }
1.83 @@ -129,7 +129,7 @@
1.84 int jh = StringSample.hashCode(j);
1.85 assertExec(
1.86 "Hashcode is the same " +jh,
1.87 - StringSample.class, "hashCode__ILjava_lang_String_2",
1.88 + StringSample.class, "hashCode__Is",
1.89 Double.valueOf(jh), j
1.90 );
1.91 }
1.92 @@ -138,28 +138,28 @@
1.93 int jh = StringSample.hashCode(j);
1.94 assertExec(
1.95 "Hashcode is the same " + jh,
1.96 - StringSample.class, "hashCode__ILjava_lang_String_2",
1.97 + StringSample.class, "hashCode__Is",
1.98 Double.valueOf(jh), j
1.99 );
1.100 }
1.101 @Test public void stringSwitch1() throws Exception {
1.102 assertExec(
1.103 "Get one",
1.104 - StringSample.class, "stringSwitch__ILjava_lang_String_2",
1.105 + StringSample.class, "stringSwitch__Is",
1.106 Double.valueOf(1), "jedna"
1.107 );
1.108 }
1.109 @Test public void stringSwitch2() throws Exception {
1.110 assertExec(
1.111 "Get two",
1.112 - StringSample.class, "stringSwitch__ILjava_lang_String_2",
1.113 + StringSample.class, "stringSwitch__Is",
1.114 Double.valueOf(2), "dve"
1.115 );
1.116 }
1.117 @Test public void stringSwitchDefault() throws Exception {
1.118 assertExec(
1.119 "Get -1",
1.120 - StringSample.class, "stringSwitch__ILjava_lang_String_2",
1.121 + StringSample.class, "stringSwitch__Is",
1.122 Double.valueOf(-1), "none"
1.123 );
1.124 }
1.125 @@ -168,12 +168,22 @@
1.126 assertEquals(StringSample.countAB("Ahoj Bedo!"), 3, "Verify Java code is sane");
1.127 assertExec(
1.128 "One A and one B adds to 3",
1.129 - StringSample.class, "countAB__ILjava_lang_String_2",
1.130 + StringSample.class, "countAB__Is",
1.131 Double.valueOf(3), "Ahoj Bedo!"
1.132 );
1.133
1.134 }
1.135
1.136 + @Test public void replaceInSB() throws Exception {
1.137 + final String text = "Ljava_lang_String_2";
1.138 + String exp = StringSample.replaceWithS(text);
1.139 + assertExec(
1.140 + "Also replaces the text",
1.141 + StringSample.class, "replaceWithS__ss",
1.142 + exp, text
1.143 + );
1.144 + }
1.145 +
1.146 private static CharSequence codeSeq;
1.147 private static Invocable code;
1.148