class TestCase::Literal::Integer {
use Fn;
use Array;
static method integer_literal_decimal_notation : int () {
# 0-9
{
my $all_numbers = 1234567890;
unless ($all_numbers isa int) {
return 0;
}
unless ($all_numbers == 1234567889 + 1) {
return 0;
}
}
# 0-9 long - suffix L
{
my $all_numbers = 1234567890L;
unless ($all_numbers isa long) {
return 0;
}
unless ($all_numbers == 1234567889L + 1L) {
return 0;
}
}
# 0-9 long - suffix l
{
my $all_numbers = 1234567890l;
unless ($all_numbers isa long) {
return 0;
}
unless ($all_numbers == 1234567889l + 1l) {
return 0;
}
}
# "-" at the beginning
{
my $minus_max = -21;
unless ($minus_max == -20 - 1) {
return 0;
}
}
# Max int value
{
my $int_max = 2147483647;
unless ($int_max == 2147483646 + 1) {
return 0;
}
}
# Minimal int value
{
my $int_min = -2147483648;
unless ($int_min == -2147483647 - 1) {
return 0;
}
}
# Max long value
{
my $long_max = 9223372036854775807L;
unless ($long_max == 9223372036854775806L + 1L) {
return 0;
}
}
# Minimal long value
{
my $long_min = -9223372036854775808L;
unless ($long_min == -9223372036854775807L - 1L) {
return 0;
}
}
# Separator
{
# Simple
{
my $separator = 123_456_789;
unless ($separator == 123456789) {
return 0;
}
}
# More complex
{
my $separator = -1_23_456__789_L;
unless ($separator isa long) {
return 0;
}
unless ($separator == -123456789) {
return 0;
}
}
}
# Combination with the unary "+" operator
{
my $plus_max = +2147483647;
unless ($plus_max == 2147483647) {
return 0;
}
}
# 1+2 (not 1 + 2)
{
my $total = 1+2;
unless ($total == 3) {
return 0;
}
}
# 1- -2 (not 1- -2)
{
my $total = 1- -2;
unless ($total == 3) {
return 0;
}
}
return 1;
}
static method integer_literal_decimal_notation_extra : int () {
# byte norrowing numeric conversion
{
my $byte_norrowing_convertion : byte = -128;
unless ($byte_norrowing_convertion == -128) {
return 0;
}
return 1;
}
# short norrowing numeric conversion
{
my $short_norrowing_convertion : short = -32768;
unless ($short_norrowing_convertion == -32768) {
return 0;
}
return 1;
}
return 1;
}
static method integer_literal_hex_notation : int () {
# 0-9a-zA-Z
{
my $all_numbers1 = 0x01234567;
my $all_numbers2 = 0x00890000;
my $all_numbers3 = 0x00ABCDEF;
my $all_numbers4 = 0x00abcdef;
unless ($all_numbers1 isa int) {
return 0;
}
unless ($all_numbers1 == 19088743) {
return 0;
}
unless ($all_numbers2 == 8978432) {
return 0;
}
unless ($all_numbers3 == 11259375) {
return 0;
}
unless ($all_numbers4 == 11259375) {
return 0;
}
}
# 0-9a-zA-Z - L suffix
{
my $all_numbers1 = 0x01234567L;
my $all_numbers2 = 0x00890000L;
my $all_numbers3 = 0x00ABCDEFL;
my $all_numbers4 = 0x00abcdefL;
unless ($all_numbers1 isa long) {
return 0;
}
unless ($all_numbers1 == 19088743L) {
return 0;
}
unless ($all_numbers2 == 8978432L) {
return 0;
}
unless ($all_numbers3 == 11259375L) {
return 0;
}
unless ($all_numbers4 == 11259375L) {
return 0;
}
}
# 0X
{
my $all_numbers1 = 0X01234567;
my $all_numbers2 = 0X00890000;
my $all_numbers3 = 0X00ABCDEF;
my $all_numbers4 = 0X00abcdef;
unless ($all_numbers1 isa int) {
return 0;
}
unless ($all_numbers1 == 19088743) {
return 0;
}
unless ($all_numbers2 == 8978432) {
return 0;
}
unless ($all_numbers3 == 11259375) {
return 0;
}
unless ($all_numbers4 == 11259375) {
return 0;
}
}
# Max int value
{
my $max_int = 0xFFFFFFFF;
unless ($max_int == -1) {
return 0;
}
}
# Max int value with "-"
{
my $max_int_minus = -0xFFFFFFFF;
unless ($max_int_minus == 1) {
return 0;
}
}
# Max long value
{
my $max_long = 0xFFFFFFFF_FFFFFFFFL;
unless ($max_long == -1L) {
return 0;
}
}
# Max long value with "-"
{
my $max_long = -0xFFFFFFFF_FFFFFFFFL;
unless ($max_long == 1L) {
return 0;
}
}
# Separator
{
# Simple
{
my $separator = 0xFF_FF_FF_FF;
unless ($separator == -1) {
return 0;
}
}
# More complex
{
my $separator = 0x_FF__FF_FF_FF_FFFFFFFF_L;
unless ($separator isa long) {
return 0;
}
unless ($separator == -1) {
return 0;
}
}
}
# Combination with the unary "+" operator
{
my $plus_max = +0xFF;
unless ($plus_max == 0xFF) {
return 0;
}
}
return 1;
}
static method integer_literal_hex_notation_extra : int () {
{
my $max_int = 0x7FFFFFFF;
unless ($max_int == Fn->INT32_MAX()) {
return 0;
}
}
{
my $min_int = 0x80000000;
unless ($min_int == Fn->INT32_MIN()) {
return 0;
}
}
{
my $combination = -0x000000FF_FFFFFFFFL;
unless ($combination == -1099511627775L) {
return 0;
}
}
return 1;
}
static method integer_literal_octal_notation : int () {
# 0-7
{
my $all_numbers = 012345670;
unless ($all_numbers isa int) {
return 0;
}
unless ($all_numbers == 2739128) {
return 0;
}
}
# L suffix
{
my $all_numbers = 012345670L;
unless ($all_numbers isa long) {
return 0;
}
unless ($all_numbers == 2739128L) {
return 0;
}
}
# l suffix
{
my $all_numbers = 012345670l;
unless ($all_numbers isa long) {
return 0;
}
unless ($all_numbers == 2739128L) {
return 0;
}
}
# Max int value
{
my $max_int = 037777777777;
unless ($max_int == -1) {
return 0;
}
}
# Max int value with "-"
{
my $max_int_minus = -037777777777;
unless ($max_int_minus == 1) {
return 0;
}
}
# Max long value
{
my $max_long = 01777777777777777777777L;
unless ($max_long == -1L) {
return 0;
}
}
# Max long value with "-"
{
my $max_long = -01777777777777777777777L;
unless ($max_long == 1L) {
return 0;
}
}
# Separator
{
# Simple
{
my $separator = 012_345_670;
unless ($separator == 2739128) {
return 0;
}
}
# More complex
{
my $separator = 0_12_345_670_L;
unless ($separator isa long) {
return 0;
}
unless ($separator == 2739128) {
return 0;
}
}
}
# Combination with the unary "+" operator
{
my $plus_max = +077;
unless ($plus_max == 077) {
return 0;
}
}
return 1;
}
static method integer_literal_octal_notation_extra : int () {
{
my $all_numbers = 012345670;
unless ($all_numbers == 2739128) {
return 0;
}
}
{
my $combination = -0777_777777777777777777L;
unless ($combination == -9223372036854775807L) {
return 0;
}
}
return 1;
}
static method integer_literal_binary_notation : int () {
# 0-1
{
my $all_numbers1 = 0b10;
unless ($all_numbers1 isa int) {
return 0;
}
unless ($all_numbers1 == 2) {
return 0;
}
}
# L suffix
{
my $all_numbers1 = 0b10L;
unless ($all_numbers1 isa long) {
return 0;
}
unless ($all_numbers1 == 2L) {
return 0;
}
}
# l suffix
{
my $all_numbers1 = 0b10l;
unless ($all_numbers1 isa long) {
return 0;
}
unless ($all_numbers1 == 2l) {
return 0;
}
}
# 0B
{
my $all_numbers1 = 0B10;
unless ($all_numbers1 isa int) {
return 0;
}
unless ($all_numbers1 == 2) {
return 0;
}
}
# Max int value
{
my $max_int = 0b11111111111111111111111111111111;
unless ($max_int == -1) {
return 0;
}
}
# Max int value with "-"
{
my $max_int_minus = -0b11111111111111111111111111111111;
unless ($max_int_minus == 1) {
return 0;
}
}
# Max long value
{
my $max_long = 0b1111111111111111111111111111111111111111111111111111111111111111L;
unless ($max_long == -1L) {
return 0;
}
}
# Max long value with "-"
{
my $max_long = -0b1111111111111111111111111111111111111111111111111111111111111111L;
unless ($max_long == 1L) {
return 0;
}
}
# Separator
{
# Simple
{
my $separator = 0b10_10_10_10;
unless ($separator == 170) {
return 0;
}
}
# More complex
{
my $separator = 0b_10_10_10_10_L;
unless ($separator isa long) {
return 0;
}
unless ($separator == 170) {
return 0;
}
}
}
# Combination with the unary "+" operator
{
my $plus_max = +0b10;
unless ($plus_max == 0b10) {
return 0;
}
}
return 1;
}
static method integer_literal_binary_notation_extra : int () {
{
my $all_numbers = 0b10101010;
unless ($all_numbers == 170) {
return 0;
}
}
{
my $combination = -0b11111111_1111111111111111111111111111111111111111111111111111111L;
unless ($combination == -9223372036854775807L) {
return 0;
}
}
return 1;
}
}