| ... | ... | @@ -213,3 +213,51 @@ test "null terminated pointer" { |
| 213 | 213 | S.doTheTest(); |
| 214 | 214 | comptime S.doTheTest(); |
| 215 | 215 | } |
| 216 | |
| 217 | test "allow any sentinel" { |
| 218 | const S = struct { |
| 219 | fn doTheTest() void { |
| 220 | var array = [_:std.math.minInt(i32)]i32{1, 2, 3, 4}; |
| 221 | var ptr: [*:std.math.minInt(i32)]i32 = &array; |
| 222 | expect(ptr[4] == std.math.minInt(i32)); |
| 223 | } |
| 224 | }; |
| 225 | S.doTheTest(); |
| 226 | comptime S.doTheTest(); |
| 227 | } |
| 228 | |
| 229 | test "pointer sentinel with enums" { |
| 230 | const S = struct { |
| 231 | const Number = enum{one, two, sentinel}; |
| 232 | |
| 233 | fn doTheTest() void { |
| 234 | var ptr: [*:.sentinel]Number = &[_:.sentinel]Number{.one, .two, .two, .one}; |
| 235 | expect(ptr[4] == .sentinel); // TODO this should be comptime expect, see #3731 |
| 236 | } |
| 237 | }; |
| 238 | S.doTheTest(); |
| 239 | comptime S.doTheTest(); |
| 240 | } |
| 241 | |
| 242 | test "pointer sentinel with optional element" { |
| 243 | const S = struct { |
| 244 | fn doTheTest() void { |
| 245 | var ptr: [*:null]?i32 = &[_:null]?i32{1, 2, 3, 4}; |
| 246 | expect(ptr[4] == null); // TODO this should be comptime expect, see #3731 |
| 247 | } |
| 248 | }; |
| 249 | S.doTheTest(); |
| 250 | comptime S.doTheTest(); |
| 251 | } |
| 252 | |
| 253 | test "pointer sentinel with +inf" { |
| 254 | const S = struct { |
| 255 | fn doTheTest() void { |
| 256 | const inf = std.math.inf_f32; |
| 257 | var ptr: [*:inf]f32 = &[_:inf]f32{1.1, 2.2, 3.3, 4.4}; |
| 258 | expect(ptr[4] == inf); // TODO this should be comptime expect, see #3731 |
| 259 | } |
| 260 | }; |
| 261 | S.doTheTest(); |
| 262 | comptime S.doTheTest(); |
| 263 | } |