coreutils / tests /expr /tests_for_null.c
AryaWu's picture
Upload folder using huggingface_hub
78d2150 verified
#include "../../unity/unity.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/* Unity required hooks */
void setUp(void) {
/* Setup code here, or leave empty */
}
void tearDown(void) {
/* Cleanup code here, or leave empty */
}
/* The following helpers and the target function `null` are defined in the
included program source (this test file is included into expr.c),
so we can call them directly:
- VALUE struct and TYPE enum
- int_value, str_value, freev
- toarith
- null
*/
/* Integer cases */
static void test_null_integer_zero_true(void) {
VALUE *v = int_value(0);
TEST_ASSERT_TRUE(null(v));
freev(v);
}
static void test_null_integer_one_false(void) {
VALUE *v = int_value(1);
TEST_ASSERT_FALSE(null(v));
freev(v);
}
static void test_null_integer_negative_false(void) {
VALUE *v = str_value("-1");
TEST_ASSERT_TRUE(toarith(v));
TEST_ASSERT_FALSE(null(v));
freev(v);
}
static void test_null_integer_negative_zero_true(void) {
VALUE *v = str_value("-0");
TEST_ASSERT_TRUE(toarith(v));
TEST_ASSERT_TRUE(null(v));
freev(v);
}
static void test_null_integer_large_nonzero_false(void) {
VALUE *v = str_value("123456789012345678901234567890");
TEST_ASSERT_TRUE(toarith(v));
TEST_ASSERT_FALSE(null(v));
freev(v);
}
/* String cases */
static void test_null_string_empty_true(void) {
VALUE *v = str_value("");
TEST_ASSERT_TRUE(null(v));
freev(v);
}
static void test_null_string_zero_true(void) {
VALUE *v = str_value("0");
TEST_ASSERT_TRUE(null(v));
freev(v);
}
static void test_null_string_many_zeros_true(void) {
VALUE *v = str_value("000000");
TEST_ASSERT_TRUE(null(v));
freev(v);
}
static void test_null_string_minus_zeros_true(void) {
VALUE *v = str_value("-00000");
TEST_ASSERT_TRUE(null(v));
freev(v);
}
static void test_null_string_single_minus_false(void) {
VALUE *v = str_value("-");
TEST_ASSERT_FALSE(null(v));
freev(v);
}
static void test_null_string_nonzero_digit_false(void) {
VALUE *v = str_value("1");
TEST_ASSERT_FALSE(null(v));
freev(v);
}
static void test_null_string_leading_zeros_then_nonzero_false(void) {
VALUE *v = str_value("000100");
TEST_ASSERT_FALSE(null(v));
freev(v);
}
static void test_null_string_minus_then_nonzero_false(void) {
VALUE *v = str_value("-10");
TEST_ASSERT_FALSE(null(v));
freev(v);
}
static void test_null_string_plus_zero_false(void) {
VALUE *v = str_value("+0");
TEST_ASSERT_FALSE(null(v));
freev(v);
}
static void test_null_string_space_zero_false(void) {
VALUE *v = str_value(" 0");
TEST_ASSERT_FALSE(null(v));
freev(v);
}
static void test_null_string_alpha_false(void) {
VALUE *v = str_value("foo");
TEST_ASSERT_FALSE(null(v));
freev(v);
}
/* Main runner */
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_null_integer_zero_true);
RUN_TEST(test_null_integer_one_false);
RUN_TEST(test_null_integer_negative_false);
RUN_TEST(test_null_integer_negative_zero_true);
RUN_TEST(test_null_integer_large_nonzero_false);
RUN_TEST(test_null_string_empty_true);
RUN_TEST(test_null_string_zero_true);
RUN_TEST(test_null_string_many_zeros_true);
RUN_TEST(test_null_string_minus_zeros_true);
RUN_TEST(test_null_string_single_minus_false);
RUN_TEST(test_null_string_nonzero_digit_false);
RUN_TEST(test_null_string_leading_zeros_then_nonzero_false);
RUN_TEST(test_null_string_minus_then_nonzero_false);
RUN_TEST(test_null_string_plus_zero_false);
RUN_TEST(test_null_string_space_zero_false);
RUN_TEST(test_null_string_alpha_false);
return UNITY_END();
}