zig/test/behavior/bugs/2889.zig
Andrew Kelley 5619ce2406 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * doc/langref.html.in
 * lib/std/enums.zig
 * lib/std/fmt.zig
 * lib/std/hash/auto_hash.zig
 * lib/std/math.zig
 * lib/std/mem.zig
 * lib/std/meta.zig
 * test/behavior/alignof.zig
 * test/behavior/bitcast.zig
 * test/behavior/bugs/1421.zig
 * test/behavior/cast.zig
 * test/behavior/ptrcast.zig
 * test/behavior/type_info.zig
 * test/behavior/vector.zig

Master branch added `try` to a bunch of testing function calls, and some
lines also had changed how to refer to the native architecture and other
`@import("builtin")` stuff.
2021-05-08 14:45:21 -07:00

32 lines
1.1 KiB
Zig

const std = @import("std");
const source = "A-";
fn parseNote() ?i32 {
const letter = source[0];
const modifier = source[1];
const semitone = blk: {
if (letter == 'C' and modifier == '-') break :blk @as(i32, 0);
if (letter == 'C' and modifier == '#') break :blk @as(i32, 1);
if (letter == 'D' and modifier == '-') break :blk @as(i32, 2);
if (letter == 'D' and modifier == '#') break :blk @as(i32, 3);
if (letter == 'E' and modifier == '-') break :blk @as(i32, 4);
if (letter == 'F' and modifier == '-') break :blk @as(i32, 5);
if (letter == 'F' and modifier == '#') break :blk @as(i32, 6);
if (letter == 'G' and modifier == '-') break :blk @as(i32, 7);
if (letter == 'G' and modifier == '#') break :blk @as(i32, 8);
if (letter == 'A' and modifier == '-') break :blk @as(i32, 9);
if (letter == 'A' and modifier == '#') break :blk @as(i32, 10);
if (letter == 'B' and modifier == '-') break :blk @as(i32, 11);
return null;
};
return semitone;
}
test "fixed" {
const result = parseNote();
try std.testing.expect(result.? == 9);
}