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 boolean equalToNull() {
46 return "Ahoj".equals(null);
49 @Compare public static Object compareURLs() throws MalformedURLException {
50 return new URL("http://apidesign.org:8080/wiki/").toExternalForm().toString();
53 @Compare public String deleteLastTwoCharacters() {
54 StringBuilder sb = new StringBuilder();
56 if (sb.toString().endsWith(".0")) {
57 final int l = sb.length();
60 return sb.toString().toString();
63 @Compare public String nameOfStringClass() throws Exception {
64 return Class.forName("java.lang.String").getName();
66 @Compare public String nameOfArrayClass() throws Exception {
67 return Class.forName("org.apidesign.bck2brwsr.tck.CompareHashTest").getName();
70 @Compare public String lowerHello() {
71 return "HeLlO".toLowerCase();
74 @Compare public String lowerA() {
75 return String.valueOf(Character.toLowerCase('A')).toString();
77 @Compare public String upperHello() {
78 return "hello".toUpperCase();
81 @Compare public String upperA() {
82 return String.valueOf(Character.toUpperCase('a')).toString();
85 @Compare public boolean matchRegExp() throws Exception {
86 return "58038503".matches("\\d*");
89 @Compare public boolean doesNotMatchRegExp() throws Exception {
90 return "58038503GH".matches("\\d*");
93 @Compare public boolean doesNotMatchRegExpFully() throws Exception {
94 return "Hello".matches("Hell");
97 @Compare public String emptyCharArray() {
98 char[] arr = new char[10];
99 return new String(arr);
102 @Compare public String variousCharacterTests() throws Exception {
103 StringBuilder sb = new StringBuilder();
105 sb.append(Character.isUpperCase('a'));
106 sb.append(Character.isUpperCase('A'));
107 sb.append(Character.isLowerCase('a'));
108 sb.append(Character.isLowerCase('A'));
110 sb.append(Character.isLetter('A'));
111 sb.append(Character.isLetterOrDigit('9'));
112 sb.append(Character.isLetterOrDigit('A'));
113 sb.append(Character.isLetter('0'));
115 return sb.toString().toString();
119 public String nullFieldInitialized() {
120 NullField nf = new NullField();
121 return ("" + nf.name).toString();
125 public static Object[] create() {
126 return VMTest.create(CompareStringsTest.class);
129 private static final class NullField {