01: //Copyright (c) Hans-Joachim Daniels 2005
02: //
03: //This program is free software; you can redistribute it and/or modify
04: //it under the terms of the GNU General Public License as published by
05: //the Free Software Foundation; either version 2 of the License, or
06: //(at your option) any later version.
07: //
08: //This program is distributed in the hope that it will be useful,
09: //but WITHOUT ANY WARRANTY; without even the implied warranty of
10: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: //GNU General Public License for more details.
12: //
13: //You can either finde the file LICENSE or LICENSE.TXT in the source
14: //distribution or in the .jar file of this application
15:
16: package de.uka.ilkd.key.ocl.gf;
17:
18: import junit.framework.Test;
19: import junit.framework.TestCase;
20: import junit.framework.TestSuite;
21:
22: public class TestUtils extends TestCase {
23: public static Test suite() {
24: TestSuite suite = new TestSuite();
25: suite.addTest(new TestGfAstNode());
26: return suite;
27: }
28:
29: public static void main(String args[]) {
30: junit.textui.TestRunner.run(suite());
31: }
32:
33: public void setUp() {
34: //testing a static method, no setup needed
35: }
36:
37: public void testReplaceAll() {
38: //perhaps not comprehensive ...
39: String[] originals = { "\\\\$fgg", "__\\$__", "__\\>__" };
40: String[] toReplaces = { "\\\\", "\\\\", "\\>" };
41: String[] replacements = { "\\", "\\", ">" };
42: String[] results = { "\\$fgg", "__\\$__", "__>__" };
43:
44: for (int i = 0; i < originals.length; i++) {
45: assertEquals(Utils.replaceAll(originals[i], toReplaces[i],
46: replacements[i]), results[i]);
47: }
48:
49: }
50:
51: public void testIndexOfNotEscaped() {
52: final String[] lines = { "abcGHFb", "abcGHFb", "abcGHFabcb",
53: "abcGHFb", "\\abcGHF", "abc\\GHFb", "abc\\GHFabcGHF",
54: "abc\\GHF\\ghcGHC\\GHC" };
55: final String[] searchStrings = { "abc", "GHF", "abc", "hhh",
56: "abc", "GHF", "GHF", "GHC" };
57: final int[] positions = { 0, 3, 0, -1, -1, -1, 10, 11 };
58:
59: for (int i = 0; i < lines.length; i++) {
60: assertTrue("wrong unescaped index of '"
61: + searchStrings[i]
62: + "' in '"
63: + lines[i]
64: + "' : "
65: + Utils.indexOfNotEscaped(lines[i],
66: searchStrings[i]) + " instead of "
67: + positions[i], Utils.indexOfNotEscaped(lines[i],
68: searchStrings[i]) == positions[i]);
69: }
70: }
71:
72: public void testRemoveQuotations() {
73: final String[] orig = { "hallo", "ha\\\"llo", //should be ha\"llo!
74: "ha\"ll\"o", "h\"a\"l\"1\"o", "h\"a\\\"ll\"o" };
75: final String[] unqu = { "hallo", "ha\\\"llo", //should be ha\"llo!
76: "hao", "hlo", "ho" };
77: for (int i = 0; i < orig.length; i++) {
78: assertEquals(Utils.removeQuotations(orig[i]), unqu[i]);
79: }
80:
81: }
82:
83: public void testCountOccurances() {
84: final String[] orig = { "ass ;; dff", "fds ;;; sdf;;",
85: "dssa;;;;sfsd;sd;", "sdff;;;;;" };
86: final int[] oc = { 1, 2, 2, 2 };
87: final String toSearch = ";;";
88: for (int i = 0; i < orig.length; i++) {
89: assertEquals(Utils.countOccurances(orig[i], toSearch),
90: oc[i]);
91: }
92: }
93: }
|