zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

test_null_terminated_array.zig (553B) - Raw


      1 const std = @import("std");
      2 const expect = std.testing.expect;
      3 
      4 test "0-terminated sentinel array" {
      5     const array = [_:0]u8{ 1, 2, 3, 4 };
      6 
      7     try expect(@TypeOf(array) == [4:0]u8);
      8     try expect(array.len == 4);
      9     try expect(array[4] == 0);
     10 }
     11 
     12 test "extra 0s in 0-terminated sentinel array" {
     13     // The sentinel value may appear earlier, but does not influence the compile-time 'len'.
     14     const array = [_:0]u8{ 1, 0, 0, 4 };
     15 
     16     try expect(@TypeOf(array) == [4:0]u8);
     17     try expect(array.len == 4);
     18     try expect(array[4] == 0);
     19 }
     20 
     21 // test