zig
zig copied to clipboard
Fix Utf8View example to compile.
Updated Utf8View example to format the single codepoint UTF-8 slice with {s}
This is a good fix, although in the long run I wonder if it would be better to replace such code examples in doc comments with doctests, such as
test Utf8View {
var utf8 = (try std.unicode.Utf8View.init("test")).iterator();
try std.testing.expectEqual(@as(?u21, 't'), utf8.nextCodepoint());
try std.testing.expectEqual(@as(?u21, 'e'), utf8.nextCodepoint());
try std.testing.expectEqual(@as(?u21, 's'), utf8.nextCodepoint());
try std.testing.expectEqual(@as(?u21, 't'), utf8.nextCodepoint());
try std.testing.expectEqual(@as(?u21, null), utf8.nextCodepoint());
}
(this example would be much nicer with #17431, or alternatively for now, try std.testing.expect(utf8.nextCodepoint() == 't')
, etc.)
In addition to being full tests in their own right (ensuring they remain valid over time), doctests will also show up in the generated documentation, with one existing example being std.mem.readInt
.
I think your test is a great addition to the library independent of this fix.
As a beginner at zig, I find it nice to have a small snippet of idiomatic zig that I can copy and paste into a new function.
thanks for the contribution @davideger !