vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 15 Jan 2013 11:53:07 +0100
changeset 456 f2f769bafeef
parent 434 2c0646d78e68
parent 447 aa48132c8a80
child 501 dc07c9001184
permissions -rw-r--r--
Bringing Martin's integer, short, byte arithmetic to default branch
     1 /**
     2  * Back 2 Browser Bytecode Translator
     3  * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     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.
     8  *
     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.
    13  *
    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.
    17  */
    18 package org.apidesign.bck2brwsr.tck;
    19 
    20 import java.net.MalformedURLException;
    21 import java.net.URL;
    22 import org.apidesign.bck2brwsr.vmtest.Compare;
    23 import org.apidesign.bck2brwsr.vmtest.VMTest;
    24 import org.testng.annotations.Factory;
    25 
    26 /**
    27  *
    28  * @author Jaroslav Tulach <jtulach@netbeans.org>
    29  */
    30 public class CompareStringsTest {
    31     @Compare public String firstChar() {
    32         return "" + ("Hello".toCharArray()[0]);
    33     }
    34     
    35     @Compare public String classCast() {
    36         Object o = firstChar();
    37         return String.class.cast(o);
    38     }
    39 
    40     @Compare public String classCastThrown() {
    41         Object o = null;
    42         return String.class.cast(o);
    43     }
    44     
    45     @Compare public static Object compareURLs() throws MalformedURLException {
    46         return new URL("http://apidesign.org:8080/wiki/").toExternalForm().toString();
    47     }
    48     
    49     @Compare public String deleteLastTwoCharacters() {
    50         StringBuilder sb = new StringBuilder();
    51         sb.append("453.0");
    52         if (sb.toString().endsWith(".0")) {
    53             final int l = sb.length();
    54             sb.delete(l - 2, l);
    55         }
    56         return sb.toString().toString();
    57     }
    58     
    59     @Compare public String nameOfStringClass() throws Exception {
    60         return Class.forName("java.lang.String").getName();
    61     }
    62     @Compare public String nameOfArrayClass() throws Exception {
    63         return Class.forName("org.apidesign.bck2brwsr.tck.CompareHashTest").getName();
    64     }
    65     
    66     @Compare public String lowerHello() {
    67         return "HeLlO".toLowerCase();
    68     }
    69     
    70     @Compare public String lowerA() {
    71         return String.valueOf(Character.toLowerCase('A')).toString();
    72     }
    73     @Compare public String upperHello() {
    74         return "hello".toUpperCase();
    75     }
    76     
    77     @Compare public String upperA() {
    78         return String.valueOf(Character.toUpperCase('a')).toString();
    79     }
    80     
    81     @Compare public boolean matchRegExp() throws Exception {
    82         return "58038503".matches("\\d*");
    83     }
    84 
    85     @Compare public boolean doesNotMatchRegExp() throws Exception {
    86         return "58038503GH".matches("\\d*");
    87     }
    88 
    89     @Compare public boolean doesNotMatchRegExpFully() throws Exception {
    90         return "Hello".matches("Hell");
    91     }
    92     
    93     @Compare public String emptyCharArray() {
    94         char[] arr = new char[10];
    95         return new String(arr);
    96     }
    97     
    98     @Compare public String variousCharacterTests() throws Exception {
    99         StringBuilder sb = new StringBuilder();
   100         
   101         sb.append(Character.isUpperCase('a'));
   102         sb.append(Character.isUpperCase('A'));
   103         sb.append(Character.isLowerCase('a'));
   104         sb.append(Character.isLowerCase('A'));
   105         
   106         sb.append(Character.isLetter('A'));
   107         sb.append(Character.isLetterOrDigit('9'));
   108         sb.append(Character.isLetterOrDigit('A'));
   109         sb.append(Character.isLetter('0'));
   110         
   111         return sb.toString().toString();
   112     }
   113         
   114     @Compare
   115     public String nullFieldInitialized() {
   116         NullField nf = new NullField();
   117         return ("" + nf.name).toString();
   118     }
   119 
   120     @Factory
   121     public static Object[] create() {
   122         return VMTest.create(CompareStringsTest.class);
   123     }
   124 
   125     private static final class NullField {
   126 
   127         String name;
   128     }
   129 }