Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /smlnj-lib/trunk/RegExp/Tests/test-fn.sml
ViewVC logotype

View of /smlnj-lib/trunk/RegExp/Tests/test-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3016 - (download) (annotate)
Mon May 5 16:41:33 2008 UTC (11 years, 2 months ago) by jhr
File size: 963 byte(s)
  Started to implement unit tests for RE matching.
(* test-fn.sml
 *
 * COPYRIGHT (c) 2008 The Fellowship of SML/NJ (http://www.smlnj.org)
 * All rights reserved.
 *)

functor TestFn (
    val engineName : string
    structure RE : REGEXP
  ) = struct

    structure M = MatchTree

    fun getc s i = if (i < String.size s) then SOME(String.sub(s, i), i+1) else NONE

    fun test (name, re, data) = let
	  val re = RE.compileString re
	  in
	    print(concat["  ", name, ": "]);
	    case RE.find re (getc data) 0
	     of NONE => print "match failed\n"
	      | SOME(M.Match({pos, len}, _), _) =>
		  print(concat[
		      "match at ", Int.toString pos, " = \"",
		      String.toString(String.substring(data, pos, len)), "\"\n"
		    ])
	    (* end case *)
	  end

    fun doTests () = (
	  print(concat["  testing ", engineName, "\n"]);
	  test ("01", "[0-9]+", "abc123xyz");
	  test ("02", "^[0-9]+", "abc123def\n987xyz");
	  test ("03", "[0-9]+$", "abc123def\n987xyz456");
	  print "** tests done\n")

  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0