2020-03-06 14:01:32 +03:00
//! Test the automatic addition of integer limits.
use proxmox_api_macro ::api ;
2021-12-07 13:51:09 +03:00
use proxmox_schema ::ApiType ;
2020-03-06 14:01:32 +03:00
/// An i16: -32768 to 32767.
#[ api ]
2024-08-06 15:23:38 +03:00
#[ allow(dead_code) ]
2020-03-06 14:01:32 +03:00
pub struct AnI16 ( i16 ) ;
#[ test ]
fn test_an_i16_schema ( ) {
2021-10-07 10:36:06 +03:00
const TEST_SCHEMA : ::proxmox_schema ::Schema =
::proxmox_schema ::IntegerSchema ::new ( " An i16: -32768 to 32767. " )
2020-03-06 14:01:32 +03:00
. minimum ( - 32768 )
. maximum ( 32767 )
. schema ( ) ;
assert_eq! ( TEST_SCHEMA , AnI16 ::API_SCHEMA ) ;
}
/// Already limited on one side.
#[ api(minimum: -50) ]
2024-08-06 15:23:38 +03:00
#[ allow(dead_code) ]
2020-03-06 14:01:32 +03:00
pub struct I16G50 ( i16 ) ;
#[ test ]
fn test_i16g50_schema ( ) {
2021-10-07 10:36:06 +03:00
const TEST_SCHEMA : ::proxmox_schema ::Schema =
::proxmox_schema ::IntegerSchema ::new ( " Already limited on one side. " )
2020-03-06 14:01:32 +03:00
. minimum ( - 50 )
. maximum ( 32767 )
. schema ( ) ;
assert_eq! ( TEST_SCHEMA , I16G50 ::API_SCHEMA ) ;
}
/// An i32: -0x8000_0000 to 0x7fff_ffff.
#[ api ]
2024-08-06 15:23:38 +03:00
#[ allow(dead_code) ]
2020-03-06 14:01:32 +03:00
pub struct AnI32 ( i32 ) ;
#[ test ]
fn test_an_i32_schema ( ) {
2021-10-07 10:36:06 +03:00
const TEST_SCHEMA : ::proxmox_schema ::Schema =
::proxmox_schema ::IntegerSchema ::new ( " An i32: -0x8000_0000 to 0x7fff_ffff. " )
2020-03-06 14:01:32 +03:00
. minimum ( - 0x8000_0000 )
. maximum ( 0x7fff_ffff )
. schema ( ) ;
assert_eq! ( TEST_SCHEMA , AnI32 ::API_SCHEMA ) ;
}
/// Unsigned implies a minimum of zero.
#[ api ]
2024-08-06 15:23:38 +03:00
#[ allow(dead_code) ]
2020-03-06 14:01:32 +03:00
pub struct AnU32 ( u32 ) ;
#[ test ]
fn test_an_u32_schema ( ) {
2021-10-07 10:36:06 +03:00
const TEST_SCHEMA : ::proxmox_schema ::Schema =
::proxmox_schema ::IntegerSchema ::new ( " Unsigned implies a minimum of zero. " )
2020-03-06 14:01:32 +03:00
. minimum ( 0 )
. maximum ( 0xffff_ffff )
. schema ( ) ;
assert_eq! ( TEST_SCHEMA , AnU32 ::API_SCHEMA ) ;
}
/// An i64: this is left unlimited.
#[ api ]
2024-08-06 15:23:38 +03:00
#[ allow(dead_code) ]
2020-03-06 14:01:32 +03:00
pub struct AnI64 ( i64 ) ;
#[ test ]
fn test_an_i64_schema ( ) {
2021-10-07 10:36:06 +03:00
const TEST_SCHEMA : ::proxmox_schema ::Schema =
::proxmox_schema ::IntegerSchema ::new ( " An i64: this is left unlimited. " ) . schema ( ) ;
2020-03-06 14:01:32 +03:00
assert_eq! ( TEST_SCHEMA , AnI64 ::API_SCHEMA ) ;
}
/// Unsigned implies a minimum of zero.
#[ api ]
2024-08-06 15:23:38 +03:00
#[ allow(dead_code) ]
2020-03-06 14:01:32 +03:00
pub struct AnU64 ( u64 ) ;
#[ test ]
fn test_an_u64_schema ( ) {
2021-10-07 10:36:06 +03:00
const TEST_SCHEMA : ::proxmox_schema ::Schema =
::proxmox_schema ::IntegerSchema ::new ( " Unsigned implies a minimum of zero. " )
2020-03-06 14:01:32 +03:00
. minimum ( 0 )
. schema ( ) ;
assert_eq! ( TEST_SCHEMA , AnU64 ::API_SCHEMA ) ;
}