diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-05-26 23:31:38 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-05-27 00:54:14 -0400 |
| commit | 2dfb1ebee2bc215271e5416b723d746af319621b (patch) | |
| tree | 9b859eebd0926cb82c7370362baafec617e763dc /test | |
| parent | d6b01931ef8a04777ae198af323c2b6ba998f7b1 (diff) | |
| download | zig-2dfb1ebee2bc215271e5416b723d746af319621b.tar.gz zig-2dfb1ebee2bc215271e5416b723d746af319621b.zip | |
const global values can reference each other
Before, if you did something like:
```
const hi1 = "hi";
const hi2 = hi1;
```
This would create the "hi" data twice in the built object.
But since the value is const we don't have to duplicate the
data, now we take advantage of this fact.
closes #336
Diffstat (limited to 'test')
| -rw-r--r-- | test/cases/eval.zig | 10 | ||||
| -rw-r--r-- | test/cases/var_args.zig | 14 | ||||
| -rw-r--r-- | test/tests.zig | 6 |
3 files changed, 26 insertions, 4 deletions
diff --git a/test/cases/eval.zig b/test/cases/eval.zig index bda67b8151..bf42062fb5 100644 --- a/test/cases/eval.zig +++ b/test/cases/eval.zig @@ -332,3 +332,13 @@ test "compile-time downcast when the bits fit" { assert(byte == 255); } } + +const hi1 = "hi"; +const hi2 = hi1; +test "const global shares pointer with other same one" { + assertEqualPtrs(&hi1[0], &hi2[0]); + comptime assert(&hi1[0] == &hi2[0]); +} +fn assertEqualPtrs(ptr1: &const u8, ptr2: &const u8) { + assert(ptr1 == ptr2); +} diff --git a/test/cases/var_args.zig b/test/cases/var_args.zig index cbdffb5581..363816bc8a 100644 --- a/test/cases/var_args.zig +++ b/test/cases/var_args.zig @@ -65,3 +65,17 @@ test "array of var args functions" { assert(foos[0]()); assert(!foos[1]()); } + + +test "pass array and slice of same array to var args should have same pointers" { + const array = "hi"; + const slice: []const u8 = array; + return assertSlicePtrsEql(array, slice); +} + +fn assertSlicePtrsEql(args: ...) { + const s1 = ([]const u8)(args[0]); + const s2 = args[1]; + assert(s1.ptr == s2.ptr); +} + diff --git a/test/tests.zig b/test/tests.zig index bdf2010fe7..35f06c1ec9 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -591,8 +591,7 @@ pub const CompileErrorContext = struct { tc.addSourceFile(".tmp_source.zig", source); comptime var arg_i = 0; inline while (arg_i < expected_lines.len) : (arg_i += 1) { - // TODO mem.dupe is because of issue #336 - tc.addExpectedError(%%mem.dupe(self.b.allocator, u8, expected_lines[arg_i])); + tc.addExpectedError(expected_lines[arg_i]); } return tc; } @@ -854,8 +853,7 @@ pub const ParseHContext = struct { tc.addSourceFile("source.h", source); comptime var arg_i = 0; inline while (arg_i < expected_lines.len) : (arg_i += 1) { - // TODO mem.dupe is because of issue #336 - tc.addExpectedError(%%mem.dupe(self.b.allocator, u8, expected_lines[arg_i])); + tc.addExpectedError(expected_lines[arg_i]); } return tc; } |
