| author | |
| committer | |
| log | 755c5580267b246983fc0b2b2fb8dccfc261b9a0 |
| tree | 4b30c2cbdfc00a59f461ec5992e02494e6ae10ba |
| parent | f59069f3d0cf6204f15dbd9c707dbefebfe88e01 |
| parent | d877eb0e8d1b6327446c72a2db28b9a7c92c35bf |
3 files changed, 35 insertions(+), 1 deletions(-)
lib/std/math.zig+24-1| ... | @@ -1169,7 +1169,7 @@ pub const Order = enum { | ... | @@ -1169,7 +1169,7 @@ pub const Order = enum { |
| 1169 | return switch (self) { | 1169 | return switch (self) { |
| 1170 | .lt => .gt, | 1170 | .lt => .gt, |
| 1171 | .eq => .eq, | 1171 | .eq => .eq, |
| 1172 | .gt => .gt, | 1172 | .gt => .lt, |
| 1173 | }; | 1173 | }; |
| 1174 | } | 1174 | } |
| 1175 | 1175 | ||
| ... | @@ -1266,6 +1266,29 @@ test "compare between signed and unsigned" { | ... | @@ -1266,6 +1266,29 @@ test "compare between signed and unsigned" { |
| 1266 | testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1))); | 1266 | testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1))); |
| 1267 | } | 1267 | } |
| 1268 | 1268 | ||
| 1269 | test "order" { | ||
| 1270 | testing.expect(order(0, 0) == .eq); | ||
| 1271 | testing.expect(order(1, 0) == .gt); | ||
| 1272 | testing.expect(order(-1, 0) == .lt); | ||
| 1273 | } | ||
| 1274 | |||
| 1275 | test "order.invert" { | ||
| 1276 | testing.expect(Order.invert(order(0, 0)) == .eq); | ||
| 1277 | testing.expect(Order.invert(order(1, 0)) == .lt); | ||
| 1278 | testing.expect(Order.invert(order(-1, 0)) == .gt); | ||
| 1279 | } | ||
| 1280 | |||
| 1281 | test "order.compare" { | ||
| 1282 | testing.expect(order(-1, 0).compare(.lt)); | ||
| 1283 | testing.expect(order(-1, 0).compare(.lte)); | ||
| 1284 | testing.expect(order(0, 0).compare(.lte)); | ||
| 1285 | testing.expect(order(0, 0).compare(.eq)); | ||
| 1286 | testing.expect(order(0, 0).compare(.gte)); | ||
| 1287 | testing.expect(order(1, 0).compare(.gte)); | ||
| 1288 | testing.expect(order(1, 0).compare(.gt)); | ||
| 1289 | testing.expect(order(1, 0).compare(.neq)); | ||
| 1290 | } | ||
| 1291 | |||
| 1269 | test "math.comptime" { | 1292 | test "math.comptime" { |
| 1270 | comptime const v = sin(@as(f32, 1)) + ln(@as(f32, 5)); | 1293 | comptime const v = sin(@as(f32, 1)) + ln(@as(f32, 5)); |
| 1271 | testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5))); | 1294 | testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5))); |
src/translate_c.zig+4| ... | @@ -1797,6 +1797,10 @@ fn exprIsStringLiteral(expr: *const clang.Expr) bool { | ... | @@ -1797,6 +1797,10 @@ fn exprIsStringLiteral(expr: *const clang.Expr) bool { |
| 1797 | const op_expr = @ptrCast(*const clang.UnaryOperator, expr).getSubExpr(); | 1797 | const op_expr = @ptrCast(*const clang.UnaryOperator, expr).getSubExpr(); |
| 1798 | return exprIsStringLiteral(op_expr); | 1798 | return exprIsStringLiteral(op_expr); |
| 1799 | }, | 1799 | }, |
| 1800 | .ParenExprClass => { | ||
| 1801 | const op_expr = @ptrCast(*const clang.ParenExpr, expr).getSubExpr(); | ||
| 1802 | return exprIsStringLiteral(op_expr); | ||
| 1803 | }, | ||
| 1800 | else => return false, | 1804 | else => return false, |
| 1801 | } | 1805 | } |
| 1802 | } | 1806 | } |
test/run_translated_c.zig+7| ... | @@ -3,6 +3,13 @@ const tests = @import("tests.zig"); | ... | @@ -3,6 +3,13 @@ const tests = @import("tests.zig"); |
| 3 | const nl = std.cstr.line_sep; | 3 | const nl = std.cstr.line_sep; |
| 4 | 4 | ||
| 5 | pub fn addCases(cases: *tests.RunTranslatedCContext) void { | 5 | pub fn addCases(cases: *tests.RunTranslatedCContext) void { |
| 6 | cases.add("parenthesized string literal", | ||
| 7 | \\void foo(const char *s) {} | ||
| 8 | \\int main(void) { | ||
| 9 | \\	foo(("bar")); | ||
| 10 | \\} | ||
| 11 | , ""); | ||
| 12 | |||
| 6 | cases.add("variable shadowing type type", | 13 | cases.add("variable shadowing type type", |
| 7 | \\#include <stdlib.h> | 14 | \\#include <stdlib.h> |
| 8 | \\int main() { | 15 | \\int main() { |