TypeScript/tests/baselines/reference/bigintWithLib.types
Nathan Shively-Sanders 71c1da020f
redo #28564 (#36665)
2020-02-07 09:55:29 -08:00

352 lines
11 KiB
Text

=== tests/cases/compiler/bigintWithLib.ts ===
// Test BigInt functions
let bigintVal: bigint = BigInt(123);
>bigintVal : bigint
>BigInt(123) : bigint
>BigInt : BigIntConstructor
>123 : 123
bigintVal = BigInt("456");
>bigintVal = BigInt("456") : bigint
>bigintVal : bigint
>BigInt("456") : bigint
>BigInt : BigIntConstructor
>"456" : "456"
new BigInt(123); // should error
>new BigInt(123) : any
>BigInt : BigIntConstructor
>123 : 123
bigintVal = BigInt.asIntN(8, 0xFFFFn);
>bigintVal = BigInt.asIntN(8, 0xFFFFn) : bigint
>bigintVal : bigint
>BigInt.asIntN(8, 0xFFFFn) : bigint
>BigInt.asIntN : (bits: number, int: bigint) => bigint
>BigInt : BigIntConstructor
>asIntN : (bits: number, int: bigint) => bigint
>8 : 8
>0xFFFFn : 65535n
bigintVal = BigInt.asUintN(8, 0xFFFFn);
>bigintVal = BigInt.asUintN(8, 0xFFFFn) : bigint
>bigintVal : bigint
>BigInt.asUintN(8, 0xFFFFn) : bigint
>BigInt.asUintN : (bits: number, int: bigint) => bigint
>BigInt : BigIntConstructor
>asUintN : (bits: number, int: bigint) => bigint
>8 : 8
>0xFFFFn : 65535n
bigintVal = bigintVal.valueOf();
>bigintVal = bigintVal.valueOf() : bigint
>bigintVal : bigint
>bigintVal.valueOf() : bigint
>bigintVal.valueOf : () => bigint
>bigintVal : bigint
>valueOf : () => bigint
let stringVal: string = bigintVal.toString();
>stringVal : string
>bigintVal.toString() : string
>bigintVal.toString : (radix?: number) => string
>bigintVal : bigint
>toString : (radix?: number) => string
stringVal = bigintVal.toString(2);
>stringVal = bigintVal.toString(2) : string
>stringVal : string
>bigintVal.toString(2) : string
>bigintVal.toString : (radix?: number) => string
>bigintVal : bigint
>toString : (radix?: number) => string
>2 : 2
stringVal = bigintVal.toLocaleString();
>stringVal = bigintVal.toLocaleString() : string
>stringVal : string
>bigintVal.toLocaleString() : string
>bigintVal.toLocaleString : () => string
>bigintVal : bigint
>toLocaleString : () => string
// Test BigInt64Array
let bigIntArray: BigInt64Array = new BigInt64Array();
>bigIntArray : BigInt64Array
>new BigInt64Array() : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
bigIntArray = new BigInt64Array(10);
>bigIntArray = new BigInt64Array(10) : BigInt64Array
>bigIntArray : BigInt64Array
>new BigInt64Array(10) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>10 : 10
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
>bigIntArray = new BigInt64Array([1n, 2n, 3n]) : BigInt64Array
>bigIntArray : BigInt64Array
>new BigInt64Array([1n, 2n, 3n]) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>[1n, 2n, 3n] : bigint[]
>1n : 1n
>2n : 2n
>3n : 3n
bigIntArray = new BigInt64Array([1, 2, 3]); // should error
>bigIntArray = new BigInt64Array([1, 2, 3]) : BigInt64Array
>bigIntArray : BigInt64Array
>new BigInt64Array([1, 2, 3]) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>[1, 2, 3] : number[]
>1 : 1
>2 : 2
>3 : 3
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
>bigIntArray = new BigInt64Array(new ArrayBuffer(80)) : BigInt64Array
>bigIntArray : BigInt64Array
>new BigInt64Array(new ArrayBuffer(80)) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
>bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8) : BigInt64Array
>bigIntArray : BigInt64Array
>new BigInt64Array(new ArrayBuffer(80), 8) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
>8 : 8
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
>bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3) : BigInt64Array
>bigIntArray : BigInt64Array
>new BigInt64Array(new ArrayBuffer(80), 8, 3) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
>8 : 8
>3 : 3
let len: number = bigIntArray.length;
>len : number
>bigIntArray.length : number
>bigIntArray : BigInt64Array
>length : number
bigIntArray.length = 10; // should error
>bigIntArray.length = 10 : 10
>bigIntArray.length : any
>bigIntArray : BigInt64Array
>length : any
>10 : 10
let arrayBufferLike: ArrayBufferView = bigIntArray;
>arrayBufferLike : ArrayBufferView
>bigIntArray : BigInt64Array
// Test BigUint64Array
let bigUintArray: BigUint64Array = new BigUint64Array();
>bigUintArray : BigUint64Array
>new BigUint64Array() : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
bigUintArray = new BigUint64Array(10);
>bigUintArray = new BigUint64Array(10) : BigUint64Array
>bigUintArray : BigUint64Array
>new BigUint64Array(10) : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
>10 : 10
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
>bigUintArray = new BigUint64Array([1n, 2n, 3n]) : BigUint64Array
>bigUintArray : BigUint64Array
>new BigUint64Array([1n, 2n, 3n]) : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
>[1n, 2n, 3n] : bigint[]
>1n : 1n
>2n : 2n
>3n : 3n
bigUintArray = new BigUint64Array([1, 2, 3]); // should error
>bigUintArray = new BigUint64Array([1, 2, 3]) : BigUint64Array
>bigUintArray : BigUint64Array
>new BigUint64Array([1, 2, 3]) : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
>[1, 2, 3] : number[]
>1 : 1
>2 : 2
>3 : 3
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
>bigUintArray = new BigUint64Array(new ArrayBuffer(80)) : BigUint64Array
>bigUintArray : BigUint64Array
>new BigUint64Array(new ArrayBuffer(80)) : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
>bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8) : BigUint64Array
>bigUintArray : BigUint64Array
>new BigUint64Array(new ArrayBuffer(80), 8) : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
>8 : 8
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);
>bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3) : BigUint64Array
>bigUintArray : BigUint64Array
>new BigUint64Array(new ArrayBuffer(80), 8, 3) : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
>8 : 8
>3 : 3
len = bigIntArray.length;
>len = bigIntArray.length : number
>len : number
>bigIntArray.length : number
>bigIntArray : BigInt64Array
>length : number
bigIntArray.length = 10; // should error
>bigIntArray.length = 10 : 10
>bigIntArray.length : any
>bigIntArray : BigInt64Array
>length : any
>10 : 10
arrayBufferLike = bigIntArray;
>arrayBufferLike = bigIntArray : BigInt64Array
>arrayBufferLike : ArrayBufferView
>bigIntArray : BigInt64Array
// Test added DataView methods
const dataView = new DataView(new ArrayBuffer(80));
>dataView : DataView
>new DataView(new ArrayBuffer(80)) : DataView
>DataView : DataViewConstructor
>new ArrayBuffer(80) : ArrayBuffer
>ArrayBuffer : ArrayBufferConstructor
>80 : 80
dataView.setBigInt64(1, -1n);
>dataView.setBigInt64(1, -1n) : void
>dataView.setBigInt64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>dataView : DataView
>setBigInt64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>1 : 1
>-1n : -1n
>1n : 1n
dataView.setBigInt64(1, -1n, true);
>dataView.setBigInt64(1, -1n, true) : void
>dataView.setBigInt64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>dataView : DataView
>setBigInt64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>1 : 1
>-1n : -1n
>1n : 1n
>true : true
dataView.setBigInt64(1, -1); // should error
>dataView.setBigInt64(1, -1) : void
>dataView.setBigInt64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>dataView : DataView
>setBigInt64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>1 : 1
>-1 : -1
>1 : 1
dataView.setBigUint64(2, 123n);
>dataView.setBigUint64(2, 123n) : void
>dataView.setBigUint64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>dataView : DataView
>setBigUint64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>2 : 2
>123n : 123n
dataView.setBigUint64(2, 123n, true);
>dataView.setBigUint64(2, 123n, true) : void
>dataView.setBigUint64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>dataView : DataView
>setBigUint64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>2 : 2
>123n : 123n
>true : true
dataView.setBigUint64(2, 123); // should error
>dataView.setBigUint64(2, 123) : void
>dataView.setBigUint64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>dataView : DataView
>setBigUint64 : (byteOffset: number, value: bigint, littleEndian?: boolean) => void
>2 : 2
>123 : 123
bigintVal = dataView.getBigInt64(1);
>bigintVal = dataView.getBigInt64(1) : bigint
>bigintVal : bigint
>dataView.getBigInt64(1) : bigint
>dataView.getBigInt64 : (byteOffset: number, littleEndian?: boolean) => bigint
>dataView : DataView
>getBigInt64 : (byteOffset: number, littleEndian?: boolean) => bigint
>1 : 1
bigintVal = dataView.getBigInt64(1, true);
>bigintVal = dataView.getBigInt64(1, true) : bigint
>bigintVal : bigint
>dataView.getBigInt64(1, true) : bigint
>dataView.getBigInt64 : (byteOffset: number, littleEndian?: boolean) => bigint
>dataView : DataView
>getBigInt64 : (byteOffset: number, littleEndian?: boolean) => bigint
>1 : 1
>true : true
bigintVal = dataView.getBigUint64(2);
>bigintVal = dataView.getBigUint64(2) : bigint
>bigintVal : bigint
>dataView.getBigUint64(2) : bigint
>dataView.getBigUint64 : (byteOffset: number, littleEndian?: boolean) => bigint
>dataView : DataView
>getBigUint64 : (byteOffset: number, littleEndian?: boolean) => bigint
>2 : 2
bigintVal = dataView.getBigUint64(2, true);
>bigintVal = dataView.getBigUint64(2, true) : bigint
>bigintVal : bigint
>dataView.getBigUint64(2, true) : bigint
>dataView.getBigUint64 : (byteOffset: number, littleEndian?: boolean) => bigint
>dataView : DataView
>getBigUint64 : (byteOffset: number, littleEndian?: boolean) => bigint
>2 : 2
>true : true
// Test emitted declarations files
const w = 12n; // should emit as const w = 12n
>w : 12n
>12n : 12n
const x = -12n; // should emit as const x = -12n
>x : -12n
>-12n : -12n
>12n : 12n
const y: 12n = 12n; // should emit type 12n
>y : 12n
>12n : 12n
let z = 12n; // should emit type bigint in declaration file
>z : bigint
>12n : 12n