Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Formalize the regex unit test
  • Loading branch information
sorear committed Aug 30, 2010
1 parent a13f32b commit d075a0b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
36 changes: 0 additions & 36 deletions lib/Cursor.cs
Expand Up @@ -119,42 +119,6 @@ public struct State {
public int GetQuant() {
return bt.obj.reps.obj;
}

private RxFrame(string st) {
orig = st.ToCharArray();
end = orig.Length;
bt = new PSN<State>(default(State), null);
bt.obj.klasses = new PSN<DynMetaObject>(null, null);
bt.obj.pos = 0;
}

private static SubInfo TestSI = new SubInfo(TestC);
private static Frame TestC(Frame th) {
if (Kernel.TraceCont) System.Console.WriteLine("At {0}", th.ip);
switch (th.ip) {
case 0:
th.rx = new RxFrame("aaaaab");
th.rx.OpenQuant();
goto case 1;
case 1:
th.rx.PushBacktrack("*", 3);
th.ip = 2;
return th.rx.ExactOne(th, 'a');
case 2:
th.rx.IncQuant();
goto case 1;
case 3:
th.rx.CloseQuant();
th.ip = 4;
return th.rx.Exact(th, "ab");
case 4:
System.Console.WriteLine("Match!");
return null;
default:
System.Console.WriteLine("Bad IP");
return null;
}
}
}

public sealed class XAct {
Expand Down
6 changes: 6 additions & 0 deletions lib/Kernel.cs
Expand Up @@ -560,6 +560,12 @@ public class Kernel {
return n;
}

public static DynObject MockBox(object v) {
DynObject n = new DynObject(ScalarMO);
n.slots["value"] = v;
return n;
}

public static Variable BoxAny(object v, IP6 proto) {
if (v == null)
return NewROScalar(proto);
Expand Down
39 changes: 39 additions & 0 deletions t/RxUnitTest.cs
@@ -0,0 +1,39 @@
using Niecza;
using System;

public class RxUnitTest {
private static SubInfo TestSI = new SubInfo(TestC);
private static Frame TestC(Frame th) {
if (Kernel.TraceCont) Console.WriteLine("At {0}", th.ip);
switch (th.ip) {
case 0:
th.rx = new RxFrame(Kernel.MockBox(new Cursor("aaaaab")));
th.rx.OpenQuant();
goto case 1;
case 1:
th.rx.PushBacktrack("*", 3);
th.ip = 2;
return th.rx.ExactOne(th, 'a');
case 2:
th.rx.IncQuant();
goto case 1;
case 3:
th.rx.CloseQuant();
th.ip = 4;
return th.rx.Exact(th, "ab");
case 4:
System.Console.WriteLine("Match!");
return null;
default:
System.Console.WriteLine("Bad IP");
return null;
}
}

public static void Main() {
Frame fr = new Frame(null, null, TestSI);

while (fr != null)
fr = fr.Continue();
}
}

0 comments on commit d075a0b

Please sign in to comment.