Skip to content

Commit

Permalink
Add new string tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterymath committed Jan 30, 2024
1 parent 09e4934 commit b46fe23
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
28 changes: 28 additions & 0 deletions SingleSource/UnitTests/strcspn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2024 LLVM-MOS
//
// Licensed under the Apache License, Version 2.0 with LLVM Exceptions,
// See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
// information.

#undef NDEBUG
#include <assert.h>
#include <stdlib.h>
#include <string.h>

// Originally from the Public Domain C Library (PDCLib)

static const char abcde[] = "abcde";
static const char abcdx[] = "abcdx";

int main(void) {
assert(strcspn(abcde, "x") == 5);
assert(strcspn(abcde, "xyz") == 5);
assert(strcspn(abcde, "zyx") == 5);
assert(strcspn(abcdx, "x") == 4);
assert(strcspn(abcdx, "xyz") == 4);
assert(strcspn(abcdx, "zyx") == 4);
assert(strcspn(abcde, "a") == 0);
assert(strcspn(abcde, "abc") == 0);
assert(strcspn(abcde, "cba") == 0);
return 0;
}
1 change: 1 addition & 0 deletions SingleSource/UnitTests/strcspn.reference_output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit 0
21 changes: 21 additions & 0 deletions SingleSource/UnitTests/strspn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2024 LLVM-MOS
//
// Licensed under the Apache License, Version 2.0 with LLVM Exceptions,
// See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
// information.

#undef NDEBUG
#include <assert.h>
#include <stdlib.h>
#include <string.h>

// Originally from the Public Domain C Library (PDCLib)

static const char abcde[] = "abcde";

int main(void) {
assert(strspn(abcde, "abc") == 3);
assert(strspn(abcde, "b") == 0);
assert(strspn(abcde, abcde) == 5);
return 0;
}
1 change: 1 addition & 0 deletions SingleSource/UnitTests/strspn.reference_output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit 0
23 changes: 23 additions & 0 deletions SingleSource/UnitTests/strstr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024 LLVM-MOS
//
// Licensed under the Apache License, Version 2.0 with LLVM Exceptions,
// See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
// information.

#undef NDEBUG
#include <assert.h>
#include <stdlib.h>
#include <string.h>

// Originally from the Public Domain C Library (PDCLib)

int main(void) {
char s[] = "abcabcabcdabcde";
assert(strstr(s, "x") == NULL);
assert(strstr(s, "xyz") == NULL);
assert(strstr(s, "a") == &s[0]);
assert(strstr(s, "abc") == &s[0]);
assert(strstr(s, "abcd") == &s[6]);
assert(strstr(s, "abcde") == &s[10]);
return 0;
}
1 change: 1 addition & 0 deletions SingleSource/UnitTests/strstr.reference_output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit 0

0 comments on commit b46fe23

Please sign in to comment.