add limits.h

main
anna 3 years ago
parent 026bfd0b39
commit 7d1227f435
Signed by: fef
GPG Key ID: EC22E476DC2D3D84

@ -0,0 +1,70 @@
/* See the end of this file for copyright and license terms. */
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "neo/_types.h"
/**
* @defgroup limits Integer Limits
*
* @{
*/
#define I8_MIN ((i8)-0x80)
#define I8_MAX ((i8) 0x7f)
#define I16_MIN ((i16)-0x8000)
#define I16_MAX ((i16) 0x7fff)
#define I32_MIN ((i32)-0x80000000)
#define I32_MAX ((i32) 0x7fffffff)
#define I64_MIN ((i64)-0x8000000000000000)
#define I64_MAX ((i64) 0x7fffffffffffffff)
#define U8_MIN ((u8)0x00)
#define U8_MAX ((u8)0xff)
#define BYTE_MIN ((byte)0x00)
#define BYTE_MAX ((byte)0xff)
#define U16_MIN ((u16)0x0000)
#define U16_MAX ((u16)0xffff)
#define U32_MIN ((u32)0x00000000)
#define U32_MAX ((u32)0xffffffff)
#define U64_MIN ((u64)0x0000000000000000)
#define U64_MAX ((u64)0xffffffffffffffff)
#define USIZE_MIN ((usize)0)
#define USIZE_MAX ((usize)__SIZE_MAX__)
#define ISIZE_MAX ((isize)(USIZE_MAX >> 1))
#define ISIZE_MIN (-ISIZE_MAX - 1)
#define NCHAR_MIN ((nchar)0)
#define NCHAR_MAX ((nchar)0x0010ffff)
/** @} */
#ifdef __cplusplus
}; /* extern "C" */
#endif
/*
* This file is part of libneo.
* Copyright (c) 2021 Fefie <owo@fef.moe>.
*
* libneo is non-violent software: you may only use, redistribute,
* and/or modify it under the terms of the CNPLv6+ as found in
* the LICENSE file in the source code root directory or at
* <https://git.pixie.town/thufie/CNPL>.
*
* libneo comes with ABSOLUTELY NO WARRANTY, to the extent
* permitted by applicable law. See the CNPLv6+ for details.
*/

@ -21,6 +21,7 @@ include(string/string.cmake)
target_sources(neo_test PRIVATE
hashtab.cpp
limits.cpp
list.cpp
nref.cpp
)

@ -0,0 +1,76 @@
/* See the end of this file for copyright and license terms. */
#include <catch2/catch.hpp>
#include <errno.h>
#include <neo/limits.h>
#include <neo/utf.h>
TEST_CASE( "limits.h: Correct values", "[limits.h]" )
{
REQUIRE( sizeof(BYTE_MIN) == 1 );
REQUIRE( sizeof(U8_MIN) == 1 );
REQUIRE( sizeof(U16_MIN) == 2 );
REQUIRE( sizeof(U32_MIN) == 4 );
REQUIRE( sizeof(U64_MIN) == 8 );
REQUIRE( sizeof(I8_MIN) == 1 );
REQUIRE( sizeof(I16_MIN) == 2 );
REQUIRE( sizeof(I32_MIN) == 4 );
REQUIRE( sizeof(I64_MIN) == 8 );
REQUIRE( sizeof(BYTE_MAX) == 1 );
REQUIRE( sizeof(U8_MAX) == 1 );
REQUIRE( sizeof(U16_MAX) == 2 );
REQUIRE( sizeof(U32_MAX) == 4);
REQUIRE( sizeof(U64_MAX) == 8 );
REQUIRE( sizeof(I8_MAX) == 1 );
REQUIRE( sizeof(I16_MAX) == 2 );
REQUIRE( sizeof(I32_MAX) == 4 );
REQUIRE( sizeof(I64_MAX) == 8 );
REQUIRE( BYTE_MAX > BYTE_MIN );
REQUIRE( U8_MAX > U8_MIN );
REQUIRE( U16_MAX > U16_MIN );
REQUIRE( U32_MAX > U32_MIN );
REQUIRE( U64_MAX > U64_MIN );
REQUIRE( USIZE_MAX > USIZE_MIN );
REQUIRE( I8_MAX > I8_MIN );
REQUIRE( I16_MAX > I16_MIN );
REQUIRE( I32_MAX > I32_MIN );
REQUIRE( I64_MAX > I64_MIN );
REQUIRE( ISIZE_MAX > ISIZE_MIN );
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverflow"
REQUIRE( (byte)(BYTE_MAX + 1) == BYTE_MIN );
REQUIRE( (u8)(U8_MAX + 1) == U8_MIN );
REQUIRE( (u16)(U16_MAX + 1) == U16_MIN );
REQUIRE( (u32)(U32_MAX + 1) == U32_MIN );
REQUIRE( (u64)(U64_MAX + 1) == U64_MIN );
REQUIRE( (usize)(USIZE_MAX + 1) == USIZE_MIN );
REQUIRE( (i8)(I8_MAX + 1) == I8_MIN );
REQUIRE( (i16)(I16_MAX + 1) == I16_MIN );
REQUIRE( (i32)(I32_MAX + 1) == I32_MIN );
REQUIRE( (i64)(I64_MAX + 1) == I64_MIN );
REQUIRE( (isize)(ISIZE_MAX + 1) == ISIZE_MIN );
#pragma GCC diagnostic pop
}
/*
* This file is part of libneo.
* Copyright (c) 2021 Fefie <owo@fef.moe>.
*
* libneo is non-violent software: you may only use, redistribute,
* and/or modify it under the terms of the CNPLv6+ as found in
* the LICENSE file in the source code root directory or at
* <https://git.pixie.town/thufie/CNPL>.
*
* libneo comes with ABSOLUTELY NO WARRANTY, to the extent
* permitted by applicable law. See the CNPLv6+ for details.
*/
Loading…
Cancel
Save