2021-03-09 21:06:34 +03:00
|
|
|
const kb = 1024
|
|
|
|
|
2021-03-10 11:40:35 +03:00
|
|
|
const buf_siz = 2 * kb
|
2021-03-09 21:06:34 +03:00
|
|
|
|
|
|
|
fn test_consts() {
|
|
|
|
assert kb == 1024
|
2021-03-10 11:40:35 +03:00
|
|
|
assert buf_siz == 2 * kb
|
|
|
|
assert buf_siz == 2048
|
2021-03-09 21:06:34 +03:00
|
|
|
println(buf_siz)
|
|
|
|
}
|
|
|
|
|
2021-03-09 21:21:36 +03:00
|
|
|
fn test_fixed_size_array_can_use_a_known_comptime_const_as_its_size() {
|
2022-04-15 18:25:45 +03:00
|
|
|
buf := [buf_siz]u8{}
|
2021-03-09 21:06:34 +03:00
|
|
|
println(buf.len)
|
2021-03-10 11:40:35 +03:00
|
|
|
assert buf.len == 2048
|
2021-03-09 21:06:34 +03:00
|
|
|
}
|
|
|
|
|
2021-03-09 21:21:36 +03:00
|
|
|
fn test_fixed_size_array_using_a_known_int_expression_directly_as_its_size() {
|
2022-04-15 18:25:45 +03:00
|
|
|
zbuf := [5 + 20 * 10]u8{}
|
2021-03-09 21:21:36 +03:00
|
|
|
assert zbuf.len == 205
|
|
|
|
}
|
2021-03-09 21:06:34 +03:00
|
|
|
|
2021-03-09 21:21:36 +03:00
|
|
|
fn test_fixed_size_array_using_a_known_int_expression_with_const_as_its_size() {
|
2022-04-15 18:25:45 +03:00
|
|
|
zbuf := [2 * kb]u8{}
|
2021-03-09 21:21:36 +03:00
|
|
|
assert zbuf.len == 2048
|
|
|
|
}
|