Merging the two TCK additions on top of 1.0 version
authorJaroslav Tulach <jaroslav.tulach@netbeans.org>
Wed, 24 Sep 2014 05:35:33 +0200
changeset 86035c8daae9242
parent 858 01f95c246eeb
parent 859 9df01bc2a27a
child 861 52b0e31920c1
Merging the two TCK additions on top of 1.0 version
json-tck/src/main/java/net/java/html/js/tests/Bodies.java
json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java
     1.1 --- a/json-tck/src/main/java/net/java/html/js/tests/Bodies.java	Wed Sep 24 05:29:57 2014 +0200
     1.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/Bodies.java	Wed Sep 24 05:35:33 2014 +0200
     1.3 @@ -171,4 +171,18 @@
     1.4          "return ret;\n"
     1.5      )
     1.6      static native Object[] forIn(Object[] in);
     1.7 +
     1.8 +    @JavaScriptBody(args = {}, javacall = true, body = 
     1.9 +        "return @net.java.html.js.tests.Bodies::problematicString()();"
    1.10 +    )
    1.11 +    public static native String problematicCallback();
    1.12 +    
    1.13 +    static String problematicString() {
    1.14 +        return "{\n" +
    1.15 +"    MyViewModel: {\n" +
    1.16 +"//      ViewModel: JavaViewModel,\n" +
    1.17 +"\n" +
    1.18 +"    }          \n" +
    1.19 +"}";
    1.20 +    }
    1.21  }
     2.1 --- a/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java	Wed Sep 24 05:29:57 2014 +0200
     2.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java	Wed Sep 24 05:35:33 2014 +0200
     2.3 @@ -217,9 +217,9 @@
     2.4      }
     2.5      
     2.6      @KOTest public void selectFromStringJavaArray() {
     2.7 -        String[] arr = { "Ahoj", "World" };
     2.8 +        String[] arr = { "Ahoj", "Wo\nrld" };
     2.9          Object res = Bodies.select(arr, 1);
    2.10 -        assert "World".equals(res) : "Expecting World, but was: " + res;
    2.11 +        assert "Wo\nrld".equals(res) : "Expecting World, but was: " + res;
    2.12      }
    2.13  
    2.14      @KOTest public void selectFromObjectJavaArray() {
    2.15 @@ -241,7 +241,7 @@
    2.16      }
    2.17  
    2.18      @KOTest public void javaArrayInOutIsCopied() {
    2.19 -        String[] arr = { "Ahoj", "World" };
    2.20 +        String[] arr = { "Ahoj", "Wo\nrld" };
    2.21          Object res = Bodies.id(arr);
    2.22          assert res != null : "Non-null is returned";
    2.23          assert res instanceof Object[] : "Returned an array: " + res;
    2.24 @@ -254,10 +254,10 @@
    2.25      }
    2.26  
    2.27      @KOTest public void modifyJavaArrayHasNoEffect() {
    2.28 -        String[] arr = { "Ahoj", "World" };
    2.29 -        String value = Bodies.modify(arr, 0, "Hello");
    2.30 -        assert "Hello".equals(value) : "Inside JS the value is changed: " + value;
    2.31 -        assert "Ahoj".equals(arr[0]) : "From a Java point of view it remains: " + arr[0];
    2.32 +        String[] arr = { "Ah\noj", "World" };
    2.33 +        String value = Bodies.modify(arr, 0, "H\tello");
    2.34 +        assert "H\tello".equals(value) : "Inside JS the value is changed: " + value;
    2.35 +        assert "Ah\noj".equals(arr[0]) : "From a Java point of view it remains: " + arr[0];
    2.36      }
    2.37  
    2.38      @KOTest
    2.39 @@ -265,17 +265,17 @@
    2.40          class A implements Callable<String[]> {
    2.41              @Override
    2.42              public String[] call() throws Exception {
    2.43 -                return new String[] { "Hello" };
    2.44 +                return new String[] { "He\nllo" };
    2.45              }
    2.46          }
    2.47          Callable<String[]> a = new A();
    2.48 -        Object b = Bodies.callbackAndPush(a, "World!");
    2.49 +        Object b = Bodies.callbackAndPush(a, "Worl\nd!");
    2.50          assert b instanceof Object[] : "Returns an array: " + b;
    2.51          Object[] arr = (Object[]) b;
    2.52          String str = Arrays.toString(arr);
    2.53          assert arr.length == 2 : "Size is two " + str;
    2.54 -        assert "Hello".equals(arr[0]) : "Hello expected: " + arr[0];
    2.55 -        assert "World!".equals(arr[1]) : "World! expected: " + arr[1];
    2.56 +        assert "He\nllo".equals(arr[0]) : "Hello expected: " + arr[0];
    2.57 +        assert "Worl\nd!".equals(arr[1]) : "World! expected: " + arr[1];
    2.58      }
    2.59      
    2.60      @KOTest public void sumVector() {
    2.61 @@ -339,6 +339,25 @@
    2.62          assert ret[2].equals("Ciao") : "Expecting Ciao: " + ret[2];
    2.63      }
    2.64      
    2.65 +    @KOTest public void problematicString() {
    2.66 +        String orig = Bodies.problematicString();
    2.67 +        String js = Bodies.problematicCallback();
    2.68 +        if (orig.equals(js)) {
    2.69 +            return;
    2.70 +        }
    2.71 +        int len = Math.min(orig.length(), js.length());
    2.72 +        for (int i = 0; i < len; i++) {
    2.73 +            if (orig.charAt(i) != js.charAt(i)) {
    2.74 +                assert false : "Difference at position " + i + 
    2.75 +                    "\norig: " +
    2.76 +                    orig.substring(i - 5, Math.min(i + 10, orig.length())) +
    2.77 +                    "\n  js: " +
    2.78 +                    js.substring(i - 5, Math.min(i + 10, js.length()));
    2.79 +            }
    2.80 +        }
    2.81 +        assert false : "The JS string is different: " + js;
    2.82 +    }
    2.83 +    
    2.84      Later l;
    2.85      @KOTest public void callLater() throws Exception{
    2.86          final Fn.Presenter p = Fn.activePresenter();