2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 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.tck;
20 import java.net.MalformedURLException;
22 import org.apidesign.bck2brwsr.vmtest.Compare;
23 import org.apidesign.bck2brwsr.vmtest.VMTest;
24 import org.testng.annotations.Factory;
28 * @author Jaroslav Tulach <jtulach@netbeans.org>
30 public class CompareStringsTest {
31 @Compare public String firstChar() {
32 return "" + ("Hello".toCharArray()[0]);
35 @Compare public String classCast() {
36 Object o = firstChar();
37 return String.class.cast(o);
40 @Compare public String classCastThrown() {
42 return String.class.cast(o);
45 @Compare public static Object compareURLs() throws MalformedURLException {
46 return new URL("http://apidesign.org:8080/wiki/").toExternalForm().toString();
49 @Compare public String deleteLastTwoCharacters() {
50 StringBuilder sb = new StringBuilder();
52 if (sb.toString().endsWith(".0")) {
53 final int l = sb.length();
56 return sb.toString().toString();
59 @Compare public String nameOfStringClass() throws Exception {
60 return Class.forName("java.lang.String").getName();
62 @Compare public String nameOfArrayClass() throws Exception {
63 return Class.forName("org.apidesign.bck2brwsr.tck.CompareHashTest").getName();
66 @Compare public String lowerHello() {
67 return "HeLlO".toLowerCase();
70 @Compare public String lowerA() {
71 return String.valueOf(Character.toLowerCase('A')).toString();
73 @Compare public String upperHello() {
74 return "hello".toUpperCase();
77 @Compare public String upperA() {
78 return String.valueOf(Character.toUpperCase('a')).toString();
81 @Compare public boolean matchRegExp() throws Exception {
82 return "58038503".matches("\\d*");
85 @Compare public boolean doesNotMatchRegExp() throws Exception {
86 return "58038503GH".matches("\\d*");
89 @Compare public boolean doesNotMatchRegExpFully() throws Exception {
90 return "Hello".matches("Hell");
93 @Compare public String emptyCharArray() {
94 char[] arr = new char[10];
95 return new String(arr);
98 @Compare public String variousCharacterTests() throws Exception {
99 StringBuilder sb = new StringBuilder();
101 sb.append(Character.isUpperCase('a'));
102 sb.append(Character.isUpperCase('A'));
103 sb.append(Character.isLowerCase('a'));
104 sb.append(Character.isLowerCase('A'));
106 sb.append(Character.isLetter('A'));
107 sb.append(Character.isLetterOrDigit('9'));
108 sb.append(Character.isLetterOrDigit('A'));
109 sb.append(Character.isLetter('0'));
111 return sb.toString().toString();
115 public String nullFieldInitialized() {
116 NullField nf = new NullField();
117 return ("" + nf.name).toString();
121 public static Object[] create() {
122 return VMTest.create(CompareStringsTest.class);
125 private static final class NullField {