001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.directwebremoting.impl;
017:
018: import org.junit.Test;
019:
020: import static org.junit.Assert.*;
021:
022: /**
023: * JUnit
024: * @author Joe Walker [joe at getahead dot ltd dot uk]
025: */
026: public class LegacyCompressorTest {
027: @Test
028: public void testCompress() {
029: assertEquals(LegacyCompressor.compress(" aaa \n aa \n",
030: LegacyCompressor.COMPRESS_TRIM_LINES), "aaa\naa\n");
031: assertEquals(LegacyCompressor.compress(
032: "//aaa//bbbb\nxx //aaa\n",
033: LegacyCompressor.COMPRESS_STRIP_SL_COMMENTS), "\nxx \n");
034: assertEquals(LegacyCompressor.compress("a/*\n*/a\n",
035: LegacyCompressor.COMPRESS_STRIP_ML_COMMENTS), "a \na\n");
036: assertEquals(LegacyCompressor.compress("a\n\na\n",
037: LegacyCompressor.COMPRESS_STRIP_BLANKLINES), "a\na\n");
038: assertEquals(LegacyCompressor.compress("a\nb\n",
039: LegacyCompressor.COMPRESS_REMOVE_NEWLINES), "a b \n");
040: }
041:
042: @Test
043: public void testStripSpaces() {
044: assertEquals(LegacyCompressor.trimLines("\n"), "\n");
045: assertEquals(LegacyCompressor.trimLines(null), null);
046:
047: assertEquals(LegacyCompressor.trimLines("a a\n"), "a a\n");
048: assertEquals(LegacyCompressor.trimLines("aaa\n"), "aaa\n");
049: assertEquals(LegacyCompressor.trimLines(" a a \n"), "a a\n");
050: assertEquals(LegacyCompressor.trimLines(" aaa \n"), "aaa\n");
051:
052: assertEquals(LegacyCompressor.trimLines(" aaa \n aa \n"),
053: "aaa\naa\n");
054: }
055:
056: @Test
057: public void testStripSingleLineComments() {
058: assertEquals(LegacyCompressor.stripSingleLineComments("\n"),
059: "\n");
060: assertEquals(LegacyCompressor.stripSingleLineComments(null),
061: null);
062:
063: assertEquals(LegacyCompressor.stripSingleLineComments("a\n"),
064: "a\n");
065: assertEquals(LegacyCompressor.stripSingleLineComments("/a\n"),
066: "/a\n");
067: assertEquals(
068: LegacyCompressor.stripSingleLineComments("/a/a\n"),
069: "/a/a\n");
070: assertEquals(LegacyCompressor.stripSingleLineComments("/ /\n"),
071: "/ /\n");
072:
073: assertEquals(LegacyCompressor.stripSingleLineComments("//\n"),
074: "\n");
075: assertEquals(LegacyCompressor
076: .stripSingleLineComments("//aaa\n"), "\n");
077: assertEquals(LegacyCompressor
078: .stripSingleLineComments("//aaa\naaa\n"), "\naaa\n");
079: assertEquals(LegacyCompressor
080: .stripSingleLineComments("//aaa//bbbb\naaa\n"),
081: "\naaa\n");
082: assertEquals(LegacyCompressor
083: .stripSingleLineComments("//aaa//bbbb\nxx //aaa\n"),
084: "\nxx \n");
085: }
086:
087: @Test
088: public void testStripMultiLineComments() {
089: assertEquals(LegacyCompressor.stripMultiLineComments("\n"),
090: "\n");
091: assertEquals(LegacyCompressor.stripMultiLineComments(null),
092: null);
093:
094: assertEquals(LegacyCompressor.stripMultiLineComments("a\n"),
095: "a\n");
096: assertEquals(LegacyCompressor.stripMultiLineComments("/a\n"),
097: "/a\n");
098: assertEquals(LegacyCompressor.stripMultiLineComments("/a*a\n"),
099: "/a*a\n");
100: assertEquals(LegacyCompressor
101: .stripMultiLineComments("/ */ *\n"), "/ */ *\n");
102:
103: assertEquals(LegacyCompressor.stripMultiLineComments("/**/\n"),
104: " \n");
105: assertEquals(
106: LegacyCompressor.stripMultiLineComments("/***/\n"),
107: " \n");
108: assertEquals(
109: LegacyCompressor.stripMultiLineComments("/*a*/\n"),
110: " \n");
111: assertEquals(LegacyCompressor
112: .stripMultiLineComments("a/**/a\n"), "a a\n");
113: assertEquals(LegacyCompressor
114: .stripMultiLineComments("a/*\n*/a\n"), "a \na\n");
115: }
116:
117: @Test
118: public void testStripBlankLines() {
119: assertEquals(LegacyCompressor.stripBlankLines("\n"), "\n");
120: assertEquals(LegacyCompressor.stripBlankLines("\n\n"), "\n");
121: assertEquals(LegacyCompressor.stripBlankLines(null), null);
122:
123: assertEquals(LegacyCompressor.stripBlankLines("a\n"), "a\n");
124: assertEquals(LegacyCompressor.stripBlankLines("a\na\n"),
125: "a\na\n");
126: assertEquals(LegacyCompressor.stripBlankLines(" \n \n"), "\n");
127: assertEquals(LegacyCompressor.stripBlankLines(" \n\t\n#\n"),
128: "#\n");
129:
130: assertEquals(LegacyCompressor.stripBlankLines("\n\n\n"), "\n");
131: assertEquals(LegacyCompressor.stripBlankLines("a\n\na\n"),
132: "a\na\n");
133: }
134:
135: @Test
136: public void testStripNewlines() {
137: assertEquals(LegacyCompressor.stripNewlines(""), "\n");
138: assertEquals(LegacyCompressor.stripNewlines("\n"), " \n");
139: assertEquals(LegacyCompressor.stripNewlines(null), null);
140:
141: assertEquals(LegacyCompressor.stripNewlines("a\nb\n"), "a b \n");
142: }
143: }
|