1   /*
2    * Jour - java profiler and monitoring library
3    *
4    * Copyright (C) 2004 Jour team
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
20   */
21  package net.sf.jour.rt.view;
22  
23  import junit.framework.TestCase;
24  
25  
26  import org.apache.log4j.Logger;
27  
28  /***
29   * TODO Add docs
30   *
31   * Created on 16.12.2004
32   * Contributing Author(s):
33   *
34   *   Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
35   *   Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
36   *
37   * @author vlads
38   * @version $Revision: 1.1 $ ($Author: vlads $)  $Date: 2004/12/16 17:40:20 $
39   */
40  public class ReplacementListTest extends TestCase {
41  	
42  	protected static final Logger log = Logger.getLogger(ReplacementListTest.class);
43  
44  	private void verify(String[] patterns, String text, String expect) { 
45  		ReplacementList l = new ReplacementList();
46  		l.buildList(patterns);
47  		String actual = l.subst(text);
48  		log.debug("[" + text + "] -> [" + actual + "]");
49  		assertEquals("for " + text, expect, actual);
50  	}
51  
52  	public void testSignaturePatterns() {
53  	    
54  	    verify(new String[] {"Bar", "Foo"}, "Bar", "Foo");
55  	    
56  	    String[] patterns = new String[] {
57  	            "^(Bar)$", "foo$1",
58  	            "(Foo)(.*)", "Bar$2",
59  	            "Ljava/lang/String", "S",
60  	            "Ljava/lang/([^/]*)", "$1",
61  	            "Ljava/util/Vector", "Vector",
62  	            "Lamdocs/APILink/implementation", "dox~"
63  	    	};
64  	    verify(patterns, "Bar", "fooBar");
65  	    verify(patterns, "Foo", "Bar");
66  	    verify(patterns, "FooBar", "BarBar");
67  	    verify(patterns, "(Ljava/lang/String;)V", "(S;)V");
68  	    verify(patterns, "(Ljava/lang/Bar;)V", "(Bar;)V");
69  	    verify(patterns, "(Ljava/util/Vector;)V", "(Vector;)V");
70  	    verify(patterns, "(Ljava/util/Vector;Ljava/lang/String;Ljava/lang/String;)V", "(Vector;S;S;)V");
71  	}
72  }