You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ce...@apache.org on 2005/01/27 15:40:13 UTC

cvs commit: logging-log4j/tests/src/java/org/apache/log4j/lbel EvaluationTest.java ParserTest.java TokenStreamTest.java

ceki        2005/01/27 06:40:13

  Added:       src/java/org/apache/log4j/lbel Token.java Parser.java
                        TokenStream.java EventEvaluator.java ScanError.java
                        Node.java
               tests/src/java/org/apache/log4j/lbel EvaluationTest.java
                        ParserTest.java TokenStreamTest.java
  Log:
  This LBEL in its skeleton form. Most of the core is already there so studying will give a fairly good idea of what is to follow.
  
  Revision  Changes    Path
  1.1                  logging-log4j/src/java/org/apache/log4j/lbel/Token.java
  
  Index: Token.java
  ===================================================================
  package org.apache.log4j.lbel;
  
  
  public class Token {
  
  	private int type;
  	private Object value;
  	
  	public Token(int type) {
  	  this(type, null);
  	}
  	
  	public Token(int type, Object value) {
  		this.type = type;
  		this.value = value;
  	}
  	
  	public String toString() {
  		return "Token("+type+", "+value+")";
  	}
  	
  	public int getType() {
  		return type;
  	}
  	
  	public Object getValue() {
  		return value;
  	}
  }
  
  
  
  1.1                  logging-log4j/src/java/org/apache/log4j/lbel/Parser.java
  
  Index: Parser.java
  ===================================================================
  package org.apache.log4j.lbel;
  
  import java.io.IOException;
  import java.util.Stack;
  
  /**
   * 
  
  
   * 
   * @author <a href="http://www.qos.ch/log4j/">Ceki G&uuml;lc&uuml;</a>
   */
  public class Parser {
  
  // The core of LBEL can be summarized by the following grammar.
    
  //  <bexp> ::= <bexp> 'OR' <bterm>
  //  <bexp> ::= <bterm>
  //  <bterm> ::= <bterm> 'AND' <bfactor>
  //  <bterm> ::= <bfactor>
  //  <bfactor> ::= NOT <bfactor>
  //  <bfactor> ::= '(' <bexp> ')'
  //  <bfactor> ::= true
  //  <bfactor> ::= false
  
  // In reality <bfactor> takes more varied forms then just true|false but
  // from a conceptual point of view, the variations are quite easy to deal with.
  
  // By eliminating left-recursion, th above grammar can be transformed into the
  // following LL(1) form. '#' stands for lambda, that is an empty sequence.
    
  // <bexp> ::= <bterm> <bexpTail>
  // <bexpTail> ::= 'OR' <bterm>
  // <bexpTail> ::= #      
  // <bterm> ::= <bfactor> <btermTail>
  // <btermTail> ::= 'AND' <bfactor> <btermTail>
  // <btermTail> ::= #
  // <bfactor> ::= NOT <bfactor>
  // <bfactor> ::= '(' <bexp> ')'
  // <bfactor> ::= true
  // <bfactor> ::= false
  
  // Which is implemented almost directly by the following top-down parser.
    
  	TokenStream ts;
  	Stack stack = new Stack();
  	
  	Parser(TokenStream bexpTS) {
  	  ts = bexpTS;
  	}
  	
  	Node parse()  throws IOException, ScanError {
  		ts.next();
  		return bexp();
  	}
  	
  	Node bexp() throws IOException, ScanError {
  		Node result;		
  		Node bterm = bterm(); 
  		Node bexpTail = bexpTail();
  		if(bexpTail == null) {
  			result = bterm;
  		} else {
  			result = bexpTail;
  			result.setLeft(bterm);
  		}
  		return result;
  	}
  	
  	Node bexpTail() throws IOException, ScanError {
      Token token = ts.getCurrent();
      switch(token.getType()) {
      case TokenStream.OR:
      	ts.next();
      	Node or = new Node(Node.OR, "OR");
        
      	Node bterm = bterm();
        Node bexpTail = bexpTail();
        if(bexpTail == null) {
        	or.setRight(bterm);	
    		} else {
    			or.setRight(bexpTail);
    			bexpTail.setLeft(bterm);
    		}
        return or;
      default: 
      	return null;
      }		
  	}
  	
  	Node bterm() throws IOException, ScanError {
  		Node result;
  		Node bfactor = bfactor(); 
  		Node btermTail = btermTail();
  		if(btermTail == null) {
  			result = bfactor;
  		} else {
  			result = btermTail;
  			btermTail.setLeft(bfactor);
  		}
  		return result;
  	}
  
  	Node btermTail() throws IOException, ScanError {
      Token token = ts.getCurrent();
      switch(token.getType()) {
      case TokenStream.AND:
      	ts.next();
    	  Node and = new Node(Node.AND, "AND");
        Node bfactor = bfactor();
        Node btermTail = btermTail();
        if(btermTail == null) {
        	and.setRight(bfactor);
        } else {
        	and.setRight(btermTail);
        	btermTail.setLeft(bfactor);
        }
        return and;
      default: 
      	return null;
      }
  	}
  	
  	Node bfactor() throws IOException, ScanError {
      Token token = ts.getCurrent();
      switch(token.getType()) {
      case TokenStream.NOT:
      	ts.next();
        Node result = new Node(Node.NOT, "NOT");
        Node bsubfactor = bsubfactor();
        result.setLeft(bsubfactor);
        return result;
      default: 
        return bsubfactor();
      }
  	}
  	
  	Node bsubfactor() throws IOException, ScanError {
  
  		Node result;
      Token token = ts.getCurrent();
      switch(token.getType()) {
      case TokenStream.TRUE:
      	ts.next();
        result = new Node(Node.TRUE, "TRUE");
        break;
      case TokenStream.FALSE:
      	ts.next();
        result = new Node(Node.FALSE, "FALSE");
        break;
      case   TokenStream.LP:
      	ts.next();
        result = bexp();
        Token token2 = ts.getCurrent();
        if(token2.getType() == TokenStream.RP) {
        	ts.next();
        } else {
        	throw new IllegalStateException("Expected right parantheses but got" +token);
        }
        break;
      default: throw new IllegalStateException("Excpected DIGIT but got" +token);
      }
      return result;
  	}
  	
  	public boolean evaluate(Node node) {
  		int type = node.getType();
  		boolean left;
  		switch(type) {
  		case Node.TRUE:
  			return true;
  		case Node.FALSE:
  			return false;
  		case Node.OR:
  			left = evaluate(node.getLeft());
  		  if(left == true) {
  		  	return true;
  		  } else {
  		  	return evaluate(node.getRight());
  		  }
  		case Node.AND:
  		  left = evaluate(node.getLeft());
  	    if(left == false) {
  	  	  return false;
  	    } else {
  	  	  return evaluate(node.getRight());
  	    }
      case Node.NOT:
      	return !evaluate(node.getLeft());
  		}
  		return false;
  	}
  
  }
  
  
  
  1.1                  logging-log4j/src/java/org/apache/log4j/lbel/TokenStream.java
  
  Index: TokenStream.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.log4j.lbel;
  
  
  import java.io.IOException;
  import java.io.Reader;
  import java.io.StreamTokenizer;
  import java.util.HashMap;
  import java.util.Map;
  
  
  public class TokenStream  {
  	public static final int TRUE = 1;
  	public static final int FALSE = 2;
  	
  	public static final int OR = 10;
    public static final int AND = 11;
    public static final int NOT = 12;
  
    public static final int IDENTIFIER = 20;
    public static final int NUMBER = 21;
  
    public static final int OPERATOR = 30;
    
    public static final int LP = 40;
    public static final int RP = 41;
    public static final int EOF = 100;
  
    static Map keywordMap = new HashMap();
    
    static {
    	keywordMap.put("true", new Token(TRUE));
    	keywordMap.put("false", new Token(FALSE));
    	keywordMap.put("not", new Token(NOT));
    	keywordMap.put("and", new Token(AND));
    	keywordMap.put("or", new Token(OR));
    	keywordMap.put("childof", new Token(OPERATOR, "childof"));
    	
    }
    
    StreamTokenizer tokenizer;
  	int token;
    Token current;
  	
    
    public TokenStream(Reader reader) {
    	tokenizer = new StreamTokenizer(reader);
    	tokenizer.resetSyntax();
    	tokenizer.whitespaceChars(' ', ' ');
    	tokenizer.whitespaceChars('\t', '\t');
    	tokenizer.whitespaceChars('\n', '\n');
    	tokenizer.whitespaceChars('\r', '\r');
    	
    	tokenizer.wordChars('a', 'z');
    	tokenizer.wordChars('A', 'Z');
    	tokenizer.wordChars('0', '9');
  
    	tokenizer.quoteChar('"');
    	tokenizer.quoteChar('\'');
    	tokenizer.parseNumbers();
    }
  
    public Token getCurrent() {
      return current;
    }
  
    public void next() throws IOException, ScanError {
    	int token2;
    	
    	if(token != StreamTokenizer.TT_EOF) {
    		token = tokenizer.nextToken();
    		switch(token) {
    		case	StreamTokenizer.TT_EOF:
    			current = new Token(EOF);
    			break;
    		case StreamTokenizer.TT_NUMBER:
     			double nval = tokenizer.nval;
  		    current = new Token(NUMBER, new Long((long) nval));
  		    break;
    		case StreamTokenizer.TT_WORD:
    			String key = tokenizer.sval;
    		  Token result = (Token) keywordMap.get(key.toLowerCase());
    		  if(result != null) {
    		  	current = result;
    		  } else {
    		  	current = new Token(IDENTIFIER, tokenizer.sval);
    		  }
          break;  		
    		case '"':
    	  case '\'':
    		  current = new Token(IDENTIFIER, tokenizer.sval);
    		  break;
    		case '>':
     			token2 = tokenizer.nextToken();
    			if(token2 == '=') {
    			  current = new Token(OPERATOR, ">=");		
    			} else {
    			  current = new Token(OPERATOR, ">");
    			  tokenizer.pushBack();
    			}
          break;
    		case '<':
    			 token2 = tokenizer.nextToken();
    			if(token2 == '=') {
    			  current = new Token(OPERATOR, "<=");		
    			} else {
    			  current = new Token(OPERATOR, "<");
    			  tokenizer.pushBack();
    			}
          break;
    		case '=':
  			  current = new Token(OPERATOR, "=");		
          break; 
    		case '~':
  			  current = new Token(OPERATOR, "~");		
          break; 
        case '!':	 
        	token2 = tokenizer.nextToken();
  			  if(token2 == '=') {
  			    current = new Token(OPERATOR, "!=");		
  			  } else if (token2 == '~') {
  			    current = new Token(OPERATOR, "!~");
  			    tokenizer.pushBack();
  			  } else {
  			  	throw new ScanError("Unrecogized token "+token+". The ! character must be followed by = or ~.");
  			  }
        break;
        case '(':
        	current = new Token(LP);
        	break;
        case ')':
        	current = new Token(RP);
        	break;
    		default:
    		  	throw new ScanError("Unrecogized token "+token);
    		}
    		
    	}
    }
  }
  
  
  
  1.1                  logging-log4j/src/java/org/apache/log4j/lbel/EventEvaluator.java
  
  Index: EventEvaluator.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.log4j.lbel;
  
  import org.apache.log4j.spi.LoggingEvent;
  
  /**
   * An EventEvaluator has the responsability to evaluate whether a given {@link 
   * LoggingEvent} matches a given criteria. 
   * 
   * <p>Implementations are free to evaluate the event as they see fit. In 
   * particular, the evaluation results <em>may</em> depend on previous events.
     *    
   * @author <a href="http://www.qos.ch/log4j/">Ceki G&uuml;lc&uuml;</a>
   * @since 1.3
   */
  
  public interface EventEvaluator {
    
    /**
     * Evaluates whether the event passed as parameter matches this evaluator's 
     * matching criteria?
     * 
     * <p>The <code>Evaluator</code> instance is free to evaluate the event as
     * it pleases. In particular, the evaluation results <em>may</em> depend on 
     * previous events. 
     * 
     * @param event The event to evaluate
     * @return true if there is a match, false otherwise.
     */
    boolean evaluate(LoggingEvent event);
  }
  
  
  
  1.1                  logging-log4j/src/java/org/apache/log4j/lbel/ScanError.java
  
  Index: ScanError.java
  ===================================================================
  package org.apache.log4j.lbel;
  
  public class ScanError extends Exception {
    public ScanError(String msg) {
      super(msg);
    }
  }
  
  
  
  1.1                  logging-log4j/src/java/org/apache/log4j/lbel/Node.java
  
  Index: Node.java
  ===================================================================
  package org.apache.log4j.lbel;
  
  public class Node {
  	
  	public static final int FALSE = 1;
  	public static final int TRUE = 2;
  
  	public static final int OR = 1000;
  	public static final int AND = 1100;
  	public static final int NOT = 1200;
  	
    Node left;
  	//Node middle;
  	Node right;
  
    final int type;
    final Object value;
    
    Node(int type) {
    	this(type, null);
    }
    
    Node(int type, Object value) {
    	this.type = type;
    	this.value = value;
    }
    
    public int getType() {
  	  return type;
    }
    
    public Object getValue() {
    	return value;
    }
  
  	public Node getLeft() {
  		return left;
  	}
  	public void setLeft(Node leftSide) {
  		if(this.left != null) {
  		  throw new IllegalStateException("The left side already set. (old="+this.left+", new="+leftSide+")");
  		}
  		this.left = leftSide;
  	}
  	//public Node getMiddle() {
  		//return middle;
  	//}
  	//public void setMiddle(Node middle) {
  		//if(this.middle != null) {
  		  //throw new IllegalStateException("The middle already set. (old="+this.middle+", new="+middle+")");
  		//}
  		//this.middle = middle;
  	//}
  	public Node getRight() {
  		return right;
  	}
  	public void setRight(Node rightSide) {
  		if(this.right != null) {
  			throw new IllegalStateException("The right side already set. (old="+this.right+", new="+rightSide+")");
  		}
  		this.right = rightSide;
  	}
  	
  	public String toString() {
  		return "Node: type="+type+", value="+value;
  	}
  	
  	public void leftFirstDump(String offset) {
  		
  		System.out.println(offset + this);
  		
  		offset += "  ";
  		
  		Node l = this.getLeft();
  		if(l != null) {
  		  System.out.println(offset +"Printing left side");
  		  l.leftFirstDump(offset);
  		}
  
  		//Node m = this.getMiddle();
  		//if(m != null) {
  			//System.out.println(offset +"Printing middle");
  			//m.leftFirstDump(offset);
  		//} 
  				
  		Node r = this.getRight();
  		if(r != null) {
    		System.out.println(offset +"Printing right side");
  	  	r.leftFirstDump(offset);
  		}
  	}
  }
  
  
  
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/lbel/EvaluationTest.java
  
  Index: EvaluationTest.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.log4j.lbel;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import java.io.IOException;
  import java.io.StringReader;
  
  
  public class EvaluationTest extends TestCase {
  	Node top;
  	Node left;
  	Node right;
  	
    public EvaluationTest(String arg0) {
      super(arg0);
    }
  
    protected void setUp() throws Exception {
      super.setUp();
    }
  
    protected void tearDown() throws Exception {
      super.tearDown();
    }
  
    public void testTrue() throws IOException, ScanError {
      StringReader sr = new StringReader("true");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      
      assertTrue(parser.evaluate(top));
      
     }
    
    public void testTrueOrFalse() throws IOException, ScanError {
      StringReader sr = new StringReader("true OR false");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
    }
    
    public void testNotTrue() throws IOException, ScanError {
      StringReader sr = new StringReader("not true");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      assertTrue(!parser.evaluate(top));
    }
    
    public void testAndOr() throws IOException, ScanError {
      StringReader sr = new StringReader("true or false and true");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      assertTrue(parser.evaluate(top));
    }
  
    public void testAndOr2() throws IOException, ScanError {
      StringReader sr = new StringReader("false or false and true");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      assertTrue(!parser.evaluate(top));
    }
  
    public void testAndOr3() throws IOException, ScanError {
      StringReader sr = new StringReader("false or true  and true");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      assertTrue(parser.evaluate(top));
    }
    
    public void testParatheses() throws IOException, ScanError {
      StringReader sr = new StringReader("(true or false)");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      assertTrue(parser.evaluate(top));
    }
  
    public void testParatheses2() throws IOException, ScanError {
      StringReader sr = new StringReader("(not (true or false)) and true");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      assertTrue(!parser.evaluate(top));
    }
   
    public void testNotPrecedence() throws IOException, ScanError {
      StringReader sr = new StringReader("not true or false and true");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      assertTrue(!parser.evaluate(top));
    }
  
    public void testNotPrecedence2() throws IOException, ScanError {
      StringReader sr = new StringReader("not true or true and true");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      assertTrue(parser.evaluate(top));
    }
  
    public void testNotPrecedence3() throws IOException, ScanError {
      StringReader sr = new StringReader("not true and true or false");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      assertTrue(!parser.evaluate(top));
    }
    
    public void testNotPrecedence4() throws IOException, ScanError {
      StringReader sr = new StringReader("not true and true or false");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      assertTrue(!parser.evaluate(top));
    }
    
    
    public static Test XXsuite() {
      TestSuite suite = new TestSuite();
      //suite.addTest(new ParserTest("testAndOr"));
      suite.addTest(new EvaluationTest("testTrue"));
      return suite;
    }
    
  }
  
  
  
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/lbel/ParserTest.java
  
  Index: ParserTest.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.log4j.lbel;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import java.io.IOException;
  import java.io.StringReader;
  
  public class ParserTest extends TestCase {
  	Node top;
  	Node left;
  	Node right;
  	
    public ParserTest(String arg0) {
      super(arg0);
    }
  
    protected void setUp() throws Exception {
      super.setUp();
    }
  
    protected void tearDown() throws Exception {
      super.tearDown();
    }
  
    public void testTrue() throws IOException, ScanError {
      StringReader sr = new StringReader("true");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      
      assertEquals(Node.TRUE, top.getType());
      assertNull(top.getLeft());
      assertNull(top.getRight());
      //System.out.println("============");
      //top.leftFirstDump("");
    }
    
    public void testTrueOrFalse() throws IOException, ScanError {
      StringReader sr = new StringReader("true OR false");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
  //    assertEquals(Node.E, top.getType());
  //    
  //    top = top.getLeftSide();
  //    assertEquals(Node.DIGIT, top.getType());
  //    assertEquals(9, ((Integer) top.getValue()).intValue());
  //    assertNull(top.getMiddle());
  //    assertNull(top.getRightSide());
      System.out.println("============");
      top.leftFirstDump("");
    }
    
    public void testNotTrue() throws IOException, ScanError {
      StringReader sr = new StringReader("not true");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
    }
    
    public void testAndOr() throws IOException, ScanError {
      StringReader sr = new StringReader("true or false and true");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      System.out.println("============");
      top.leftFirstDump("");
    }
  
    public void testParatheses() throws IOException, ScanError {
      StringReader sr = new StringReader("(true or false)");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      System.out.println("============");
      top.leftFirstDump("");
    }
  
    public void testParatheses2() throws IOException, ScanError {
      StringReader sr = new StringReader("(not (true or false)) and true");
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      top = parser.parse();
      System.out.println("============");
      top.leftFirstDump("");
    }
    
    public static Test suite() {
      TestSuite suite = new TestSuite();
      //suite.addTest(new ParserTest("testAndOr"));
      suite.addTest(new ParserTest("testParatheses2"));
      return suite;
    }
    
  }
  
  
  
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/lbel/TokenStreamTest.java
  
  Index: TokenStreamTest.java
  ===================================================================
  package org.apache.log4j.lbel;
  
  import java.io.IOException;
  import java.io.StringReader;
  
  import junit.framework.TestCase;
  
  public class TokenStreamTest extends TestCase {
  
  	Token t;
  	
  	protected void setUp() throws Exception {
  		super.setUp();
  	}
  
  	protected void tearDown() throws Exception {
  		super.tearDown();
  	}
  
  	public TokenStreamTest(String arg0) {
  		super(arg0);
  	}
  
  	public void testSingleDigit() throws IOException, ScanError {
  	  StringReader sr = new StringReader("9");
  	  TokenStream ts = new TokenStream(sr);
  
  	  assertNull(ts.getCurrent());
      ts.next();
  	  
  	  t = ts.getCurrent();
  	  assertEquals(TokenStream.NUMBER, t.getType());
  	  assertEquals(9, ((Long) t.getValue()).longValue());
  	  
  	  ts.next();
  	  t = ts.getCurrent();
  	  assertEquals(TokenStream.EOF, t.getType());
  	}
  
  	public void testLongerDigit() throws IOException, ScanError {
  	  StringReader sr = new StringReader(" 980 ");
  	  TokenStream ts = new TokenStream(sr);
      ts.next();
  	  t = ts.getCurrent();
  	  assertEquals(TokenStream.NUMBER, t.getType());
  	  assertEquals(980, ((Long) t.getValue()).longValue());
  	  
  	  ts.next(); t = ts.getCurrent();
  	  assertEquals(TokenStream.EOF, t.getType());
  	}
  	
  	public void testComparison() throws IOException, ScanError {
  	  StringReader sr = new StringReader(" time >= 17");
  	  TokenStream ts = new TokenStream(sr);
      ts.next();
  	  t = ts.getCurrent();
  	  
  	  assertEquals(TokenStream.IDENTIFIER, t.getType());
  	  assertEquals("time", t.getValue());
  	  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.OPERATOR, t.getType());
  	  assertEquals(">=", t.getValue());
  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.NUMBER, t.getType());
  	  assertEquals(17, ((Long) t.getValue()).longValue());
  	  		
  	  ts.next(); t = ts.getCurrent();
  	  assertEquals(TokenStream.EOF, t.getType());
  	}
  	
  	public void testFull() throws IOException, ScanError {
  	  StringReader sr = new StringReader(" time >= 19 NOT \"hello world\" ");
  	  TokenStream ts = new TokenStream(sr);
      ts.next();
  	  t = ts.getCurrent();
  	  
  	  assertEquals(TokenStream.IDENTIFIER, t.getType());
  	  assertEquals("time", t.getValue());
  	  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.OPERATOR, t.getType());
  	  assertEquals(">=", t.getValue());
  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.NUMBER, t.getType());
  	  assertEquals(19, ((Long) t.getValue()).longValue());
  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.NOT, t.getType());
  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.IDENTIFIER, t.getType());
  	  assertEquals("hello world", t.getValue());
  
  	  		
  	  ts.next(); t = ts.getCurrent();
  	  assertEquals(TokenStream.EOF, t.getType());
  	}
  	
  	public void testNoSpaceFull() throws IOException, ScanError {
  	  StringReader sr = new StringReader(" time>=19 NOT \"hello world\" ");
  	  TokenStream ts = new TokenStream(sr);
      ts.next();
  	  t = ts.getCurrent();
  	  
  	  assertEquals(TokenStream.IDENTIFIER, t.getType());
  	  assertEquals("time", t.getValue());
  	  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.OPERATOR, t.getType());
  	  assertEquals(">=", t.getValue());
  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.NUMBER, t.getType());
  	  assertEquals(19, ((Long) t.getValue()).longValue());
  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.NOT, t.getType());
  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.IDENTIFIER, t.getType());
  	  assertEquals("hello world", t.getValue());
  
  	  		
  	  ts.next(); t = ts.getCurrent();
  	  assertEquals(TokenStream.EOF, t.getType());
  	}
  	
  	public void testSingleQuote() throws IOException, ScanError {
  	  StringReader sr = new StringReader(" logger ~ 'hello world' ");
  	  TokenStream ts = new TokenStream(sr);
      ts.next();
  	  t = ts.getCurrent();
  	  
  	  assertEquals(TokenStream.IDENTIFIER, t.getType());
  	  assertEquals("logger", t.getValue());
  	  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.OPERATOR, t.getType());
  	  assertEquals("~", t.getValue());
  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.IDENTIFIER, t.getType());
  	  assertEquals("hello world", t.getValue());
  
  	  		
  	  ts.next(); t = ts.getCurrent();
  	  assertEquals(TokenStream.EOF, t.getType());
  	}
  	
  	public void testTrueOrFalse() throws IOException, ScanError {
  	  StringReader sr = new StringReader(" true OR false");
  	  TokenStream ts = new TokenStream(sr);
     
  	  ts.next(); t = ts.getCurrent();
  	  assertEquals(TokenStream.TRUE, t.getType());
  	  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.OR, t.getType());
  	  
  	  ts.next();  t = ts.getCurrent();
  	  assertEquals(TokenStream.FALSE, t.getType());
  	  		
  	  ts.next(); t = ts.getCurrent();
  	  assertEquals(TokenStream.EOF, t.getType());
  	}
  	
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org