Skip to content

Commit

Permalink
fix Issue 7718 - regex and ctRegex produce different results
Browse files Browse the repository at this point in the history
also fix unittest in std.range
  • Loading branch information
DmitryOlshansky committed Mar 23, 2012
1 parent ac5251b commit 88ecf28
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
19 changes: 19 additions & 0 deletions std/range.d
Expand Up @@ -6457,6 +6457,19 @@ unittest
assert(equal(r[2], [ 40, 40, 50, 60 ]));
}

unittest
{
auto a = [ "A", "AG", "B", "E", "F" ];
auto r = assumeSorted!"cmp(a,b) < 0"(a).trisect("B"w);
assert(equal(r[0], [ "A", "AG" ]));
assert(equal(r[1], [ "B" ]));
assert(equal(r[2], [ "E", "F" ]));
r = assumeSorted!"cmp(a,b) < 0"(a).trisect("A"d);
assert(r[0].empty);
assert(equal(r[1], [ "A" ]));
assert(equal(r[2], [ "AG", "B", "E", "F" ]));
}

unittest
{
static void test(SearchPolicy pol)()
Expand Down Expand Up @@ -6548,13 +6561,17 @@ unittest
assert(equal(p, [0, 1, 2, 3, 4]));
p = assumeSorted(a).lowerBound(6);
assert(equal(p, [ 0, 1, 2, 3, 4, 5]));
p = assumeSorted(a).lowerBound(6.9);
assert(equal(p, [ 0, 1, 2, 3, 4, 5, 6]));
}

unittest
{
int[] a = [ 1, 2, 3, 3, 3, 4, 4, 5, 6 ];
auto p = assumeSorted(a).upperBound(3);
assert(equal(p, [4, 4, 5, 6 ]));
p = assumeSorted(a).upperBound(4.2);
assert(equal(p, [ 5, 6 ]));
}

unittest
Expand All @@ -6570,6 +6587,8 @@ unittest
assert(p.empty);
p = assumeSorted(a).equalRange(7);
assert(p.empty);
p = assumeSorted(a).equalRange(3.0);
assert(equal(p, [ 3, 3, 3]));
}

unittest
Expand Down
26 changes: 18 additions & 8 deletions std/regex.d
Expand Up @@ -4852,8 +4852,6 @@ enum OneShot { Fwd, Bwd };
if(is(Char : dchar))
{
alias Stream.DataIndex DataIndex;
alias const(Char)[] String;
enum threadAllocSize = 16;
Thread!DataIndex* freelist;
ThreadList!DataIndex clist, nlist;
DataIndex[] merge;
Expand Down Expand Up @@ -4960,7 +4958,6 @@ enum OneShot { Fwd, Bwd };
writeln("------------------------------------------");
if(exhausted)
{

return false;
}
if(re.flags & RegexInfo.oneShot)
Expand Down Expand Up @@ -5021,8 +5018,7 @@ enum OneShot { Fwd, Bwd };
break;
}
}
else
exhausted = true;

genCounter++; //increment also on each end
debug(fred_matching) writefln("Threaded matching threads at end");
//try out all zero-width posibilities
Expand All @@ -5032,8 +5028,17 @@ enum OneShot { Fwd, Bwd };
}
if(!matched)
eval!false(createStart(index), matches);//new thread starting at end of input
if(matched && !(re.flags & RegexOption.global))
exhausted = true;
if(matched)
{//in case NFA found match along the way
//and last possible longer alternative ultimately failed
s.reset(matches[0].end);//reset to last successful match
next();//and reload front character
//--- here the exact state of stream was restored ---
exhausted = atEnd || !(re.flags & RegexOption.global);
//+ empty match advances the input
if(!exhausted && matches[0].begin == matches[0].end)
next();
}
return matched;
}

Expand Down Expand Up @@ -7435,6 +7440,11 @@ else
if(ch != '-') //'--' is an operator
assert(match(to!string(ch),regex(`[\`~ch~`-\`~ch~`]`)));
}
//bugzilla 7718
string strcmd = "./myApp.rb -os OSX -path \"/GIT/Ruby Apps/sec\" -conf 'notimer'";
auto reStrCmd = regex (`(".*")|('.*')`, "g");
assert(equal(map!"a[0]"(matchFn(strcmd, reStrCmd)),
[`"/GIT/Ruby Apps/sec"`, `'notimer'`]));
}
test_body!bmatch();
test_body!match();
Expand Down Expand Up @@ -7518,7 +7528,7 @@ else
unittest
{//bugzilla 7300
assert(!match("a"d, "aa"d));
}
}

unittest
{//bugzilla 7674
Expand Down

0 comments on commit 88ecf28

Please sign in to comment.