ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/JsniCommentTokenizerTest.java
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.ide.editor;
20 import java.io.IOException;
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.testng.Assert;
24 import org.testng.annotations.Test;
26 public class JsniCommentTokenizerTest {
28 private static class MockSink implements JsniCommentTokenizer.Sink {
29 final List<String> out = new ArrayList<String>();
31 public void javascript(String s) {
35 public void method(String clazz, String method, String signature) {
36 out.add("M " + clazz + "|" + method + "|" + signature);
39 public void field(String clazz, String field) {
40 out.add("F " + clazz + "|" + field);
46 public void testProcess_nop() throws IOException {
47 final String in = "foo bar";
48 final List<String> expected = new ArrayList<String>();
49 expected.add("J foo bar");
51 final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
52 final MockSink out = new MockSink();
53 jsniCommentTokenizer.process(in, out);
55 Assert.assertEquals(expected, out.out);
59 public void testProcess_read_static_field() throws IOException {
60 final String in = " @com.google.gwt.examples.JSNIExample::myStaticField = val + \" and stuff\";";
61 final List<String> expected = new ArrayList<String>();
63 expected.add("F com.google.gwt.examples.JSNIExample|myStaticField");
64 expected.add("J = val + \" and stuff\";");
66 final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
67 final MockSink out = new MockSink();
68 jsniCommentTokenizer.process(in, out);
70 Assert.assertEquals(expected, out.out);
74 public void testProcess_write_instance_field() throws IOException {
75 final String in = " x.@com.google.gwt.examples.JSNIExample::myInstanceField = val + \" and stuff\";";
76 final List<String> expected = new ArrayList<String>();
78 expected.add("F com.google.gwt.examples.JSNIExample|myInstanceField");
79 expected.add("J = val + \" and stuff\";");
81 final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
82 final MockSink out = new MockSink();
83 jsniCommentTokenizer.process(in, out);
85 Assert.assertEquals(expected, out.out);
89 public void testProcess_read_instance_field() throws IOException {
90 final String in = " var val = this.@com.google.gwt.examples.JSNIExample::myInstanceField;";
91 final List<String> expected = new ArrayList<String>();
92 expected.add("J var val = this.");
93 expected.add("F com.google.gwt.examples.JSNIExample|myInstanceField");
96 final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
97 final MockSink out = new MockSink();
98 jsniCommentTokenizer.process(in, out);
100 Assert.assertEquals(expected, out.out);
105 public void testProcess_static_method() throws IOException {
106 final String in = " @com.google.gwt.examples.JSNIExample::staticFoo(Ljava/lang/String;)(s);";
107 final List<String> expected = new ArrayList<String>();
109 expected.add("M com.google.gwt.examples.JSNIExample|staticFoo|Ljava/lang/String;");
110 expected.add("J (s);");
112 final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
113 final MockSink out = new MockSink();
114 jsniCommentTokenizer.process(in, out);
116 Assert.assertEquals(expected, out.out);
121 public void testProcess_instance_method() throws IOException {
122 final String in = " x.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);";
123 final List<String> expected = new ArrayList<String>();
124 expected.add("J x.");
125 expected.add("M com.google.gwt.examples.JSNIExample|instanceFoo|Ljava/lang/String;");
126 expected.add("J (s);");
128 final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
129 final MockSink out = new MockSink();
130 jsniCommentTokenizer.process(in, out);
132 Assert.assertEquals(expected, out.out);
137 public void testProcess_multiline() throws IOException {
139 " x.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);" +
140 " @com.google.gwt.examples.JSNIExample::myStaticField = val + \" and stuff\";";
141 final List<String> expected = new ArrayList<String>();
142 expected.add("J x.");
143 expected.add("M com.google.gwt.examples.JSNIExample|instanceFoo|Ljava/lang/String;");
144 expected.add("J (s); ");
145 expected.add("F com.google.gwt.examples.JSNIExample|myStaticField");
146 expected.add("J = val + \" and stuff\";");
148 final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
149 final MockSink out = new MockSink();
150 jsniCommentTokenizer.process(in, out);
152 Assert.assertEquals(expected, out.out);