Skip to content
Snippets Groups Projects
Commit 6ced871d authored by SamwiseFilmore's avatar SamwiseFilmore
Browse files

ctype: tests and reorganize

Wrote tests for the functions implemented in 40558b26 and maybe made that
test a little more comprehensible.

Also made sure that fmt.sh and test.sh were being executed by bash all
the time (compatibility with other shells).
parent 42de0a0a
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
ARGS=() ARGS=()
for crate in relibc $(find src -name Cargo.toml | cut -d '/' -f2 | grep -v template) for crate in relibc $(find src -name Cargo.toml | cut -d '/' -f2 | grep -v template)
......
...@@ -21,6 +21,11 @@ pub extern "C" fn isascii(c: c_int) -> c_int { ...@@ -21,6 +21,11 @@ pub extern "C" fn isascii(c: c_int) -> c_int {
(!(c & !0x7f)) as c_int (!(c & !0x7f)) as c_int
} }
#[no_mangle]
pub extern "C" fn isblank(c: c_int) -> c_int {
(c == ' ' as c_int || c == '\t' as c_int) as c_int
}
#[no_mangle] #[no_mangle]
pub extern "C" fn iscntrl(c: c_int) -> c_int { pub extern "C" fn iscntrl(c: c_int) -> c_int {
((c as c_uint) < 0x20 || c == 0x7f) as c_int ((c as c_uint) < 0x20 || c == 0x7f) as c_int
...@@ -48,7 +53,7 @@ pub extern "C" fn isprint(c: c_int) -> c_int { ...@@ -48,7 +53,7 @@ pub extern "C" fn isprint(c: c_int) -> c_int {
#[no_mangle] #[no_mangle]
pub extern "C" fn ispunct(c: c_int) -> c_int { pub extern "C" fn ispunct(c: c_int) -> c_int {
(isgraph(c) == 0 && !isalnum(c) == 0) as c_int (isgraph(c) != 0 && !isalnum(c) != 0) as c_int
} }
#[no_mangle] #[no_mangle]
...@@ -63,17 +68,12 @@ pub extern "C" fn isupper(c: c_int) -> c_int { ...@@ -63,17 +68,12 @@ pub extern "C" fn isupper(c: c_int) -> c_int {
#[no_mangle] #[no_mangle]
pub extern "C" fn isxdigit(c: c_int) -> c_int { pub extern "C" fn isxdigit(c: c_int) -> c_int {
(isdigit(c) == 0 || ((c as c_int) | 32) - ('a' as c_int) < 6) as c_int (isdigit(c) != 0 || ((c as c_int) | 32) - ('a' as c_int) < 6) as c_int
}
#[no_mangle]
pub extern "C" fn isblank(c: c_int) -> c_int {
(c == ' ' as c_int || c == '\t' as c_int) as c_int
} }
#[no_mangle] #[no_mangle]
/// The comment in musl: /// The comment in musl:
/// `/* nonsense function that should NEVER be used! */` /// "nonsense function that should NEVER be used!"
pub extern "C" fn toascii(c: c_int) -> c_int { pub extern "C" fn toascii(c: c_int) -> c_int {
c & 0x7f c & 0x7f
} }
......
...@@ -63,7 +63,7 @@ pub fn fchdir(fildes: c_int) -> c_int { ...@@ -63,7 +63,7 @@ pub fn fchdir(fildes: c_int) -> c_int {
} }
pub fn fork() -> pid_t { pub fn fork() -> pid_t {
e(unsafe {syscall!(FORK) }) as pid_t e(unsafe { syscall!(FORK) }) as pid_t
} }
pub fn fsync(fildes: c_int) -> c_int { pub fn fsync(fildes: c_int) -> c_int {
......
...@@ -64,7 +64,7 @@ pub fn fchdir(fd: c_int) -> c_int { ...@@ -64,7 +64,7 @@ pub fn fchdir(fd: c_int) -> c_int {
} }
pub fn fork() -> pid_t { pub fn fork() -> pid_t {
e(unsafe { syscall::clone(0) }) as pid_t e(unsafe { syscall::clone(0) }) as pid_t
} }
pub fn fsync(fd: c_int) -> c_int { pub fn fsync(fd: c_int) -> c_int {
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
#![no_std] #![no_std]
extern crate errno;
extern crate platform; extern crate platform;
extern crate va_list as vl; extern crate va_list as vl;
extern crate errno;
use core::str; use core::str;
use core::fmt::Write; use core::fmt::Write;
......
#!/bin/bash
set -ex set -ex
cargo build cargo build
......
...@@ -6,17 +6,28 @@ struct test_case { ...@@ -6,17 +6,28 @@ struct test_case {
int isalnum; int isalnum;
int isalpha; int isalpha;
int isascii; int isascii;
int isblank;
int iscntrl;
int isdigit; int isdigit;
int isgraph;
int islower; int islower;
int isprint;
int ispunct;
int isspace; int isspace;
int isupper; int isupper;
int isxdigit;
} test_cases[] = { } test_cases[] = {
{ 'A', 1, 1, 1, 0, 0, 0, 1}, // a a a b c d g l p p s u x
{ 'z', 1, 1, 1, 0, 1, 0, 0}, // l l s l n i r o r u p p d
{ ' ', 0, 0, 1, 0, 0, 1, 0}, // n p c a t g a w i n a p i
{ '1', 1, 0, 1, 1, 0, 0, 0}, // u h i n r i p e n c c e g
{ '9', 1, 0, 1, 1, 0, 0, 0}, // m a i k l t h r t t e r i
{0x80, 0, 0, 0, 0, 0, 0, 0} { 'A', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1},
{ 'z', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{ ' ', 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0},
{ '1', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1},
{ '9', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1},
{0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
}; };
size_t num_test_cases = sizeof(test_cases)/sizeof(struct test_case); size_t num_test_cases = sizeof(test_cases)/sizeof(struct test_case);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment