vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 12 Jan 2013 15:40:20 +0100
changeset 430 b4940ef87438
parent 346 b671ac44bc55
child 434 2c0646d78e68
permissions -rw-r--r--
Support for reflection on char parameter/return type
     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 static Object compareURLs() throws MalformedURLException {
    36         return new URL("http://apidesign.org:8080/wiki/").toExternalForm().toString();
    37     }
    38     
    39     @Compare public String deleteLastTwoCharacters() {
    40         StringBuilder sb = new StringBuilder();
    41         sb.append("453.0");
    42         if (sb.toString().endsWith(".0")) {
    43             final int l = sb.length();
    44             sb.delete(l - 2, l);
    45         }
    46         return sb.toString().toString();
    47     }
    48     
    49     @Compare public String nameOfStringClass() throws Exception {
    50         return Class.forName("java.lang.String").getName();
    51     }
    52     @Compare public String nameOfArrayClass() throws Exception {
    53         return Class.forName("org.apidesign.bck2brwsr.tck.CompareHashTest").getName();
    54     }
    55     
    56     @Compare public String lowerHello() {
    57         return "HeLlO".toLowerCase();
    58     }
    59     
    60     @Compare public String lowerA() {
    61         return String.valueOf(Character.toLowerCase('A')).toString();
    62     }
    63     @Compare public String upperHello() {
    64         return "hello".toUpperCase();
    65     }
    66     
    67     @Compare public String upperA() {
    68         return String.valueOf(Character.toUpperCase('a')).toString();
    69     }
    70     
    71     @Compare public boolean matchRegExp() throws Exception {
    72         return "58038503".matches("\\d*");
    73     }
    74 
    75     @Compare public boolean doesNotMatchRegExp() throws Exception {
    76         return "58038503GH".matches("\\d*");
    77     }
    78 
    79     @Compare public boolean doesNotMatchRegExpFully() throws Exception {
    80         return "Hello".matches("Hell");
    81     }
    82     
    83     @Compare public String variousCharacterTests() throws Exception {
    84         StringBuilder sb = new StringBuilder();
    85         
    86         sb.append(Character.isUpperCase('a'));
    87         sb.append(Character.isUpperCase('A'));
    88         sb.append(Character.isLowerCase('a'));
    89         sb.append(Character.isLowerCase('A'));
    90         
    91         sb.append(Character.isLetter('A'));
    92         sb.append(Character.isLetterOrDigit('9'));
    93         sb.append(Character.isLetterOrDigit('A'));
    94         sb.append(Character.isLetter('0'));
    95         
    96         return sb.toString().toString();
    97     }
    98         
    99     @Compare
   100     public String nullFieldInitialized() {
   101         NullField nf = new NullField();
   102         return ("" + nf.name).toString();
   103     }
   104 
   105     @Factory
   106     public static Object[] create() {
   107         return VMTest.create(CompareStringsTest.class);
   108     }
   109 
   110     private static final class NullField {
   111 
   112         String name;
   113     }
   114 }