Commit 6cb7906394

Andrew Kelley <andrew@ziglang.org>
2021-09-29 01:55:42
add missing zig fmt test for saturating arithmetic
1 parent 51673bc
Changed files (1)
lib
lib/std/zig/parser_test.zig
@@ -4739,6 +4739,26 @@ test "zig fmt: assignment with inline for and inline while" {
     );
 }
 
+test "zig fmt: saturating arithmetic" {
+    try testCanonical(
+        \\test {
+        \\    const actual = switch (op) {
+        \\        .add => a +| b,
+        \\        .sub => a -| b,
+        \\        .mul => a *| b,
+        \\        .shl => a <<| b,
+        \\    };
+        \\    switch (op) {
+        \\        .add => actual +|= b,
+        \\        .sub => actual -|= b,
+        \\        .mul => actual *|= b,
+        \\        .shl => actual <<|= b,
+        \\    }
+        \\}
+        \\
+    );
+}
+
 test "zig fmt: insert trailing comma if there are comments between switch values" {
     try testTransform(
         \\const a = switch (b) {