forked from Mirror/wren
Don't test bitwise operations on operands that don't fit in u32.
The current behavior is undefined in C when converting the double to a u32, so the tests fail on some compilers. For now, I'm just removing those parts of the tests because I'm not sure what I want the behavior to be. Modulo? Truncate? Runtime error?
This commit is contained in:
@ -618,9 +618,7 @@ DEF_PRIMITIVE(num_bangeq)
|
||||
DEF_PRIMITIVE(num_bitwiseNot)
|
||||
{
|
||||
// Bitwise operators always work on 32-bit unsigned ints.
|
||||
uint64_t wideVal = AS_NUM(args[0]);
|
||||
uint32_t val = wideVal & 0xFFFFFFFF;
|
||||
RETURN_NUM(~(uint32_t)val);
|
||||
RETURN_NUM(~(uint32_t)AS_NUM(args[0]));
|
||||
}
|
||||
|
||||
DEF_PRIMITIVE(num_dotDot)
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
System.print(0 & 0) // expect: 0
|
||||
System.print(2863311530 & 1431655765) // expect: 0
|
||||
System.print(4042322160 & 1010580540) // expect: 808464432
|
||||
System.print(0xaaaaaaaa & 0x55555555) // expect: 0
|
||||
System.print(0xf0f0f0f0 & 0x3c3c3c3c) // expect: 808464432
|
||||
|
||||
// Max u32 value.
|
||||
System.print(4294967295 & 4294967295) // expect: 4294967295
|
||||
|
||||
// Past max u32 value.
|
||||
System.print(4294967296 & 4294967296) // expect: 0
|
||||
System.print(0xffffffff & 0xffffffff) // expect: 4294967295
|
||||
|
||||
// TODO: Negative numbers.
|
||||
// TODO: Floating-point numbers.
|
||||
// TODO: Numbers that don't fit in u32.
|
||||
|
||||
@ -2,14 +2,12 @@ System.print(0 << 0) // expect: 0
|
||||
System.print(1 << 0) // expect: 1
|
||||
System.print(0 << 1) // expect: 0
|
||||
System.print(1 << 1) // expect: 2
|
||||
System.print(2863311530 << 1) // expect: 1431655764
|
||||
System.print(4042322160 << 1) // expect: 3789677024
|
||||
System.print(0xaaaaaaaa << 1) // expect: 1431655764
|
||||
System.print(0xf0f0f0f0 << 1) // expect: 3789677024
|
||||
|
||||
// Max u32 value.
|
||||
System.print(4294967295 << 1) // expect: 4294967294
|
||||
|
||||
// Past max u32 value.
|
||||
System.print(4294967296 << 1) // expect: 0
|
||||
System.print(0xffffffff << 0) // expect: 4294967295
|
||||
|
||||
// TODO: Negative numbers.
|
||||
// TODO: Floating-point numbers.
|
||||
// TODO: Numbers that don't fit in u32.
|
||||
|
||||
@ -3,20 +3,18 @@ System.print(~1) // expect: 4294967294
|
||||
System.print(~23) // expect: 4294967272
|
||||
|
||||
// Max u32 value.
|
||||
System.print(~4294967295) // expect: 0
|
||||
|
||||
// Past max u32 value.
|
||||
System.print(~4294967296) // expect: 4294967295
|
||||
System.print(~0xffffffff) // expect: 0
|
||||
|
||||
// Negative numbers.
|
||||
System.print(~-1) // expect: 0
|
||||
System.print(~-123) // expect: 122
|
||||
System.print(~-4294967294) // expect: 4294967293
|
||||
System.print(~-4294967295) // expect: 4294967294
|
||||
System.print(~-4294967296) // expect: 4294967295
|
||||
System.print(~-0xfffffffe) // expect: 4294967293
|
||||
System.print(~-0xffffffff) // expect: 4294967294
|
||||
|
||||
// Floating point values.
|
||||
System.print(~1.23) // expect: 4294967294
|
||||
System.print(~0.00123) // expect: 4294967295
|
||||
System.print(~345.67) // expect: 4294966950
|
||||
System.print(~-12.34) // expect: 11
|
||||
|
||||
// TODO: Numbers that don't fit in u32.
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
System.print(0 | 0) // expect: 0
|
||||
System.print(2863311530 | 1431655765) // expect: 4294967295
|
||||
System.print(3435973836 | 1717986918) // expect: 4008636142
|
||||
System.print(0xaaaaaaaa | 0x55555555) // expect: 4294967295
|
||||
System.print(0xcccccccc | 0x66666666) // expect: 4008636142
|
||||
|
||||
// Max u32 value.
|
||||
System.print(4294967295 | 4294967295) // expect: 4294967295
|
||||
|
||||
// Past max u32 value.
|
||||
System.print(4294967296 | 4294967296) // expect: 0
|
||||
System.print(0xffffffff | 0xffffffff) // expect: 4294967295
|
||||
|
||||
// TODO: Negative numbers.
|
||||
// TODO: Floating-point numbers.
|
||||
// TODO: Numbers that don't fit in u32.
|
||||
|
||||
@ -2,14 +2,12 @@ System.print(0 >> 0) // expect: 0
|
||||
System.print(1 >> 0) // expect: 1
|
||||
System.print(0 >> 1) // expect: 0
|
||||
System.print(1 >> 1) // expect: 0
|
||||
System.print(2863311530 >> 1) // expect: 1431655765
|
||||
System.print(4042322160 >> 1) // expect: 2021161080
|
||||
System.print(0xaaaaaaaa >> 1) // expect: 1431655765
|
||||
System.print(0xf0f0f0f0 >> 1) // expect: 2021161080
|
||||
|
||||
// Max u32 value.
|
||||
System.print(4294967295 >> 1) // expect: 2147483647
|
||||
|
||||
// Past max u32 value.
|
||||
System.print(4294967296 >> 1) // expect: 0
|
||||
System.print(0xffffffff >> 1) // expect: 2147483647
|
||||
|
||||
// TODO: Negative numbers.
|
||||
// TODO: Floating-point numbers.
|
||||
// TODO: Numbers that don't fit in u32.
|
||||
|
||||
@ -2,14 +2,12 @@ System.print(0 ^ 0) // expect: 0
|
||||
System.print(1 ^ 1) // expect: 0
|
||||
System.print(0 ^ 1) // expect: 1
|
||||
System.print(1 ^ 0) // expect: 1
|
||||
System.print(2863311530 ^ 1431655765) // expect: 4294967295
|
||||
System.print(4042322160 ^ 1010580540) // expect: 3435973836
|
||||
System.print(0xaaaaaaaa ^ 0x55555555) // expect: 4294967295
|
||||
System.print(0xf0f0f0f0 ^ 0x3c3c3c3c) // expect: 3435973836
|
||||
|
||||
// Max u32 value.
|
||||
System.print(4294967295 ^ 4294967295) // expect: 0
|
||||
|
||||
// Past max u32 value.
|
||||
System.print(4294967296 ^ 4294967296) // expect: 0
|
||||
System.print(0xffffffff ^ 0xffffffff) // expect: 0
|
||||
|
||||
// TODO: Negative numbers.
|
||||
// TODO: Floating-point numbers.
|
||||
// TODO: Numbers that don't fit in u32.
|
||||
|
||||
10
util/test.py
10
util/test.py
@ -11,16 +11,18 @@ from subprocess import Popen, PIPE
|
||||
import sys
|
||||
from threading import Timer
|
||||
|
||||
# Runs the tests.
|
||||
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('--suffix', default='d')
|
||||
parser.add_argument('suite', nargs='?')
|
||||
|
||||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
config=args.suffix.lstrip('d')
|
||||
is_debug=args.suffix.startswith('d')
|
||||
config_dir=("debug" if is_debug else "release") + config
|
||||
# Runs the tests.
|
||||
config = args.suffix.lstrip('d')
|
||||
is_debug = args.suffix.startswith('d')
|
||||
config_dir = ("debug" if is_debug else "release") + config
|
||||
|
||||
WREN_DIR = dirname(dirname(realpath(__file__)))
|
||||
WREN_APP = join(WREN_DIR, 'bin', 'wren' + args.suffix)
|
||||
TEST_APP = join(WREN_DIR, 'build', config_dir, 'test', 'wren' + args.suffix)
|
||||
|
||||
Reference in New Issue
Block a user