Skip to content

Commit

Permalink
Merge branch 'master' into fix-wrong-condition-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ndbn authored Jan 22, 2024
2 parents 2a1789f + fdb4eb3 commit ae2ac84
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 6 deletions.
14 changes: 14 additions & 0 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,7 @@ test "expect addOne adds one to 41" {

test addOne {
// A test name can also be written using an identifier.
// This is a doctest, and serves as documentation for `addOne`.
try std.testing.expect(addOne(41) == 42);
}

Expand Down Expand Up @@ -1170,6 +1171,19 @@ fn addOne(number: i32) i32 {
be written before or after the code under test.
</p>
{#see_also|The Global Error Set|Grammar#}
{#header_open|Doctests#}
<p>
Test declarations named using an identifier are <em>doctests</em>. The identifier must refer to another declaration in
scope. A doctest, like a {#link|doc comment|Doc Comments#}, serves as documentation for the associated declaration, and
will appear in the generated documentation for the declaration.
</p>
<p>
An effective doctest should be self-contained and focused on the declaration being tested, answering questions a new
user might have about its interface or intended usage, while avoiding unnecessary or confusing details. A doctest is not
a substitute for a doc comment, but rather a supplement and companion providing a testable, code-driven example, verified
by <kbd>zig test</kbd>.
</p>
{#header_close#}
{#header_close#}
{#header_open|Test Failure#}
<p>
Expand Down
8 changes: 4 additions & 4 deletions lib/std/Build/Step/ConfigHeader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ fn replace_variables(
switch (value) {
.boolean => |b| {
const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, @intFromBool(b), endline });
last_index = start_index + 1;
last_index = prefix_index + 1;

allocator.free(content_buf);
content_buf = buf;
Expand All @@ -546,22 +546,22 @@ fn replace_variables(
const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, i, endline });
const isNegative = i < 0;
const digits = (if (0 < i) std.math.log10(@abs(i)) else 0) + 1;
last_index = start_index + @intFromBool(isNegative) + digits + 1;
last_index = prefix_index + @intFromBool(isNegative) + digits;

allocator.free(content_buf);
content_buf = buf;
},
.string, .ident => |x| {
const buf = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ beginline, x, endline });
last_index = start_index + x.len + 1;
last_index = prefix_index + x.len;

allocator.free(content_buf);
content_buf = buf;
},

else => {
const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ beginline, endline });
last_index = start_index + 1;
last_index = prefix_index;

allocator.free(content_buf);
content_buf = buf;
Expand Down
54 changes: 53 additions & 1 deletion test/standalone/cmakedefine/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,24 @@
// no substition
// @noval@

// no substition
// @noval@@noval@

// no substition
// @noval@.@noval@

// 1
// @trueval@

// 0
// @falseval@

// 10
// @trueval@@falseval@

// 0.1
// @falseval@.@trueval@

// 0
// @zeroval@

Expand All @@ -64,21 +76,47 @@
// 10
// @tenval@

// 01
// @zeroval@@oneval@

// 0.10
// @zeroval@.@tenval@

// test
// @stringval@

// testtest
// @stringval@@stringval@

// test.test
// @stringval@.@stringval@

// test10
// @noval@@stringval@@trueval@@zeroval@

// ${} substition

// removal
// no substition
// ${noval}

// no substition
// ${noval}${noval}

// no substition
// ${noval}.${noval}

// 1
// ${trueval}

// 0
// ${falseval}

// 10
// ${trueval}${falseval}

// 0.1
// ${falseval}.${trueval}

// 0
// ${zeroval}

Expand All @@ -88,6 +126,20 @@
// 10
// ${tenval}

// 01
// ${zeroval}${oneval}

// 0.10
// ${zeroval}.${tenval}

// test
// ${stringval}

// testtest
// ${stringval}${stringval}

// test.test
// ${stringval}.${stringval}

// test10
// ${noval}${stringval}${trueval}${zeroval}
54 changes: 53 additions & 1 deletion test/standalone/cmakedefine/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,24 @@
// no substition
//

// no substition
//

// no substition
// .

// 1
// 1

// 0
// 0

// 10
// 10

// 0.1
// 0.1

// 0
// 0

Expand All @@ -64,21 +76,47 @@
// 10
// 10

// 01
// 01

// 0.10
// 0.10

// test
// test

// testtest
// testtest

// test.test
// test.test

// test10
// test10

// substition

// removal
// no substition
//

// no substition
//

// no substition
// .

// 1
// 1

// 0
// 0

// 10
// 10

// 0.1
// 0.1

// 0
// 0

Expand All @@ -88,6 +126,20 @@
// 10
// 10

// 01
// 01

// 0.10
// 0.10

// test
// test

// testtest
// testtest

// test.test
// test.test

// test10
// test10

0 comments on commit ae2ac84

Please sign in to comment.