| ... | @@ -533,6 +533,55 @@ pub const Version = struct { | ... | @@ -533,6 +533,55 @@ pub const Version = struct { |
| 533 | } | 533 | } |
| 534 | }; | 534 | }; |
| 535 | | 535 | |
| | 536 | test "Version.parse" { |
| | 537 | @setEvalBranchQuota(3000); |
| | 538 | try testVersionParse(); |
| | 539 | comptime (try testVersionParse()); |
| | 540 | } |
| | 541 | |
| | 542 | pub fn testVersionParse() !void { |
| | 543 | const f = struct { |
| | 544 | fn eql(text: []const u8, v1: u32, v2: u32, v3: u32) !void { |
| | 545 | const v = try Version.parse(text); |
| | 546 | std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3); |
| | 547 | } |
| | 548 | |
| | 549 | fn err(text: []const u8, expected_err: anyerror) !void { |
| | 550 | _ = Version.parse(text) catch |actual_err| { |
| | 551 | if (actual_err == expected_err) return; |
| | 552 | return actual_err; |
| | 553 | }; |
| | 554 | return error.Unreachable; |
| | 555 | } |
| | 556 | }; |
| | 557 | |
| | 558 | try f.eql("2.6.32.11-svn21605", 2, 6, 32); // Debian PPC |
| | 559 | try f.eql("2.11.2(0.329/5/3)", 2, 11, 2); // MinGW |
| | 560 | try f.eql("5.4.0-1018-raspi", 5, 4, 0); // Ubuntu |
| | 561 | try f.eql("5.7.12_3", 5, 7, 12); // Void |
| | 562 | try f.eql("2.13-DEVELOPMENT", 2, 13, 0); // DragonFly |
| | 563 | try f.eql("2.3-35", 2, 3, 0); |
| | 564 | try f.eql("1a.4", 1, 0, 0); |
| | 565 | try f.eql("3.b1.0", 3, 0, 0); |
| | 566 | try f.eql("1.4beta", 1, 4, 0); |
| | 567 | try f.eql("2.7.pre", 2, 7, 0); |
| | 568 | try f.eql("0..3", 0, 0, 0); |
| | 569 | try f.eql("8.008.", 8, 8, 0); |
| | 570 | try f.eql("55", 55, 0, 0); |
| | 571 | try f.eql("4294967295.0.1", 4294967295, 0, 1); |
| | 572 | try f.eql("429496729_6", 429496729, 0, 0); |
| | 573 | |
| | 574 | try f.err("foobar", error.InvalidVersion); |
| | 575 | try f.err("", error.InvalidVersion); |
| | 576 | try f.err("-1", error.InvalidVersion); |
| | 577 | try f.err("+4", error.InvalidVersion); |
| | 578 | try f.err(".", error.InvalidVersion); |
| | 579 | try f.err("....3", error.InvalidVersion); |
| | 580 | try f.err("4294967296", error.Overflow); |
| | 581 | try f.err("5000877755", error.Overflow); |
| | 582 | // error.InvalidCharacter is not possible anymore |
| | 583 | } |
| | 584 | |
| 536 | /// This data structure is used by the Zig language code generation and | 585 | /// This data structure is used by the Zig language code generation and |
| 537 | /// therefore must be kept in sync with the compiler implementation. | 586 | /// therefore must be kept in sync with the compiler implementation. |
| 538 | pub const CallOptions = struct { | 587 | pub const CallOptions = struct { |