aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-12-26 16:04:14 -0500
committerAndrew Kelley <superjoe30@gmail.com>2016-12-26 16:04:14 -0500
commitc8a7ab7eff0f261c47926cf0637e919d42e41940 (patch)
treee06648c3784b8fdfcd626b34956565fccc5d7454 /test
parent7504be923b1721a5a5e094a306aad029887270e8 (diff)
downloadzig-c8a7ab7eff0f261c47926cf0637e919d42e41940.tar.gz
zig-c8a7ab7eff0f261c47926cf0637e919d42e41940.zip
IR: pass cStringConcatenation test
Diffstat (limited to 'test')
-rw-r--r--test/cases/misc.zig22
-rw-r--r--test/self_hosted.zig16
2 files changed, 22 insertions, 16 deletions
diff --git a/test/cases/misc.zig b/test/cases/misc.zig
index 62de3dd05c..5ae312c0dc 100644
--- a/test/cases/misc.zig
+++ b/test/cases/misc.zig
@@ -436,6 +436,28 @@ fn ptrEql(a: &[]const u8, b: &[]const u8) -> bool {
}
+fn cStringConcatenation() {
+ @setFnTest(this);
+
+ const a = c"OK" ++ c" IT " ++ c"WORKED";
+ const b = c"OK IT WORKED";
+
+ const len = cstrlen(b);
+ const len_with_null = len + 1;
+ {var i: u32 = 0; while (i < len_with_null; i += 1) {
+ assert(a[i] == b[i]);
+ }}
+ assert(a[len] == 0);
+ assert(b[len] == 0);
+}
+
+// TODO import from std.cstr
+pub fn cstrlen(ptr: &const u8) -> usize {
+ var count: usize = 0;
+ while (ptr[count] != 0; count += 1) {}
+ return count;
+}
+
// TODO import from std.str
pub fn memeql(a: []const u8, b: []const u8) -> bool {
sliceEql(u8, a, b)
diff --git a/test/self_hosted.zig b/test/self_hosted.zig
index a6d3bcc001..539d14a446 100644
--- a/test/self_hosted.zig
+++ b/test/self_hosted.zig
@@ -59,22 +59,6 @@ fn returnsTen() -> %i32 {
}
// TODO not passing
-fn cStringConcatenation() {
- @setFnTest(this, true);
-
- const a = c"OK" ++ c" IT " ++ c"WORKED";
- const b = c"OK IT WORKED";
-
- const len = cstrlen(b);
- const len_with_null = len + 1;
- {var i: u32 = 0; while (i < len_with_null; i += 1) {
- assert(a[i] == b[i]);
- }}
- assert(a[len] == 0);
- assert(b[len] == 0);
-}
-
-// TODO not passing
fn castSliceToU8Slice() {
@setFnTest(this);