jaroslav@717
|
1 |
/**
|
jaroslav@717
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@717
|
3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@717
|
4 |
*
|
jaroslav@717
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@717
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@717
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@717
|
8 |
*
|
jaroslav@717
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@717
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@717
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@717
|
12 |
* GNU General Public License for more details.
|
jaroslav@717
|
13 |
*
|
jaroslav@717
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@717
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@717
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@717
|
17 |
*/
|
jaroslav@717
|
18 |
package org.apidesign.bck2brwsr.ide.editor;
|
jaroslav@717
|
19 |
|
jaroslav@717
|
20 |
import java.io.IOException;
|
jaroslav@717
|
21 |
import java.util.ArrayList;
|
jaroslav@717
|
22 |
import java.util.List;
|
jaroslav@717
|
23 |
import org.testng.Assert;
|
jaroslav@717
|
24 |
import org.testng.annotations.Test;
|
jaroslav@717
|
25 |
|
jaroslav@717
|
26 |
public class JsniCommentTokenizerTest {
|
jaroslav@717
|
27 |
|
jaroslav@717
|
28 |
private static class MockSink implements JsniCommentTokenizer.Sink {
|
jaroslav@717
|
29 |
final List<String> out = new ArrayList<String>();
|
jaroslav@717
|
30 |
|
jaroslav@717
|
31 |
public void javascript(String s) {
|
jaroslav@717
|
32 |
out.add("J " + s);
|
jaroslav@717
|
33 |
}
|
jaroslav@717
|
34 |
|
jaroslav@717
|
35 |
public void method(String clazz, String method, String signature) {
|
jaroslav@717
|
36 |
out.add("M " + clazz + "|" + method + "|" + signature);
|
jaroslav@717
|
37 |
}
|
jaroslav@717
|
38 |
|
jaroslav@717
|
39 |
public void field(String clazz, String field) {
|
jaroslav@717
|
40 |
out.add("F " + clazz + "|" + field);
|
jaroslav@717
|
41 |
}
|
jaroslav@717
|
42 |
}
|
jaroslav@717
|
43 |
|
jaroslav@717
|
44 |
|
jaroslav@717
|
45 |
@Test
|
jaroslav@717
|
46 |
public void testProcess_nop() throws IOException {
|
jaroslav@717
|
47 |
final String in = "foo bar";
|
jaroslav@717
|
48 |
final List<String> expected = new ArrayList<String>();
|
jaroslav@717
|
49 |
expected.add("J foo bar");
|
jaroslav@717
|
50 |
|
jaroslav@717
|
51 |
final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
|
jaroslav@717
|
52 |
final MockSink out = new MockSink();
|
jaroslav@717
|
53 |
jsniCommentTokenizer.process(in, out);
|
jaroslav@717
|
54 |
|
jaroslav@717
|
55 |
Assert.assertEquals(expected, out.out);
|
jaroslav@717
|
56 |
}
|
jaroslav@717
|
57 |
|
jaroslav@717
|
58 |
@Test
|
jaroslav@717
|
59 |
public void testProcess_read_static_field() throws IOException {
|
jaroslav@717
|
60 |
final String in = " @com.google.gwt.examples.JSNIExample::myStaticField = val + \" and stuff\";";
|
jaroslav@717
|
61 |
final List<String> expected = new ArrayList<String>();
|
jaroslav@717
|
62 |
expected.add("J ");
|
jaroslav@717
|
63 |
expected.add("F com.google.gwt.examples.JSNIExample|myStaticField");
|
jaroslav@717
|
64 |
expected.add("J = val + \" and stuff\";");
|
jaroslav@717
|
65 |
|
jaroslav@717
|
66 |
final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
|
jaroslav@717
|
67 |
final MockSink out = new MockSink();
|
jaroslav@717
|
68 |
jsniCommentTokenizer.process(in, out);
|
jaroslav@717
|
69 |
|
jaroslav@717
|
70 |
Assert.assertEquals(expected, out.out);
|
jaroslav@717
|
71 |
}
|
jaroslav@717
|
72 |
|
jaroslav@717
|
73 |
@Test
|
jaroslav@717
|
74 |
public void testProcess_write_instance_field() throws IOException {
|
jaroslav@717
|
75 |
final String in = " x.@com.google.gwt.examples.JSNIExample::myInstanceField = val + \" and stuff\";";
|
jaroslav@717
|
76 |
final List<String> expected = new ArrayList<String>();
|
jaroslav@717
|
77 |
expected.add("J x.");
|
jaroslav@717
|
78 |
expected.add("F com.google.gwt.examples.JSNIExample|myInstanceField");
|
jaroslav@717
|
79 |
expected.add("J = val + \" and stuff\";");
|
jaroslav@717
|
80 |
|
jaroslav@717
|
81 |
final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
|
jaroslav@717
|
82 |
final MockSink out = new MockSink();
|
jaroslav@717
|
83 |
jsniCommentTokenizer.process(in, out);
|
jaroslav@717
|
84 |
|
jaroslav@717
|
85 |
Assert.assertEquals(expected, out.out);
|
jaroslav@717
|
86 |
}
|
jaroslav@717
|
87 |
|
jaroslav@717
|
88 |
@Test
|
jaroslav@717
|
89 |
public void testProcess_read_instance_field() throws IOException {
|
jaroslav@717
|
90 |
final String in = " var val = this.@com.google.gwt.examples.JSNIExample::myInstanceField;";
|
jaroslav@717
|
91 |
final List<String> expected = new ArrayList<String>();
|
jaroslav@717
|
92 |
expected.add("J var val = this.");
|
jaroslav@717
|
93 |
expected.add("F com.google.gwt.examples.JSNIExample|myInstanceField");
|
jaroslav@717
|
94 |
expected.add("J ;");
|
jaroslav@717
|
95 |
|
jaroslav@717
|
96 |
final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
|
jaroslav@717
|
97 |
final MockSink out = new MockSink();
|
jaroslav@717
|
98 |
jsniCommentTokenizer.process(in, out);
|
jaroslav@717
|
99 |
|
jaroslav@717
|
100 |
Assert.assertEquals(expected, out.out);
|
jaroslav@717
|
101 |
}
|
jaroslav@717
|
102 |
|
jaroslav@717
|
103 |
|
jaroslav@717
|
104 |
@Test
|
jaroslav@717
|
105 |
public void testProcess_static_method() throws IOException {
|
jaroslav@717
|
106 |
final String in = " @com.google.gwt.examples.JSNIExample::staticFoo(Ljava/lang/String;)(s);";
|
jaroslav@717
|
107 |
final List<String> expected = new ArrayList<String>();
|
jaroslav@717
|
108 |
expected.add("J ");
|
jaroslav@717
|
109 |
expected.add("M com.google.gwt.examples.JSNIExample|staticFoo|Ljava/lang/String;");
|
jaroslav@717
|
110 |
expected.add("J (s);");
|
jaroslav@717
|
111 |
|
jaroslav@717
|
112 |
final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
|
jaroslav@717
|
113 |
final MockSink out = new MockSink();
|
jaroslav@717
|
114 |
jsniCommentTokenizer.process(in, out);
|
jaroslav@717
|
115 |
|
jaroslav@717
|
116 |
Assert.assertEquals(expected, out.out);
|
jaroslav@717
|
117 |
}
|
jaroslav@717
|
118 |
|
jaroslav@717
|
119 |
|
jaroslav@717
|
120 |
@Test
|
jaroslav@717
|
121 |
public void testProcess_instance_method() throws IOException {
|
jaroslav@717
|
122 |
final String in = " x.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);";
|
jaroslav@717
|
123 |
final List<String> expected = new ArrayList<String>();
|
jaroslav@717
|
124 |
expected.add("J x.");
|
jaroslav@717
|
125 |
expected.add("M com.google.gwt.examples.JSNIExample|instanceFoo|Ljava/lang/String;");
|
jaroslav@717
|
126 |
expected.add("J (s);");
|
jaroslav@717
|
127 |
|
jaroslav@717
|
128 |
final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
|
jaroslav@717
|
129 |
final MockSink out = new MockSink();
|
jaroslav@717
|
130 |
jsniCommentTokenizer.process(in, out);
|
jaroslav@717
|
131 |
|
jaroslav@717
|
132 |
Assert.assertEquals(expected, out.out);
|
jaroslav@717
|
133 |
}
|
jaroslav@717
|
134 |
|
jaroslav@717
|
135 |
|
jaroslav@717
|
136 |
@Test
|
jaroslav@717
|
137 |
public void testProcess_multiline() throws IOException {
|
jaroslav@717
|
138 |
final String in =
|
jaroslav@717
|
139 |
" x.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);" +
|
jaroslav@717
|
140 |
" @com.google.gwt.examples.JSNIExample::myStaticField = val + \" and stuff\";";
|
jaroslav@717
|
141 |
final List<String> expected = new ArrayList<String>();
|
jaroslav@717
|
142 |
expected.add("J x.");
|
jaroslav@717
|
143 |
expected.add("M com.google.gwt.examples.JSNIExample|instanceFoo|Ljava/lang/String;");
|
jaroslav@717
|
144 |
expected.add("J (s); ");
|
jaroslav@717
|
145 |
expected.add("F com.google.gwt.examples.JSNIExample|myStaticField");
|
jaroslav@717
|
146 |
expected.add("J = val + \" and stuff\";");
|
jaroslav@717
|
147 |
|
jaroslav@717
|
148 |
final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
|
jaroslav@717
|
149 |
final MockSink out = new MockSink();
|
jaroslav@717
|
150 |
jsniCommentTokenizer.process(in, out);
|
jaroslav@717
|
151 |
|
jaroslav@717
|
152 |
Assert.assertEquals(expected, out.out);
|
jaroslav@717
|
153 |
}
|
jaroslav@717
|
154 |
}
|