[Issue 17501] New: Runnable unittest problem with AST rewrite
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Jun 14 02:45:58 PDT 2017
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 at puremagic.com
Reporter: petar.p.kirov at gmail.com
I noticed that there are cases where the assert -> writeln rewrite does
something wrong. Here's an example:
http://dlang.org/phobos-prerelease/std_algorithm_iteration#.splitter.3
----
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]] ]));
----
--
More information about the Digitalmars-d-bugs
mailing list