Comparing slice to an Array in assert

madwebness madwebness at noreply.noreply
Tue Jun 11 09:29:05 UTC 2024


On Tuesday, 11 June 2024 at 09:17:21 UTC, madwebness wrote:
> While I do understand what you're saying, I'm not sure I 
> understand how to fix the code.

With the following function definition what the function returns 
is correct and the problem is in the unittest code. Note that 
`writeln()` prints what's expected here program fails only when 
it gets to `assert()`:

```
auto sliceIt(string[] words_arr) {...};

unittest {
   auto words = ["HELLO", "world", "hi", "ENDOFTHERUNWAY"];
   auto resulting_arr = sliceIt(words);
   writeln(resulting_arr[0]); // => "world"
   assert(resulting_arr[0] == "world"); // => ERROR mentioned in 
(3) in the previous post.
}
```


More information about the Digitalmars-d-learn mailing list