Class RETest


  • public class RETest
    extends java.lang.Object
    Data driven (and optionally interactive) testing harness to exercise regular expression compiler and matching engine.
    Version:
    $Id: RETest.java 518156 2007-03-14 14:31:26Z vgritsenko $
    Author:
    Jonathan Locke, Jon S. Stevens, Michael McCallum
    • Constructor Summary

      Constructors 
      Constructor Description
      RETest()
      Constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void assertEquals​(java.lang.String message, int expected, int actual)  
      void assertEquals​(java.lang.String message, java.lang.String expected, java.lang.String actual)  
      (package private) void die​(java.lang.String s)
      Exit with a fatal error.
      (package private) void fail​(java.lang.String s)
      Fail with an error.
      (package private) void fail​(java.lang.StringBuffer log, java.lang.String s)
      Fail with an error.
      private java.lang.String findNextTest​(java.io.BufferedReader br)
      Finds next test description in a given script.
      private boolean getExpectedResult​(java.lang.String yesno)
      Converts yesno string to boolean.
      private RETestCase getNextTestCase​(java.io.BufferedReader br)
      Creates testcase for the next test description in the script file.
      static void main​(java.lang.String[] args)
      Main program entrypoint.
      (package private) void runAutomatedTests​(java.lang.String testDocument)
      Run automated tests in RETest.txt file (from Perl 4.0 test battery)
      (package private) void runInteractiveTests​(java.lang.String expr)
      Compile and test matching against a single expression
      (package private) void say​(java.lang.String s)
      Say something to standard out
      (package private) void showParens​(RE r)
      Dump parenthesized subexpressions found by a regular expression matcher object
      static boolean test​(java.lang.String[] args)
      Testing entrypoint.
      (package private) void testOther()
      Run automated unit test
      private void testPrecompiledRE()  
      private void testSplitAndGrep()  
      private void testSubst()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NEW_LINE

        static final java.lang.String NEW_LINE
      • testCount

        int testCount
      • failures

        int failures
    • Constructor Detail

      • RETest

        public RETest()
        Constructor
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
        Main program entrypoint. If an argument is given, it will be compiled and interactive matching will ensue. If no argument is given, the file RETest.txt will be used as automated testing input.
        Parameters:
        args - Command line arguments (optional regular expression)
      • test

        public static boolean test​(java.lang.String[] args)
                            throws java.lang.Exception
        Testing entrypoint.
        Parameters:
        args - Command line arguments
        Throws:
        java.lang.Exception - thrown in case of error
      • runInteractiveTests

        void runInteractiveTests​(java.lang.String expr)
        Compile and test matching against a single expression
        Parameters:
        expr - Expression to compile and test
      • die

        void die​(java.lang.String s)
        Exit with a fatal error.
        Parameters:
        s - Last famous words before exiting
      • fail

        void fail​(java.lang.StringBuffer log,
                  java.lang.String s)
        Fail with an error. Will print a big failure message to System.out.
        Parameters:
        log - Output before failure
        s - Failure description
      • fail

        void fail​(java.lang.String s)
        Fail with an error. Will print a big failure message to System.out.
        Parameters:
        s - Failure description
      • say

        void say​(java.lang.String s)
        Say something to standard out
        Parameters:
        s - What to say
      • showParens

        void showParens​(RE r)
        Dump parenthesized subexpressions found by a regular expression matcher object
        Parameters:
        r - Matcher object with results to show
      • runAutomatedTests

        void runAutomatedTests​(java.lang.String testDocument)
                        throws java.lang.Exception
        Run automated tests in RETest.txt file (from Perl 4.0 test battery)
        Throws:
        java.lang.Exception - thrown in case of error
      • testOther

        void testOther()
                throws java.lang.Exception
        Run automated unit test
        Throws:
        java.lang.Exception - thrown in case of error
      • testPrecompiledRE

        private void testPrecompiledRE()
      • testSplitAndGrep

        private void testSplitAndGrep()
      • testSubst

        private void testSubst()
      • assertEquals

        public void assertEquals​(java.lang.String message,
                                 java.lang.String expected,
                                 java.lang.String actual)
      • assertEquals

        public void assertEquals​(java.lang.String message,
                                 int expected,
                                 int actual)
      • getExpectedResult

        private boolean getExpectedResult​(java.lang.String yesno)
        Converts yesno string to boolean.
        Parameters:
        yesno - string representation of expected result
        Returns:
        true if yesno is "YES", false if yesno is "NO" stops program otherwise.
      • findNextTest

        private java.lang.String findNextTest​(java.io.BufferedReader br)
                                       throws java.io.IOException
        Finds next test description in a given script.
        Parameters:
        br - BufferedReader for a script file
        Returns:
        strign tag for next test description
        Throws:
        java.io.IOException - if some io problems occured
      • getNextTestCase

        private RETestCase getNextTestCase​(java.io.BufferedReader br)
                                    throws java.io.IOException
        Creates testcase for the next test description in the script file.
        Parameters:
        br - BufferedReader for script file.
        Returns:
        a new tescase or null.
        Throws:
        java.io.IOException - if some io problems occured