www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17501] New: Runnable unittest problem with AST rewrite

https://issues.dlang.org/show_bug.cgi?id=17501

          Issue ID: 17501
           Summary: Runnable unittest problem with AST rewrite
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dlang.org
          Assignee: nobody puremagic.com
          Reporter: petar.p.kirov gmail.com

I noticed that there are cases where the assert -> writeln rewrite does
something wrong. Here's an example:



----
import std.algorithm.comparison : equal;
import std.range.primitives : front;

writeln(a); // ' '
int[] a = [ 1, 2, 0, 0, 3, 0, 4, 5, 0 ];
int[][] w = [ [1, 2], [], [3], [4, 5], [] ];
writeln(a); // 0
a = [ 0 ];
writeln(a); // 0
a = [ 0, 1 ];
writeln(a); // 0
w = [ [0], [1], [2] ];
writeln(a.front); // 1
----

And the actual unittest:
----
import std.algorithm.comparison : equal;
import std.range.primitives : front;

assert(equal(splitter!(a => a == ' ')("hello  world"), [ "hello", "", "world"
]));
int[] a = [ 1, 2, 0, 0, 3, 0, 4, 5, 0 ];
int[][] w = [ [1, 2], [], [3], [4, 5], [] ];
assert(equal(splitter!(a => a == 0)(a), w));
a = [ 0 ];
assert(equal(splitter!(a => a == 0)(a), [ (int[]).init, (int[]).init ]));
a = [ 0, 1 ];
assert(equal(splitter!(a => a == 0)(a), [ [], [1] ]));
w = [ [0], [1], [2] ];
assert(equal(splitter!(a => a.front == 1)(w), [ [[0]], [[2]] ]));
----

--
Jun 14 2017