2018-09-20 23:04:31 +08:00
|
|
|
const std = @import("std");
|
|
|
|
const mem = std.mem;
|
2019-02-09 07:18:47 +08:00
|
|
|
const expect = std.testing.expect;
|
2018-09-20 23:04:31 +08:00
|
|
|
|
|
|
|
test "comptime code should not modify constant data" {
|
2021-05-05 02:23:22 +08:00
|
|
|
try testCastPtrOfArrayToSliceAndPtr();
|
|
|
|
comptime try testCastPtrOfArrayToSliceAndPtr();
|
2018-09-20 23:04:31 +08:00
|
|
|
}
|
|
|
|
|
2021-05-05 02:23:22 +08:00
|
|
|
fn testCastPtrOfArrayToSliceAndPtr() !void {
|
2019-11-20 09:29:08 +08:00
|
|
|
{
|
|
|
|
var array = "aoeu".*;
|
|
|
|
const x: [*]u8 = &array;
|
|
|
|
x[0] += 1;
|
2021-05-05 02:23:22 +08:00
|
|
|
try expect(mem.eql(u8, array[0..], "boeu"));
|
2019-11-20 09:29:08 +08:00
|
|
|
}
|
|
|
|
{
|
|
|
|
var array: [4]u8 = "aoeu".*;
|
|
|
|
const x: [*]u8 = &array;
|
|
|
|
x[0] += 1;
|
2021-05-05 02:23:22 +08:00
|
|
|
try expect(mem.eql(u8, array[0..], "boeu"));
|
2019-11-20 09:29:08 +08:00
|
|
|
}
|
2018-09-20 23:04:31 +08:00
|
|
|
}
|