Debian Codegraph @

test/com/google/javascript/jscomp/deps/JsFileLineParserTest.java

raw symbols SCIP
1 /*
2 * Copyright 2010 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.javascript.jscomp.deps;
18
19 import com.google.javascript.jscomp.ErrorManager;
20 import com.google.javascript.jscomp.PrintStreamErrorManager;
21
22 import junit.framework.TestCase;
23
24 import java.io.StringReader;
25
26 /**
27 * Tests for {@link JsFileLineParser}.
28 *
29 * @author [email protected] (Nick Santos)
30 */
31 public class JsFileLineParserTest extends TestCase {
32
33 TestParser parser;
34 private ErrorManager errorManager;
35
36 @Override
37 public void setUp() {
38 errorManager = new PrintStreamErrorManager(System.err);
39 parser = new TestParser(errorManager);
40 }
41
42 public void testSingleLine1() {
43 assertStrip("2", "// 1\n2");
44 }
45
46 public void testSingleLine2() {
47 assertStrip("2 ", "// 1\n2 // 3 // 4 \n");
48 }
49
50 public void testMultiLine1() {
51 assertStrip("1", "/* hi */\n1");
52 }
53
54 public void testMultiLine2() {
55 assertStrip("123", "1/* hi */2\n3");
56 }
57
58 public void testMultiLine3() {
59 assertStrip("14", "1/* hi 2\n3*/4");
60 }
61
62 public void testMultiLine4() {
63 assertStrip("15", "1/* hi x\ny\nz*/5");
64 }
65
66 public void testMultiLine5() {
67 assertStrip("1234", "1/* hi */2/**/3/*\n/** bye */4");
68 }
69
70 public void testMultiLine6() {
71 assertStrip("12", "1/*** hi *** 3 **/2");
72 }
73
74 public void testMixedLine1() {
75 assertStrip("14", "1// /** 2 **/ 3\n4");
76 }
77
78 public void testMixedLine2() {
79 assertStrip("1 34", "1/** // 2 **/ 3\n4");
80 }
81
82 private void assertStrip(String expected, String input) {
83 parser.doParse("file", new StringReader(input));
84 assertEquals(expected, parser.toString());
85 }
86
87 private static class TestParser extends JsFileLineParser {
88 StringBuilder sb = new StringBuilder();
89
90 TestParser(ErrorManager errorManager) {
91 super(errorManager);
92 }
93
94 @Override
95 boolean parseLine(String line) {
96 sb.append(line);
97 return true;
98 }
99
100 @Override
101 public String toString() {
102 return sb.toString();
103 }
104 }
105 }