From 580e126266b2ccef8f73c1b5aa49f2983339641b Mon Sep 17 00:00:00 2001 From: Nuno Mendes <98030270+nm-remarkable@users.noreply.github.com> Date: Sun, 15 Sep 2024 20:16:57 +0200 Subject: Add .patch for 108_labeled_switch --- patches/patches/108_labeled_switch.patch | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 patches/patches/108_labeled_switch.patch (limited to 'patches') diff --git a/patches/patches/108_labeled_switch.patch b/patches/patches/108_labeled_switch.patch new file mode 100644 index 0000000..dfb65dd --- /dev/null +++ b/patches/patches/108_labeled_switch.patch @@ -0,0 +1,11 @@ +--- a/exercises/108_labeled_switch.zig ++++ b/exercises/108_labeled_switch.zig +@@ -26,7 +26,7 @@ pub fn main() void { + // try to fix it! + pr: switch (@as(PullRequestState, PullRequestState.Draft)) { + PullRequestState.Draft => continue :pr PullRequestState.InReview, +- PullRequestState.InReview => continue :pr PullRequestState.Rejected, ++ PullRequestState.InReview => continue :pr PullRequestState.Approved, + PullRequestState.Approved => continue :pr PullRequestState.Merged, + PullRequestState.Rejected => std.debug.print("The pull request has been rejected", .{}), + PullRequestState.Merged => std.debug.print("The pull request has been merged", .{}), -- cgit v1.2.3 From db569a1478d11c1014ce9569ad65fc5cea9a09c9 Mon Sep 17 00:00:00 2001 From: Nuno Mendes <98030270+nm-remarkable@users.noreply.github.com> Date: Mon, 16 Sep 2024 18:38:43 +0200 Subject: update labeled switch to also have a break statement --- exercises/108_labeled_switch.zig | 16 ++++++++++------ patches/patches/108_labeled_switch.patch | 15 +++++++++++---- 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'patches') diff --git a/exercises/108_labeled_switch.zig b/exercises/108_labeled_switch.zig index 623e359..dfc061a 100644 --- a/exercises/108_labeled_switch.zig +++ b/exercises/108_labeled_switch.zig @@ -6,14 +6,14 @@ // foo: switch (state) { // 1 => continue :foo 2, // 2 => continue :foo 3, -// 3 => return, +// 3 => break :foo, // 4 => {}, // ... // } // const std = @import("std"); -const PullRequestState = enum { +const PullRequestState = enum(u8) { Draft, InReview, Approved, @@ -22,13 +22,17 @@ const PullRequestState = enum { }; pub fn main() void { - // Something is wrong, it seems your Pull Request can never be merged - // try to fix it! + // Oh no, your pull request keeps being rejected, + // how would you fix it? pr: switch (@as(PullRequestState, PullRequestState.Draft)) { PullRequestState.Draft => continue :pr PullRequestState.InReview, PullRequestState.InReview => continue :pr PullRequestState.Rejected, PullRequestState.Approved => continue :pr PullRequestState.Merged, - PullRequestState.Rejected => std.debug.print("The pull request has been rejected", .{}), - PullRequestState.Merged => std.debug.print("The pull request has been merged", .{}), + PullRequestState.Rejected => { + std.debug.print("The pull request has been rejected", .{}); + return; + }, + PullRequestState.Merged => break, // Would you know where to break to? } + std.debug.print("The pull request has been merged", .{}); } diff --git a/patches/patches/108_labeled_switch.patch b/patches/patches/108_labeled_switch.patch index dfb65dd..230b8fb 100644 --- a/patches/patches/108_labeled_switch.patch +++ b/patches/patches/108_labeled_switch.patch @@ -1,11 +1,18 @@ --- a/exercises/108_labeled_switch.zig +++ b/exercises/108_labeled_switch.zig -@@ -26,7 +26,7 @@ pub fn main() void { - // try to fix it! +@@ -26,13 +26,13 @@ pub fn main() void { + // how would you fix it? pr: switch (@as(PullRequestState, PullRequestState.Draft)) { PullRequestState.Draft => continue :pr PullRequestState.InReview, - PullRequestState.InReview => continue :pr PullRequestState.Rejected, + PullRequestState.InReview => continue :pr PullRequestState.Approved, PullRequestState.Approved => continue :pr PullRequestState.Merged, - PullRequestState.Rejected => std.debug.print("The pull request has been rejected", .{}), - PullRequestState.Merged => std.debug.print("The pull request has been merged", .{}), + PullRequestState.Rejected => { + std.debug.print("The pull request has been rejected", .{}); + return; + }, +- PullRequestState.Merged => break, // Would you know where to break to? ++ PullRequestState.Merged => break :pr, // Would you know where to break to? + } + std.debug.print("The pull request has been merged", .{}); + } -- cgit v1.2.3 From f0c2c56087bfd4398b896d3a8304a90cddbb3583 Mon Sep 17 00:00:00 2001 From: Nuno Mendes <98030270+nm-remarkable@users.noreply.github.com> Date: Wed, 18 Sep 2024 23:29:08 +0200 Subject: update108 .patch due to line change --- patches/patches/108_labeled_switch.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'patches') diff --git a/patches/patches/108_labeled_switch.patch b/patches/patches/108_labeled_switch.patch index 230b8fb..467540c 100644 --- a/patches/patches/108_labeled_switch.patch +++ b/patches/patches/108_labeled_switch.patch @@ -1,6 +1,6 @@ --- a/exercises/108_labeled_switch.zig +++ b/exercises/108_labeled_switch.zig -@@ -26,13 +26,13 @@ pub fn main() void { +@@ -65,13 +65,13 @@ pub fn main() void { // how would you fix it? pr: switch (@as(PullRequestState, PullRequestState.Draft)) { PullRequestState.Draft => continue :pr PullRequestState.InReview, -- cgit v1.2.3