From 117eb74f5234f82230790eb7e8f9518d3e9126c5 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sun, 8 Feb 2015 23:34:16 -0800 Subject: [PATCH 001/126] Migrate fixnum to Github. --- pkgs/fixnum/LICENSE | 26 + pkgs/fixnum/README.md | 22 + pkgs/fixnum/lib/fixnum.dart | 19 + pkgs/fixnum/lib/src/int32.dart | 377 +++++++++++ pkgs/fixnum/lib/src/int64.dart | 1053 +++++++++++++++++++++++++++++ pkgs/fixnum/lib/src/intx.dart | 237 +++++++ pkgs/fixnum/pubspec.yaml | 9 + pkgs/fixnum/test/int_32_test.dart | 367 ++++++++++ pkgs/fixnum/test/int_64_test.dart | 754 +++++++++++++++++++++ 9 files changed, 2864 insertions(+) create mode 100644 pkgs/fixnum/LICENSE create mode 100644 pkgs/fixnum/README.md create mode 100644 pkgs/fixnum/lib/fixnum.dart create mode 100644 pkgs/fixnum/lib/src/int32.dart create mode 100644 pkgs/fixnum/lib/src/int64.dart create mode 100644 pkgs/fixnum/lib/src/intx.dart create mode 100644 pkgs/fixnum/pubspec.yaml create mode 100644 pkgs/fixnum/test/int_32_test.dart create mode 100644 pkgs/fixnum/test/int_64_test.dart diff --git a/pkgs/fixnum/LICENSE b/pkgs/fixnum/LICENSE new file mode 100644 index 00000000..5c60afea --- /dev/null +++ b/pkgs/fixnum/LICENSE @@ -0,0 +1,26 @@ +Copyright 2014, the Dart project authors. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md new file mode 100644 index 00000000..81f64674 --- /dev/null +++ b/pkgs/fixnum/README.md @@ -0,0 +1,22 @@ +fixnum +====== + +A fixed-size integer library for Dart. +- - - +The fixnum package provides data types for signed 32- and 64-bit integers. +The integer implementations in this library are designed to work identically +whether executed on the Dart VM or compiled to JavaScript. + +Installing +---------- + +Use [pub](http://pub.dartlang.org) to install this package. Add the following +to your `pubspec.yaml` file: + + dependencies: + fixnum: any + +Then run `pub install`. + +For more information, see the +[fixnum package on pub.dartlang.org](http://pub.dartlang.org/packages/fixnum). diff --git a/pkgs/fixnum/lib/fixnum.dart b/pkgs/fixnum/lib/fixnum.dart new file mode 100644 index 00000000..fe21c479 --- /dev/null +++ b/pkgs/fixnum/lib/fixnum.dart @@ -0,0 +1,19 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/** + * Signed 32- and 64-bit integer support. + * + * The integer implementations in this library are designed to work + * identically whether executed on the Dart VM or compiled to JavaScript. + * + * For information on installing and importing this library, see the + * [fixnum package on pub.dartlang.org] + * (http://pub.dartlang.org/packages/fixnum). + */ +library fixnum; + +part 'src/intx.dart'; +part 'src/int32.dart'; +part 'src/int64.dart'; diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart new file mode 100644 index 00000000..f7e24aa3 --- /dev/null +++ b/pkgs/fixnum/lib/src/int32.dart @@ -0,0 +1,377 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +part of fixnum; + +/** + * An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1]. + * Arithmetic operations may overflow in order to maintain this range. + */ +class Int32 implements IntX { + + /** + * The maximum positive value attainable by an [Int32], namely + * 2147483647. + */ + static const Int32 MAX_VALUE = const Int32._internal(0x7FFFFFFF); + + /** + * The minimum positive value attainable by an [Int32], namely + * -2147483648. + */ + static const Int32 MIN_VALUE = const Int32._internal(-0x80000000); + + /** + * An [Int32] constant equal to 0. + */ + static const Int32 ZERO = const Int32._internal(0); + + /** + * An [Int32] constant equal to 1. + */ + static const Int32 ONE = const Int32._internal(1); + + /** + * An [Int32] constant equal to 2. + */ + static const Int32 TWO = const Int32._internal(2); + + // Hex digit char codes + static const int _CC_0 = 48; // '0'.codeUnitAt(0) + static const int _CC_9 = 57; // '9'.codeUnitAt(0) + static const int _CC_a = 97; // 'a'.codeUnitAt(0) + static const int _CC_z = 122; // 'z'.codeUnitAt(0) + static const int _CC_A = 65; // 'A'.codeUnitAt(0) + static const int _CC_Z = 90; // 'Z'.codeUnitAt(0) + + static int _decodeDigit(int c) { + if (c >= _CC_0 && c <= _CC_9) { + return c - _CC_0; + } else if (c >= _CC_a && c <= _CC_z) { + return c - _CC_a + 10; + } else if (c >= _CC_A && c <= _CC_Z) { + return c - _CC_A + 10; + } else { + return -1; // bad char code + } + } + + /** + * Parses a [String] in a given [radix] between 2 and 16 and returns an + * [Int32]. + */ + // TODO(rice) - Make this faster by converting several digits at once. + static Int32 parseRadix(String s, int radix) { + if ((radix <= 1) || (radix > 16)) { + throw new ArgumentError("Bad radix: $radix"); + } + Int32 x = ZERO; + for (int i = 0; i < s.length; i++) { + int c = s.codeUnitAt(i); + int digit = _decodeDigit(c); + if (digit < 0 || digit >= radix) { + throw new FormatException("Non-radix code unit: $c"); + } + x = (x * radix) + digit; + } + return x; + } + + /** + * Parses a decimal [String] and returns an [Int32]. + */ + static Int32 parseInt(String s) => new Int32(int.parse(s)); + + /** + * Parses a hexadecimal [String] and returns an [Int32]. + */ + static Int32 parseHex(String s) => parseRadix(s, 16); + + // Assumes i is <= 32-bit. + static int _bitCount(int i) { + // See "Hacker's Delight", section 5-1, "Counting 1-Bits". + + // The basic strategy is to use "divide and conquer" to + // add pairs (then quads, etc.) of bits together to obtain + // sub-counts. + // + // A straightforward approach would look like: + // + // i = (i & 0x55555555) + ((i >> 1) & 0x55555555); + // i = (i & 0x33333333) + ((i >> 2) & 0x33333333); + // i = (i & 0x0F0F0F0F) + ((i >> 4) & 0x0F0F0F0F); + // i = (i & 0x00FF00FF) + ((i >> 8) & 0x00FF00FF); + // i = (i & 0x0000FFFF) + ((i >> 16) & 0x0000FFFF); + // + // The code below removes unnecessary &'s and uses a + // trick to remove one instruction in the first line. + + i -= ((i >> 1) & 0x55555555); + i = (i & 0x33333333) + ((i >> 2) & 0x33333333); + i = ((i + (i >> 4)) & 0x0F0F0F0F); + i += (i >> 8); + i += (i >> 16); + return (i & 0x0000003F); + } + + // Assumes i is <= 32-bit + static int _numberOfLeadingZeros(int i) { + i |= i >> 1; + i |= i >> 2; + i |= i >> 4; + i |= i >> 8; + i |= i >> 16; + return _bitCount(~i); + } + + static int _numberOfTrailingZeros(int i) => _bitCount((i & -i) - 1); + + // The internal value, kept in the range [MIN_VALUE, MAX_VALUE]. + final int _i; + + const Int32._internal(int i) : _i = i; + + /** + * Constructs an [Int32] from an [int]. Only the low 32 bits of the input + * are used. + */ + Int32([int i=0]) : _i = (i & 0x7fffffff) - (i & 0x80000000); + + // Returns the [int] representation of the specified value. Throws + // [ArgumentError] for non-integer arguments. + int _toInt(val) { + if (val is Int32) { + return val._i; + } else if (val is int) { + return val; + } + throw new ArgumentError(val); + } + + // The +, -, * , &, |, and ^ operaters deal with types as follows: + // + // Int32 + int => Int32 + // Int32 + Int32 => Int32 + // Int32 + Int64 => Int64 + // + // The %, ~/ and remainder operators return an Int32 even with an Int64 + // argument, since the result cannot be greater than the value on the + // left-hand side: + // + // Int32 % int => Int32 + // Int32 % Int32 => Int32 + // Int32 % Int64 => Int32 + + IntX operator +(other) { + if (other is Int64) { + return this.toInt64() + other; + } + return new Int32(_i + _toInt(other)); + } + + IntX operator -(other) { + if (other is Int64) { + return this.toInt64() - other; + } + return new Int32(_i - _toInt(other)); + } + + Int32 operator -() => new Int32(-_i); + + IntX operator *(other) { + if (other is Int64) { + return this.toInt64() * other; + } + // TODO(rice) - optimize + return (this.toInt64() * other).toInt32(); + } + + Int32 operator %(other) { + if (other is Int64) { + // Result will be Int32 + return (this.toInt64() % other).toInt32(); + } + return new Int32(_i % _toInt(other)); + } + + Int32 operator ~/(other) { + if (other is Int64) { + return (this.toInt64() ~/ other).toInt32(); + } + return new Int32(_i ~/ _toInt(other)); + } + + Int32 remainder(other) { + if (other is Int64) { + Int64 t = this.toInt64(); + return (t - (t ~/ other) * other).toInt32(); + } + return this - (this ~/ other) * other; + } + + Int32 operator &(other) { + if (other is Int64) { + return (this.toInt64() & other).toInt32(); + } + return new Int32(_i & _toInt(other)); + } + + Int32 operator |(other) { + if (other is Int64) { + return (this.toInt64() | other).toInt32(); + } + return new Int32(_i | _toInt(other)); + } + + Int32 operator ^(other) { + if (other is Int64) { + return (this.toInt64() ^ other).toInt32(); + } + return new Int32(_i ^ _toInt(other)); + } + + Int32 operator ~() => new Int32(~_i); + + Int32 operator <<(int n) { + if (n < 0) { + throw new ArgumentError(n); + } + n &= 31; + return new Int32(_i << n); + } + + Int32 operator >>(int n) { + if (n < 0) { + throw new ArgumentError(n); + } + n &= 31; + int value; + if (_i >= 0) { + value = _i >> n; + } else { + value = (_i >> n) | (0xffffffff << (32 - n)); + } + return new Int32(value); + } + + Int32 shiftRightUnsigned(int n) { + if (n < 0) { + throw new ArgumentError(n); + } + n &= 31; + int value; + if (_i >= 0) { + value = _i >> n; + } else { + value = (_i >> n) & ((1 << (32 - n)) - 1); + } + return new Int32(value); + } + + /** + * Returns [:true:] if this [Int32] has the same numeric value as the + * given object. The argument may be an [int] or an [IntX]. + */ + bool operator ==(other) { + if (other is Int32) { + return _i == other._i; + } else if (other is Int64) { + return this.toInt64() == other; + } else if (other is int) { + return _i == other; + } + return false; + } + + int compareTo(Comparable other) { + if (other is Int64) { + return this.toInt64().compareTo(other); + } + return _i.compareTo(_toInt(other)); + } + + bool operator <(other) { + if (other is Int64) { + return this.toInt64() < other; + } + return _i < _toInt(other); + } + + bool operator <=(other) { + if (other is Int64) { + return this.toInt64() <= other; + } + return _i <= _toInt(other); + } + + bool operator >(other) { + if (other is Int64) { + return this.toInt64() > other; + } + return _i > _toInt(other); + } + + bool operator >=(other) { + if (other is Int64) { + return this.toInt64() >= other; + } + return _i >= _toInt(other); + } + + bool get isEven => (_i & 0x1) == 0; + bool get isMaxValue => _i == 2147483647; + bool get isMinValue => _i == -2147483648; + bool get isNegative => _i < 0; + bool get isOdd => (_i & 0x1) == 1; + bool get isZero => _i == 0; + int get bitLength => _i.bitLength; + + int get hashCode => _i; + + Int32 abs() => _i < 0 ? new Int32(-_i) : this; + + Int32 clamp(lowerLimit, upperLimit) { + if (this < lowerLimit) { + if (lowerLimit is IntX) return lowerLimit.toInt32(); + if (lowerLimit is int) return new Int32(lowerLimit); + throw new ArgumentError(lowerLimit); + } else if (this > upperLimit) { + if (upperLimit is IntX) return upperLimit.toInt32(); + if (upperLimit is int) return new Int32(upperLimit); + throw new ArgumentError(upperLimit); + } + return this; + } + + int numberOfLeadingZeros() => _numberOfLeadingZeros(_i); + int numberOfTrailingZeros() => _numberOfTrailingZeros(_i); + + Int32 toSigned(int width) { + if (width < 1 || width > 32) throw new ArgumentError(width); + return new Int32(_i.toSigned(width)); + } + + Int32 toUnsigned(int width) { + if (width < 0 || width > 32) throw new ArgumentError(width); + return new Int32(_i.toUnsigned(width)); + } + + List toBytes() { + List result = new List(4); + result[0] = _i & 0xff; + result[1] = (_i >> 8) & 0xff; + result[2] = (_i >> 16) & 0xff; + result[3] = (_i >> 24) & 0xff; + return result; + } + + double toDouble() => _i.toDouble(); + int toInt() => _i; + Int32 toInt32() => this; + Int64 toInt64() => new Int64(_i); + + String toString() => _i.toString(); + String toHexString() => _i.toRadixString(16); + String toRadixString(int radix) => _i.toRadixString(radix); +} diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart new file mode 100644 index 00000000..de306564 --- /dev/null +++ b/pkgs/fixnum/lib/src/int64.dart @@ -0,0 +1,1053 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +part of fixnum; + +/** + * An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1]. + * Arithmetic operations may overflow in order to maintain this range. + */ +class Int64 implements IntX { + + // A 64-bit integer is represented internally as three non-negative + // integers, storing the 22 low, 22 middle, and 20 high bits of the + // 64-bit value. _l (low) and _m (middle) are in the range + // [0, 2^22 - 1] and _h (high) is in the range [0, 2^20 - 1]. + // + // The values being assigned to _l, _m and _h in initialization are masked to + // force them into the above ranges. Sometimes we know that the value is a + // small non-negative integer but the dart2js compiler can't infer that, so a + // few of the masking operations are not needed for correctness but are + // helpful for dart2js code quality. + + final int _l, _m, _h; + + // Note: several functions require _BITS == 22 -- do not change this value. + static const int _BITS = 22; + static const int _BITS01 = 44; // 2 * _BITS + static const int _BITS2 = 20; // 64 - _BITS01 + static const int _MASK = 4194303; // (1 << _BITS) - 1 + static const int _MASK2 = 1048575; // (1 << _BITS2) - 1 + static const int _SIGN_BIT = 19; // _BITS2 - 1 + static const int _SIGN_BIT_MASK = 524288; // 1 << _SIGN_BIT + + /** + * The maximum positive value attainable by an [Int64], namely + * 9,223,372,036,854,775,807. + */ + static const Int64 MAX_VALUE = const Int64._bits(_MASK, _MASK, _MASK2 >> 1); + + /** + * The minimum positive value attainable by an [Int64], namely + * -9,223,372,036,854,775,808. + */ + static const Int64 MIN_VALUE = const Int64._bits(0, 0, _SIGN_BIT_MASK); + + /** + * An [Int64] constant equal to 0. + */ + static const Int64 ZERO = const Int64._bits(0, 0, 0); + + /** + * An [Int64] constant equal to 1. + */ + static const Int64 ONE = const Int64._bits(1, 0, 0); + + /** + * An [Int64] constant equal to 2. + */ + static const Int64 TWO = const Int64._bits(2, 0, 0); + + /** + * Constructs an [Int64] with a given bitwise representation. No validation + * is performed. + */ + const Int64._bits(int this._l, int this._m, int this._h); + + /** + * Parses a [String] in a given [radix] between 2 and 36 and returns an + * [Int64]. + */ + static Int64 parseRadix(String s, int radix) { + if ((radix <= 1) || (radix > 36)) { + throw new ArgumentError("Bad radix: $radix"); + } + return _parseRadix(s, radix); + } + + static Int64 _parseRadix(String s, int radix) { + int i = 0; + bool negative = false; + if (s[0] == '-') { + negative = true; + i++; + } + int d0 = 0, d1 = 0, d2 = 0; // low, middle, high components. + for (; i < s.length; i++) { + int c = s.codeUnitAt(i); + int digit = Int32._decodeDigit(c); + if (digit < 0 || digit >= radix) { + throw new FormatException("Non-radix char code: $c"); + } + + // [radix] and [digit] are at most 6 bits, component is 22, so we can + // multiply and add within 30 bit temporary values. + d0 = d0 * radix + digit; + int carry = d0 >> _BITS; + d0 = _MASK & d0; + + d1 = d1 * radix + carry; + carry = d1 >> _BITS; + d1 = _MASK & d1;; + + d2 = d2 * radix + carry; + d2 = _MASK2 & d2; + } + + if (negative) return _negate(d0, d1, d2); + + return new Int64._bits(d0, d1, d2); + } + + /** + * Parses a decimal [String] and returns an [Int64]. + */ + static Int64 parseInt(String s) => _parseRadix(s, 10); + + /** + * Parses a hexadecimal [String] and returns an [Int64]. + */ + static Int64 parseHex(String s) => _parseRadix(s, 16); + + // + // Public constructors + // + + /** + * Constructs an [Int64] with a given [int] value; zero by default. + */ + factory Int64([int value=0]) { + int v0 = 0, v1 = 0, v2 = 0; + bool negative = false; + if (value < 0) { + negative = true; + value = -value - 1; + } + if (_haveBigInts) { + v0 = _MASK & value; + v1 = _MASK & (value >> _BITS); + v2 = _MASK2 & (value >> _BITS01); + } else { + // Avoid using bitwise operations that coerce their input to 32 bits. + v2 = value ~/ 17592186044416; // 2^44 + value -= v2 * 17592186044416; + v1 = value ~/ 4194304; // 2^22 + value -= v1 * 4194304; + v0 = value; + } + + if (negative) { + v0 = ~v0; + v1 = ~v1; + v2 = ~v2; + } + return Int64._masked(v0, v1, v2); + } + + factory Int64.fromBytes(List bytes) { + int top = bytes[7] & 0xff; + top <<= 8; + top |= bytes[6] & 0xff; + top <<= 8; + top |= bytes[5] & 0xff; + top <<= 8; + top |= bytes[4] & 0xff; + + int bottom = bytes[3] & 0xff; + bottom <<= 8; + bottom |= bytes[2] & 0xff; + bottom <<= 8; + bottom |= bytes[1] & 0xff; + bottom <<= 8; + bottom |= bytes[0] & 0xff; + + return new Int64.fromInts(top, bottom); + } + + factory Int64.fromBytesBigEndian(List bytes) { + int top = bytes[0] & 0xff; + top <<= 8; + top |= bytes[1] & 0xff; + top <<= 8; + top |= bytes[2] & 0xff; + top <<= 8; + top |= bytes[3] & 0xff; + + int bottom = bytes[4] & 0xff; + bottom <<= 8; + bottom |= bytes[5] & 0xff; + bottom <<= 8; + bottom |= bytes[6] & 0xff; + bottom <<= 8; + bottom |= bytes[7] & 0xff; + + return new Int64.fromInts(top, bottom); + } + + /** + * Constructs an [Int64] from a pair of 32-bit integers having the value + * [:((top & 0xffffffff) << 32) | (bottom & 0xffffffff):]. + */ + factory Int64.fromInts(int top, int bottom) { + top &= 0xffffffff; + bottom &= 0xffffffff; + int d0 = bottom & _MASK; + int d1 = ((top & 0xfff) << 10) | ((bottom >> _BITS) & 0x3ff); + int d2 = (top >> 12) & _MASK2; + return new Int64._bits(d0, d1, d2); + } + + // Returns the [Int64] representation of the specified value. Throws + // [ArgumentError] for non-integer arguments. + static Int64 _promote(val) { + if (val is Int64) { + return val; + } else if (val is int) { + return new Int64(val); + } else if (val is Int32) { + return val.toInt64(); + } + throw new ArgumentError(val); + } + + Int64 operator +(other) { + Int64 o = _promote(other); + int sum0 = _l + o._l; + int sum1 = _m + o._m + (sum0 >> _BITS); + int sum2 = _h + o._h + (sum1 >> _BITS); + return Int64._masked(sum0, sum1, sum2); + } + + Int64 operator -(other) { + Int64 o = _promote(other); + return _sub(_l, _m, _h, o._l, o._m, o._h); + } + + Int64 operator -() => _negate(_l, _m, _h); + + Int64 operator *(other) { + Int64 o = _promote(other); + + // Grab 13-bit chunks. + int a0 = _l & 0x1fff; + int a1 = (_l >> 13) | ((_m & 0xf) << 9); + int a2 = (_m >> 4) & 0x1fff; + int a3 = (_m >> 17) | ((_h & 0xff) << 5); + int a4 = (_h & 0xfff00) >> 8; + + int b0 = o._l & 0x1fff; + int b1 = (o._l >> 13) | ((o._m & 0xf) << 9); + int b2 = (o._m >> 4) & 0x1fff; + int b3 = (o._m >> 17) | ((o._h & 0xff) << 5); + int b4 = (o._h & 0xfff00) >> 8; + + // Compute partial products. + // Optimization: if b is small, avoid multiplying by parts that are 0. + int p0 = a0 * b0; // << 0 + int p1 = a1 * b0; // << 13 + int p2 = a2 * b0; // << 26 + int p3 = a3 * b0; // << 39 + int p4 = a4 * b0; // << 52 + + if (b1 != 0) { + p1 += a0 * b1; + p2 += a1 * b1; + p3 += a2 * b1; + p4 += a3 * b1; + } + if (b2 != 0) { + p2 += a0 * b2; + p3 += a1 * b2; + p4 += a2 * b2; + } + if (b3 != 0) { + p3 += a0 * b3; + p4 += a1 * b3; + } + if (b4 != 0) { + p4 += a0 * b4; + } + + // Accumulate into 22-bit chunks: + // .........................................c10|...................c00| + // |....................|..................xxxx|xxxxxxxxxxxxxxxxxxxxxx| p0 + // |....................|......................|......................| + // |....................|...................c11|......c01.............| + // |....................|....xxxxxxxxxxxxxxxxxx|xxxxxxxxx.............| p1 + // |....................|......................|......................| + // |.................c22|...............c12....|......................| + // |..........xxxxxxxxxx|xxxxxxxxxxxxxxxxxx....|......................| p2 + // |....................|......................|......................| + // |.................c23|..c13.................|......................| + // |xxxxxxxxxxxxxxxxxxxx|xxxxx.................|......................| p3 + // |....................|......................|......................| + // |.........c24........|......................|......................| + // |xxxxxxxxxxxx........|......................|......................| p4 + + int c00 = p0 & 0x3fffff; + int c01 = (p1 & 0x1ff) << 13; + int c0 = c00 + c01; + + int c10 = p0 >> 22; + int c11 = p1 >> 9; + int c12 = (p2 & 0x3ffff) << 4; + int c13 = (p3 & 0x1f) << 17; + int c1 = c10 + c11 + c12 + c13; + + int c22 = p2 >> 18; + int c23 = p3 >> 5; + int c24 = (p4 & 0xfff) << 8; + int c2 = c22 + c23 + c24; + + // Propagate high bits from c0 -> c1, c1 -> c2. + c1 += c0 >> _BITS; + c0 &= _MASK; + c2 += c1 >> _BITS; + c1 &= _MASK; + c2 &= _MASK2; + + return new Int64._bits(c0, c1, c2); + } + + Int64 operator %(other) => _divide(this, other, _RETURN_MOD); + + Int64 operator ~/(other) => _divide(this, other, _RETURN_DIV); + + Int64 remainder(other) => _divide(this, other, _RETURN_REM); + + Int64 operator &(other) { + Int64 o = _promote(other); + int a0 = _l & o._l; + int a1 = _m & o._m; + int a2 = _h & o._h; + return new Int64._bits(a0, a1, a2); + } + + Int64 operator |(other) { + Int64 o = _promote(other); + int a0 = _l | o._l; + int a1 = _m | o._m; + int a2 = _h | o._h; + return new Int64._bits(a0, a1, a2); + } + + Int64 operator ^(other) { + Int64 o = _promote(other); + int a0 = _l ^ o._l; + int a1 = _m ^ o._m; + int a2 = _h ^ o._h; + return new Int64._bits(a0, a1, a2); + } + + Int64 operator ~() { + return Int64._masked(~_l, ~_m, ~_h); + } + + Int64 operator <<(int n) { + if (n < 0) { + throw new ArgumentError(n); + } + n &= 63; + + int res0, res1, res2; + if (n < _BITS) { + res0 = _l << n; + res1 = (_m << n) | (_l >> (_BITS - n)); + res2 = (_h << n) | (_m >> (_BITS - n)); + } else if (n < _BITS01) { + res0 = 0; + res1 = _l << (n - _BITS); + res2 = (_m << (n - _BITS)) | (_l >> (_BITS01 - n)); + } else { + res0 = 0; + res1 = 0; + res2 = _l << (n - _BITS01); + } + + return Int64._masked(res0, res1, res2); + } + + Int64 operator >>(int n) { + if (n < 0) { + throw new ArgumentError(n); + } + n &= 63; + + int res0, res1, res2; + + // Sign extend h(a). + int a2 = _h; + bool negative = (a2 & _SIGN_BIT_MASK) != 0; + if (negative && _MASK > _MASK2) { + // Add extra one bits on the left so the sign gets shifted into the wider + // lower words. + a2 += (_MASK - _MASK2); + } + + if (n < _BITS) { + res2 = _shiftRight(a2, n); + if (negative) { + res2 |= _MASK2 & ~(_MASK2 >> n); + } + res1 = _shiftRight(_m, n) | (a2 << (_BITS - n)); + res0 = _shiftRight(_l, n) | (_m << (_BITS - n)); + } else if (n < _BITS01) { + res2 = negative ? _MASK2 : 0; + res1 = _shiftRight(a2, n - _BITS); + if (negative) { + res1 |= _MASK & ~(_MASK >> (n - _BITS)); + } + res0 = _shiftRight(_m, n - _BITS) | (a2 << (_BITS01 - n)); + } else { + res2 = negative ? _MASK2 : 0; + res1 = negative ? _MASK : 0; + res0 = _shiftRight(a2, n - _BITS01); + if (negative) { + res0 |= _MASK & ~(_MASK >> (n - _BITS01)); + } + } + + return Int64._masked(res0, res1, res2); + } + + Int64 shiftRightUnsigned(int n) { + if (n < 0) { + throw new ArgumentError(n); + } + n &= 63; + + int res0, res1, res2; + int a2 = _MASK2 & _h; // Ensure a2 is positive. + if (n < _BITS) { + res2 = a2 >> n; + res1 = (_m >> n) | (a2 << (_BITS - n)); + res0 = (_l >> n) | (_m << (_BITS - n)); + } else if (n < _BITS01) { + res2 = 0; + res1 = a2 >> (n - _BITS); + res0 = (_m >> (n - _BITS)) | (_h << (_BITS01 - n)); + } else { + res2 = 0; + res1 = 0; + res0 = a2 >> (n - _BITS01); + } + + return Int64._masked(res0, res1, res2); + } + + /** + * Returns [:true:] if this [Int64] has the same numeric value as the + * given object. The argument may be an [int] or an [IntX]. + */ + bool operator ==(other) { + Int64 o; + if (other is Int64) { + o = other; + } else if (other is int) { + if (_h == 0 && _m == 0) return _l == other; + // Since we know one of [_h] or [_m] is non-zero, if [other] fits in the + // low word then it can't be numerically equal. + if ((_MASK & other) == other) return false; + o = new Int64(other); + } else if (other is Int32) { + o = other.toInt64(); + } + if (o != null) { + return _l == o._l && _m == o._m && _h == o._h; + } + return false; + } + + int compareTo(Comparable other) { + Int64 o = _promote(other); + int signa = _h >> (_BITS2 - 1); + int signb = o._h >> (_BITS2 - 1); + if (signa != signb) { + return signa == 0 ? 1 : -1; + } + if (_h > o._h) { + return 1; + } else if (_h < o._h) { + return -1; + } + if (_m > o._m) { + return 1; + } else if (_m < o._m) { + return -1; + } + if (_l > o._l) { + return 1; + } else if (_l < o._l) { + return -1; + } + return 0; + } + + bool operator <(other) { + return this.compareTo(other) < 0; + } + + bool operator <=(other) { + return this.compareTo(other) <= 0; + } + + bool operator >(other) { + return this.compareTo(other) > 0; + } + + bool operator >=(other) { + return this.compareTo(other) >= 0; + } + + bool get isEven => (_l & 0x1) == 0; + bool get isMaxValue => (_h == _MASK2 >> 1) && _m == _MASK && _l == _MASK; + bool get isMinValue => _h == _SIGN_BIT_MASK && _m == 0 && _l == 0; + bool get isNegative => (_h & _SIGN_BIT_MASK) != 0; + bool get isOdd => (_l & 0x1) == 1; + bool get isZero => _h == 0 && _m == 0 && _l == 0; + + int get bitLength { + if (isZero) return 0; + int a0 = _l, a1 = _m, a2 = _h; + if (isNegative) { + a0 = _MASK & ~a0; + a1 = _MASK & ~a1; + a2 = _MASK2 & ~a2; + } + if (a2 != 0) return _BITS01 + a2.bitLength; + if (a1 != 0) return _BITS + a1.bitLength; + return a0.bitLength; + } + + /** + * Returns a hash code based on all the bits of this [Int64]. + */ + int get hashCode { + // TODO(sra): Should we ensure that hashCode values match corresponding int? + // i.e. should `new Int64(x).hashCode == x.hashCode`? + int bottom = ((_m & 0x3ff) << _BITS) | _l; + int top = (_h << 12) | ((_m >> 10) & 0xfff); + return bottom ^ top; + } + + Int64 abs() { + return this.isNegative ? -this : this; + } + + Int64 clamp(lowerLimit, upperLimit) { + Int64 lower = _promote(lowerLimit); + Int64 upper = _promote(upperLimit); + if (this < lower) return lower; + if (this > upper) return upper; + return this; + } + + /** + * Returns the number of leading zeros in this [Int64] as an [int] + * between 0 and 64. + */ + int numberOfLeadingZeros() { + int b2 = Int32._numberOfLeadingZeros(_h); + if (b2 == 32) { + int b1 = Int32._numberOfLeadingZeros(_m); + if (b1 == 32) { + return Int32._numberOfLeadingZeros(_l) + 32; + } else { + return b1 + _BITS2 - (32 - _BITS); + } + } else { + return b2 - (32 - _BITS2); + } + } + + /** + * Returns the number of trailing zeros in this [Int64] as an [int] + * between 0 and 64. + */ + int numberOfTrailingZeros() { + int zeros = Int32._numberOfTrailingZeros(_l); + if (zeros < 32) { + return zeros; + } + + zeros = Int32._numberOfTrailingZeros(_m); + if (zeros < 32) { + return _BITS + zeros; + } + + zeros = Int32._numberOfTrailingZeros(_h); + if (zeros < 32) { + return _BITS01 + zeros; + } + // All zeros + return 64; + } + + Int64 toSigned(int width) { + if (width < 1 || width > 64) throw new ArgumentError(width); + if (width > _BITS01) { + return Int64._masked(_l, _m, _h.toSigned(width - _BITS01)); + } else if (width > _BITS) { + int m = _m.toSigned(width - _BITS); + return m.isNegative + ? Int64._masked(_l, m, _MASK2) + : Int64._masked(_l, m, 0); // Masking for type inferrer. + } else { + int l = _l.toSigned(width); + return l.isNegative + ? Int64._masked(l, _MASK, _MASK2) + : Int64._masked(l, 0, 0); // Masking for type inferrer. + } + } + + Int64 toUnsigned(int width) { + if (width < 0 || width > 64) throw new ArgumentError(width); + if (width > _BITS01) { + int h = _h.toUnsigned(width - _BITS01); + return Int64._masked(_l, _m, h); + } else if (width > _BITS) { + int m = _m.toUnsigned(width - _BITS); + return Int64._masked(_l, m, 0); + } else { + int l = _l.toUnsigned(width); + return Int64._masked(l, 0, 0); + } + } + + List toBytes() { + List result = new List(8); + result[0] = _l & 0xff; + result[1] = (_l >> 8) & 0xff; + result[2] = ((_m << 6) & 0xfc) | ((_l >> 16) & 0x3f); + result[3] = (_m >> 2) & 0xff; + result[4] = (_m >> 10) & 0xff; + result[5] = ((_h << 4) & 0xf0) | ((_m >> 18) & 0xf); + result[6] = (_h >> 4) & 0xff; + result[7] = (_h >> 12) & 0xff; + return result; + } + + double toDouble() => toInt().toDouble(); + + int toInt() { + int l = _l; + int m = _m; + int h = _h; + bool negative = false; + if ((_h & _SIGN_BIT_MASK) != 0) { + l = _MASK & ~_l; + m = _MASK & ~_m; + h = _MASK2 & ~_h; + negative = true; + } + + if (_haveBigInts) { + int result = (h << _BITS01) | (m << _BITS) | l; + return negative ? -result - 1 : result; + } else { + if (negative) { + return -((l + 1) + (m * 4194304) + (h * 17592186044416)); + } else { + return (l + (m * 4194304)) + (h * 17592186044416); + } + } + } + + /** + * Returns an [Int32] containing the low 32 bits of this [Int64]. + */ + Int32 toInt32() { + return new Int32(((_m & 0x3ff) << _BITS) | _l); + } + + /** + * Returns [this]. + */ + Int64 toInt64() => this; + + /** + * Returns the value of this [Int64] as a decimal [String]. + */ + String toString() => _toRadixString(10); + + // TODO(rice) - Make this faster by avoiding arithmetic. + String toHexString() { + if (isZero) return "0"; + Int64 x = this; + String hexStr = ""; + Int64 digit_f = new Int64(0xf); + while (!x.isZero) { + int digit = x._l & 0xf; + hexStr = "${_hexDigit(digit)}$hexStr"; + x = x.shiftRightUnsigned(4); + } + return hexStr; + } + + String toRadixString(int radix) { + if ((radix <= 1) || (radix > 36)) { + throw new ArgumentError("Bad radix: $radix"); + } + return _toRadixString(radix); + } + + String _toRadixString(int radix) { + int d0 = _l; + int d1 = _m; + int d2 = _h; + + if (d0 == 0 && d1 == 0 && d2 == 0) return '0'; + + String sign = ''; + if ((d2 & _SIGN_BIT_MASK) != 0) { + sign = '-'; + + // Negate in-place. + d0 = 0 - d0; + int borrow = (d0 >> _BITS) & 1; + d0 &= _MASK; + d1 = 0 - d1 - borrow; + borrow = (d1 >> _BITS) & 1; + d1 &= _MASK; + d2 = 0 - d2 - borrow; + d2 &= _MASK2; + // d2, d1, d0 now are an unsigned 64 bit integer for MIN_VALUE and an + // unsigned 63 bit integer for other values. + } + + // Rearrange components into five components where all but the most + // significant are 10 bits wide. + // + // d4, d3, d4, d1, d0: 24 + 10 + 10 + 10 + 10 bits + // + // The choice of 10 bits allows a remainder of 20 bits to be scaled by 10 + // bits and added during division while keeping all intermediate values + // within 30 bits (unsigned small integer range for 32 bit implementations + // of Dart VM and V8). + // + // 6 6 5 4 3 2 1 + // 3210987654321098765432109876543210987654321098765432109876543210 + // [--------d2--------][---------d1---------][---------d0---------] + // --> + // [----------d4----------][---d3---][---d2---][---d1---][---d0---] + + + int d4 = (d2 << 4) | (d1 >> 18); + int d3 = (d1 >> 8) & 0x3ff; + d2 = ((d1 << 2) | (d0 >> 20)) & 0x3ff; + d1 = (d0 >> 10) & 0x3ff; + d0 = d0 & 0x3ff; + + int fatRadix = _fatRadixTable[radix]; + + // Generate chunks of digits. In radix 10, generate 6 digits per chunk. + // + // This loop generates at most 3 chunks, so we store the chunks in locals + // rather than a list. We are trying to generate digits 20 bits at a time + // until we have only 30 bits left. 20 + 20 + 30 > 64 would imply that we + // need only two chunks, but radix values 17-19 and 33-36 generate only 15 + // or 16 bits per iteration, so sometimes the third chunk is needed. + + String chunk1 = "", chunk2 = "", chunk3 = ""; + + while (!(d4 == 0 && d3 == 0)) { + int q = d4 ~/ fatRadix; + int r = d4 - q * fatRadix; + d4 = q; + d3 += r << 10; + + q = d3 ~/ fatRadix; + r = d3 - q * fatRadix; + d3 = q; + d2 += r << 10; + + q = d2 ~/ fatRadix; + r = d2 - q * fatRadix; + d2 = q; + d1 += r << 10; + + q = d1 ~/ fatRadix; + r = d1 - q * fatRadix; + d1 = q; + d0 += r << 10; + + q = d0 ~/ fatRadix; + r = d0 - q * fatRadix; + d0 = q; + + assert(chunk3 == ""); + chunk3 = chunk2; + chunk2 = chunk1; + // Adding [fatRadix] Forces an extra digit which we discard to get a fixed + // width. E.g. (1000000 + 123) -> "1000123" -> "000123". An alternative + // would be to pad to the left with zeroes. + chunk1 = (fatRadix + r).toRadixString(radix).substring(1); + } + int residue = (d2 << 20) + (d1 << 10) + d0; + String leadingDigits = residue == 0 ? '' : residue.toRadixString(radix); + return '$sign$leadingDigits$chunk1$chunk2$chunk3'; + } + + // Table of 'fat' radix values. Each entry for index `i` is the largest power + // of `i` whose remainder fits in 20 bits. + static const _fatRadixTable = const [ + 0, + 0, + 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 + * 2, + 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3, + 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4, + 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, + 6 * 6 * 6 * 6 * 6 * 6 * 6, + 7 * 7 * 7 * 7 * 7 * 7 * 7, + 8 * 8 * 8 * 8 * 8 * 8, + 9 * 9 * 9 * 9 * 9 * 9, + 10 * 10 * 10 * 10 * 10 * 10, + 11 * 11 * 11 * 11 * 11, + 12 * 12 * 12 * 12 * 12, + 13 * 13 * 13 * 13 * 13, + 14 * 14 * 14 * 14 * 14, + 15 * 15 * 15 * 15 * 15, + 16 * 16 * 16 * 16 * 16, + 17 * 17 * 17 * 17, + 18 * 18 * 18 * 18, + 19 * 19 * 19 * 19, + 20 * 20 * 20 * 20, + 21 * 21 * 21 * 21, + 22 * 22 * 22 * 22, + 23 * 23 * 23 * 23, + 24 * 24 * 24 * 24, + 25 * 25 * 25 * 25, + 26 * 26 * 26 * 26, + 27 * 27 * 27 * 27, + 28 * 28 * 28 * 28, + 29 * 29 * 29 * 29, + 30 * 30 * 30 * 30, + 31 * 31 * 31 * 31, + 32 * 32 * 32 * 32, + 33 * 33 * 33, + 34 * 34 * 34, + 35 * 35 * 35, + 36 * 36 * 36 + ]; + + String toDebugString() { + return "Int64[_l=$_l, _m=$_m, _h=$_h]"; + } + + + static Int64 _masked(int a0, int a1, int a2) => + new Int64._bits(_MASK & a0, _MASK & a1, _MASK2 & a2); + + static Int64 _sub(int a0, int a1, int a2, int b0, int b1, int b2) { + int diff0 = a0 - b0; + int diff1 = a1 - b1 - ((diff0 >> _BITS) & 1); + int diff2 = a2 - b2 - ((diff1 >> _BITS) & 1); + return _masked(diff0, diff1, diff2); + } + + static Int64 _negate(int b0, int b1, int b2) { + return _sub(0, 0, 0, b0, b1, b2); + } + + // Determine whether the platform supports ints greater than 2^53 + // without loss of precision. + static bool _haveBigIntsCached = null; + + static bool get _haveBigInts { + if (_haveBigIntsCached == null) { + var x = 9007199254740992; + // Defeat compile-time constant folding. + if (2 + 2 != 4) { + x = 0; + } + var y = x + 1; + var same = y == x; + _haveBigIntsCached = !same; + } + return _haveBigIntsCached; + } + + String _hexDigit(int digit) => "0123456789ABCDEF"[digit]; + + + // Work around dart2js bugs with negative arguments to '>>' operator. + static int _shiftRight(int x, int n) { + if (x >= 0) { + return x >> n; + } else { + int shifted = x >> n; + if (shifted >= 0x80000000) { + shifted -= 4294967296; + } + return shifted; + } + } + + + // Implementation of '~/', '%' and 'remainder'. + + static Int64 _divide(Int64 a, other, int what) { + Int64 b = _promote(other); + if (b.isZero) { + throw new IntegerDivisionByZeroException(); + } + if (a.isZero) return ZERO; + + bool aNeg = a.isNegative; + bool bNeg = b.isNegative; + a = a.abs(); + b = b.abs(); + + int a0 = a._l; + int a1 = a._m; + int a2 = a._h; + + int b0 = b._l; + int b1 = b._m; + int b2 = b._h; + return _divideHelper(a0, a1, a2, aNeg, b0, b1, b2, bNeg, what); + } + + static const _RETURN_DIV = 1; + static const _RETURN_REM = 2; + static const _RETURN_MOD = 3; + + static _divideHelper( + // up to 64 bits unsigned in a2/a1/a0 and b2/b1/b0 + int a0, int a1, int a2, bool aNeg, // input A. + int b0, int b1, int b2, bool bNeg, // input B. + int what) { + int q0 = 0, q1 = 0, q2 = 0; // result Q. + int r0 = 0, r1 = 0, r2 = 0; // result R. + + if (b2 == 0 && b1 == 0 && b0 < (1 << (30 - _BITS))) { + // Small divisor can be handled by single-digit division within Smi range. + // + // Handling small divisors here helps the estimate version below by + // handling cases where the estimate is off by more than a small amount. + + q2 = a2 ~/ b0; + int carry = a2 - q2 * b0; + int d1 = a1 + (carry << _BITS); + q1 = d1 ~/ b0; + carry = d1 - q1 * b0; + int d0 = a0 + (carry << _BITS); + q0 = d0 ~/ b0; + r0 = d0 - q0 * b0; + } else { + // Approximate Q = A ~/ B and R = A - Q * B using doubles. + + // The floating point approximation is very close to the correct value + // when floor(A/B) fits in fewer that 53 bits. + + // We use double arithmetic for intermediate values. Double arithmetic on + // non-negative values is exact under the following conditions: + // + // - The values are integer values that fit in 53 bits. + // - Dividing by powers of two (adjusts exponent only). + // - Floor (zeroes bits with fractional weight). + + const double K2 = 17592186044416.0; // 2^44 + const double K1 = 4194304.0; // 2^22 + + // Approximate double values for [a] and [b]. + double ad = a0 + K1 * a1 + K2 * a2; + double bd = b0 + K1 * b1 + K2 * b2; + // Approximate quotient. + double qd = (ad / bd).floorToDouble(); + + // Extract components of [qd] using double arithmetic. + double q2d = (qd / K2).floorToDouble(); + qd = qd - K2 * q2d; + double q1d = (qd / K1).floorToDouble(); + double q0d = qd - K1 * q1d; + q2 = q2d.toInt(); + q1 = q1d.toInt(); + q0 = q0d.toInt(); + + assert(q0 + K1 * q1 + K2 * q2 == (ad / bd).floorToDouble()); + assert(q2 == 0 || b2 == 0); // Q and B can't both be big since Q*B <= A. + + // P = Q * B, using doubles to hold intermediates. + // We don't need all partial sums since Q*B <= A. + double p0d = q0d * b0; + double p0carry = (p0d / K1).floorToDouble(); + p0d = p0d - p0carry * K1; + double p1d = q1d * b0 + q0d * b1 + p0carry; + double p1carry = (p1d / K1).floorToDouble(); + p1d = p1d - p1carry * K1; + double p2d = q2d * b0 + q1d * b1 + q0d * b2 + p1carry; + assert(p2d <= _MASK2); // No partial sum overflow. + + // R = A - P + int diff0 = a0 - p0d.toInt(); + int diff1 = a1 - p1d.toInt() - ((diff0 >> _BITS) & 1); + int diff2 = a2 - p2d.toInt() - ((diff1 >> _BITS) & 1); + r0 = _MASK & diff0; + r1 = _MASK & diff1; + r2 = _MASK2 & diff2; + + // while (R < 0 || R >= B) + // adjust R towards [0, B) + while ( + r2 >= _SIGN_BIT_MASK || + r2 > b2 || + (r2 == b2 && (r1 > b1 || (r1 == b1 && r0 >= b0)))) { + // Direction multiplier for adjustment. + int m = (r2 & _SIGN_BIT_MASK) == 0 ? 1 : -1; + // R = R - B or R = R + B + int d0 = r0 - m * b0; + int d1 = r1 - m * (b1 + ((d0 >> _BITS) & 1)); + int d2 = r2 - m * (b2 + ((d1 >> _BITS) & 1)); + r0 = _MASK & d0; + r1 = _MASK & d1; + r2 = _MASK2 & d2; + + // Q = Q + 1 or Q = Q - 1 + d0 = q0 + m; + d1 = q1 + m * ((d0 >> _BITS) & 1); + d2 = q2 + m * ((d1 >> _BITS) & 1); + q0 = _MASK & d0; + q1 = _MASK & d1; + q2 = _MASK2 & d2; + } + } + + // 0 <= R < B + assert(Int64.ZERO <= new Int64._bits(r0, r1, r2)); + assert(r2 < b2 || // Handles case where B = -(MIN_VALUE) + new Int64._bits(r0, r1, r2) < new Int64._bits(b0, b1, b2)); + + assert(what == _RETURN_DIV || what == _RETURN_MOD || what == _RETURN_REM); + if (what == _RETURN_DIV) { + if (aNeg != bNeg) return _negate(q0, q1, q2); + return Int64._masked(q0, q1, q2); // Masking for type inferrer. + } + + if (!aNeg) { + return new Int64._bits(_MASK & r0, r1, r2); // Masking for type inferrer. + } + + if (what == _RETURN_MOD) { + if (r0 == 0 && r1 == 0 && r2 == 0) { + return ZERO; + } else { + return _sub(b0, b1, b2, r0, r1, r2); + } + } else { + return _negate(r0, r1, r2); + } + } +} diff --git a/pkgs/fixnum/lib/src/intx.dart b/pkgs/fixnum/lib/src/intx.dart new file mode 100644 index 00000000..859cb957 --- /dev/null +++ b/pkgs/fixnum/lib/src/intx.dart @@ -0,0 +1,237 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +part of fixnum; + +/** + * A fixed-precision integer. + */ +abstract class IntX implements Comparable { + + /** Addition operator. */ + IntX operator +(other); + + /** Subtraction operator. */ + IntX operator -(other); + + /** + * Negate operator. + * + * Note that `-MIN_VALUE` is equal to `MIN_VALUE` due to overflow. + */ + IntX operator -(); + + /** Multiplication operator. */ + IntX operator *(other); + + /** + * Euclidean modulo operator. + * + * Returns the remainder of the euclidean division. The euclidean division + * of two integers `a` and `b` yields two integers `q` and `r` such that + * `a == b * q + r` and `0 <= r < a.abs()`. + */ + IntX operator %(other); + + /** Truncating division operator. */ + IntX operator ~/(other); + + /** + * Returns the remainder of the truncating division of this integer by + * [other]. + */ + IntX remainder(other); + + /** Bitwise and operator. */ + IntX operator &(other); + + /** Bitwise or operator. */ + IntX operator |(other); + + /** Bitwise xor operator. */ + IntX operator ^(other); + + /** Bitwise negate operator. */ + IntX operator ~(); + + /** + * Left bit-shift operator. + * + * Returns the result of shifting the bits of this integer by [shiftAmount] + * bits to the left. Low-order bits are filled with zeros. + */ + IntX operator <<(int shiftAmount); + + /** + * Right bit-shift operator. + * + * Returns the result of shifting the bits of this integer by [shiftAmount] + * bits to the right. High-order bits are filled with zero in the case where + * this integer is positive, or one in the case where it is negative. + */ + IntX operator >>(int shiftAmount); + + /** + * Unsigned right-shift operator. + * + * Returns the result of shifting the bits of this integer by [shiftAmount] + * bits to the right. High-order bits are filled with zeros. + */ + IntX shiftRightUnsigned(int shiftAmount); + + int compareTo(Comparable other); + + /** + * Returns `true` if and only if [other] is an int or IntX equal in + * value to this integer. + */ + bool operator ==(other); + + /** Relational less than operator. */ + bool operator <(other); + + /** Relational less than or equal to operator. */ + bool operator <=(other); + + /** Relational greater than operator. */ + bool operator >(other); + + /** Relational greater than or equal to operator. */ + bool operator >=(other); + + /** Returns `true` if and only if this integer is even. */ + bool get isEven; + + /** + * Returns `true` if and only if this integer is the maximum signed value + * that can be represented within its bit size. + */ + bool get isMaxValue; + + /** + * Returns `true` if and only if this integer is the minimum signed value + * that can be represented within its bit size. + */ + bool get isMinValue; + + /** Returns `true` if and only if this integer is less than zero. */ + bool get isNegative; + + /** Returns `true` if and only if this integer is odd. */ + bool get isOdd; + + /** Returns `true` if and only if this integer is zero. */ + bool get isZero; + + int get hashCode; + + /** Returns the absolute value of this integer. */ + IntX abs(); + + /** Clamps this integer to be in the range [lowerLimit] - [upperLimit]. */ + IntX clamp(IntX lowerLimit, IntX upperLimit); + + /** + * Returns the minimum number of bits required to store this integer. + * + * The number of bits excludes the sign bit, which gives the natural length + * for non-negative (unsigned) values. Negative values are complemented to + * return the bit position of the first bit that differs from the sign bit. + * + * To find the the number of bits needed to store the value as a signed value, + * add one, i.e. use `x.bitLength + 1`. + */ + int get bitLength; + + /** + * Returns the number of high-order zeros in this integer's bit + * representation. + */ + int numberOfLeadingZeros(); + + /** + * Returns the number of low-order zeros in this integer's bit representation. + */ + int numberOfTrailingZeros(); + + /** + * Returns the least significant [width] bits of this integer, extending the + * highest retained bit to the sign. This is the same as truncating the value + * to fit in [width] bits using an signed 2-s complement representation. The + * returned value has the same bit value in all positions higher than [width]. + * + * If the input value fits in [width] bits without truncation, the result is + * the same as the input. The minimum width needed to avoid truncation of `x` + * is `x.bitLength + 1`, i.e. + * + * x == x.toSigned(x.bitLength + 1); + */ + IntX toSigned(int width); + + /** + * Returns the least significant [width] bits of this integer as a + * non-negative number (i.e. unsigned representation). The returned value has + * zeros in all bit positions higher than [width]. + * + * If the input fits in [width] bits without truncation, the result is the + * same as the input. The minimum width needed to avoid truncation of `x` is + * given by `x.bitLength`, i.e. + * + * x == x.toUnsigned(x.bitLength); + */ + IntX toUnsigned(int width); + + /** + * Returns a byte-sequence representation of this integer. + * + * Returns a list of int, starting with the least significant byte. + */ + List toBytes(); + + /** + * Returns the double representation of this integer. + * + * On some platforms, inputs with large absolute values (i.e., > 2^52) may + * lose some of their low-order bits. + */ + double toDouble(); + + /** + * Returns the int representation of this integer. + * + * On some platforms, inputs with large absolute values (i.e., > 2^52) may + * lose some of their low-order bits. + */ + int toInt(); + + /** + * Returns an Int32 representation of this integer. + * + * Narrower values are sign-extended and wider values have their high bits + * truncated. + */ + Int32 toInt32(); + + /** Returns an Int64 representation of this integer. */ + Int64 toInt64(); + + /** + * Returns a string representing the value of this integer in decimal + * notation; example: `'13'`. + */ + String toString(); + + /** + * Returns a string representing the value of this integer in hexadecimal + * notation; example: `'0xd'`. + */ + String toHexString(); + + /** + * Returns a string representing the value of this integer in the given radix. + * + * [radix] must be an integer in the range 2 .. 16, inclusive. + */ + String toRadixString(int radix); +} diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml new file mode 100644 index 00000000..7eb50c15 --- /dev/null +++ b/pkgs/fixnum/pubspec.yaml @@ -0,0 +1,9 @@ +name: fixnum +version: 0.9.0-dev+1 +author: Dart Team +description: Library for 32- and 64-bit fixed size integers. +homepage: http://www.dartlang.org +dev_dependencies: + unittest: ">=0.9.0 <0.10.0" +environment: + sdk: ">=0.8.10+6 <2.0.0" diff --git a/pkgs/fixnum/test/int_32_test.dart b/pkgs/fixnum/test/int_32_test.dart new file mode 100644 index 00000000..8ce78248 --- /dev/null +++ b/pkgs/fixnum/test/int_32_test.dart @@ -0,0 +1,367 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +library Int32test; +import 'package:fixnum/fixnum.dart'; +import 'package:unittest/unittest.dart'; + +void main() { + group("isX tests", () { + test("isEven", () { + expect((-Int32.ONE).isEven, false); + expect(Int32.ZERO.isEven, true); + expect(Int32.ONE.isEven, false); + expect(Int32.TWO.isEven, true); + }); + test("isMaxValue", () { + expect(Int32.MIN_VALUE.isMaxValue, false); + expect(Int32.ZERO.isMaxValue, false); + expect(Int32.MAX_VALUE.isMaxValue, true); + }); + test("isMinValue", () { + expect(Int32.MIN_VALUE.isMinValue, true); + expect(Int32.ZERO.isMinValue, false); + expect(Int32.MAX_VALUE.isMinValue, false); + }); + test("isNegative", () { + expect(Int32.MIN_VALUE.isNegative, true); + expect(Int32.ZERO.isNegative, false); + expect(Int32.ONE.isNegative, false); + }); + test("isOdd", () { + expect((-Int32.ONE).isOdd, true); + expect(Int32.ZERO.isOdd, false); + expect(Int32.ONE.isOdd, true); + expect(Int32.TWO.isOdd, false); + }); + test("isZero", () { + expect(Int32.MIN_VALUE.isZero, false); + expect(Int32.ZERO.isZero, true); + expect(Int32.MAX_VALUE.isZero, false); + }); + test("bitLength", () { + expect(new Int32(-2).bitLength, 1); + expect((-Int32.ONE).bitLength, 0); + expect(Int32.ZERO.bitLength, 0); + expect(Int32.ONE.bitLength, 1); + expect(new Int32(2).bitLength, 2); + expect(Int32.MAX_VALUE.bitLength, 31); + expect(Int32.MIN_VALUE.bitLength, 31); + }); + }); + + group("arithmetic operators", () { + Int32 n1 = new Int32(1234); + Int32 n2 = new Int32(9876); + Int32 n3 = new Int32(-1234); + Int32 n4 = new Int32(-9876); + Int32 n5 = new Int32(0x12345678); + Int32 n6 = new Int32(0x22222222); + + test("+", () { + expect(n1 + n2, new Int32(11110)); + expect(n3 + n2, new Int32(8642)); + expect(n3 + n4, new Int32(-11110)); + expect(Int32.MAX_VALUE + 1, Int32.MIN_VALUE); + expect(() => new Int32(17) + null, throws); + }); + + test("-", () { + expect(n1 - n2, new Int32(-8642)); + expect(n3 - n2, new Int32(-11110)); + expect(n3 - n4, new Int32(8642)); + expect(Int32.MIN_VALUE - 1, Int32.MAX_VALUE); + expect(() => new Int32(17) - null, throws); + }); + + test("unary -", () { + expect(-n1, new Int32(-1234)); + expect(-Int32.ZERO, Int32.ZERO); + }); + + test("*", () { + expect(n1 * n2, new Int32(12186984)); + expect(n2 * n3, new Int32(-12186984)); + expect(n3 * n3, new Int32(1522756)); + expect(n3 * n2, new Int32(-12186984)); + expect(new Int32(0x12345678) * new Int32(0x22222222), + new Int32(-899716112)); + expect((new Int32(123456789) * new Int32(987654321)), + new Int32(-67153019)); + expect(new Int32(0x12345678) * new Int64(0x22222222), + new Int64.fromInts(0x026D60DC, 0xCA5F6BF0)); + expect((new Int32(123456789) * 987654321), + new Int32(-67153019)); + expect(() => new Int32(17) * null, throws); + }); + + test("~/", () { + expect(new Int32(829893893) ~/ new Int32(1919), new Int32(432461)); + expect(new Int32(0x12345678) ~/ new Int32(0x22), + new Int32(0x12345678 ~/ 0x22)); + expect(new Int32(829893893) ~/ new Int64(1919), new Int32(432461)); + expect(new Int32(0x12345678) ~/ new Int64(0x22), + new Int32(0x12345678 ~/ 0x22)); + expect(new Int32(829893893) ~/ 1919, new Int32(432461)); + expect(() => new Int32(17) ~/ Int32.ZERO, throws); + expect(() => new Int32(17) ~/ null, throws); + }); + + test("%", () { + expect(new Int32(0x12345678) % new Int32(0x22), + new Int32(0x12345678 % 0x22)); + expect(new Int32(0x12345678) % new Int64(0x22), + new Int32(0x12345678 % 0x22)); + expect(() => new Int32(17) % null, throws); + }); + + test("remainder", () { + expect(new Int32(0x12345678).remainder(new Int32(0x22)), + new Int32(0x12345678.remainder(0x22))); + expect(new Int32(0x12345678).remainder(new Int32(-0x22)), + new Int32(0x12345678.remainder(-0x22))); + expect(new Int32(-0x12345678).remainder(new Int32(-0x22)), + new Int32(-0x12345678.remainder(-0x22))); + expect(new Int32(-0x12345678).remainder(new Int32(0x22)), + new Int32(-0x12345678.remainder(0x22))); + expect(new Int32(0x12345678).remainder(new Int64(0x22)), + new Int32(0x12345678.remainder(0x22))); + expect(() => new Int32(17).remainder(null), throws); + }); + + test("clamp", () { + Int32 val = new Int32(17); + expect(val.clamp(20, 30), new Int32(20)); + expect(val.clamp(10, 20), new Int32(17)); + expect(val.clamp(10, 15), new Int32(15)); + + expect(val.clamp(new Int32(20), new Int32(30)), new Int32(20)); + expect(val.clamp(new Int32(10), new Int32(20)), new Int32(17)); + expect(val.clamp(new Int32(10), new Int32(15)), new Int32(15)); + + expect(val.clamp(new Int64(20), new Int64(30)), new Int32(20)); + expect(val.clamp(new Int64(10), new Int64(20)), new Int32(17)); + expect(val.clamp(new Int64(10), new Int64(15)), new Int32(15)); + expect(val.clamp(Int64.MIN_VALUE, new Int64(30)), new Int32(17)); + expect(val.clamp(new Int64(10), Int64.MAX_VALUE), new Int32(17)); + + expect(() => val.clamp(1, 'b'), throwsA(isArgumentError)); + expect(() => val.clamp('a', 1), throwsA(isArgumentError)); + }); + }); + + group("comparison operators", () { + test("<", () { + expect(new Int32(17) < new Int32(18), true); + expect(new Int32(17) < new Int32(17), false); + expect(new Int32(17) < new Int32(16), false); + expect(new Int32(17) < new Int64(18), true); + expect(new Int32(17) < new Int64(17), false); + expect(new Int32(17) < new Int64(16), false); + expect(Int32.MIN_VALUE < Int32.MAX_VALUE, true); + expect(Int32.MAX_VALUE < Int32.MIN_VALUE, false); + expect(() => new Int32(17) < null, throws); + }); + + test("<=", () { + expect(new Int32(17) <= new Int32(18), true); + expect(new Int32(17) <= new Int32(17), true); + expect(new Int32(17) <= new Int32(16), false); + expect(new Int32(17) <= new Int64(18), true); + expect(new Int32(17) <= new Int64(17), true); + expect(new Int32(17) <= new Int64(16), false); + expect(Int32.MIN_VALUE <= Int32.MAX_VALUE, true); + expect(Int32.MAX_VALUE <= Int32.MIN_VALUE, false); + expect(() => new Int32(17) <= null, throws); + }); + + test("==", () { + expect(new Int32(17) == new Int32(18), false); + expect(new Int32(17) == new Int32(17), true); + expect(new Int32(17) == new Int32(16), false); + expect(new Int32(17) == new Int64(18), false); + expect(new Int32(17) == new Int64(17), true); + expect(new Int32(17) == new Int64(16), false); + expect(Int32.MIN_VALUE == Int32.MAX_VALUE, false); + expect(new Int32(17) == new Object(), false); + expect(new Int32(17) == null, false); + }); + + test(">=", () { + expect(new Int32(17) >= new Int32(18), false); + expect(new Int32(17) >= new Int32(17), true); + expect(new Int32(17) >= new Int32(16), true); + expect(new Int32(17) >= new Int64(18), false); + expect(new Int32(17) >= new Int64(17), true); + expect(new Int32(17) >= new Int64(16), true); + expect(Int32.MIN_VALUE >= Int32.MAX_VALUE, false); + expect(Int32.MAX_VALUE >= Int32.MIN_VALUE, true); + expect(() => new Int32(17) >= null, throws); + }); + + test(">", () { + expect(new Int32(17) > new Int32(18), false); + expect(new Int32(17) > new Int32(17), false); + expect(new Int32(17) > new Int32(16), true); + expect(new Int32(17) > new Int64(18), false); + expect(new Int32(17) > new Int64(17), false); + expect(new Int32(17) > new Int64(16), true); + expect(Int32.MIN_VALUE > Int32.MAX_VALUE, false); + expect(Int32.MAX_VALUE > Int32.MIN_VALUE, true); + expect(() => new Int32(17) > null, throws); + }); + }); + + group("bitwise operators", () { + test("&", () { + expect(new Int32(0x12345678) & new Int32(0x22222222), + new Int32(0x12345678 & 0x22222222)); + expect(new Int32(0x12345678) & new Int64(0x22222222), + new Int64(0x12345678 & 0x22222222)); + expect(() => new Int32(17) & null, throwsArgumentError); + }); + + test("|", () { + expect(new Int32(0x12345678) | new Int32(0x22222222), + new Int32(0x12345678 | 0x22222222)); + expect(new Int32(0x12345678) | new Int64(0x22222222), + new Int64(0x12345678 | 0x22222222)); + expect(() => new Int32(17) | null, throws); + }); + + test("^", () { + expect(new Int32(0x12345678) ^ new Int32(0x22222222), + new Int32(0x12345678 ^ 0x22222222)); + expect(new Int32(0x12345678) ^ new Int64(0x22222222), + new Int64(0x12345678 ^ 0x22222222)); + expect(() => new Int32(17) ^ null, throws); + }); + + test("~", () { + expect(~(new Int32(0x12345678)), new Int32(~0x12345678)); + expect(-(new Int32(0x12345678)), new Int64(-0x12345678)); + }); + }); + + group("bitshift operators", () { + test("<<", () { + expect(new Int32(0x12345678) << 7, new Int32(0x12345678 << 7)); + expect(() => new Int32(17) << -1, throwsArgumentError); + expect(() => new Int32(17) << null, throws); + }); + + test(">>", () { + expect(new Int32(0x12345678) >> 7, new Int32(0x12345678 >> 7)); + expect(() => new Int32(17) >> -1, throwsArgumentError); + expect(() => new Int32(17) >> null, throws); + }); + + test("shiftRightUnsigned", () { + expect(new Int32(0x12345678).shiftRightUnsigned(7), + new Int32(0x12345678 >> 7)); + expect(() => (new Int32(17).shiftRightUnsigned(-1)), throwsArgumentError); + expect(() => (new Int32(17).shiftRightUnsigned(null)), throws); + }); + }); + + group("conversions", () { + test("toSigned", () { + expect(Int32.ONE.toSigned(2), Int32.ONE); + expect(Int32.ONE.toSigned(1), -Int32.ONE); + expect(Int32.MAX_VALUE.toSigned(32), Int32.MAX_VALUE); + expect(Int32.MIN_VALUE.toSigned(32), Int32.MIN_VALUE); + expect(Int32.MAX_VALUE.toSigned(31), -Int32.ONE); + expect(Int32.MIN_VALUE.toSigned(31), Int32.ZERO); + expect(() => Int32.ONE.toSigned(0), throws); + expect(() => Int32.ONE.toSigned(33), throws); + }); + test("toUnsigned", () { + expect(Int32.ONE.toUnsigned(1), Int32.ONE); + expect(Int32.ONE.toUnsigned(0), Int32.ZERO); + expect(Int32.MAX_VALUE.toUnsigned(32), Int32.MAX_VALUE); + expect(Int32.MIN_VALUE.toUnsigned(32), Int32.MIN_VALUE); + expect(Int32.MAX_VALUE.toUnsigned(31), Int32.MAX_VALUE); + expect(Int32.MIN_VALUE.toUnsigned(31), Int32.ZERO); + expect(() => Int32.ONE.toUnsigned(-1), throws); + expect(() => Int32.ONE.toUnsigned(33), throws); + }); + test("toDouble", () { + expect(new Int32(17).toDouble(), same(17.0)); + expect(new Int32(-17).toDouble(), same(-17.0)); + }); + test("toInt", () { + expect(new Int32(17).toInt(), 17); + expect(new Int32(-17).toInt(), -17); + }); + test("toInt32", () { + expect(new Int32(17).toInt32(), new Int32(17)); + expect(new Int32(-17).toInt32(), new Int32(-17)); + }); + test("toInt64", () { + expect(new Int32(17).toInt64(), new Int64(17)); + expect(new Int32(-17).toInt64(), new Int64(-17)); + }); + }); + + group("parse", () { + test("base 10", () { + checkInt(int x) { + expect(Int32.parseRadix('$x', 10), new Int32(x)); + } + checkInt(0); + checkInt(1); + checkInt(1000); + checkInt(12345678); + checkInt(2147483647); + checkInt(2147483648); + checkInt(4294967295); + checkInt(4294967296); + expect(() => Int32.parseRadix('xyzzy', -1), throwsArgumentError); + expect(() => Int32.parseRadix('plugh', 10), + throwsA(new isInstanceOf())); + }); + + test("parseRadix", () { + check(String s, int r, String x) { + expect(Int32.parseRadix(s, r).toString(), x); + } + check('deadbeef', 16, '-559038737'); + check('95', 12, '113'); + }); + }); + + group("string representation", () { + test("toString", () { + expect(new Int32(0).toString(), "0"); + expect(new Int32(1).toString(), "1"); + expect(new Int32(-1).toString(), "-1"); + expect(new Int32(1000).toString(), "1000"); + expect(new Int32(-1000).toString(), "-1000"); + expect(new Int32(123456789).toString(), "123456789"); + expect(new Int32(2147483647).toString(), "2147483647"); + expect(new Int32(2147483648).toString(), "-2147483648"); + expect(new Int32(2147483649).toString(), "-2147483647"); + expect(new Int32(2147483650).toString(), "-2147483646"); + expect(new Int32(-2147483648).toString(), "-2147483648"); + expect(new Int32(-2147483649).toString(), "2147483647"); + expect(new Int32(-2147483650).toString(), "2147483646"); + }); + }); + + group("toHexString", () { + test("returns hexadecimal string representation", () { + expect(new Int32(-1).toHexString(), "-1"); + expect((new Int32(-1) >> 8).toHexString(), "-1"); + expect((new Int32(-1) << 8).toHexString(), "-100"); + expect(new Int32(123456789).toHexString(), "75bcd15"); + expect(new Int32(-1).shiftRightUnsigned(8).toHexString(), "ffffff"); + }); + }); + + group("toRadixString", () { + test("returns base n string representation", () { + expect(new Int32(123456789).toRadixString(5), "223101104124"); + }); + }); +} diff --git a/pkgs/fixnum/test/int_64_test.dart b/pkgs/fixnum/test/int_64_test.dart new file mode 100644 index 00000000..a3921829 --- /dev/null +++ b/pkgs/fixnum/test/int_64_test.dart @@ -0,0 +1,754 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +library int64test; +import 'package:fixnum/fixnum.dart'; +import 'package:unittest/unittest.dart'; + +void main() { + group("is-tests", () { + test("isEven", () { + expect((-Int64.ONE).isEven, false); + expect(Int64.ZERO.isEven, true); + expect(Int64.ONE.isEven, false); + expect(Int64.TWO.isEven, true); + }); + test("isMaxValue", () { + expect(Int64.MIN_VALUE.isMaxValue, false); + expect(Int64.ZERO.isMaxValue, false); + expect(Int64.MAX_VALUE.isMaxValue, true); + }); + test("isMinValue", () { + expect(Int64.MIN_VALUE.isMinValue, true); + expect(Int64.ZERO.isMinValue, false); + expect(Int64.MAX_VALUE.isMinValue, false); + }); + test("isNegative", () { + expect(Int64.MIN_VALUE.isNegative, true); + expect(Int64.ZERO.isNegative, false); + expect(Int64.ONE.isNegative, false); + }); + test("isOdd", () { + expect((-Int64.ONE).isOdd, true); + expect(Int64.ZERO.isOdd, false); + expect(Int64.ONE.isOdd, true); + expect(Int64.TWO.isOdd, false); + }); + test("isZero", () { + expect(Int64.MIN_VALUE.isZero, false); + expect(Int64.ZERO.isZero, true); + expect(Int64.MAX_VALUE.isZero, false); + }); + test("bitLength", () { + expect(new Int64(-2).bitLength, 1); + expect((-Int64.ONE).bitLength, 0); + expect(Int64.ZERO.bitLength, 0); + expect((Int64.ONE << 21).bitLength, 22); + expect((Int64.ONE << 22).bitLength, 23); + expect((Int64.ONE << 43).bitLength, 44); + expect((Int64.ONE << 44).bitLength, 45); + expect(new Int64(2).bitLength, 2); + expect(Int64.MAX_VALUE.bitLength, 63); + expect(Int64.MIN_VALUE.bitLength, 63); + }); + }); + + group("arithmetic operators", () { + Int64 n1 = new Int64(1234); + Int64 n2 = new Int64(9876); + Int64 n3 = new Int64(-1234); + Int64 n4 = new Int64(-9876); + Int64 n5 = new Int64.fromInts(0x12345678, 0xabcdabcd); + Int64 n6 = new Int64.fromInts(0x77773333, 0x22224444); + + test("+", () { + expect(n1 + n2, new Int64(11110)); + expect(n3 + n2, new Int64(8642)); + expect(n3 + n4, new Int64(-11110)); + expect(n5 + n6, new Int64.fromInts(0x89ab89ab, 0xcdeff011)); + expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE); + }); + + test("-", () { + expect(n1 - n2, new Int64(-8642)); + expect(n3 - n2, new Int64(-11110)); + expect(n3 - n4, new Int64(8642)); + expect(n5 - n6, new Int64.fromInts(0x9abd2345, 0x89ab6789)); + expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE); + }); + + test("unary -", () { + expect(-n1, new Int64(-1234)); + expect(-Int64.ZERO, Int64.ZERO); + }); + + test("*", () { + expect(new Int64(1111) * new Int64(3), new Int64(3333)); + expect(new Int64(1111) * new Int64(-3), new Int64(-3333)); + expect(new Int64(-1111) * new Int64(3), new Int64(-3333)); + expect(new Int64(-1111) * new Int64(-3), new Int64(3333)); + expect(new Int64(100) * Int64.ZERO, Int64.ZERO); + + expect(new Int64.fromInts(0x12345678, 0x12345678) * + new Int64.fromInts(0x1234, 0x12345678), + new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); + expect(new Int64.fromInts(0xf2345678, 0x12345678) * + new Int64.fromInts(0x1234, 0x12345678), + new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); + expect(new Int64.fromInts(0xf2345678, 0x12345678) * + new Int64.fromInts(0xffff1234, 0x12345678), + new Int64.fromInts(0x297e3f7c, 0x1df4d840)); + + // RHS Int32 + expect((new Int64(123456789) * new Int32(987654321)), + new Int64.fromInts(0x1b13114, 0xfbff5385)); + expect((new Int64(123456789) * new Int32(987654321)), + new Int64.fromInts(0x1b13114, 0xfbff5385)); + + // Wraparound + expect((new Int64(123456789) * new Int64(987654321)), + new Int64.fromInts(0x1b13114, 0xfbff5385)); + + expect(Int64.MIN_VALUE * new Int64(2), Int64.ZERO); + expect(Int64.MIN_VALUE * new Int64(1), Int64.MIN_VALUE); + expect(Int64.MIN_VALUE * new Int64(-1), Int64.MIN_VALUE); + }); + + test("~/", () { + Int64 deadBeef = new Int64.fromInts(0xDEADBEEF, 0xDEADBEEF); + Int64 ten = new Int64(10); + + expect(deadBeef ~/ ten, new Int64.fromInts(0xfcaaf97e, 0x63115fe5)); + expect(Int64.ONE ~/ Int64.TWO, Int64.ZERO); + expect(Int64.MAX_VALUE ~/ Int64.TWO, + new Int64.fromInts(0x3fffffff, 0xffffffff)); + expect(Int64.ZERO ~/ new Int64(1000), Int64.ZERO); + expect(Int64.MIN_VALUE ~/ Int64.MIN_VALUE, Int64.ONE); + expect(new Int64(1000) ~/ Int64.MIN_VALUE, Int64.ZERO); + expect(Int64.MIN_VALUE ~/ new Int64(8192), new Int64(-1125899906842624)); + expect(Int64.MIN_VALUE ~/ new Int64(8193), new Int64(-1125762484664320)); + expect(new Int64(-1000) ~/ new Int64(8192), Int64.ZERO); + expect(new Int64(-1000) ~/ new Int64(8193), Int64.ZERO); + expect(new Int64(-1000000000) ~/ new Int64(8192), new Int64(-122070)); + expect(new Int64(-1000000000) ~/ new Int64(8193), new Int64(-122055)); + expect(new Int64(1000000000) ~/ new Int64(8192), new Int64(122070)); + expect(new Int64(1000000000) ~/ new Int64(8193), new Int64(122055)); + expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00000400), + new Int64.fromInts(0x1fffff, 0xffffffff)); + expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00040000), + new Int64.fromInts(0x1fff, 0xffffffff)); + expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x04000000), + new Int64.fromInts(0x1f, 0xffffffff)); + expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000004, 0x00000000), + new Int64(536870911)); + expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000400, 0x00000000), + new Int64(2097151)); + expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00040000, 0x00000000), + new Int64(8191)); + expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x04000000, 0x00000000), + new Int64(31)); + expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00000300), + new Int64.fromInts(0x2AAAAA, 0xAAAAAAAA)); + expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x30000000), + new Int64.fromInts(0x2, 0xAAAAAAAA)); + expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00300000, 0x00000000), + new Int64(0x2AA)); + expect(Int64.MAX_VALUE ~/ new Int64(0x123456), + new Int64.fromInts(0x708, 0x002E9501)); + expect(Int64.MAX_VALUE % new Int64(0x123456), new Int64(0x3BDA9)); + expect(new Int64(5) ~/ new Int64(5), Int64.ONE); + expect(new Int64(1000) ~/ new Int64(3), new Int64(333)); + expect(new Int64(1000) ~/ new Int64(-3), new Int64(-333)); + expect(new Int64(-1000) ~/ new Int64(3), new Int64(-333)); + expect(new Int64(-1000) ~/ new Int64(-3), new Int64(333)); + expect(new Int64(3) ~/ new Int64(1000), Int64.ZERO); + expect(new Int64.fromInts( 0x12345678, 0x12345678) ~/ + new Int64.fromInts(0x0, 0x123), + new Int64.fromInts(0x1003d0, 0xe84f5ae8)); + expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ + new Int64.fromInts(0x1234, 0x12345678), + new Int64.fromInts(0x0, 0x10003)); + expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ + new Int64.fromInts(0x1234, 0x12345678), + new Int64.fromInts(0xffffffff, 0xffff3dfe)); + expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ + new Int64.fromInts(0xffff1234, 0x12345678), + new Int64.fromInts(0x0, 0xeda)); + expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461)); + expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461)); + expect(new Int64(829893893) ~/ 1919, new Int32(432461)); + expect(() => new Int64(1) ~/ Int64.ZERO, + throwsA(new isInstanceOf())); + expect(Int64.MIN_VALUE ~/ new Int64(2), + new Int64.fromInts(0xc0000000, 0x00000000)); + expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE); + expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE); + expect(() => new Int64(17) ~/ Int64.ZERO, throws); + expect(() => new Int64(17) ~/ null, throwsArgumentError); + }); + + test("%", () { + // Define % as Euclidean mod, with positive result for all arguments + expect(Int64.ZERO % new Int64(1000), Int64.ZERO); + expect(Int64.MIN_VALUE % Int64.MIN_VALUE, Int64.ZERO); + expect(new Int64(1000) % Int64.MIN_VALUE, new Int64(1000)); + expect(Int64.MIN_VALUE % new Int64(8192), Int64.ZERO); + expect(Int64.MIN_VALUE % new Int64(8193), new Int64(6145)); + expect(new Int64(-1000) % new Int64(8192), new Int64(7192)); + expect(new Int64(-1000) % new Int64(8193), new Int64(7193)); + expect(new Int64(-1000000000) % new Int64(8192), new Int64(5632)); + expect(new Int64(-1000000000) % new Int64(8193), new Int64(4808)); + expect(new Int64(1000000000) % new Int64(8192), new Int64(2560)); + expect(new Int64(1000000000) % new Int64(8193), new Int64(3385)); + expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x00000400), + new Int64.fromInts(0x0, 0x3ff)); + expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x00040000), + new Int64.fromInts(0x0, 0x3ffff)); + expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x04000000), + new Int64.fromInts(0x0, 0x3ffffff)); + expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000004, 0x00000000), + new Int64.fromInts(0x3, 0xffffffff)); + expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000400, 0x00000000), + new Int64.fromInts(0x3ff, 0xffffffff)); + expect(Int64.MAX_VALUE % new Int64.fromInts(0x00040000, 0x00000000), + new Int64.fromInts(0x3ffff, 0xffffffff)); + expect(Int64.MAX_VALUE % new Int64.fromInts(0x04000000, 0x00000000), + new Int64.fromInts(0x3ffffff, 0xffffffff)); + expect(new Int64(0x12345678).remainder(new Int64(0x22)), + new Int64(0x12345678.remainder(0x22))); + expect(new Int64(0x12345678).remainder(new Int64(-0x22)), + new Int64(0x12345678.remainder(-0x22))); + expect(new Int64(-0x12345678).remainder(new Int64(-0x22)), + new Int64(-0x12345678.remainder(-0x22))); + expect(new Int64(-0x12345678).remainder(new Int64(0x22)), + new Int64(-0x12345678.remainder(0x22))); + expect(new Int32(0x12345678).remainder(new Int64(0x22)), + new Int64(0x12345678.remainder(0x22))); + }); + + test("clamp", () { + Int64 val = new Int64(17); + expect(val.clamp(20, 30), new Int64(20)); + expect(val.clamp(10, 20), new Int64(17)); + expect(val.clamp(10, 15), new Int64(15)); + + expect(val.clamp(new Int32(20), new Int32(30)), new Int64(20)); + expect(val.clamp(new Int32(10), new Int32(20)), new Int64(17)); + expect(val.clamp(new Int32(10), new Int32(15)), new Int64(15)); + + expect(val.clamp(new Int64(20), new Int64(30)), new Int64(20)); + expect(val.clamp(new Int64(10), new Int64(20)), new Int64(17)); + expect(val.clamp(new Int64(10), new Int64(15)), new Int64(15)); + expect(val.clamp(Int64.MIN_VALUE, new Int64(30)), new Int64(17)); + expect(val.clamp(new Int64(10), Int64.MAX_VALUE), new Int64(17)); + + expect(() => val.clamp(1, 'b'), throwsA(isArgumentError)); + expect(() => val.clamp('a', 1), throwsA(isArgumentError)); + }); + }); + + group("comparison operators", () { + Int64 largeNeg = new Int64.fromInts(0x82341234, 0x0); + Int64 largePos = new Int64.fromInts(0x12341234, 0x0); + Int64 largePosPlusOne = largePos + new Int64(1); + + test("<", () { + expect(new Int64(10) < new Int64(11), true); + expect(new Int64(10) < new Int64(10), false); + expect(new Int64(10) < new Int64(9), false); + expect(new Int64(10) < new Int32(11), true); + expect(new Int64(10) < new Int32(10), false); + expect(new Int64(10) < new Int32(9), false); + expect(new Int64(-10) < new Int64(-11), false); + expect(Int64.MIN_VALUE < Int64.ZERO, true); + expect(largeNeg < largePos, true); + expect(largePos < largePosPlusOne, true); + expect(largePos < largePos, false); + expect(largePosPlusOne < largePos, false); + expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true); + expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false); + expect(() => new Int64(17) < null, throwsArgumentError); + }); + + test("<=", () { + expect(new Int64(10) <= new Int64(11), true); + expect(new Int64(10) <= new Int64(10), true); + expect(new Int64(10) <= new Int64(9), false); + expect(new Int64(10) <= new Int32(11), true); + expect(new Int64(10) <= new Int32(10), true); + expect(new Int64(10) <= new Int64(9), false); + expect(new Int64(-10) <= new Int64(-11), false); + expect(new Int64(-10) <= new Int64(-10), true); + expect(largeNeg <= largePos, true); + expect(largePos <= largeNeg, false); + expect(largePos <= largePosPlusOne, true); + expect(largePos <= largePos, true); + expect(largePosPlusOne <= largePos, false); + expect(Int64.MIN_VALUE <= Int64.MAX_VALUE, true); + expect(Int64.MAX_VALUE <= Int64.MIN_VALUE, false); + expect(() => new Int64(17) <= null, throwsArgumentError); + }); + + test("==", () { + expect(new Int64(10) == new Int64(11), false); + expect(new Int64(10) == new Int64(10), true); + expect(new Int64(10) == new Int64(9), false); + expect(new Int64(10) == new Int32(11), false); + expect(new Int64(10) == new Int32(10), true); + expect(new Int64(10) == new Int32(9), false); + expect(new Int64(-10) == new Int64(-10), true); + expect(new Int64(-10) != new Int64(-10), false); + expect(largePos == largePos, true); + expect(largePos == largePosPlusOne, false); + expect(largePosPlusOne == largePos, false); + expect(Int64.MIN_VALUE == Int64.MAX_VALUE, false); + expect(new Int64(17) == new Object(), false); + expect(new Int64(17) == null, false); + }); + + test(">=", () { + expect(new Int64(10) >= new Int64(11), false); + expect(new Int64(10) >= new Int64(10), true); + expect(new Int64(10) >= new Int64(9), true); + expect(new Int64(10) >= new Int32(11), false); + expect(new Int64(10) >= new Int32(10), true); + expect(new Int64(10) >= new Int32(9), true); + expect(new Int64(-10) >= new Int64(-11), true); + expect(new Int64(-10) >= new Int64(-10), true); + expect(largePos >= largeNeg, true); + expect(largeNeg >= largePos, false); + expect(largePos >= largePosPlusOne, false); + expect(largePos >= largePos, true); + expect(largePosPlusOne >= largePos, true); + expect(Int64.MIN_VALUE >= Int64.MAX_VALUE, false); + expect(Int64.MAX_VALUE >= Int64.MIN_VALUE, true); + expect(() => new Int64(17) >= null, throwsArgumentError); + }); + + test(">", () { + expect(new Int64(10) > new Int64(11), false); + expect(new Int64(10) > new Int64(10), false); + expect(new Int64(10) > new Int64(9), true); + expect(new Int64(10) > new Int32(11), false); + expect(new Int64(10) > new Int32(10), false); + expect(new Int64(10) > new Int32(9), true); + expect(new Int64(-10) > new Int64(-11), true); + expect(new Int64(10) > new Int64(-11), true); + expect(new Int64(-10) > new Int64(11), false); + expect(largePos > largeNeg, true); + expect(largeNeg > largePos, false); + expect(largePos > largePosPlusOne, false); + expect(largePos > largePos, false); + expect(largePosPlusOne > largePos, true); + expect(Int64.ZERO > Int64.MIN_VALUE, true); + expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false); + expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true); + expect(() => new Int64(17) > null, throwsArgumentError); + }); + }); + + group("bitwise operators", () { + Int64 n1 = new Int64(1234); + Int64 n2 = new Int64(9876); + Int64 n3 = new Int64(-1234); + Int64 n4 = new Int64(0x1234) << 32; + Int64 n5 = new Int64(0x9876) << 32; + + test("&", () { + expect(n1 & n2, new Int64(1168)); + expect(n3 & n2, new Int64(8708)); + expect(n4 & n5, new Int64(0x1034) << 32); + expect(() => n1 & null, throwsArgumentError); + }); + + test("|", () { + expect(n1 | n2, new Int64(9942)); + expect(n3 | n2, new Int64(-66)); + expect(n4 | n5, new Int64(0x9a76) << 32); + expect(() => n1 | null, throwsArgumentError); + }); + + test("^", () { + expect(n1 ^ n2, new Int64(8774)); + expect(n3 ^ n2, new Int64(-8774)); + expect(n4 ^ n5, new Int64(0x8a42) << 32); + expect(() => n1 ^ null, throwsArgumentError); + }); + + test("~", () { + expect(-new Int64(1), new Int64(-1)); + expect(-new Int64(-1), new Int64(1)); + expect(-Int64.MIN_VALUE, Int64.MIN_VALUE); + + expect(~n1, new Int64(-1235)); + expect(~n2, new Int64(-9877)); + expect(~n3, new Int64(1233)); + expect(~n4, new Int64.fromInts(0xffffedcb, 0xffffffff)); + expect(~n5, new Int64.fromInts(0xffff6789, 0xffffffff)); + }); + }); + + group("bitshift operators", () { + test("<<", () { + expect(new Int64.fromInts(0x12341234, 0x45674567) << 10, + new Int64.fromInts(0xd048d115, 0x9d159c00)); + expect(new Int64.fromInts(0x92341234, 0x45674567) << 10, + new Int64.fromInts(0xd048d115, 0x9d159c00)); + expect(new Int64(-1) << 5, new Int64(-32)); + expect(new Int64(-1) << 0, new Int64(-1)); + expect(() => new Int64(17) << -1, throwsArgumentError); + expect(() => new Int64(17) << null, throws); + }); + + test(">>", () { + expect((Int64.MIN_VALUE >> 13).toString(), "-1125899906842624"); + expect(new Int64.fromInts(0x12341234, 0x45674567) >> 10, + new Int64.fromInts(0x48d04, 0x8d1159d1)); + expect(new Int64.fromInts(0x92341234, 0x45674567) >> 10, + new Int64.fromInts(0xffe48d04, 0x8d1159d1)); + expect(new Int64.fromInts(0xFFFFFFF, 0xFFFFFFFF) >> 34, + new Int64(67108863)); + for (int n = 0; n <= 66; n++) { + expect(new Int64(-1) >> n, new Int64(-1)); + } + expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 8, + new Int64.fromInts(0x00723456, 0x789abcde)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 16, + new Int64.fromInts(0x00007234, 0x56789abc)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 24, + new Int64.fromInts(0x00000072, 0x3456789a)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 28, + new Int64.fromInts(0x00000007, 0x23456789)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 32, + new Int64.fromInts(0x00000000, 0x72345678)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 36, + new Int64.fromInts(0x00000000, 0x07234567)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 40, + new Int64.fromInts(0x00000000, 0x00723456)); + expect(new Int64.fromInts(0x72345678, 0x9abcde00) >> 44, + new Int64.fromInts(0x00000000, 0x00072345)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 48, + new Int64.fromInts(0x00000000, 0x00007234)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 8, + new Int64.fromInts(0xff923456, 0x789abcde)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 16, + new Int64.fromInts(0xffff9234, 0x56789abc)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 24, + new Int64.fromInts(0xffffff92, 0x3456789a)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 28, + new Int64.fromInts(0xfffffff9, 0x23456789)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 32, + new Int64.fromInts(0xffffffff, 0x92345678)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 36, + new Int64.fromInts(0xffffffff, 0xf9234567)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 40, + new Int64.fromInts(0xffffffff, 0xff923456)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 44, + new Int64.fromInts(0xffffffff, 0xfff92345)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 48, + new Int64.fromInts(0xffffffff, 0xffff9234)); + expect(() => new Int64(17) >> -1, throwsArgumentError); + expect(() => new Int64(17) >> null, throws); + }); + + test("shiftRightUnsigned", () { + expect(new Int64.fromInts(0x12341234, 0x45674567).shiftRightUnsigned(10), + new Int64.fromInts(0x48d04, 0x8d1159d1)); + expect(new Int64.fromInts(0x92341234, 0x45674567).shiftRightUnsigned(10), + new Int64.fromInts(0x248d04, 0x8d1159d1)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(8), + new Int64.fromInts(0x00723456, 0x789abcde)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(16), + new Int64.fromInts(0x00007234, 0x56789abc)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(24), + new Int64.fromInts(0x00000072, 0x3456789a)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(28), + new Int64.fromInts(0x00000007, 0x23456789)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(32), + new Int64.fromInts(0x00000000, 0x72345678)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(36), + new Int64.fromInts(0x00000000, 0x07234567)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(40), + new Int64.fromInts(0x00000000, 0x00723456)); + expect(new Int64.fromInts(0x72345678, 0x9abcde00).shiftRightUnsigned(44), + new Int64.fromInts(0x00000000, 0x00072345)); + expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(48), + new Int64.fromInts(0x00000000, 0x00007234)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(8), + new Int64.fromInts(0x00923456, 0x789abcde)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(16), + new Int64.fromInts(0x00009234, 0x56789abc)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(24), + new Int64.fromInts(0x00000092, 0x3456789a)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(28), + new Int64.fromInts(0x00000009, 0x23456789)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(32), + new Int64.fromInts(0x00000000, 0x92345678)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(36), + new Int64.fromInts(0x00000000, 0x09234567)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(40), + new Int64.fromInts(0x00000000, 0x00923456)); + expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(44), + new Int64.fromInts(0x00000000, 0x00092345)); + expect(new Int64.fromInts(0x00000000, 0x00009234), + new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48)); + expect(() => new Int64(17).shiftRightUnsigned(-1), + throwsArgumentError); + expect(() => new Int64(17).shiftRightUnsigned(null), throws); + }); + + test("overflow", () { + expect((new Int64(1) << 63) >> 1, + -new Int64.fromInts(0x40000000, 0x00000000)); + expect((new Int64(-1) << 32) << 32, new Int64(0)); + expect(Int64.MIN_VALUE << 0, Int64.MIN_VALUE); + expect(Int64.MIN_VALUE << 1, new Int64(0)); + expect((-new Int64.fromInts(8, 0)) >> 1, + new Int64.fromInts(0xfffffffc, 0x00000000)); + expect((-new Int64.fromInts(8, 0)).shiftRightUnsigned(1), + new Int64.fromInts(0x7ffffffc, 0x0)); + }); + }); + + group("conversions", () { + test("toSigned", () { + expect((Int64.ONE << 44).toSigned(46), Int64.ONE << 44); + expect((Int64.ONE << 44).toSigned(45), -(Int64.ONE << 44)); + expect((Int64.ONE << 22).toSigned(24), Int64.ONE << 22); + expect((Int64.ONE << 22).toSigned(23), -(Int64.ONE << 22)); + expect(Int64.ONE.toSigned(2), Int64.ONE); + expect(Int64.ONE.toSigned(1), -Int64.ONE); + expect(Int64.MAX_VALUE.toSigned(64), Int64.MAX_VALUE); + expect(Int64.MIN_VALUE.toSigned(64), Int64.MIN_VALUE); + expect(Int64.MAX_VALUE.toSigned(63), -Int64.ONE); + expect(Int64.MIN_VALUE.toSigned(63), Int64.ZERO); + expect(() => Int64.ONE.toSigned(0), throws); + expect(() => Int64.ONE.toSigned(65), throws); + }); + test("toUnsigned", () { + expect((Int64.ONE << 44).toUnsigned(45), Int64.ONE << 44); + expect((Int64.ONE << 44).toUnsigned(44), Int64.ZERO); + expect((Int64.ONE << 22).toUnsigned(23), Int64.ONE << 22); + expect((Int64.ONE << 22).toUnsigned(22), Int64.ZERO); + expect(Int64.ONE.toUnsigned(1), Int64.ONE); + expect(Int64.ONE.toUnsigned(0), Int64.ZERO); + expect(Int64.MAX_VALUE.toUnsigned(64), Int64.MAX_VALUE); + expect(Int64.MIN_VALUE.toUnsigned(64), Int64.MIN_VALUE); + expect(Int64.MAX_VALUE.toUnsigned(63), Int64.MAX_VALUE); + expect(Int64.MIN_VALUE.toUnsigned(63), Int64.ZERO); + expect(() => Int64.ONE.toUnsigned(-1), throws); + expect(() => Int64.ONE.toUnsigned(65), throws); + }); + test("toDouble", () { + expect(new Int64(0).toDouble(), same(0.0)); + expect(new Int64(100).toDouble(), same(100.0)); + expect(new Int64(-100).toDouble(), same(-100.0)); + expect(new Int64(2147483647).toDouble(), same(2147483647.0)); + expect(new Int64(2147483648).toDouble(), same(2147483648.0)); + expect(new Int64(-2147483647).toDouble(), same(-2147483647.0)); + expect(new Int64(-2147483648).toDouble(), same(-2147483648.0)); + expect(new Int64(4503599627370495).toDouble(), same(4503599627370495.0)); + expect(new Int64(4503599627370496).toDouble(), same(4503599627370496.0)); + expect(new Int64(-4503599627370495).toDouble(), + same(-4503599627370495.0)); + expect(new Int64(-4503599627370496).toDouble(), + same(-4503599627370496.0)); + expect(Int64.parseInt("-10000000000000000").toDouble().toStringAsFixed(1), + "-10000000000000000.0"); + expect(Int64.parseInt("-10000000000000001").toDouble().toStringAsFixed(1), + "-10000000000000000.0"); + expect(Int64.parseInt("-10000000000000002").toDouble().toStringAsFixed(1), + "-10000000000000002.0"); + expect(Int64.parseInt("-10000000000000003").toDouble().toStringAsFixed(1), + "-10000000000000004.0"); + expect(Int64.parseInt("-10000000000000004").toDouble().toStringAsFixed(1), + "-10000000000000004.0"); + expect(Int64.parseInt("-10000000000000005").toDouble().toStringAsFixed(1), + "-10000000000000004.0"); + expect(Int64.parseInt("-10000000000000006").toDouble().toStringAsFixed(1), + "-10000000000000006.0"); + expect(Int64.parseInt("-10000000000000007").toDouble().toStringAsFixed(1), + "-10000000000000008.0"); + expect(Int64.parseInt("-10000000000000008").toDouble().toStringAsFixed(1), + "-10000000000000008.0"); + }); + + test("toInt", () { + expect(new Int64(0).toInt(), 0); + expect(new Int64(100).toInt(), 100); + expect(new Int64(-100).toInt(), -100); + expect(new Int64(2147483647).toInt(), 2147483647); + expect(new Int64(2147483648).toInt(), 2147483648); + expect(new Int64(-2147483647).toInt(), -2147483647); + expect(new Int64(-2147483648).toInt(), -2147483648); + expect(new Int64(4503599627370495).toInt(), 4503599627370495); + expect(new Int64(4503599627370496).toInt(), 4503599627370496); + expect(new Int64(-4503599627370495).toInt(), -4503599627370495); + expect(new Int64(-4503599627370496).toInt(), -4503599627370496); + expect(Int64.parseInt("-10000000000000000").toInt(), + same(-10000000000000000)); + expect(Int64.parseInt("-10000000000000001").toInt(), + same(-10000000000000001)); + expect(Int64.parseInt("-10000000000000002").toInt(), + same(-10000000000000002)); + expect(Int64.parseInt("-10000000000000003").toInt(), + same(-10000000000000003)); + expect(Int64.parseInt("-10000000000000004").toInt(), + same(-10000000000000004)); + expect(Int64.parseInt("-10000000000000005").toInt(), + same(-10000000000000005)); + expect(Int64.parseInt("-10000000000000006").toInt(), + same(-10000000000000006)); + expect(Int64.parseInt("-10000000000000007").toInt(), + same(-10000000000000007)); + expect(Int64.parseInt("-10000000000000008").toInt(), + same(-10000000000000008)); + }); + + test("toInt32", () { + expect(new Int64(0).toInt32(), new Int32(0)); + expect(new Int64(1).toInt32(), new Int32(1)); + expect(new Int64(-1).toInt32(), new Int32(-1)); + expect(new Int64(2147483647).toInt32(), new Int32(2147483647)); + expect(new Int64(2147483648).toInt32(), new Int32(-2147483648)); + expect(new Int64(2147483649).toInt32(), new Int32(-2147483647)); + expect(new Int64(2147483650).toInt32(), new Int32(-2147483646)); + expect(new Int64(-2147483648).toInt32(), new Int32(-2147483648)); + expect(new Int64(-2147483649).toInt32(), new Int32(2147483647)); + expect(new Int64(-2147483650).toInt32(), new Int32(2147483646)); + expect(new Int64(-2147483651).toInt32(), new Int32(2147483645)); + }); + }); + + test("JavaScript 53-bit integer boundary", () { + Int64 _factorial(Int64 n) { + if (n.isZero) { + return new Int64(1); + } else { + return n * _factorial(n - new Int64(1)); + } + } + Int64 fact18 = _factorial(new Int64(18)); + Int64 fact17 = _factorial(new Int64(17)); + expect(fact18 ~/ fact17, new Int64(18)); + }); + + test("min, max values", () { + expect(new Int64(1) << 63, Int64.MIN_VALUE); + expect(-(Int64.MIN_VALUE + new Int64(1)), Int64.MAX_VALUE); + }); + + group("parse", () { + test("parseRadix10", () { + checkInt(int x) { + expect(Int64.parseRadix('$x', 10), new Int64(x)); + } + checkInt(0); + checkInt(1); + checkInt(-1); + checkInt(1000); + checkInt(12345678); + checkInt(-12345678); + checkInt(2147483647); + checkInt(2147483648); + checkInt(-2147483647); + checkInt(-2147483648); + checkInt(4294967295); + checkInt(4294967296); + checkInt(-4294967295); + checkInt(-4294967296); + expect(() => Int64.parseRadix('xyzzy', -1), throwsArgumentError); + expect(() => Int64.parseRadix('plugh', 10), + throwsA(new isInstanceOf())); + }); + + test("parseRadix", () { + check(String s, int r, String x) { + expect(Int64.parseRadix(s, r).toString(), x); + } + check('ghoul', 36, '27699213'); + check('ghoul', 35, '24769346'); + // Min and max value. + check("-9223372036854775808", 10, "-9223372036854775808"); + check("9223372036854775807", 10, "9223372036854775807"); + // Overflow during parsing. + check("9223372036854775808", 10, "-9223372036854775808"); + }); + + test("parseRadixN", () { + check(String s, int r) { + expect(Int64.parseRadix(s, r).toRadixString(r), s); + } + check("2ppp111222333", 33); // This value & radix requires three chunks. + }); + }); + + group("string representation", () { + test("toString", () { + expect(new Int64(0).toString(), "0"); + expect(new Int64(1).toString(), "1"); + expect(new Int64(-1).toString(), "-1"); + expect(new Int64(-10).toString(), "-10"); + expect(Int64.MIN_VALUE.toString(), "-9223372036854775808"); + expect(Int64.MAX_VALUE.toString(), "9223372036854775807"); + + int top = 922337201; + int bottom = 967490662; + Int64 fullnum = (new Int64(1000000000) * new Int64(top)) + + new Int64(bottom); + expect(fullnum.toString(), "922337201967490662"); + expect((-fullnum).toString(), "-922337201967490662"); + expect(new Int64(123456789).toString(), "123456789"); + }); + + test("toHexString", () { + Int64 deadbeef12341234 = new Int64.fromInts(0xDEADBEEF, 0x12341234); + expect(Int64.ZERO.toHexString(), "0"); + expect(deadbeef12341234.toHexString(), "DEADBEEF12341234"); + expect(new Int64.fromInts(0x17678A7, 0xDEF01234).toHexString(), + "17678A7DEF01234"); + expect(new Int64(123456789).toHexString(), "75BCD15"); + }); + + test("toRadixString", () { + expect(new Int64(123456789).toRadixString(5), "223101104124"); + expect(Int64.MIN_VALUE.toRadixString(2), + "-1000000000000000000000000000000000000000000000000000000000000000"); + expect(Int64.MIN_VALUE.toRadixString(3), + "-2021110011022210012102010021220101220222"); + expect(Int64.MIN_VALUE.toRadixString(4), + "-20000000000000000000000000000000"); + expect(Int64.MIN_VALUE.toRadixString(5), "-1104332401304422434310311213"); + expect(Int64.MIN_VALUE.toRadixString(6), "-1540241003031030222122212"); + expect(Int64.MIN_VALUE.toRadixString(7), "-22341010611245052052301"); + expect(Int64.MIN_VALUE.toRadixString(8), "-1000000000000000000000"); + expect(Int64.MIN_VALUE.toRadixString(9), "-67404283172107811828"); + expect(Int64.MIN_VALUE.toRadixString(10), "-9223372036854775808"); + expect(Int64.MIN_VALUE.toRadixString(11), "-1728002635214590698"); + expect(Int64.MIN_VALUE.toRadixString(12), "-41a792678515120368"); + expect(Int64.MIN_VALUE.toRadixString(13), "-10b269549075433c38"); + expect(Int64.MIN_VALUE.toRadixString(14), "-4340724c6c71dc7a8"); + expect(Int64.MIN_VALUE.toRadixString(15), "-160e2ad3246366808"); + expect(Int64.MIN_VALUE.toRadixString(16), "-8000000000000000"); + expect(Int64.MAX_VALUE.toRadixString(2), + "111111111111111111111111111111111111111111111111111111111111111"); + expect(Int64.MAX_VALUE.toRadixString(3), + "2021110011022210012102010021220101220221"); + expect(Int64.MAX_VALUE.toRadixString(4), + "13333333333333333333333333333333"); + expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212"); + expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211"); + expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300"); + expect(Int64.MAX_VALUE.toRadixString(8), "777777777777777777777"); + expect(Int64.MAX_VALUE.toRadixString(9), "67404283172107811827"); + expect(Int64.MAX_VALUE.toRadixString(10), "9223372036854775807"); + expect(Int64.MAX_VALUE.toRadixString(11), "1728002635214590697"); + expect(Int64.MAX_VALUE.toRadixString(12), "41a792678515120367"); + expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37"); + expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); + expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); + expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); + }); + }); +} From 78229e29eb6158ee80d7c5645cae1ce2a2c57240 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sun, 8 Feb 2015 23:34:39 -0800 Subject: [PATCH 002/126] Add CONTRIBUTING.md. --- pkgs/fixnum/CONTRIBUTING.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 pkgs/fixnum/CONTRIBUTING.md diff --git a/pkgs/fixnum/CONTRIBUTING.md b/pkgs/fixnum/CONTRIBUTING.md new file mode 100644 index 00000000..8dab68d0 --- /dev/null +++ b/pkgs/fixnum/CONTRIBUTING.md @@ -0,0 +1,10 @@ +# How to contribute + +### Sign our Contributor License Agreement (CLA) + +Even for small changes, we ask that you please sign the CLA electronically +[here](https://developers.google.com/open-source/cla/individual). +The CLA is necessary because you own the copyright to your changes, even +after your contribution becomes part of our codebase, so we need your permission +to use and distribute your code. You can find more details +[here](https://code.google.com/p/dart/wiki/Contributing). From 65759ff8422505c1f191eee53923617cc2c461e6 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sun, 8 Feb 2015 23:44:51 -0800 Subject: [PATCH 003/126] Version 0.9.1 --- pkgs/fixnum/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 7eb50c15..2d54f859 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 0.9.0-dev+1 +version: 0.9.1 author: Dart Team description: Library for 32- and 64-bit fixed size integers. homepage: http://www.dartlang.org From 16706334b41dfd211adceb0bb582428452be8ab2 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sun, 8 Feb 2015 23:41:28 -0800 Subject: [PATCH 004/126] Format with dart_style. --- pkgs/fixnum/lib/src/int32.dart | 2 +- pkgs/fixnum/lib/src/int64.dart | 131 ++++++++++++++++-------------- pkgs/fixnum/test/int_32_test.dart | 12 +-- pkgs/fixnum/test/int_64_test.dart | 53 ++++++------ 4 files changed, 104 insertions(+), 94 deletions(-) diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index f7e24aa3..32f36209 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -136,7 +136,7 @@ class Int32 implements IntX { * Constructs an [Int32] from an [int]. Only the low 32 bits of the input * are used. */ - Int32([int i=0]) : _i = (i & 0x7fffffff) - (i & 0x80000000); + Int32([int i = 0]) : _i = (i & 0x7fffffff) - (i & 0x80000000); // Returns the [int] representation of the specified value. Throws // [ArgumentError] for non-integer arguments. diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index de306564..641bf71e 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -83,7 +83,9 @@ class Int64 implements IntX { negative = true; i++; } - int d0 = 0, d1 = 0, d2 = 0; // low, middle, high components. + int d0 = 0, + d1 = 0, + d2 = 0; // low, middle, high components. for (; i < s.length; i++) { int c = s.codeUnitAt(i); int digit = Int32._decodeDigit(c); @@ -99,7 +101,7 @@ class Int64 implements IntX { d1 = d1 * radix + carry; carry = d1 >> _BITS; - d1 = _MASK & d1;; + d1 = _MASK & d1; d2 = d2 * radix + carry; d2 = _MASK2 & d2; @@ -127,8 +129,10 @@ class Int64 implements IntX { /** * Constructs an [Int64] with a given [int] value; zero by default. */ - factory Int64([int value=0]) { - int v0 = 0, v1 = 0, v2 = 0; + factory Int64([int value = 0]) { + int v0 = 0, + v1 = 0, + v2 = 0; bool negative = false; if (value < 0) { negative = true; @@ -193,7 +197,7 @@ class Int64 implements IntX { bottom |= bytes[7] & 0xff; return new Int64.fromInts(top, bottom); - } + } /** * Constructs an [Int64] from a pair of 32-bit integers having the value @@ -519,7 +523,9 @@ class Int64 implements IntX { int get bitLength { if (isZero) return 0; - int a0 = _l, a1 = _m, a2 = _h; + int a0 = _l, + a1 = _m, + a2 = _h; if (isNegative) { a0 = _MASK & ~a0; a1 = _MASK & ~a1; @@ -602,12 +608,12 @@ class Int64 implements IntX { int m = _m.toSigned(width - _BITS); return m.isNegative ? Int64._masked(_l, m, _MASK2) - : Int64._masked(_l, m, 0); // Masking for type inferrer. + : Int64._masked(_l, m, 0); // Masking for type inferrer. } else { int l = _l.toSigned(width); return l.isNegative ? Int64._masked(l, _MASK, _MASK2) - : Int64._masked(l, 0, 0); // Masking for type inferrer. + : Int64._masked(l, 0, 0); // Masking for type inferrer. } } @@ -742,7 +748,6 @@ class Int64 implements IntX { // --> // [----------d4----------][---d3---][---d2---][---d1---][---d0---] - int d4 = (d2 << 4) | (d1 >> 18); int d3 = (d1 >> 8) & 0x3ff; d2 = ((d1 << 2) | (d0 >> 20)) & 0x3ff; @@ -759,7 +764,9 @@ class Int64 implements IntX { // need only two chunks, but radix values 17-19 and 33-36 generate only 15 // or 16 bits per iteration, so sometimes the third chunk is needed. - String chunk1 = "", chunk2 = "", chunk3 = ""; + String chunk1 = "", + chunk2 = "", + chunk3 = ""; while (!(d4 == 0 && d3 == 0)) { int q = d4 ~/ fatRadix; @@ -802,51 +809,50 @@ class Int64 implements IntX { // Table of 'fat' radix values. Each entry for index `i` is the largest power // of `i` whose remainder fits in 20 bits. static const _fatRadixTable = const [ - 0, - 0, - 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 - * 2, - 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3, - 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4, - 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, - 6 * 6 * 6 * 6 * 6 * 6 * 6, - 7 * 7 * 7 * 7 * 7 * 7 * 7, - 8 * 8 * 8 * 8 * 8 * 8, - 9 * 9 * 9 * 9 * 9 * 9, - 10 * 10 * 10 * 10 * 10 * 10, - 11 * 11 * 11 * 11 * 11, - 12 * 12 * 12 * 12 * 12, - 13 * 13 * 13 * 13 * 13, - 14 * 14 * 14 * 14 * 14, - 15 * 15 * 15 * 15 * 15, - 16 * 16 * 16 * 16 * 16, - 17 * 17 * 17 * 17, - 18 * 18 * 18 * 18, - 19 * 19 * 19 * 19, - 20 * 20 * 20 * 20, - 21 * 21 * 21 * 21, - 22 * 22 * 22 * 22, - 23 * 23 * 23 * 23, - 24 * 24 * 24 * 24, - 25 * 25 * 25 * 25, - 26 * 26 * 26 * 26, - 27 * 27 * 27 * 27, - 28 * 28 * 28 * 28, - 29 * 29 * 29 * 29, - 30 * 30 * 30 * 30, - 31 * 31 * 31 * 31, - 32 * 32 * 32 * 32, - 33 * 33 * 33, - 34 * 34 * 34, - 35 * 35 * 35, - 36 * 36 * 36 + 0, + 0, + 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 + * 2, + 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3, + 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4, + 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, + 6 * 6 * 6 * 6 * 6 * 6 * 6, + 7 * 7 * 7 * 7 * 7 * 7 * 7, + 8 * 8 * 8 * 8 * 8 * 8, + 9 * 9 * 9 * 9 * 9 * 9, + 10 * 10 * 10 * 10 * 10 * 10, + 11 * 11 * 11 * 11 * 11, + 12 * 12 * 12 * 12 * 12, + 13 * 13 * 13 * 13 * 13, + 14 * 14 * 14 * 14 * 14, + 15 * 15 * 15 * 15 * 15, + 16 * 16 * 16 * 16 * 16, + 17 * 17 * 17 * 17, + 18 * 18 * 18 * 18, + 19 * 19 * 19 * 19, + 20 * 20 * 20 * 20, + 21 * 21 * 21 * 21, + 22 * 22 * 22 * 22, + 23 * 23 * 23 * 23, + 24 * 24 * 24 * 24, + 25 * 25 * 25 * 25, + 26 * 26 * 26 * 26, + 27 * 27 * 27 * 27, + 28 * 28 * 28 * 28, + 29 * 29 * 29 * 29, + 30 * 30 * 30 * 30, + 31 * 31 * 31 * 31, + 32 * 32 * 32 * 32, + 33 * 33 * 33, + 34 * 34 * 34, + 35 * 35 * 35, + 36 * 36 * 36 ]; String toDebugString() { return "Int64[_l=$_l, _m=$_m, _h=$_h]"; } - static Int64 _masked(int a0, int a1, int a2) => new Int64._bits(_MASK & a0, _MASK & a1, _MASK2 & a2); @@ -881,7 +887,6 @@ class Int64 implements IntX { String _hexDigit(int digit) => "0123456789ABCDEF"[digit]; - // Work around dart2js bugs with negative arguments to '>>' operator. static int _shiftRight(int x, int n) { if (x >= 0) { @@ -895,7 +900,6 @@ class Int64 implements IntX { } } - // Implementation of '~/', '%' and 'remainder'. static Int64 _divide(Int64 a, other, int what) { @@ -926,11 +930,15 @@ class Int64 implements IntX { static _divideHelper( // up to 64 bits unsigned in a2/a1/a0 and b2/b1/b0 - int a0, int a1, int a2, bool aNeg, // input A. - int b0, int b1, int b2, bool bNeg, // input B. + int a0, int a1, int a2, bool aNeg, // input A. + int b0, int b1, int b2, bool bNeg, // input B. int what) { - int q0 = 0, q1 = 0, q2 = 0; // result Q. - int r0 = 0, r1 = 0, r2 = 0; // result R. + int q0 = 0, + q1 = 0, + q2 = 0; // result Q. + int r0 = 0, + r1 = 0, + r2 = 0; // result R. if (b2 == 0 && b1 == 0 && b0 < (1 << (30 - _BITS))) { // Small divisor can be handled by single-digit division within Smi range. @@ -978,7 +986,7 @@ class Int64 implements IntX { q0 = q0d.toInt(); assert(q0 + K1 * q1 + K2 * q2 == (ad / bd).floorToDouble()); - assert(q2 == 0 || b2 == 0); // Q and B can't both be big since Q*B <= A. + assert(q2 == 0 || b2 == 0); // Q and B can't both be big since Q*B <= A. // P = Q * B, using doubles to hold intermediates. // We don't need all partial sums since Q*B <= A. @@ -989,7 +997,7 @@ class Int64 implements IntX { double p1carry = (p1d / K1).floorToDouble(); p1d = p1d - p1carry * K1; double p2d = q2d * b0 + q1d * b1 + q0d * b2 + p1carry; - assert(p2d <= _MASK2); // No partial sum overflow. + assert(p2d <= _MASK2); // No partial sum overflow. // R = A - P int diff0 = a0 - p0d.toInt(); @@ -1001,8 +1009,7 @@ class Int64 implements IntX { // while (R < 0 || R >= B) // adjust R towards [0, B) - while ( - r2 >= _SIGN_BIT_MASK || + while (r2 >= _SIGN_BIT_MASK || r2 > b2 || (r2 == b2 && (r1 > b1 || (r1 == b1 && r0 >= b0)))) { // Direction multiplier for adjustment. @@ -1027,17 +1034,17 @@ class Int64 implements IntX { // 0 <= R < B assert(Int64.ZERO <= new Int64._bits(r0, r1, r2)); - assert(r2 < b2 || // Handles case where B = -(MIN_VALUE) + assert(r2 < b2 || // Handles case where B = -(MIN_VALUE) new Int64._bits(r0, r1, r2) < new Int64._bits(b0, b1, b2)); assert(what == _RETURN_DIV || what == _RETURN_MOD || what == _RETURN_REM); if (what == _RETURN_DIV) { if (aNeg != bNeg) return _negate(q0, q1, q2); - return Int64._masked(q0, q1, q2); // Masking for type inferrer. + return Int64._masked(q0, q1, q2); // Masking for type inferrer. } if (!aNeg) { - return new Int64._bits(_MASK & r0, r1, r2); // Masking for type inferrer. + return new Int64._bits(_MASK & r0, r1, r2); // Masking for type inferrer. } if (what == _RETURN_MOD) { diff --git a/pkgs/fixnum/test/int_32_test.dart b/pkgs/fixnum/test/int_32_test.dart index 8ce78248..dd8038d1 100644 --- a/pkgs/fixnum/test/int_32_test.dart +++ b/pkgs/fixnum/test/int_32_test.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. library Int32test; + import 'package:fixnum/fixnum.dart'; import 'package:unittest/unittest.dart'; @@ -85,14 +86,13 @@ void main() { expect(n2 * n3, new Int32(-12186984)); expect(n3 * n3, new Int32(1522756)); expect(n3 * n2, new Int32(-12186984)); - expect(new Int32(0x12345678) * new Int32(0x22222222), - new Int32(-899716112)); - expect((new Int32(123456789) * new Int32(987654321)), - new Int32(-67153019)); + expect( + new Int32(0x12345678) * new Int32(0x22222222), new Int32(-899716112)); + expect( + (new Int32(123456789) * new Int32(987654321)), new Int32(-67153019)); expect(new Int32(0x12345678) * new Int64(0x22222222), new Int64.fromInts(0x026D60DC, 0xCA5F6BF0)); - expect((new Int32(123456789) * 987654321), - new Int32(-67153019)); + expect((new Int32(123456789) * 987654321), new Int32(-67153019)); expect(() => new Int32(17) * null, throws); }); diff --git a/pkgs/fixnum/test/int_64_test.dart b/pkgs/fixnum/test/int_64_test.dart index a3921829..35109881 100644 --- a/pkgs/fixnum/test/int_64_test.dart +++ b/pkgs/fixnum/test/int_64_test.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. library int64test; + import 'package:fixnum/fixnum.dart'; import 'package:unittest/unittest.dart'; @@ -91,13 +92,13 @@ void main() { expect(new Int64(100) * Int64.ZERO, Int64.ZERO); expect(new Int64.fromInts(0x12345678, 0x12345678) * - new Int64.fromInts(0x1234, 0x12345678), + new Int64.fromInts(0x1234, 0x12345678), new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); expect(new Int64.fromInts(0xf2345678, 0x12345678) * - new Int64.fromInts(0x1234, 0x12345678), + new Int64.fromInts(0x1234, 0x12345678), new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); expect(new Int64.fromInts(0xf2345678, 0x12345678) * - new Int64.fromInts(0xffff1234, 0x12345678), + new Int64.fromInts(0xffff1234, 0x12345678), new Int64.fromInts(0x297e3f7c, 0x1df4d840)); // RHS Int32 @@ -163,17 +164,17 @@ void main() { expect(new Int64(-1000) ~/ new Int64(3), new Int64(-333)); expect(new Int64(-1000) ~/ new Int64(-3), new Int64(333)); expect(new Int64(3) ~/ new Int64(1000), Int64.ZERO); - expect(new Int64.fromInts( 0x12345678, 0x12345678) ~/ - new Int64.fromInts(0x0, 0x123), + expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ + new Int64.fromInts(0x0, 0x123), new Int64.fromInts(0x1003d0, 0xe84f5ae8)); expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ - new Int64.fromInts(0x1234, 0x12345678), + new Int64.fromInts(0x1234, 0x12345678), new Int64.fromInts(0x0, 0x10003)); expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ - new Int64.fromInts(0x1234, 0x12345678), + new Int64.fromInts(0x1234, 0x12345678), new Int64.fromInts(0xffffffff, 0xffff3dfe)); expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ - new Int64.fromInts(0xffff1234, 0x12345678), + new Int64.fromInts(0xffff1234, 0x12345678), new Int64.fromInts(0x0, 0xeda)); expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461)); expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461)); @@ -407,8 +408,8 @@ void main() { new Int64.fromInts(0x48d04, 0x8d1159d1)); expect(new Int64.fromInts(0x92341234, 0x45674567) >> 10, new Int64.fromInts(0xffe48d04, 0x8d1159d1)); - expect(new Int64.fromInts(0xFFFFFFF, 0xFFFFFFFF) >> 34, - new Int64(67108863)); + expect( + new Int64.fromInts(0xFFFFFFF, 0xFFFFFFFF) >> 34, new Int64(67108863)); for (int n = 0; n <= 66; n++) { expect(new Int64(-1) >> n, new Int64(-1)); } @@ -493,8 +494,7 @@ void main() { new Int64.fromInts(0x00000000, 0x00092345)); expect(new Int64.fromInts(0x00000000, 0x00009234), new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48)); - expect(() => new Int64(17).shiftRightUnsigned(-1), - throwsArgumentError); + expect(() => new Int64(17).shiftRightUnsigned(-1), throwsArgumentError); expect(() => new Int64(17).shiftRightUnsigned(null), throws); }); @@ -550,12 +550,14 @@ void main() { expect(new Int64(-2147483648).toDouble(), same(-2147483648.0)); expect(new Int64(4503599627370495).toDouble(), same(4503599627370495.0)); expect(new Int64(4503599627370496).toDouble(), same(4503599627370496.0)); - expect(new Int64(-4503599627370495).toDouble(), - same(-4503599627370495.0)); - expect(new Int64(-4503599627370496).toDouble(), - same(-4503599627370496.0)); - expect(Int64.parseInt("-10000000000000000").toDouble().toStringAsFixed(1), - "-10000000000000000.0"); + expect( + new Int64(-4503599627370495).toDouble(), same(-4503599627370495.0)); + expect( + new Int64(-4503599627370496).toDouble(), same(-4503599627370496.0)); + expect(Int64 + .parseInt("-10000000000000000") + .toDouble() + .toStringAsFixed(1), "-10000000000000000.0"); expect(Int64.parseInt("-10000000000000001").toDouble().toStringAsFixed(1), "-10000000000000000.0"); expect(Int64.parseInt("-10000000000000002").toDouble().toStringAsFixed(1), @@ -586,8 +588,9 @@ void main() { expect(new Int64(4503599627370496).toInt(), 4503599627370496); expect(new Int64(-4503599627370495).toInt(), -4503599627370495); expect(new Int64(-4503599627370496).toInt(), -4503599627370496); - expect(Int64.parseInt("-10000000000000000").toInt(), - same(-10000000000000000)); + expect(Int64 + .parseInt("-10000000000000000") + .toInt(), same(-10000000000000000)); expect(Int64.parseInt("-10000000000000001").toInt(), same(-10000000000000001)); expect(Int64.parseInt("-10000000000000002").toInt(), @@ -680,7 +683,7 @@ void main() { check(String s, int r) { expect(Int64.parseRadix(s, r).toRadixString(r), s); } - check("2ppp111222333", 33); // This value & radix requires three chunks. + check("2ppp111222333", 33); // This value & radix requires three chunks. }); }); @@ -695,8 +698,8 @@ void main() { int top = 922337201; int bottom = 967490662; - Int64 fullnum = (new Int64(1000000000) * new Int64(top)) + - new Int64(bottom); + Int64 fullnum = + (new Int64(1000000000) * new Int64(top)) + new Int64(bottom); expect(fullnum.toString(), "922337201967490662"); expect((-fullnum).toString(), "-922337201967490662"); expect(new Int64(123456789).toString(), "123456789"); @@ -735,8 +738,8 @@ void main() { "111111111111111111111111111111111111111111111111111111111111111"); expect(Int64.MAX_VALUE.toRadixString(3), "2021110011022210012102010021220101220221"); - expect(Int64.MAX_VALUE.toRadixString(4), - "13333333333333333333333333333333"); + expect( + Int64.MAX_VALUE.toRadixString(4), "13333333333333333333333333333333"); expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212"); expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211"); expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300"); From eddb1e2e5b37b7e4bdf4a4c7aed12789489c95de Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sun, 8 Feb 2015 23:49:23 -0800 Subject: [PATCH 005/126] Version 0.9.1+1 --- pkgs/fixnum/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 2d54f859..98741a8a 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 0.9.1 +version: 0.9.1+1 author: Dart Team description: Library for 32- and 64-bit fixed size integers. homepage: http://www.dartlang.org From 6bd3c5f6a3604ba82e2e8d8080b94c9e7f0e2cfb Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sun, 8 Feb 2015 23:57:00 -0800 Subject: [PATCH 006/126] Add AUTHORS, PATENTS files. --- pkgs/fixnum/AUTHORS | 9 +++++++++ pkgs/fixnum/PATENTS | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 pkgs/fixnum/AUTHORS create mode 100644 pkgs/fixnum/PATENTS diff --git a/pkgs/fixnum/AUTHORS b/pkgs/fixnum/AUTHORS new file mode 100644 index 00000000..3d772aa2 --- /dev/null +++ b/pkgs/fixnum/AUTHORS @@ -0,0 +1,9 @@ +# Names should be added to this file with this pattern: +# +# For individuals: +# Name +# +# For organizations: +# Organization +# +Google Inc. <*@google.com> \ No newline at end of file diff --git a/pkgs/fixnum/PATENTS b/pkgs/fixnum/PATENTS new file mode 100644 index 00000000..39b78bab --- /dev/null +++ b/pkgs/fixnum/PATENTS @@ -0,0 +1,23 @@ +Additional IP Rights Grant (Patents) + +"This implementation" means the copyrightable works distributed by +Google as part of the Dart Project. + +Google hereby grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable (except as stated in this +section) patent license to make, have made, use, offer to sell, sell, +import, transfer, and otherwise run, modify and propagate the contents +of this implementation of Dart, where such license applies only to +those patent claims, both currently owned by Google and acquired in +the future, licensable by Google that are necessarily infringed by +this implementation of Dart. This grant does not include claims that +would be infringed only as a consequence of further modification of +this implementation. If you or your agent or exclusive licensee +institute or order or agree to the institution of patent litigation +against any entity (including a cross-claim or counterclaim in a +lawsuit) alleging that this implementation of Dart or any code +incorporated within this implementation of Dart constitutes direct or +contributory patent infringement, or inducement of patent +infringement, then any patent rights granted to you under this License +for this implementation of Dart shall terminate as of the date such +litigation is filed. \ No newline at end of file From c294c50d5640f7e8b6fbb522c949c3da42140078 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sun, 8 Feb 2015 23:56:08 -0800 Subject: [PATCH 007/126] Document example version constraint in README. --- pkgs/fixnum/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index 81f64674..8ec44835 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -14,7 +14,7 @@ Use [pub](http://pub.dartlang.org) to install this package. Add the following to your `pubspec.yaml` file: dependencies: - fixnum: any + fixnum: '>=0.9.1 <1.0.0' Then run `pub install`. From bd78aad63e59a0e312dad0fe4584a9d6d93da0ad Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 00:05:13 -0800 Subject: [PATCH 008/126] Eliminate extra underscore in test filenames. --- pkgs/fixnum/test/{int_32_test.dart => int32_test.dart} | 0 pkgs/fixnum/test/{int_64_test.dart => int64_test.dart} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename pkgs/fixnum/test/{int_32_test.dart => int32_test.dart} (100%) rename pkgs/fixnum/test/{int_64_test.dart => int64_test.dart} (100%) diff --git a/pkgs/fixnum/test/int_32_test.dart b/pkgs/fixnum/test/int32_test.dart similarity index 100% rename from pkgs/fixnum/test/int_32_test.dart rename to pkgs/fixnum/test/int32_test.dart diff --git a/pkgs/fixnum/test/int_64_test.dart b/pkgs/fixnum/test/int64_test.dart similarity index 100% rename from pkgs/fixnum/test/int_64_test.dart rename to pkgs/fixnum/test/int64_test.dart From 3a37274de5664f88b93950388dcb2b6868a76b61 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 00:05:42 -0800 Subject: [PATCH 009/126] Add all_tests.dart. --- pkgs/fixnum/test/all_tests.dart | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 pkgs/fixnum/test/all_tests.dart diff --git a/pkgs/fixnum/test/all_tests.dart b/pkgs/fixnum/test/all_tests.dart new file mode 100644 index 00000000..a93d00b9 --- /dev/null +++ b/pkgs/fixnum/test/all_tests.dart @@ -0,0 +1,7 @@ +import 'int32_test.dart' as int32_test; +import 'int64_test.dart' as int64_test; + +main() { + int32_test.main(); + int64_test.main(); +} From eae3a2d8ae4f98234c560b83e4a8e46b373a742e Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 00:07:58 -0800 Subject: [PATCH 010/126] Add Travis CI configuration. --- pkgs/fixnum/.travis.yml | 4 ++++ pkgs/fixnum/tool/travis.sh | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 pkgs/fixnum/.travis.yml create mode 100755 pkgs/fixnum/tool/travis.sh diff --git a/pkgs/fixnum/.travis.yml b/pkgs/fixnum/.travis.yml new file mode 100644 index 00000000..9dfa8c35 --- /dev/null +++ b/pkgs/fixnum/.travis.yml @@ -0,0 +1,4 @@ +language: dart +script: ./tool/travis.sh +env: + - DARTANALYZER_FLAGS=--fatal-warnings diff --git a/pkgs/fixnum/tool/travis.sh b/pkgs/fixnum/tool/travis.sh new file mode 100755 index 00000000..d0b2b235 --- /dev/null +++ b/pkgs/fixnum/tool/travis.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file for +# details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +# Fast fail the script on failures. +set -e + +# Verify that the libraries are error and warning-free. +echo "Running dartanalyzer..." +dartanalyzer lib/fixnum.dart test/all_tests.dart + +# Run the tests. +echo "Running tests..." +dart -c test/all_tests.dart From d8493ed261c1d7174a5ff3a3cb58133b3146ed59 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 00:11:06 -0800 Subject: [PATCH 011/126] Add .gitignore. --- pkgs/fixnum/.gitignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 pkgs/fixnum/.gitignore diff --git a/pkgs/fixnum/.gitignore b/pkgs/fixnum/.gitignore new file mode 100644 index 00000000..bda251a6 --- /dev/null +++ b/pkgs/fixnum/.gitignore @@ -0,0 +1,6 @@ +*.sw? +.idea +.pub +build +packages +pubspec.lock From c492f7c5383f6b5f69b28be246f4d95be7c77ef3 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 00:12:05 -0800 Subject: [PATCH 012/126] Add codereview.settings. --- pkgs/fixnum/codereview.settings | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pkgs/fixnum/codereview.settings diff --git a/pkgs/fixnum/codereview.settings b/pkgs/fixnum/codereview.settings new file mode 100644 index 00000000..25faff74 --- /dev/null +++ b/pkgs/fixnum/codereview.settings @@ -0,0 +1,3 @@ +CODE_REVIEW_SERVER: http://codereview.chromium.org/ +VIEW_VC: https://github.com/dart-lang/fixnum/commit/ +CC_LIST: reviews@dartlang.org From b705a55649a04183c6c035006745b2f7f7169317 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 00:18:15 -0800 Subject: [PATCH 013/126] Update installation instructions in README. --- pkgs/fixnum/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index 8ec44835..798a3437 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -16,7 +16,6 @@ to your `pubspec.yaml` file: dependencies: fixnum: '>=0.9.1 <1.0.0' -Then run `pub install`. - For more information, see the -[fixnum package on pub.dartlang.org](http://pub.dartlang.org/packages/fixnum). +[fixnum package](http://pub.dartlang.org/packages/fixnum) on +[pub.dartlang.org](http://pub.dartlang.org). From 1ae12c8f1dc1739eca9527464aa2331e385e42e9 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 09:22:30 -0800 Subject: [PATCH 014/126] Re-worded package description. --- pkgs/fixnum/README.md | 2 +- pkgs/fixnum/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index 798a3437..b3387ebc 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -1,7 +1,7 @@ fixnum ====== -A fixed-size integer library for Dart. +A fixed-width size integer library for Dart. - - - The fixnum package provides data types for signed 32- and 64-bit integers. The integer implementations in this library are designed to work identically diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 98741a8a..19709c7d 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,7 +1,7 @@ name: fixnum version: 0.9.1+1 author: Dart Team -description: Library for 32- and 64-bit fixed size integers. +description: Library for 32- and 64-bit signed fixed-width integers. homepage: http://www.dartlang.org dev_dependencies: unittest: ">=0.9.0 <0.10.0" From fa0bb30f106311d68bcd8ac99bb22ebff049b0ba Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 09:38:51 -0800 Subject: [PATCH 015/126] Fixed typo in README. --- pkgs/fixnum/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index b3387ebc..63cecda6 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -1,7 +1,7 @@ fixnum ====== -A fixed-width size integer library for Dart. +A fixed-width 32- and 64- bit integer library for Dart. - - - The fixnum package provides data types for signed 32- and 64-bit integers. The integer implementations in this library are designed to work identically From 2a31f5f61c46b043aedb6424a5b199053026bc64 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 09:44:08 -0800 Subject: [PATCH 016/126] README: Add Travis CI status badge. Update installation, contribution guidelines. --- pkgs/fixnum/README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index 63cecda6..448b4963 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -1,14 +1,17 @@ -fixnum +Fixnum ====== A fixed-width 32- and 64- bit integer library for Dart. -- - - + +[![Build Status](https://travis-ci.org/dart-lang/fixnum.svg?branch=master)](https://travis-ci.org/dart-lang/fixnum) + +## Documentation + The fixnum package provides data types for signed 32- and 64-bit integers. The integer implementations in this library are designed to work identically whether executed on the Dart VM or compiled to JavaScript. -Installing ----------- +## Installation Use [pub](http://pub.dartlang.org) to install this package. Add the following to your `pubspec.yaml` file: From c3d5495ad79a00fa1490858a9e070a8b77650259 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 16:58:23 -0800 Subject: [PATCH 017/126] Update fixnum homepage in pubspec.yaml. --- pkgs/fixnum/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 19709c7d..9e157461 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -2,7 +2,7 @@ name: fixnum version: 0.9.1+1 author: Dart Team description: Library for 32- and 64-bit signed fixed-width integers. -homepage: http://www.dartlang.org +homepage: https://github.com/dart-lang/fixnum dev_dependencies: unittest: ">=0.9.0 <0.10.0" environment: From 2498571238bb68ae09d17fe074d275dc5ea99f46 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 17:33:22 -0800 Subject: [PATCH 018/126] Update upper bound on unittest dev dependency to <0.12. --- pkgs/fixnum/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 9e157461..31fc5dd4 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -4,6 +4,6 @@ author: Dart Team description: Library for 32- and 64-bit signed fixed-width integers. homepage: https://github.com/dart-lang/fixnum dev_dependencies: - unittest: ">=0.9.0 <0.10.0" + unittest: ">=0.9.0 <0.12.0" environment: sdk: ">=0.8.10+6 <2.0.0" From 1d783970870eee4a321f8dc37f0bb16515f73271 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 17:37:14 -0800 Subject: [PATCH 019/126] Updated recommended dependency upper-bound in README. --- pkgs/fixnum/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index 448b4963..d9cd2ed5 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -17,7 +17,7 @@ Use [pub](http://pub.dartlang.org) to install this package. Add the following to your `pubspec.yaml` file: dependencies: - fixnum: '>=0.9.1 <1.0.0' + fixnum: '>=0.9.1 <0.10.0' For more information, see the [fixnum package](http://pub.dartlang.org/packages/fixnum) on From f4b9519231c2e7328fd89bd9f9cde7171a53b8ad Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 17:38:14 -0800 Subject: [PATCH 020/126] Version 0.9.1+2 --- pkgs/fixnum/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 31fc5dd4..1a3f4742 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 0.9.1+1 +version: 0.9.1+2 author: Dart Team description: Library for 32- and 64-bit signed fixed-width integers. homepage: https://github.com/dart-lang/fixnum From f46fbea1b182ef4ff2f7bbc6a3f69b4fc6b31146 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 21:11:56 -0800 Subject: [PATCH 021/126] Collect coverage during Travis CI run. --- pkgs/fixnum/README.md | 2 ++ pkgs/fixnum/tool/travis.sh | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index d9cd2ed5..d364fb7a 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -5,6 +5,8 @@ A fixed-width 32- and 64- bit integer library for Dart. [![Build Status](https://travis-ci.org/dart-lang/fixnum.svg?branch=master)](https://travis-ci.org/dart-lang/fixnum) +[![Coverage Status](https://img.shields.io/coveralls/dart-lang/fixnum.svg)](https://coveralls.io/r/dart-lang/fixnum) + ## Documentation The fixnum package provides data types for signed 32- and 64-bit integers. diff --git a/pkgs/fixnum/tool/travis.sh b/pkgs/fixnum/tool/travis.sh index d0b2b235..fc32dd0f 100755 --- a/pkgs/fixnum/tool/travis.sh +++ b/pkgs/fixnum/tool/travis.sh @@ -14,3 +14,13 @@ dartanalyzer lib/fixnum.dart test/all_tests.dart # Run the tests. echo "Running tests..." dart -c test/all_tests.dart + +# Gather and send coverage data. +if [ "$REPO_TOKEN" ]; then + pub global activate dart_coveralls + pub global run dart_coveralls report \ + --token $REPO_TOKEN \ + --retry 2 \ + --exclude-test-files \ + test/all_tests.dart +fi From 76c11b64f6f8d13598c3681c65d7bcaad92f172f Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 21:23:32 -0800 Subject: [PATCH 022/126] fixup! Collect coverage during Travis CI run. --- pkgs/fixnum/tool/travis.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/fixnum/tool/travis.sh b/pkgs/fixnum/tool/travis.sh index fc32dd0f..b7cc146f 100755 --- a/pkgs/fixnum/tool/travis.sh +++ b/pkgs/fixnum/tool/travis.sh @@ -17,6 +17,7 @@ dart -c test/all_tests.dart # Gather and send coverage data. if [ "$REPO_TOKEN" ]; then + echo "Collecting coverage..." pub global activate dart_coveralls pub global run dart_coveralls report \ --token $REPO_TOKEN \ From 04c367d93901d53679099f4278736db73173f206 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 21:28:56 -0800 Subject: [PATCH 023/126] Reformat badge placement in README.md --- pkgs/fixnum/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index d364fb7a..bb39a08a 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -4,7 +4,6 @@ Fixnum A fixed-width 32- and 64- bit integer library for Dart. [![Build Status](https://travis-ci.org/dart-lang/fixnum.svg?branch=master)](https://travis-ci.org/dart-lang/fixnum) - [![Coverage Status](https://img.shields.io/coveralls/dart-lang/fixnum.svg)](https://coveralls.io/r/dart-lang/fixnum) ## Documentation From 652ecb7acae9fba627ca87d345ec5e1c2b5b0a36 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 22:47:37 -0800 Subject: [PATCH 024/126] Add tests for illegal toRadixString arguments. --- pkgs/fixnum/test/int64_test.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 35109881..42292d8a 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -752,6 +752,9 @@ void main() { expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); + expect(() => new Int64(42).toRadixString(-1), throwsArgumentError); + expect(() => new Int64(42).toRadixString(0), throwsArgumentError); + expect(() => new Int64(42).toRadixString(37), throwsArgumentError); }); }); } From 4536379bf74a5df71467f2eeafab7befb7cf8045 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 22:34:24 -0800 Subject: [PATCH 025/126] Add tests for Int64 fromBytes, fromBytesBigEndian constructors. --- pkgs/fixnum/test/int64_test.dart | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 42292d8a..a6d3837f 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -8,6 +8,33 @@ import 'package:fixnum/fixnum.dart'; import 'package:unittest/unittest.dart'; void main() { + group("fromBytes", () { + test("fromBytes", () { + checkBytes(List bytes, int h, int l) { + expect(new Int64.fromBytes(bytes), new Int64.fromInts(h, l)); + } + checkBytes([ 0, 0, 0, 0, 0, 0, 0, 0 ], 0, 0); + checkBytes([ 1, 0, 0, 0, 0, 0, 0, 0 ], 0, 1); + checkBytes([ 1, 2, 3, 4, 5, 6, 7, 8 ], 0x08070605, 0x04030201); + checkBytes([ 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ], + 0xffffffff, 0xfffffffe); + checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ], + 0xffffffff, 0xffffffff); + }); + test("fromBytesBigEndian", () { + checkBytes(List bytes, int h, int l) { + expect(new Int64.fromBytesBigEndian(bytes), new Int64.fromInts(h, l)); + } + checkBytes([ 0, 0, 0, 0, 0, 0, 0, 0 ], 0, 0); + checkBytes([ 0, 0, 0, 0, 0, 0, 0, 1 ], 0, 1); + checkBytes([ 8, 7, 6, 5, 4, 3, 2, 1 ], 0x08070605, 0x04030201); + checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe ], + 0xffffffff, 0xfffffffe); + checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ], + 0xffffffff, 0xffffffff); + }); + }); + group("is-tests", () { test("isEven", () { expect((-Int64.ONE).isEven, false); From 11e8119d690bdce182b5de136c5dcb7aa456d969 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 22:40:18 -0800 Subject: [PATCH 026/126] Add operator == tests for int RHS. --- pkgs/fixnum/test/int64_test.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index a6d3837f..b180ed5e 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -319,14 +319,25 @@ void main() { }); test("==", () { + expect(new Int64(0) == new Int64(0), true); + expect(new Int64(0) == new Int64(1), false); + expect(new Int64(0) == new Int32(0), true); + expect(new Int64(0) == new Int32(1), false); + expect(new Int64(0) == 0, true); + expect(new Int64(0) == 1, false); expect(new Int64(10) == new Int64(11), false); expect(new Int64(10) == new Int64(10), true); expect(new Int64(10) == new Int64(9), false); expect(new Int64(10) == new Int32(11), false); expect(new Int64(10) == new Int32(10), true); expect(new Int64(10) == new Int32(9), false); + expect(new Int64(10) == 11, false); + expect(new Int64(10) == 10, true); + expect(new Int64(10) == 9, false); expect(new Int64(-10) == new Int64(-10), true); expect(new Int64(-10) != new Int64(-10), false); + expect(new Int64(-10) == -10, true); + expect(new Int64(-10) == -9, false); expect(largePos == largePos, true); expect(largePos == largePosPlusOne, false); expect(largePosPlusOne == largePos, false); From 51c151963f67dd4c6e79cfeab3222f1b1df89225 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 9 Feb 2015 22:08:27 -0800 Subject: [PATCH 027/126] Add unit tests for Int64.parseHex() --- pkgs/fixnum/test/int64_test.dart | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index b180ed5e..3601c8ac 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -704,6 +704,25 @@ void main() { throwsA(new isInstanceOf())); }); + test("parseHex", () { + checkHex(String hexStr, int h, int l) { + expect(Int64.parseHex(hexStr), new Int64.fromInts(h, l)); + } + checkHex('0', 0, 0); + checkHex('-0', 0, 0); + checkHex('00', 0, 0); + checkHex('01', 0, 1); + checkHex('-01', 0xffffffff, 0xffffffff); + checkHex('0a', 0, 10); + checkHex('0A', 0, 10); + checkHex('10', 0, 16); + checkHex('3FFFFF', 0, 0x3fffff); + checkHex('400000', 0, 0x400000); + checkHex('FFFFFFFFFFF', 0xfff, 0xffffffff); + checkHex('FFFFFFFFFFFFFFFE', 0xffffffff, 0xfffffffe); + checkHex('FFFFFFFFFFFFFFFF', 0xffffffff, 0xffffffff); + }); + test("parseRadix", () { check(String s, int r, String x) { expect(Int64.parseRadix(s, r).toString(), x); From 0acd88be85665aefbe064f49d4e25b7b0946f181 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 21:45:38 -0800 Subject: [PATCH 028/126] Add tests for Int64.numberOfLeadingZeros. --- pkgs/fixnum/test/int64_test.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 3601c8ac..4b647d7e 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -276,6 +276,19 @@ void main() { }); }); + group("leading/trailing zeros", () { + test("numberOfLeadingZeros", () { + expect(new Int64(0).numberOfLeadingZeros(), 64); + expect(new Int64(1).numberOfLeadingZeros(), 63); + expect(new Int64.fromInts(0x00000000, 0x003fffff).numberOfLeadingZeros(), 42); + expect(new Int64.fromInts(0x00000000, 0x00400000).numberOfLeadingZeros(), 41); + expect(new Int64.fromInts(0x00000fff, 0xffffffff).numberOfLeadingZeros(), 20); + expect(new Int64.fromInts(0x00001000, 0x00000000).numberOfLeadingZeros(), 19); + expect(new Int64.fromInts(0x7fffffff, 0xffffffff).numberOfLeadingZeros(), 1); + expect(new Int64(-1).numberOfLeadingZeros(), 0); + }); + }); + group("comparison operators", () { Int64 largeNeg = new Int64.fromInts(0x82341234, 0x0); Int64 largePos = new Int64.fromInts(0x12341234, 0x0); From 325ce3001e870d5f38599899aa50f3ccf33b56fd Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 21:56:49 -0800 Subject: [PATCH 029/126] Minor Int64 test cleanup. --- pkgs/fixnum/test/int64_test.dart | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 4b647d7e..f25dece3 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -278,14 +278,17 @@ void main() { group("leading/trailing zeros", () { test("numberOfLeadingZeros", () { - expect(new Int64(0).numberOfLeadingZeros(), 64); - expect(new Int64(1).numberOfLeadingZeros(), 63); - expect(new Int64.fromInts(0x00000000, 0x003fffff).numberOfLeadingZeros(), 42); - expect(new Int64.fromInts(0x00000000, 0x00400000).numberOfLeadingZeros(), 41); - expect(new Int64.fromInts(0x00000fff, 0xffffffff).numberOfLeadingZeros(), 20); - expect(new Int64.fromInts(0x00001000, 0x00000000).numberOfLeadingZeros(), 19); - expect(new Int64.fromInts(0x7fffffff, 0xffffffff).numberOfLeadingZeros(), 1); - expect(new Int64(-1).numberOfLeadingZeros(), 0); + checkZeros(Int64 value, int zeros) { + expect(value.numberOfLeadingZeros(), zeros); + } + checkZeros(new Int64(0), 64); + checkZeros(new Int64(1), 63); + checkZeros(new Int64.fromInts(0x00000000, 0x003fffff), 42); + checkZeros(new Int64.fromInts(0x00000000, 0x00400000), 41); + checkZeros(new Int64.fromInts(0x00000fff, 0xffffffff), 20); + checkZeros(new Int64.fromInts(0x00001000, 0x00000000), 19); + checkZeros(new Int64.fromInts(0x7fffffff, 0xffffffff), 1); + checkZeros(new Int64(-1), 0); }); }); From 05dc3c9c94aef134d2d25dfbac3c29a1ad1508f5 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 22:34:05 -0800 Subject: [PATCH 030/126] Add tests for Int64.numberOfTrailingZeros. --- pkgs/fixnum/test/int64_test.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index f25dece3..5d4b5c63 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -290,6 +290,21 @@ void main() { checkZeros(new Int64.fromInts(0x7fffffff, 0xffffffff), 1); checkZeros(new Int64(-1), 0); }); + + test("numberOfTrailingZeros", () { + checkZeros(Int64 value, int zeros) { + expect(value.numberOfTrailingZeros(), zeros); + } + checkZeros(new Int64(-1), 0); + checkZeros(new Int64(1), 0); + checkZeros(new Int64(2), 1); + checkZeros(new Int64.fromInts(0x00000000, 0x00200000), 21); + checkZeros(new Int64.fromInts(0x00000000, 0x00400000), 22); + checkZeros(new Int64.fromInts(0x00000800, 0x00000000), 43); + checkZeros(new Int64.fromInts(0x00001000, 0x00000000), 44); + checkZeros(new Int64.fromInts(0x80000000, 0x00000000), 63); + checkZeros(new Int64(0), 64); + }); }); group("comparison operators", () { From f86792f21b38d5ef5db3e234bdec487dcfacf670 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 22:53:58 -0800 Subject: [PATCH 031/126] Add tests for Int64.toBytes. --- pkgs/fixnum/test/int64_test.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 5d4b5c63..e7caa8fd 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -691,6 +691,16 @@ void main() { expect(new Int64(-2147483650).toInt32(), new Int32(2147483646)); expect(new Int64(-2147483651).toInt32(), new Int32(2147483645)); }); + + test("toBytes", () { + expect(new Int64(0).toBytes(), [ 0, 0, 0, 0, 0, 0, 0, 0 ]); + expect(new Int64.fromInts(0x08070605, 0x04030201).toBytes(), + [ 1, 2, 3, 4, 5, 6, 7, 8 ]); + expect(new Int64.fromInts(0x01020304, 0x05060708).toBytes(), + [ 8, 7, 6, 5, 4, 3, 2, 1 ]); + expect(new Int64(-1).toBytes(), + [ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ]); + }); }); test("JavaScript 53-bit integer boundary", () { From b4b33173dba6052ad9a52370c2193992db448c1e Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 23:22:02 -0800 Subject: [PATCH 032/126] Add tests for Int64 RHS for Int32 +, - operators. --- pkgs/fixnum/test/int32_test.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index dd8038d1..c6571d1f 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -64,6 +64,7 @@ void main() { expect(n1 + n2, new Int32(11110)); expect(n3 + n2, new Int32(8642)); expect(n3 + n4, new Int32(-11110)); + expect(n3 + new Int64(1), new Int64(-1233)); expect(Int32.MAX_VALUE + 1, Int32.MIN_VALUE); expect(() => new Int32(17) + null, throws); }); @@ -72,6 +73,7 @@ void main() { expect(n1 - n2, new Int32(-8642)); expect(n3 - n2, new Int32(-11110)); expect(n3 - n4, new Int32(8642)); + expect(n3 - new Int64(1), new Int64(-1235)); expect(Int32.MIN_VALUE - 1, Int32.MAX_VALUE); expect(() => new Int32(17) - null, throws); }); From e9b4e3a1a4f24980e213a37b54f117d5e96bd79d Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 23:56:58 -0800 Subject: [PATCH 033/126] Add tests for operator == with int RHS. --- pkgs/fixnum/test/int32_test.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index c6571d1f..4571bbd0 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -186,6 +186,9 @@ void main() { expect(new Int32(17) == new Int64(17), true); expect(new Int32(17) == new Int64(16), false); expect(Int32.MIN_VALUE == Int32.MAX_VALUE, false); + expect(new Int32(17) == 18, false); + expect(new Int32(17) == 17, true); + expect(new Int32(17) == 16, false); expect(new Int32(17) == new Object(), false); expect(new Int32(17) == null, false); }); From 2fc80698370e9f1b0caf1294ffc92e2d13fb0792 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 23:24:40 -0800 Subject: [PATCH 034/126] Add tests for Int32.compareTo. --- pkgs/fixnum/test/int32_test.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 4571bbd0..f2be733e 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -154,6 +154,18 @@ void main() { }); group("comparison operators", () { + test("compareTo", () { + expect(new Int32(0).compareTo(-1), 1); + expect(new Int32(0).compareTo(0), 0); + expect(new Int32(0).compareTo(1), -1); + expect(new Int32(0).compareTo(new Int32(-1)), 1); + expect(new Int32(0).compareTo(new Int32(0)), 0); + expect(new Int32(0).compareTo(new Int32(1)), -1); + expect(new Int32(0).compareTo(new Int64(-1)), 1); + expect(new Int32(0).compareTo(new Int64(0)), 0); + expect(new Int32(0).compareTo(new Int64(1)), -1); + }); + test("<", () { expect(new Int32(17) < new Int32(18), true); expect(new Int32(17) < new Int32(17), false); From df5fdb4fbca578bd6085dfe010f7c820581f1bef Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 23:26:59 -0800 Subject: [PATCH 035/126] Add tests for Int32.abs. --- pkgs/fixnum/test/int32_test.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index f2be733e..fe786f17 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -132,6 +132,15 @@ void main() { expect(() => new Int32(17).remainder(null), throws); }); + test("abs", () { + // NOTE: Int32.MIN_VALUE.abs() is undefined + expect((Int32.MIN_VALUE + 1).abs(), Int32.MAX_VALUE); + expect(new Int32(-1).abs(), new Int32(1)); + expect(new Int32(0).abs(), new Int32(0)); + expect(new Int32(1).abs(), new Int32(1)); + expect(Int32.MAX_VALUE.abs(), Int32.MAX_VALUE); + }); + test("clamp", () { Int32 val = new Int32(17); expect(val.clamp(20, 30), new Int32(20)); From c9c62f73f95a3d8a5583c8e0a9838a66d16ea9f9 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 23:40:39 -0800 Subject: [PATCH 036/126] Added Int32.clamp exception tests. --- pkgs/fixnum/test/int32_test.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index fe786f17..52474c61 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -157,8 +157,11 @@ void main() { expect(val.clamp(Int64.MIN_VALUE, new Int64(30)), new Int32(17)); expect(val.clamp(new Int64(10), Int64.MAX_VALUE), new Int32(17)); - expect(() => val.clamp(1, 'b'), throwsA(isArgumentError)); - expect(() => val.clamp('a', 1), throwsA(isArgumentError)); + expect(() => val.clamp(30.5, 40.5), throwsArgumentError); + expect(() => val.clamp(5.5, 10.5), throwsArgumentError); + expect(() => val.clamp('a', 1), throwsArgumentError); + expect(() => val.clamp(1, 'b'), throwsArgumentError); + expect(() => val.clamp('a', 1), throwsArgumentError); }); }); From d44d73e377cba7b057403c8c14f04bb2f780bd50 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 23:43:05 -0800 Subject: [PATCH 037/126] Add tests for Int32.numberOfLeadingZeros. --- pkgs/fixnum/test/int32_test.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 52474c61..f33c1c59 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -165,6 +165,15 @@ void main() { }); }); + group("leading/trailing zeros", () { + test("numberOfLeadingZeros", () { + expect(new Int32(0).numberOfLeadingZeros(), 32); + expect(new Int32(1).numberOfLeadingZeros(), 31); + expect(new Int32(0xffff).numberOfLeadingZeros(), 16); + expect(new Int32(-1).numberOfLeadingZeros(), 0); + }); + }); + group("comparison operators", () { test("compareTo", () { expect(new Int32(0).compareTo(-1), 1); From 8405b42910d04015e473edc8c36c79f86ab35ad1 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 23:44:44 -0800 Subject: [PATCH 038/126] Add tests for Int32.numberOfTrailingZeros. --- pkgs/fixnum/test/int32_test.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index f33c1c59..b5699f58 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -172,6 +172,12 @@ void main() { expect(new Int32(0xffff).numberOfLeadingZeros(), 16); expect(new Int32(-1).numberOfLeadingZeros(), 0); }); + test("numberOfTrailingZeros", () { + expect(new Int32(0).numberOfTrailingZeros(), 32); + expect(new Int32(0x80000000).numberOfTrailingZeros(), 31); + expect(new Int32(1).numberOfTrailingZeros(), 0); + expect(new Int32(0x10000).numberOfTrailingZeros(), 16); + }); }); group("comparison operators", () { From 377402a19cdde83388b6f9afce677f692672052f Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 23:48:54 -0800 Subject: [PATCH 039/126] Add tests for Int32.toBytes. --- pkgs/fixnum/test/int32_test.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index b5699f58..2d27e71e 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -346,6 +346,12 @@ void main() { expect(new Int32(17).toInt64(), new Int64(17)); expect(new Int32(-17).toInt64(), new Int64(-17)); }); + test("toBytes", () { + expect(new Int32(0).toBytes(), [ 0, 0, 0, 0 ]); + expect(new Int32(0x01020304).toBytes(), [ 4, 3, 2, 1 ]); + expect(new Int32(0x04030201).toBytes(), [ 1, 2, 3, 4 ]); + expect(new Int32(-1).toBytes(), [ 0xff, 0xff, 0xff, 0xff ]); + }); }); group("parse", () { From 477060c1e8c1a68c4af5d7a4b7f220b68fabd589 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 23:54:09 -0800 Subject: [PATCH 040/126] Add tests for Int32.parseInt. --- pkgs/fixnum/test/int32_test.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 2d27e71e..7d48371f 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -379,6 +379,12 @@ void main() { check('deadbeef', 16, '-559038737'); check('95', 12, '113'); }); + + test("parseInt", () { + expect(Int32.parseInt('0'), new Int32(0)); + expect(Int32.parseInt('1000'), new Int32(1000)); + expect(Int32.parseInt('4294967296'), new Int32(4294967296)); + }); }); group("string representation", () { From aa8749d91351fd467e64c655c8c70ea0ecf80a53 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 10 Feb 2015 23:54:25 -0800 Subject: [PATCH 041/126] Add tests for Int32.parseHex. --- pkgs/fixnum/test/int32_test.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 7d48371f..a5a5a00f 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -385,6 +385,12 @@ void main() { expect(Int32.parseInt('1000'), new Int32(1000)); expect(Int32.parseInt('4294967296'), new Int32(4294967296)); }); + + test("parseHex", () { + expect(Int32.parseHex('deadbeef'), new Int32(0xdeadbeef)); + expect(Int32.parseHex('cafebabe'), new Int32(0xcafebabe)); + expect(Int32.parseHex('8badf00d'), new Int32(0x8badf00d)); + }); }); group("string representation", () { From d2efd1da35b1c402f51401692b5bea7c737d45f4 Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Thu, 21 Apr 2016 10:12:34 -0700 Subject: [PATCH 042/126] Merge in changes from SDK branch Includes performance fixes and error tests. R=kevmoo@google.com Review URL: https://codereview.chromium.org//1834783004 . --- pkgs/fixnum/README.md | 8 -- pkgs/fixnum/lib/src/int32.dart | 13 ++- pkgs/fixnum/lib/src/int64.dart | 185 +++++++++++-------------------- pkgs/fixnum/lib/src/intx.dart | 2 +- pkgs/fixnum/pubspec.yaml | 2 +- pkgs/fixnum/test/int32_test.dart | 10 +- pkgs/fixnum/test/int64_test.dart | 63 +++++++---- 7 files changed, 116 insertions(+), 167 deletions(-) diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index bb39a08a..3e6af187 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -12,14 +12,6 @@ The fixnum package provides data types for signed 32- and 64-bit integers. The integer implementations in this library are designed to work identically whether executed on the Dart VM or compiled to JavaScript. -## Installation - -Use [pub](http://pub.dartlang.org) to install this package. Add the following -to your `pubspec.yaml` file: - - dependencies: - fixnum: '>=0.9.1 <0.10.0' - For more information, see the [fixnum package](http://pub.dartlang.org/packages/fixnum) on [pub.dartlang.org](http://pub.dartlang.org). diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index 32f36209..c5996f8a 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -57,15 +57,18 @@ class Int32 implements IntX { } } + static int _validateRadix(int radix) { + if (2 <= radix && radix <= 36) return radix; + throw new RangeError.range(radix, 2, 36, 'radix'); + } + /** * Parses a [String] in a given [radix] between 2 and 16 and returns an * [Int32]. */ // TODO(rice) - Make this faster by converting several digits at once. static Int32 parseRadix(String s, int radix) { - if ((radix <= 1) || (radix > 16)) { - throw new ArgumentError("Bad radix: $radix"); - } + _validateRadix(radix); Int32 x = ZERO; for (int i = 0; i < s.length; i++) { int c = s.codeUnitAt(i); @@ -348,12 +351,12 @@ class Int32 implements IntX { int numberOfTrailingZeros() => _numberOfTrailingZeros(_i); Int32 toSigned(int width) { - if (width < 1 || width > 32) throw new ArgumentError(width); + if (width < 1 || width > 32) throw new RangeError.range(width, 1, 32); return new Int32(_i.toSigned(width)); } Int32 toUnsigned(int width) { - if (width < 0 || width > 32) throw new ArgumentError(width); + if (width < 0 || width > 32) throw new RangeError.range(width, 0, 32); return new Int32(_i.toUnsigned(width)); } diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index 641bf71e..2ff48229 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -30,7 +30,7 @@ class Int64 implements IntX { static const int _MASK = 4194303; // (1 << _BITS) - 1 static const int _MASK2 = 1048575; // (1 << _BITS2) - 1 static const int _SIGN_BIT = 19; // _BITS2 - 1 - static const int _SIGN_BIT_MASK = 524288; // 1 << _SIGN_BIT + static const int _SIGN_BIT_MASK = 1 << _SIGN_BIT; /** * The maximum positive value attainable by an [Int64], namely @@ -70,10 +70,7 @@ class Int64 implements IntX { * [Int64]. */ static Int64 parseRadix(String s, int radix) { - if ((radix <= 1) || (radix > 36)) { - throw new ArgumentError("Bad radix: $radix"); - } - return _parseRadix(s, radix); + return _parseRadix(s, Int32._validateRadix(radix)); } static Int64 _parseRadix(String s, int radix) { @@ -83,9 +80,7 @@ class Int64 implements IntX { negative = true; i++; } - int d0 = 0, - d1 = 0, - d2 = 0; // low, middle, high components. + int d0 = 0, d1 = 0, d2 = 0; // low, middle, high components. for (; i < s.length; i++) { int c = s.codeUnitAt(i); int digit = Int32._decodeDigit(c); @@ -109,7 +104,7 @@ class Int64 implements IntX { if (negative) return _negate(d0, d1, d2); - return new Int64._bits(d0, d1, d2); + return Int64._masked(d0, d1, d2); } /** @@ -129,27 +124,20 @@ class Int64 implements IntX { /** * Constructs an [Int64] with a given [int] value; zero by default. */ - factory Int64([int value = 0]) { - int v0 = 0, - v1 = 0, - v2 = 0; + factory Int64([int value=0]) { + int v0 = 0, v1 = 0, v2 = 0; bool negative = false; if (value < 0) { negative = true; value = -value - 1; } - if (_haveBigInts) { - v0 = _MASK & value; - v1 = _MASK & (value >> _BITS); - v2 = _MASK2 & (value >> _BITS01); - } else { - // Avoid using bitwise operations that coerce their input to 32 bits. - v2 = value ~/ 17592186044416; // 2^44 - value -= v2 * 17592186044416; - v1 = value ~/ 4194304; // 2^22 - value -= v1 * 4194304; - v0 = value; - } + // Avoid using bitwise operations that in JavaScript coerce their input to + // 32 bits. + v2 = value ~/ 17592186044416; // 2^44 + value -= v2 * 17592186044416; + v1 = value ~/ 4194304; // 2^22 + value -= v1 * 4194304; + v0 = value; if (negative) { v0 = ~v0; @@ -197,7 +185,7 @@ class Int64 implements IntX { bottom |= bytes[7] & 0xff; return new Int64.fromInts(top, bottom); - } + } /** * Constructs an [Int64] from a pair of 32-bit integers having the value @@ -206,23 +194,23 @@ class Int64 implements IntX { factory Int64.fromInts(int top, int bottom) { top &= 0xffffffff; bottom &= 0xffffffff; - int d0 = bottom & _MASK; - int d1 = ((top & 0xfff) << 10) | ((bottom >> _BITS) & 0x3ff); - int d2 = (top >> 12) & _MASK2; - return new Int64._bits(d0, d1, d2); + int d0 = _MASK & bottom; + int d1 = ((0xfff & top) << 10) | (0x3ff & (bottom >> _BITS)); + int d2 = _MASK2 & (top >> 12); + return Int64._masked(d0, d1, d2); } // Returns the [Int64] representation of the specified value. Throws // [ArgumentError] for non-integer arguments. - static Int64 _promote(val) { - if (val is Int64) { - return val; - } else if (val is int) { - return new Int64(val); - } else if (val is Int32) { - return val.toInt64(); + static Int64 _promote(value) { + if (value is Int64) { + return value; + } else if (value is int) { + return new Int64(value); + } else if (value is Int32) { + return value.toInt64(); } - throw new ArgumentError(val); + throw new ArgumentError.value(value); } Int64 operator +(other) { @@ -316,12 +304,9 @@ class Int64 implements IntX { // Propagate high bits from c0 -> c1, c1 -> c2. c1 += c0 >> _BITS; - c0 &= _MASK; c2 += c1 >> _BITS; - c1 &= _MASK; - c2 &= _MASK2; - return new Int64._bits(c0, c1, c2); + return Int64._masked(c0, c1, c2); } Int64 operator %(other) => _divide(this, other, _RETURN_MOD); @@ -335,7 +320,7 @@ class Int64 implements IntX { int a0 = _l & o._l; int a1 = _m & o._m; int a2 = _h & o._h; - return new Int64._bits(a0, a1, a2); + return Int64._masked(a0, a1, a2); } Int64 operator |(other) { @@ -343,7 +328,7 @@ class Int64 implements IntX { int a0 = _l | o._l; int a1 = _m | o._m; int a2 = _h | o._h; - return new Int64._bits(a0, a1, a2); + return Int64._masked(a0, a1, a2); } Int64 operator ^(other) { @@ -351,7 +336,7 @@ class Int64 implements IntX { int a0 = _l ^ o._l; int a1 = _m ^ o._m; int a2 = _h ^ o._h; - return new Int64._bits(a0, a1, a2); + return Int64._masked(a0, a1, a2); } Int64 operator ~() { @@ -360,7 +345,7 @@ class Int64 implements IntX { Int64 operator <<(int n) { if (n < 0) { - throw new ArgumentError(n); + throw new ArgumentError.value(n); } n &= 63; @@ -384,7 +369,7 @@ class Int64 implements IntX { Int64 operator >>(int n) { if (n < 0) { - throw new ArgumentError(n); + throw new ArgumentError.value(n); } n &= 63; @@ -427,7 +412,7 @@ class Int64 implements IntX { Int64 shiftRightUnsigned(int n) { if (n < 0) { - throw new ArgumentError(n); + throw new ArgumentError.value(n); } n &= 63; @@ -473,7 +458,9 @@ class Int64 implements IntX { return false; } - int compareTo(Comparable other) { + int compareTo(Comparable other) =>_compareTo(other); + + int _compareTo(other) { Int64 o = _promote(other); int signa = _h >> (_BITS2 - 1); int signb = o._h >> (_BITS2 - 1); @@ -498,21 +485,10 @@ class Int64 implements IntX { return 0; } - bool operator <(other) { - return this.compareTo(other) < 0; - } - - bool operator <=(other) { - return this.compareTo(other) <= 0; - } - - bool operator >(other) { - return this.compareTo(other) > 0; - } - - bool operator >=(other) { - return this.compareTo(other) >= 0; - } + bool operator <(other) => _compareTo(other) < 0; + bool operator <=(other) => _compareTo(other) <= 0; + bool operator >(other) => this._compareTo(other) > 0; + bool operator >=(other) => _compareTo(other) >= 0; bool get isEven => (_l & 0x1) == 0; bool get isMaxValue => (_h == _MASK2 >> 1) && _m == _MASK && _l == _MASK; @@ -523,9 +499,7 @@ class Int64 implements IntX { int get bitLength { if (isZero) return 0; - int a0 = _l, - a1 = _m, - a2 = _h; + int a0 = _l, a1 = _m, a2 = _h; if (isNegative) { a0 = _MASK & ~a0; a1 = _MASK & ~a1; @@ -601,24 +575,24 @@ class Int64 implements IntX { } Int64 toSigned(int width) { - if (width < 1 || width > 64) throw new ArgumentError(width); + if (width < 1 || width > 64) throw new RangeError.range(width, 1, 64); if (width > _BITS01) { return Int64._masked(_l, _m, _h.toSigned(width - _BITS01)); } else if (width > _BITS) { int m = _m.toSigned(width - _BITS); return m.isNegative ? Int64._masked(_l, m, _MASK2) - : Int64._masked(_l, m, 0); // Masking for type inferrer. + : Int64._masked(_l, m, 0); // Masking for type inferrer. } else { int l = _l.toSigned(width); return l.isNegative ? Int64._masked(l, _MASK, _MASK2) - : Int64._masked(l, 0, 0); // Masking for type inferrer. + : Int64._masked(l, 0, 0); // Masking for type inferrer. } } Int64 toUnsigned(int width) { - if (width < 0 || width > 64) throw new ArgumentError(width); + if (width < 0 || width > 64) throw new RangeError.range(width, 0, 64); if (width > _BITS01) { int h = _h.toUnsigned(width - _BITS01); return Int64._masked(_l, _m, h); @@ -650,23 +624,15 @@ class Int64 implements IntX { int l = _l; int m = _m; int h = _h; - bool negative = false; + // In the sum we add least significant to most significant so that in + // JavaScript double arithmetic rounding occurs on only the last addition. if ((_h & _SIGN_BIT_MASK) != 0) { l = _MASK & ~_l; m = _MASK & ~_m; h = _MASK2 & ~_h; - negative = true; - } - - if (_haveBigInts) { - int result = (h << _BITS01) | (m << _BITS) | l; - return negative ? -result - 1 : result; + return -((1 + l) + (4194304 * m) + (17592186044416 * h)); } else { - if (negative) { - return -((l + 1) + (m * 4194304) + (h * 17592186044416)); - } else { - return (l + (m * 4194304)) + (h * 17592186044416); - } + return l + (4194304 * m) + (17592186044416 * h); } } @@ -692,7 +658,6 @@ class Int64 implements IntX { if (isZero) return "0"; Int64 x = this; String hexStr = ""; - Int64 digit_f = new Int64(0xf); while (!x.isZero) { int digit = x._l & 0xf; hexStr = "${_hexDigit(digit)}$hexStr"; @@ -702,10 +667,7 @@ class Int64 implements IntX { } String toRadixString(int radix) { - if ((radix <= 1) || (radix > 36)) { - throw new ArgumentError("Bad radix: $radix"); - } - return _toRadixString(radix); + return _toRadixString(Int32._validateRadix(radix)); } String _toRadixString(int radix) { @@ -764,9 +726,7 @@ class Int64 implements IntX { // need only two chunks, but radix values 17-19 and 33-36 generate only 15 // or 16 bits per iteration, so sometimes the third chunk is needed. - String chunk1 = "", - chunk2 = "", - chunk3 = ""; + String chunk1 = "", chunk2 = "", chunk3 = ""; while (!(d4 == 0 && d3 == 0)) { int q = d4 ~/ fatRadix; @@ -867,24 +827,6 @@ class Int64 implements IntX { return _sub(0, 0, 0, b0, b1, b2); } - // Determine whether the platform supports ints greater than 2^53 - // without loss of precision. - static bool _haveBigIntsCached = null; - - static bool get _haveBigInts { - if (_haveBigIntsCached == null) { - var x = 9007199254740992; - // Defeat compile-time constant folding. - if (2 + 2 != 4) { - x = 0; - } - var y = x + 1; - var same = y == x; - _haveBigIntsCached = !same; - } - return _haveBigIntsCached; - } - String _hexDigit(int digit) => "0123456789ABCDEF"[digit]; // Work around dart2js bugs with negative arguments to '>>' operator. @@ -930,15 +872,11 @@ class Int64 implements IntX { static _divideHelper( // up to 64 bits unsigned in a2/a1/a0 and b2/b1/b0 - int a0, int a1, int a2, bool aNeg, // input A. - int b0, int b1, int b2, bool bNeg, // input B. + int a0, int a1, int a2, bool aNeg, // input A. + int b0, int b1, int b2, bool bNeg, // input B. int what) { - int q0 = 0, - q1 = 0, - q2 = 0; // result Q. - int r0 = 0, - r1 = 0, - r2 = 0; // result R. + int q0 = 0, q1 = 0, q2 = 0; // result Q. + int r0 = 0, r1 = 0, r2 = 0; // result R. if (b2 == 0 && b1 == 0 && b0 < (1 << (30 - _BITS))) { // Small divisor can be handled by single-digit division within Smi range. @@ -986,7 +924,7 @@ class Int64 implements IntX { q0 = q0d.toInt(); assert(q0 + K1 * q1 + K2 * q2 == (ad / bd).floorToDouble()); - assert(q2 == 0 || b2 == 0); // Q and B can't both be big since Q*B <= A. + assert(q2 == 0 || b2 == 0); // Q and B can't both be big since Q*B <= A. // P = Q * B, using doubles to hold intermediates. // We don't need all partial sums since Q*B <= A. @@ -997,7 +935,7 @@ class Int64 implements IntX { double p1carry = (p1d / K1).floorToDouble(); p1d = p1d - p1carry * K1; double p2d = q2d * b0 + q1d * b1 + q0d * b2 + p1carry; - assert(p2d <= _MASK2); // No partial sum overflow. + assert(p2d <= _MASK2); // No partial sum overflow. // R = A - P int diff0 = a0 - p0d.toInt(); @@ -1009,7 +947,8 @@ class Int64 implements IntX { // while (R < 0 || R >= B) // adjust R towards [0, B) - while (r2 >= _SIGN_BIT_MASK || + while ( + r2 >= _SIGN_BIT_MASK || r2 > b2 || (r2 == b2 && (r1 > b1 || (r1 == b1 && r0 >= b0)))) { // Direction multiplier for adjustment. @@ -1034,17 +973,17 @@ class Int64 implements IntX { // 0 <= R < B assert(Int64.ZERO <= new Int64._bits(r0, r1, r2)); - assert(r2 < b2 || // Handles case where B = -(MIN_VALUE) + assert(r2 < b2 || // Handles case where B = -(MIN_VALUE) new Int64._bits(r0, r1, r2) < new Int64._bits(b0, b1, b2)); assert(what == _RETURN_DIV || what == _RETURN_MOD || what == _RETURN_REM); if (what == _RETURN_DIV) { if (aNeg != bNeg) return _negate(q0, q1, q2); - return Int64._masked(q0, q1, q2); // Masking for type inferrer. + return Int64._masked(q0, q1, q2); // Masking for type inferrer. } if (!aNeg) { - return new Int64._bits(_MASK & r0, r1, r2); // Masking for type inferrer. + return Int64._masked(r0, r1, r2); // Masking for type inferrer. } if (what == _RETURN_MOD) { diff --git a/pkgs/fixnum/lib/src/intx.dart b/pkgs/fixnum/lib/src/intx.dart index 859cb957..b47a35e1 100644 --- a/pkgs/fixnum/lib/src/intx.dart +++ b/pkgs/fixnum/lib/src/intx.dart @@ -130,7 +130,7 @@ abstract class IntX implements Comparable { IntX abs(); /** Clamps this integer to be in the range [lowerLimit] - [upperLimit]. */ - IntX clamp(IntX lowerLimit, IntX upperLimit); + IntX clamp(lowerLimit, upperLimit); /** * Returns the minimum number of bits required to store this integer. diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 1a3f4742..99f990eb 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 0.9.1+2 +version: 0.10.4 author: Dart Team description: Library for 32- and 64-bit signed fixed-width integers. homepage: https://github.com/dart-lang/fixnum diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index a5a5a00f..df958943 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -57,8 +57,6 @@ void main() { Int32 n2 = new Int32(9876); Int32 n3 = new Int32(-1234); Int32 n4 = new Int32(-9876); - Int32 n5 = new Int32(0x12345678); - Int32 n6 = new Int32(0x22222222); test("+", () { expect(n1 + n2, new Int32(11110)); @@ -317,8 +315,8 @@ void main() { expect(Int32.MIN_VALUE.toSigned(32), Int32.MIN_VALUE); expect(Int32.MAX_VALUE.toSigned(31), -Int32.ONE); expect(Int32.MIN_VALUE.toSigned(31), Int32.ZERO); - expect(() => Int32.ONE.toSigned(0), throws); - expect(() => Int32.ONE.toSigned(33), throws); + expect(() => Int32.ONE.toSigned(0), throwsRangeError); + expect(() => Int32.ONE.toSigned(33), throwsRangeError); }); test("toUnsigned", () { expect(Int32.ONE.toUnsigned(1), Int32.ONE); @@ -327,8 +325,8 @@ void main() { expect(Int32.MIN_VALUE.toUnsigned(32), Int32.MIN_VALUE); expect(Int32.MAX_VALUE.toUnsigned(31), Int32.MAX_VALUE); expect(Int32.MIN_VALUE.toUnsigned(31), Int32.ZERO); - expect(() => Int32.ONE.toUnsigned(-1), throws); - expect(() => Int32.ONE.toUnsigned(33), throws); + expect(() => Int32.ONE.toUnsigned(-1), throwsRangeError); + expect(() => Int32.ONE.toUnsigned(33), throwsRangeError); }); test("toDouble", () { expect(new Int32(17).toDouble(), same(17.0)); diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index e7caa8fd..c4498226 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -35,6 +35,14 @@ void main() { }); }); + argumentErrorTest(name, op, [receiver = Int64.ONE]) { + throwsArgumentErrorMentioning(substring) => + throwsA((e) => e is ArgumentError && '$e'.contains(substring)); + + expect(() => op(receiver, null), throwsArgumentErrorMentioning('null')); + expect(() => op(receiver, 'foo'), throwsArgumentErrorMentioning(r'"foo"')); + } + group("is-tests", () { test("isEven", () { expect((-Int64.ONE).isEven, false); @@ -96,6 +104,7 @@ void main() { expect(n3 + n4, new Int64(-11110)); expect(n5 + n6, new Int64.fromInts(0x89ab89ab, 0xcdeff011)); expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE); + argumentErrorTest("+", (a, b) => a + b); }); test("-", () { @@ -104,6 +113,7 @@ void main() { expect(n3 - n4, new Int64(8642)); expect(n5 - n6, new Int64.fromInts(0x9abd2345, 0x89ab6789)); expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE); + argumentErrorTest("-", (a, b) => a - b); }); test("unary -", () { @@ -141,6 +151,7 @@ void main() { expect(Int64.MIN_VALUE * new Int64(2), Int64.ZERO); expect(Int64.MIN_VALUE * new Int64(1), Int64.MIN_VALUE); expect(Int64.MIN_VALUE * new Int64(-1), Int64.MIN_VALUE); + argumentErrorTest("*", (a, b) => a * b); }); test("~/", () { @@ -213,7 +224,7 @@ void main() { expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE); expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE); expect(() => new Int64(17) ~/ Int64.ZERO, throws); - expect(() => new Int64(17) ~/ null, throwsArgumentError); + argumentErrorTest("~/", (a, b) => a ~/ b); }); test("%", () { @@ -253,6 +264,7 @@ void main() { new Int64(-0x12345678.remainder(0x22))); expect(new Int32(0x12345678).remainder(new Int64(0x22)), new Int64(0x12345678.remainder(0x22))); + argumentErrorTest("%", (a, b) => a % b); }); test("clamp", () { @@ -327,7 +339,7 @@ void main() { expect(largePosPlusOne < largePos, false); expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true); expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false); - expect(() => new Int64(17) < null, throwsArgumentError); + argumentErrorTest("<", (a, b) => a < b); }); test("<=", () { @@ -346,7 +358,7 @@ void main() { expect(largePosPlusOne <= largePos, false); expect(Int64.MIN_VALUE <= Int64.MAX_VALUE, true); expect(Int64.MAX_VALUE <= Int64.MIN_VALUE, false); - expect(() => new Int64(17) <= null, throwsArgumentError); + argumentErrorTest("<=", (a, b) => a <= b); }); test("==", () { @@ -393,7 +405,7 @@ void main() { expect(largePosPlusOne >= largePos, true); expect(Int64.MIN_VALUE >= Int64.MAX_VALUE, false); expect(Int64.MAX_VALUE >= Int64.MIN_VALUE, true); - expect(() => new Int64(17) >= null, throwsArgumentError); + argumentErrorTest(">=", (a, b) => a >= b); }); test(">", () { @@ -414,7 +426,7 @@ void main() { expect(Int64.ZERO > Int64.MIN_VALUE, true); expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false); expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true); - expect(() => new Int64(17) > null, throwsArgumentError); + argumentErrorTest(">", (a, b) => a > b); }); }); @@ -430,6 +442,7 @@ void main() { expect(n3 & n2, new Int64(8708)); expect(n4 & n5, new Int64(0x1034) << 32); expect(() => n1 & null, throwsArgumentError); + argumentErrorTest("&", (a, b) => a & b); }); test("|", () { @@ -437,6 +450,7 @@ void main() { expect(n3 | n2, new Int64(-66)); expect(n4 | n5, new Int64(0x9a76) << 32); expect(() => n1 | null, throwsArgumentError); + argumentErrorTest("|", (a, b) => a | b); }); test("^", () { @@ -444,6 +458,7 @@ void main() { expect(n3 ^ n2, new Int64(-8774)); expect(n4 ^ n5, new Int64(0x8a42) << 32); expect(() => n1 ^ null, throwsArgumentError); + argumentErrorTest("^", (a, b) => a ^ b); }); test("~", () { @@ -592,8 +607,8 @@ void main() { expect(Int64.MIN_VALUE.toSigned(64), Int64.MIN_VALUE); expect(Int64.MAX_VALUE.toSigned(63), -Int64.ONE); expect(Int64.MIN_VALUE.toSigned(63), Int64.ZERO); - expect(() => Int64.ONE.toSigned(0), throws); - expect(() => Int64.ONE.toSigned(65), throws); + expect(() => Int64.ONE.toSigned(0), throwsRangeError); + expect(() => Int64.ONE.toSigned(65), throwsRangeError); }); test("toUnsigned", () { expect((Int64.ONE << 44).toUnsigned(45), Int64.ONE << 44); @@ -606,8 +621,8 @@ void main() { expect(Int64.MIN_VALUE.toUnsigned(64), Int64.MIN_VALUE); expect(Int64.MAX_VALUE.toUnsigned(63), Int64.MAX_VALUE); expect(Int64.MIN_VALUE.toUnsigned(63), Int64.ZERO); - expect(() => Int64.ONE.toUnsigned(-1), throws); - expect(() => Int64.ONE.toUnsigned(65), throws); + expect(() => Int64.ONE.toUnsigned(-1), throwsRangeError); + expect(() => Int64.ONE.toUnsigned(65), throwsRangeError); }); test("toDouble", () { expect(new Int64(0).toDouble(), same(0.0)); @@ -619,14 +634,12 @@ void main() { expect(new Int64(-2147483648).toDouble(), same(-2147483648.0)); expect(new Int64(4503599627370495).toDouble(), same(4503599627370495.0)); expect(new Int64(4503599627370496).toDouble(), same(4503599627370496.0)); - expect( - new Int64(-4503599627370495).toDouble(), same(-4503599627370495.0)); - expect( - new Int64(-4503599627370496).toDouble(), same(-4503599627370496.0)); - expect(Int64 - .parseInt("-10000000000000000") - .toDouble() - .toStringAsFixed(1), "-10000000000000000.0"); + expect(new Int64(-4503599627370495).toDouble(), + same(-4503599627370495.0)); + expect(new Int64(-4503599627370496).toDouble(), + same(-4503599627370496.0)); + expect(Int64.parseInt("-10000000000000000").toDouble().toStringAsFixed(1), + "-10000000000000000.0"); expect(Int64.parseInt("-10000000000000001").toDouble().toStringAsFixed(1), "-10000000000000000.0"); expect(Int64.parseInt("-10000000000000002").toDouble().toStringAsFixed(1), @@ -657,9 +670,8 @@ void main() { expect(new Int64(4503599627370496).toInt(), 4503599627370496); expect(new Int64(-4503599627370495).toInt(), -4503599627370495); expect(new Int64(-4503599627370496).toInt(), -4503599627370496); - expect(Int64 - .parseInt("-10000000000000000") - .toInt(), same(-10000000000000000)); + expect(Int64.parseInt("-10000000000000000").toInt(), + same(-10000000000000000)); expect(Int64.parseInt("-10000000000000001").toInt(), same(-10000000000000001)); expect(Int64.parseInt("-10000000000000002").toInt(), @@ -775,13 +787,18 @@ void main() { check("9223372036854775807", 10, "9223372036854775807"); // Overflow during parsing. check("9223372036854775808", 10, "-9223372036854775808"); + + expect(() => Int64.parseRadix('0', 1), throwsRangeError); + expect(() => Int64.parseRadix('0', 37), throwsRangeError); + expect(() => Int64.parseRadix('xyzzy', -1), throwsRangeError); + expect(() => Int64.parseRadix('xyzzy', 10), throwsFormatException); }); test("parseRadixN", () { check(String s, int r) { expect(Int64.parseRadix(s, r).toRadixString(r), s); } - check("2ppp111222333", 33); // This value & radix requires three chunks. + check("2ppp111222333", 33); // This value & radix requires three chunks. }); }); @@ -836,8 +853,8 @@ void main() { "111111111111111111111111111111111111111111111111111111111111111"); expect(Int64.MAX_VALUE.toRadixString(3), "2021110011022210012102010021220101220221"); - expect( - Int64.MAX_VALUE.toRadixString(4), "13333333333333333333333333333333"); + expect(Int64.MAX_VALUE.toRadixString(4), + "13333333333333333333333333333333"); expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212"); expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211"); expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300"); From ee40f979f60a8c8d0bb94eb622effd0477f2fc1d Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Tue, 10 May 2016 14:48:41 -0700 Subject: [PATCH 043/126] Fix parameter types for compareTo(). Also adding a CHANGELOG and analysis_options since it's strong mode clean now. R=cbracken@google.com, leafp@google.com Review URL: https://codereview.chromium.org//1963283002 . --- pkgs/fixnum/.analysis_options | 2 ++ pkgs/fixnum/.gitignore | 1 + pkgs/fixnum/CHANGELOG.md | 5 +++++ pkgs/fixnum/lib/src/int32.dart | 2 +- pkgs/fixnum/lib/src/int64.dart | 2 +- pkgs/fixnum/lib/src/intx.dart | 4 ++-- pkgs/fixnum/pubspec.yaml | 2 +- 7 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 pkgs/fixnum/.analysis_options create mode 100644 pkgs/fixnum/CHANGELOG.md diff --git a/pkgs/fixnum/.analysis_options b/pkgs/fixnum/.analysis_options new file mode 100644 index 00000000..a10d4c5a --- /dev/null +++ b/pkgs/fixnum/.analysis_options @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true diff --git a/pkgs/fixnum/.gitignore b/pkgs/fixnum/.gitignore index bda251a6..0dceb6e0 100644 --- a/pkgs/fixnum/.gitignore +++ b/pkgs/fixnum/.gitignore @@ -3,4 +3,5 @@ .pub build packages +.packages pubspec.lock diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md new file mode 100644 index 00000000..9ec23ff9 --- /dev/null +++ b/pkgs/fixnum/CHANGELOG.md @@ -0,0 +1,5 @@ +## 0.10.5 + +* Fix strong mode warning in overridden `compareTo()` methods. + +*No changelog entries for previous versions...* diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index c5996f8a..786f2bb5 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -287,7 +287,7 @@ class Int32 implements IntX { return false; } - int compareTo(Comparable other) { + int compareTo(other) { if (other is Int64) { return this.toInt64().compareTo(other); } diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index 2ff48229..b7127eec 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -458,7 +458,7 @@ class Int64 implements IntX { return false; } - int compareTo(Comparable other) =>_compareTo(other); + int compareTo(other) => _compareTo(other); int _compareTo(other) { Int64 o = _promote(other); diff --git a/pkgs/fixnum/lib/src/intx.dart b/pkgs/fixnum/lib/src/intx.dart index b47a35e1..6b4a4540 100644 --- a/pkgs/fixnum/lib/src/intx.dart +++ b/pkgs/fixnum/lib/src/intx.dart @@ -7,7 +7,7 @@ part of fixnum; /** * A fixed-precision integer. */ -abstract class IntX implements Comparable { +abstract class IntX implements Comparable { /** Addition operator. */ IntX operator +(other); @@ -80,7 +80,7 @@ abstract class IntX implements Comparable { */ IntX shiftRightUnsigned(int shiftAmount); - int compareTo(Comparable other); + int compareTo(other); /** * Returns `true` if and only if [other] is an int or IntX equal in diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 99f990eb..96ccfa01 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 0.10.4 +version: 0.10.5 author: Dart Team description: Library for 32- and 64-bit signed fixed-width integers. homepage: https://github.com/dart-lang/fixnum From d659ba7e1444741b74b00724597f444b43baddea Mon Sep 17 00:00:00 2001 From: Keerti Parthasarathy Date: Fri, 14 Jul 2017 13:39:28 -0700 Subject: [PATCH 044/126] Migrate tests to using package test BUG= R=rnystrom@google.com Review-Url: https://codereview.chromium.org//2979043002 . --- pkgs/fixnum/pubspec.yaml | 2 +- pkgs/fixnum/test/int32_test.dart | 2 +- pkgs/fixnum/test/int64_test.dart | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 96ccfa01..185275fa 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -4,6 +4,6 @@ author: Dart Team description: Library for 32- and 64-bit signed fixed-width integers. homepage: https://github.com/dart-lang/fixnum dev_dependencies: - unittest: ">=0.9.0 <0.12.0" + test: ^0.12.0 environment: sdk: ">=0.8.10+6 <2.0.0" diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index df958943..d237a030 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -5,7 +5,7 @@ library Int32test; import 'package:fixnum/fixnum.dart'; -import 'package:unittest/unittest.dart'; +import 'package:test/test.dart'; void main() { group("isX tests", () { diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index c4498226..1ea7e75b 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -5,7 +5,7 @@ library int64test; import 'package:fixnum/fixnum.dart'; -import 'package:unittest/unittest.dart'; +import 'package:test/test.dart'; void main() { group("fromBytes", () { @@ -129,13 +129,13 @@ void main() { expect(new Int64(100) * Int64.ZERO, Int64.ZERO); expect(new Int64.fromInts(0x12345678, 0x12345678) * - new Int64.fromInts(0x1234, 0x12345678), + new Int64.fromInts(0x1234, 0x12345678), new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); expect(new Int64.fromInts(0xf2345678, 0x12345678) * - new Int64.fromInts(0x1234, 0x12345678), + new Int64.fromInts(0x1234, 0x12345678), new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); expect(new Int64.fromInts(0xf2345678, 0x12345678) * - new Int64.fromInts(0xffff1234, 0x12345678), + new Int64.fromInts(0xffff1234, 0x12345678), new Int64.fromInts(0x297e3f7c, 0x1df4d840)); // RHS Int32 @@ -203,16 +203,16 @@ void main() { expect(new Int64(-1000) ~/ new Int64(-3), new Int64(333)); expect(new Int64(3) ~/ new Int64(1000), Int64.ZERO); expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ - new Int64.fromInts(0x0, 0x123), + new Int64.fromInts(0x0, 0x123), new Int64.fromInts(0x1003d0, 0xe84f5ae8)); expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ - new Int64.fromInts(0x1234, 0x12345678), + new Int64.fromInts(0x1234, 0x12345678), new Int64.fromInts(0x0, 0x10003)); expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ - new Int64.fromInts(0x1234, 0x12345678), + new Int64.fromInts(0x1234, 0x12345678), new Int64.fromInts(0xffffffff, 0xffff3dfe)); expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ - new Int64.fromInts(0xffff1234, 0x12345678), + new Int64.fromInts(0xffff1234, 0x12345678), new Int64.fromInts(0x0, 0xeda)); expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461)); expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461)); From d3c525b69cf7913d326080008e3b33514b8e73a3 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 18 Jul 2017 10:33:45 -0700 Subject: [PATCH 045/126] dartfmt --- pkgs/fixnum/lib/src/int32.dart | 1 - pkgs/fixnum/lib/src/int64.dart | 62 ++++++++++++++------- pkgs/fixnum/lib/src/intx.dart | 1 - pkgs/fixnum/test/int32_test.dart | 13 +++-- pkgs/fixnum/test/int64_test.dart | 94 +++++++++++++++++++------------- 5 files changed, 105 insertions(+), 66 deletions(-) diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index 786f2bb5..562ff0c2 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -9,7 +9,6 @@ part of fixnum; * Arithmetic operations may overflow in order to maintain this range. */ class Int32 implements IntX { - /** * The maximum positive value attainable by an [Int32], namely * 2147483647. diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index b7127eec..87b8debb 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -9,7 +9,6 @@ part of fixnum; * Arithmetic operations may overflow in order to maintain this range. */ class Int64 implements IntX { - // A 64-bit integer is represented internally as three non-negative // integers, storing the 22 low, 22 middle, and 20 high bits of the // 64-bit value. _l (low) and _m (middle) are in the range @@ -80,7 +79,7 @@ class Int64 implements IntX { negative = true; i++; } - int d0 = 0, d1 = 0, d2 = 0; // low, middle, high components. + int d0 = 0, d1 = 0, d2 = 0; // low, middle, high components. for (; i < s.length; i++) { int c = s.codeUnitAt(i); int digit = Int32._decodeDigit(c); @@ -124,7 +123,7 @@ class Int64 implements IntX { /** * Constructs an [Int64] with a given [int] value; zero by default. */ - factory Int64([int value=0]) { + factory Int64([int value = 0]) { int v0 = 0, v1 = 0, v2 = 0; bool negative = false; if (value < 0) { @@ -185,7 +184,7 @@ class Int64 implements IntX { bottom |= bytes[7] & 0xff; return new Int64.fromInts(top, bottom); - } + } /** * Constructs an [Int64] from a pair of 32-bit integers having the value @@ -197,7 +196,7 @@ class Int64 implements IntX { int d0 = _MASK & bottom; int d1 = ((0xfff & top) << 10) | (0x3ff & (bottom >> _BITS)); int d2 = _MASK2 & (top >> 12); - return Int64._masked(d0, d1, d2); + return Int64._masked(d0, d1, d2); } // Returns the [Int64] representation of the specified value. Throws @@ -582,12 +581,12 @@ class Int64 implements IntX { int m = _m.toSigned(width - _BITS); return m.isNegative ? Int64._masked(_l, m, _MASK2) - : Int64._masked(_l, m, 0); // Masking for type inferrer. + : Int64._masked(_l, m, 0); // Masking for type inferrer. } else { int l = _l.toSigned(width); return l.isNegative ? Int64._masked(l, _MASK, _MASK2) - : Int64._masked(l, 0, 0); // Masking for type inferrer. + : Int64._masked(l, 0, 0); // Masking for type inferrer. } } @@ -771,8 +770,26 @@ class Int64 implements IntX { static const _fatRadixTable = const [ 0, 0, - 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 - * 2, + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2 * + 2, 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3, 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4, 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, @@ -872,11 +889,17 @@ class Int64 implements IntX { static _divideHelper( // up to 64 bits unsigned in a2/a1/a0 and b2/b1/b0 - int a0, int a1, int a2, bool aNeg, // input A. - int b0, int b1, int b2, bool bNeg, // input B. + int a0, + int a1, + int a2, + bool aNeg, // input A. + int b0, + int b1, + int b2, + bool bNeg, // input B. int what) { - int q0 = 0, q1 = 0, q2 = 0; // result Q. - int r0 = 0, r1 = 0, r2 = 0; // result R. + int q0 = 0, q1 = 0, q2 = 0; // result Q. + int r0 = 0, r1 = 0, r2 = 0; // result R. if (b2 == 0 && b1 == 0 && b0 < (1 << (30 - _BITS))) { // Small divisor can be handled by single-digit division within Smi range. @@ -924,7 +947,7 @@ class Int64 implements IntX { q0 = q0d.toInt(); assert(q0 + K1 * q1 + K2 * q2 == (ad / bd).floorToDouble()); - assert(q2 == 0 || b2 == 0); // Q and B can't both be big since Q*B <= A. + assert(q2 == 0 || b2 == 0); // Q and B can't both be big since Q*B <= A. // P = Q * B, using doubles to hold intermediates. // We don't need all partial sums since Q*B <= A. @@ -935,7 +958,7 @@ class Int64 implements IntX { double p1carry = (p1d / K1).floorToDouble(); p1d = p1d - p1carry * K1; double p2d = q2d * b0 + q1d * b1 + q0d * b2 + p1carry; - assert(p2d <= _MASK2); // No partial sum overflow. + assert(p2d <= _MASK2); // No partial sum overflow. // R = A - P int diff0 = a0 - p0d.toInt(); @@ -947,8 +970,7 @@ class Int64 implements IntX { // while (R < 0 || R >= B) // adjust R towards [0, B) - while ( - r2 >= _SIGN_BIT_MASK || + while (r2 >= _SIGN_BIT_MASK || r2 > b2 || (r2 == b2 && (r1 > b1 || (r1 == b1 && r0 >= b0)))) { // Direction multiplier for adjustment. @@ -973,17 +995,17 @@ class Int64 implements IntX { // 0 <= R < B assert(Int64.ZERO <= new Int64._bits(r0, r1, r2)); - assert(r2 < b2 || // Handles case where B = -(MIN_VALUE) + assert(r2 < b2 || // Handles case where B = -(MIN_VALUE) new Int64._bits(r0, r1, r2) < new Int64._bits(b0, b1, b2)); assert(what == _RETURN_DIV || what == _RETURN_MOD || what == _RETURN_REM); if (what == _RETURN_DIV) { if (aNeg != bNeg) return _negate(q0, q1, q2); - return Int64._masked(q0, q1, q2); // Masking for type inferrer. + return Int64._masked(q0, q1, q2); // Masking for type inferrer. } if (!aNeg) { - return Int64._masked(r0, r1, r2); // Masking for type inferrer. + return Int64._masked(r0, r1, r2); // Masking for type inferrer. } if (what == _RETURN_MOD) { diff --git a/pkgs/fixnum/lib/src/intx.dart b/pkgs/fixnum/lib/src/intx.dart index 6b4a4540..3c2207da 100644 --- a/pkgs/fixnum/lib/src/intx.dart +++ b/pkgs/fixnum/lib/src/intx.dart @@ -8,7 +8,6 @@ part of fixnum; * A fixed-precision integer. */ abstract class IntX implements Comparable { - /** Addition operator. */ IntX operator +(other); diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index d237a030..6f904cfd 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -302,8 +302,9 @@ void main() { test("shiftRightUnsigned", () { expect(new Int32(0x12345678).shiftRightUnsigned(7), new Int32(0x12345678 >> 7)); - expect(() => (new Int32(17).shiftRightUnsigned(-1)), throwsArgumentError); expect(() => (new Int32(17).shiftRightUnsigned(null)), throws); + expect(() => (new Int32(17).shiftRightUnsigned(null)), + throwsNoSuchMethodError); }); }); @@ -345,10 +346,10 @@ void main() { expect(new Int32(-17).toInt64(), new Int64(-17)); }); test("toBytes", () { - expect(new Int32(0).toBytes(), [ 0, 0, 0, 0 ]); - expect(new Int32(0x01020304).toBytes(), [ 4, 3, 2, 1 ]); - expect(new Int32(0x04030201).toBytes(), [ 1, 2, 3, 4 ]); - expect(new Int32(-1).toBytes(), [ 0xff, 0xff, 0xff, 0xff ]); + expect(new Int32(0).toBytes(), [0, 0, 0, 0]); + expect(new Int32(0x01020304).toBytes(), [4, 3, 2, 1]); + expect(new Int32(0x04030201).toBytes(), [1, 2, 3, 4]); + expect(new Int32(-1).toBytes(), [0xff, 0xff, 0xff, 0xff]); }); }); @@ -357,6 +358,7 @@ void main() { checkInt(int x) { expect(Int32.parseRadix('$x', 10), new Int32(x)); } + checkInt(0); checkInt(1); checkInt(1000); @@ -374,6 +376,7 @@ void main() { check(String s, int r, String x) { expect(Int32.parseRadix(s, r).toString(), x); } + check('deadbeef', 16, '-559038737'); check('95', 12, '113'); }); diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 1ea7e75b..8e6a90e3 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -13,25 +13,27 @@ void main() { checkBytes(List bytes, int h, int l) { expect(new Int64.fromBytes(bytes), new Int64.fromInts(h, l)); } - checkBytes([ 0, 0, 0, 0, 0, 0, 0, 0 ], 0, 0); - checkBytes([ 1, 0, 0, 0, 0, 0, 0, 0 ], 0, 1); - checkBytes([ 1, 2, 3, 4, 5, 6, 7, 8 ], 0x08070605, 0x04030201); - checkBytes([ 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ], - 0xffffffff, 0xfffffffe); - checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ], - 0xffffffff, 0xffffffff); + + checkBytes([0, 0, 0, 0, 0, 0, 0, 0], 0, 0); + checkBytes([1, 0, 0, 0, 0, 0, 0, 0], 0, 1); + checkBytes([1, 2, 3, 4, 5, 6, 7, 8], 0x08070605, 0x04030201); + checkBytes([0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], 0xffffffff, + 0xfffffffe); + checkBytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], 0xffffffff, + 0xffffffff); }); test("fromBytesBigEndian", () { checkBytes(List bytes, int h, int l) { expect(new Int64.fromBytesBigEndian(bytes), new Int64.fromInts(h, l)); } - checkBytes([ 0, 0, 0, 0, 0, 0, 0, 0 ], 0, 0); - checkBytes([ 0, 0, 0, 0, 0, 0, 0, 1 ], 0, 1); - checkBytes([ 8, 7, 6, 5, 4, 3, 2, 1 ], 0x08070605, 0x04030201); - checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe ], - 0xffffffff, 0xfffffffe); - checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ], - 0xffffffff, 0xffffffff); + + checkBytes([0, 0, 0, 0, 0, 0, 0, 0], 0, 0); + checkBytes([0, 0, 0, 0, 0, 0, 0, 1], 0, 1); + checkBytes([8, 7, 6, 5, 4, 3, 2, 1], 0x08070605, 0x04030201); + checkBytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe], 0xffffffff, + 0xfffffffe); + checkBytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], 0xffffffff, + 0xffffffff); }); }); @@ -128,14 +130,17 @@ void main() { expect(new Int64(-1111) * new Int64(-3), new Int64(3333)); expect(new Int64(100) * Int64.ZERO, Int64.ZERO); - expect(new Int64.fromInts(0x12345678, 0x12345678) * - new Int64.fromInts(0x1234, 0x12345678), + expect( + new Int64.fromInts(0x12345678, 0x12345678) * + new Int64.fromInts(0x1234, 0x12345678), new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); - expect(new Int64.fromInts(0xf2345678, 0x12345678) * - new Int64.fromInts(0x1234, 0x12345678), + expect( + new Int64.fromInts(0xf2345678, 0x12345678) * + new Int64.fromInts(0x1234, 0x12345678), new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); - expect(new Int64.fromInts(0xf2345678, 0x12345678) * - new Int64.fromInts(0xffff1234, 0x12345678), + expect( + new Int64.fromInts(0xf2345678, 0x12345678) * + new Int64.fromInts(0xffff1234, 0x12345678), new Int64.fromInts(0x297e3f7c, 0x1df4d840)); // RHS Int32 @@ -202,17 +207,21 @@ void main() { expect(new Int64(-1000) ~/ new Int64(3), new Int64(-333)); expect(new Int64(-1000) ~/ new Int64(-3), new Int64(333)); expect(new Int64(3) ~/ new Int64(1000), Int64.ZERO); - expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ - new Int64.fromInts(0x0, 0x123), + expect( + new Int64.fromInts(0x12345678, 0x12345678) ~/ + new Int64.fromInts(0x0, 0x123), new Int64.fromInts(0x1003d0, 0xe84f5ae8)); - expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ - new Int64.fromInts(0x1234, 0x12345678), + expect( + new Int64.fromInts(0x12345678, 0x12345678) ~/ + new Int64.fromInts(0x1234, 0x12345678), new Int64.fromInts(0x0, 0x10003)); - expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ - new Int64.fromInts(0x1234, 0x12345678), + expect( + new Int64.fromInts(0xf2345678, 0x12345678) ~/ + new Int64.fromInts(0x1234, 0x12345678), new Int64.fromInts(0xffffffff, 0xffff3dfe)); - expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ - new Int64.fromInts(0xffff1234, 0x12345678), + expect( + new Int64.fromInts(0xf2345678, 0x12345678) ~/ + new Int64.fromInts(0xffff1234, 0x12345678), new Int64.fromInts(0x0, 0xeda)); expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461)); expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461)); @@ -293,6 +302,7 @@ void main() { checkZeros(Int64 value, int zeros) { expect(value.numberOfLeadingZeros(), zeros); } + checkZeros(new Int64(0), 64); checkZeros(new Int64(1), 63); checkZeros(new Int64.fromInts(0x00000000, 0x003fffff), 42); @@ -307,6 +317,7 @@ void main() { checkZeros(Int64 value, int zeros) { expect(value.numberOfTrailingZeros(), zeros); } + checkZeros(new Int64(-1), 0); checkZeros(new Int64(1), 0); checkZeros(new Int64(2), 1); @@ -634,10 +645,10 @@ void main() { expect(new Int64(-2147483648).toDouble(), same(-2147483648.0)); expect(new Int64(4503599627370495).toDouble(), same(4503599627370495.0)); expect(new Int64(4503599627370496).toDouble(), same(4503599627370496.0)); - expect(new Int64(-4503599627370495).toDouble(), - same(-4503599627370495.0)); - expect(new Int64(-4503599627370496).toDouble(), - same(-4503599627370496.0)); + expect( + new Int64(-4503599627370495).toDouble(), same(-4503599627370495.0)); + expect( + new Int64(-4503599627370496).toDouble(), same(-4503599627370496.0)); expect(Int64.parseInt("-10000000000000000").toDouble().toStringAsFixed(1), "-10000000000000000.0"); expect(Int64.parseInt("-10000000000000001").toDouble().toStringAsFixed(1), @@ -705,13 +716,13 @@ void main() { }); test("toBytes", () { - expect(new Int64(0).toBytes(), [ 0, 0, 0, 0, 0, 0, 0, 0 ]); + expect(new Int64(0).toBytes(), [0, 0, 0, 0, 0, 0, 0, 0]); expect(new Int64.fromInts(0x08070605, 0x04030201).toBytes(), - [ 1, 2, 3, 4, 5, 6, 7, 8 ]); + [1, 2, 3, 4, 5, 6, 7, 8]); expect(new Int64.fromInts(0x01020304, 0x05060708).toBytes(), - [ 8, 7, 6, 5, 4, 3, 2, 1 ]); + [8, 7, 6, 5, 4, 3, 2, 1]); expect(new Int64(-1).toBytes(), - [ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ]); + [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]); }); }); @@ -723,6 +734,7 @@ void main() { return n * _factorial(n - new Int64(1)); } } + Int64 fact18 = _factorial(new Int64(18)); Int64 fact17 = _factorial(new Int64(17)); expect(fact18 ~/ fact17, new Int64(18)); @@ -738,6 +750,7 @@ void main() { checkInt(int x) { expect(Int64.parseRadix('$x', 10), new Int64(x)); } + checkInt(0); checkInt(1); checkInt(-1); @@ -761,6 +774,7 @@ void main() { checkHex(String hexStr, int h, int l) { expect(Int64.parseHex(hexStr), new Int64.fromInts(h, l)); } + checkHex('0', 0, 0); checkHex('-0', 0, 0); checkHex('00', 0, 0); @@ -780,6 +794,7 @@ void main() { check(String s, int r, String x) { expect(Int64.parseRadix(s, r).toString(), x); } + check('ghoul', 36, '27699213'); check('ghoul', 35, '24769346'); // Min and max value. @@ -798,7 +813,8 @@ void main() { check(String s, int r) { expect(Int64.parseRadix(s, r).toRadixString(r), s); } - check("2ppp111222333", 33); // This value & radix requires three chunks. + + check("2ppp111222333", 33); // This value & radix requires three chunks. }); }); @@ -853,8 +869,8 @@ void main() { "111111111111111111111111111111111111111111111111111111111111111"); expect(Int64.MAX_VALUE.toRadixString(3), "2021110011022210012102010021220101220221"); - expect(Int64.MAX_VALUE.toRadixString(4), - "13333333333333333333333333333333"); + expect( + Int64.MAX_VALUE.toRadixString(4), "13333333333333333333333333333333"); expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212"); expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211"); expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300"); From 86afd3fb08536e56c32bb5ed086992fd68597b9e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 18 Jul 2017 10:33:19 -0700 Subject: [PATCH 046/126] Cleanup some lints --- pkgs/fixnum/lib/src/int64.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index 87b8debb..cc78ab64 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -62,7 +62,7 @@ class Int64 implements IntX { * Constructs an [Int64] with a given bitwise representation. No validation * is performed. */ - const Int64._bits(int this._l, int this._m, int this._h); + const Int64._bits(this._l, this._m, this._h); /** * Parses a [String] in a given [radix] between 2 and 36 and returns an @@ -887,7 +887,7 @@ class Int64 implements IntX { static const _RETURN_REM = 2; static const _RETURN_MOD = 3; - static _divideHelper( + static Int64 _divideHelper( // up to 64 bits unsigned in a2/a1/a0 and b2/b1/b0 int a0, int a1, From 39e26ea5f2445de2eaa94e0c66e9daa701d5f49d Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 18 Jul 2017 10:33:27 -0700 Subject: [PATCH 047/126] cleanup throws uses --- pkgs/fixnum/test/int32_test.dart | 37 ++++++++++++++++++-------------- pkgs/fixnum/test/int64_test.dart | 12 ++++++----- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 6f904cfd..63149cf8 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -64,7 +64,7 @@ void main() { expect(n3 + n4, new Int32(-11110)); expect(n3 + new Int64(1), new Int64(-1233)); expect(Int32.MAX_VALUE + 1, Int32.MIN_VALUE); - expect(() => new Int32(17) + null, throws); + expect(() => new Int32(17) + null, throwsArgumentError); }); test("-", () { @@ -73,7 +73,7 @@ void main() { expect(n3 - n4, new Int32(8642)); expect(n3 - new Int64(1), new Int64(-1235)); expect(Int32.MIN_VALUE - 1, Int32.MAX_VALUE); - expect(() => new Int32(17) - null, throws); + expect(() => new Int32(17) - null, throwsArgumentError); }); test("unary -", () { @@ -93,7 +93,7 @@ void main() { expect(new Int32(0x12345678) * new Int64(0x22222222), new Int64.fromInts(0x026D60DC, 0xCA5F6BF0)); expect((new Int32(123456789) * 987654321), new Int32(-67153019)); - expect(() => new Int32(17) * null, throws); + expect(() => new Int32(17) * null, throwsArgumentError); }); test("~/", () { @@ -104,8 +104,13 @@ void main() { expect(new Int32(0x12345678) ~/ new Int64(0x22), new Int32(0x12345678 ~/ 0x22)); expect(new Int32(829893893) ~/ 1919, new Int32(432461)); - expect(() => new Int32(17) ~/ Int32.ZERO, throws); - expect(() => new Int32(17) ~/ null, throws); + expect( + () => new Int32(17) ~/ Int32.ZERO, + // with dart2js, `UnsupportedError` is thrown + // on the VM: IntegerDivisionByZeroException + throwsA(anyOf(new isInstanceOf(), + isUnsupportedError))); + expect(() => new Int32(17) ~/ null, throwsArgumentError); }); test("%", () { @@ -113,7 +118,7 @@ void main() { new Int32(0x12345678 % 0x22)); expect(new Int32(0x12345678) % new Int64(0x22), new Int32(0x12345678 % 0x22)); - expect(() => new Int32(17) % null, throws); + expect(() => new Int32(17) % null, throwsArgumentError); }); test("remainder", () { @@ -127,7 +132,7 @@ void main() { new Int32(-0x12345678.remainder(0x22))); expect(new Int32(0x12345678).remainder(new Int64(0x22)), new Int32(0x12345678.remainder(0x22))); - expect(() => new Int32(17).remainder(null), throws); + expect(() => new Int32(17).remainder(null), throwsArgumentError); }); test("abs", () { @@ -200,7 +205,7 @@ void main() { expect(new Int32(17) < new Int64(16), false); expect(Int32.MIN_VALUE < Int32.MAX_VALUE, true); expect(Int32.MAX_VALUE < Int32.MIN_VALUE, false); - expect(() => new Int32(17) < null, throws); + expect(() => new Int32(17) < null, throwsArgumentError); }); test("<=", () { @@ -212,7 +217,7 @@ void main() { expect(new Int32(17) <= new Int64(16), false); expect(Int32.MIN_VALUE <= Int32.MAX_VALUE, true); expect(Int32.MAX_VALUE <= Int32.MIN_VALUE, false); - expect(() => new Int32(17) <= null, throws); + expect(() => new Int32(17) <= null, throwsArgumentError); }); test("==", () { @@ -239,7 +244,7 @@ void main() { expect(new Int32(17) >= new Int64(16), true); expect(Int32.MIN_VALUE >= Int32.MAX_VALUE, false); expect(Int32.MAX_VALUE >= Int32.MIN_VALUE, true); - expect(() => new Int32(17) >= null, throws); + expect(() => new Int32(17) >= null, throwsArgumentError); }); test(">", () { @@ -251,7 +256,7 @@ void main() { expect(new Int32(17) > new Int64(16), true); expect(Int32.MIN_VALUE > Int32.MAX_VALUE, false); expect(Int32.MAX_VALUE > Int32.MIN_VALUE, true); - expect(() => new Int32(17) > null, throws); + expect(() => new Int32(17) > null, throwsArgumentError); }); }); @@ -269,7 +274,7 @@ void main() { new Int32(0x12345678 | 0x22222222)); expect(new Int32(0x12345678) | new Int64(0x22222222), new Int64(0x12345678 | 0x22222222)); - expect(() => new Int32(17) | null, throws); + expect(() => new Int32(17) | null, throwsArgumentError); }); test("^", () { @@ -277,7 +282,7 @@ void main() { new Int32(0x12345678 ^ 0x22222222)); expect(new Int32(0x12345678) ^ new Int64(0x22222222), new Int64(0x12345678 ^ 0x22222222)); - expect(() => new Int32(17) ^ null, throws); + expect(() => new Int32(17) ^ null, throwsArgumentError); }); test("~", () { @@ -290,19 +295,19 @@ void main() { test("<<", () { expect(new Int32(0x12345678) << 7, new Int32(0x12345678 << 7)); expect(() => new Int32(17) << -1, throwsArgumentError); - expect(() => new Int32(17) << null, throws); + expect(() => new Int32(17) << null, throwsNoSuchMethodError); }); test(">>", () { expect(new Int32(0x12345678) >> 7, new Int32(0x12345678 >> 7)); expect(() => new Int32(17) >> -1, throwsArgumentError); - expect(() => new Int32(17) >> null, throws); + expect(() => new Int32(17) >> null, throwsNoSuchMethodError); }); test("shiftRightUnsigned", () { expect(new Int32(0x12345678).shiftRightUnsigned(7), new Int32(0x12345678 >> 7)); - expect(() => (new Int32(17).shiftRightUnsigned(null)), throws); + expect(() => (new Int32(17).shiftRightUnsigned(-1)), throwsArgumentError); expect(() => (new Int32(17).shiftRightUnsigned(null)), throwsNoSuchMethodError); }); diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 8e6a90e3..4ae7aea7 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -38,7 +38,7 @@ void main() { }); argumentErrorTest(name, op, [receiver = Int64.ONE]) { - throwsArgumentErrorMentioning(substring) => + throwsArgumentErrorMentioning(String substring) => throwsA((e) => e is ArgumentError && '$e'.contains(substring)); expect(() => op(receiver, null), throwsArgumentErrorMentioning('null')); @@ -232,7 +232,8 @@ void main() { new Int64.fromInts(0xc0000000, 0x00000000)); expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE); expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE); - expect(() => new Int64(17) ~/ Int64.ZERO, throws); + expect(() => new Int64(17) ~/ Int64.ZERO, + throwsA(new isInstanceOf())); argumentErrorTest("~/", (a, b) => a ~/ b); }); @@ -494,7 +495,7 @@ void main() { expect(new Int64(-1) << 5, new Int64(-32)); expect(new Int64(-1) << 0, new Int64(-1)); expect(() => new Int64(17) << -1, throwsArgumentError); - expect(() => new Int64(17) << null, throws); + expect(() => new Int64(17) << null, throwsNoSuchMethodError); }); test(">>", () { @@ -545,7 +546,7 @@ void main() { expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 48, new Int64.fromInts(0xffffffff, 0xffff9234)); expect(() => new Int64(17) >> -1, throwsArgumentError); - expect(() => new Int64(17) >> null, throws); + expect(() => new Int64(17) >> null, throwsNoSuchMethodError); }); test("shiftRightUnsigned", () { @@ -590,7 +591,8 @@ void main() { expect(new Int64.fromInts(0x00000000, 0x00009234), new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48)); expect(() => new Int64(17).shiftRightUnsigned(-1), throwsArgumentError); - expect(() => new Int64(17).shiftRightUnsigned(null), throws); + expect(() => new Int64(17).shiftRightUnsigned(null), + throwsNoSuchMethodError); }); test("overflow", () { From 4c9351b006695579ec454286ec920c27655ac9b5 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 18 Jul 2017 10:37:08 -0700 Subject: [PATCH 048/126] Use correct name of analysis_options --- pkgs/fixnum/{.analysis_options => analysis_options.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pkgs/fixnum/{.analysis_options => analysis_options.yaml} (100%) diff --git a/pkgs/fixnum/.analysis_options b/pkgs/fixnum/analysis_options.yaml similarity index 100% rename from pkgs/fixnum/.analysis_options rename to pkgs/fixnum/analysis_options.yaml From f6cd486e9915ba00c4425008036c80ef20214a4e Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Tue, 18 Jul 2017 11:29:14 -0700 Subject: [PATCH 049/126] travis: migrated to dart_task and added dart2js testing (firefox) (dart-lang/fixnum#25) --- pkgs/fixnum/.travis.yml | 27 ++++++++++++++++++++++++--- pkgs/fixnum/tool/travis.sh | 27 --------------------------- 2 files changed, 24 insertions(+), 30 deletions(-) delete mode 100755 pkgs/fixnum/tool/travis.sh diff --git a/pkgs/fixnum/.travis.yml b/pkgs/fixnum/.travis.yml index 9dfa8c35..c2842f8d 100644 --- a/pkgs/fixnum/.travis.yml +++ b/pkgs/fixnum/.travis.yml @@ -1,4 +1,25 @@ language: dart -script: ./tool/travis.sh -env: - - DARTANALYZER_FLAGS=--fatal-warnings +sudo: false + +dart: + - dev + - stable + +dart_task: + - test: --platform vm + xvfb: false + - test: --platform firefox -j 1 + - dartanalyzer --fatal-warnings + +matrix: + include: + - dart: stable + dart_task: dartfmt + +# Only building master means that we don't run two builds for each pull request. +branches: + only: [master] + +cache: + directories: + - $HOME/.pub-cache diff --git a/pkgs/fixnum/tool/travis.sh b/pkgs/fixnum/tool/travis.sh deleted file mode 100755 index b7cc146f..00000000 --- a/pkgs/fixnum/tool/travis.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file for -# details. All rights reserved. Use of this source code is governed by a -# BSD-style license that can be found in the LICENSE file. - -# Fast fail the script on failures. -set -e - -# Verify that the libraries are error and warning-free. -echo "Running dartanalyzer..." -dartanalyzer lib/fixnum.dart test/all_tests.dart - -# Run the tests. -echo "Running tests..." -dart -c test/all_tests.dart - -# Gather and send coverage data. -if [ "$REPO_TOKEN" ]; then - echo "Collecting coverage..." - pub global activate dart_coveralls - pub global run dart_coveralls report \ - --token $REPO_TOKEN \ - --retry 2 \ - --exclude-test-files \ - test/all_tests.dart -fi From d0d0dd0c45fce7aac0410cd51868603eb7f35e10 Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Wed, 19 Jul 2017 12:30:53 -0700 Subject: [PATCH 050/126] Int64(int value) should not be sensitive to rounding errors (dart-lang/fixnum#26) * Int64(int value) should not be sensitive to rounding errors * fix error in test * fix constructor * new package version number --- pkgs/fixnum/CHANGELOG.md | 7 +++++++ pkgs/fixnum/lib/src/int64.dart | 11 ++++------- pkgs/fixnum/pubspec.yaml | 4 ++-- pkgs/fixnum/test/int64_test.dart | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 9ec23ff9..228c9975 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.10.6 + +* Fix `Int64([int value])` constructor to avoid rounding error on intermediate + results for large negative inputs when compiled to JavaScript. `new + Int64(-1000000000000000000)` used to produce the same value as + `Int64.parseInt("-1000000000000000001")` + ## 0.10.5 * Fix strong mode warning in overridden `compareTo()` methods. diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index cc78ab64..c25b8fa5 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -128,7 +128,7 @@ class Int64 implements IntX { bool negative = false; if (value < 0) { negative = true; - value = -value - 1; + value = -value; } // Avoid using bitwise operations that in JavaScript coerce their input to // 32 bits. @@ -138,12 +138,9 @@ class Int64 implements IntX { value -= v1 * 4194304; v0 = value; - if (negative) { - v0 = ~v0; - v1 = ~v1; - v2 = ~v2; - } - return Int64._masked(v0, v1, v2); + return negative + ? Int64._negate(_MASK & v0, _MASK & v1, _MASK2 & v2) + : Int64._masked(v0, v1, v2); } factory Int64.fromBytes(List bytes) { diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 185275fa..a80a13ed 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,9 +1,9 @@ name: fixnum -version: 0.10.5 +version: 0.10.6 author: Dart Team description: Library for 32- and 64-bit signed fixed-width integers. homepage: https://github.com/dart-lang/fixnum dev_dependencies: test: ^0.12.0 environment: - sdk: ">=0.8.10+6 <2.0.0" + sdk: ">=1.8.3 <2.0.0-dev.infinity" diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 4ae7aea7..fbd008d7 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -747,6 +747,20 @@ void main() { expect(-(Int64.MIN_VALUE + new Int64(1)), Int64.MAX_VALUE); }); + test("", () { + check(int n) { + // Sign change should commute with conversion. + expect(-new Int64(-n), new Int64(n)); + expect(new Int64(-n), -new Int64(n)); + } + + check(10); + check(1000000000000000000); + check(9223372000000000000); // near Int64.MAX_VALUE, has exact double value + check(9223372036854775807); // Int64.MAX_VALUE, rounds up to -MIN_VALUE + check(-9223372036854775808); // Int64.MIN_VALUE + }); + group("parse", () { test("parseRadix10", () { checkInt(int x) { From 961caec29bb25cf2fd82e999a7e07dc764cd2f41 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 21 Sep 2017 11:51:09 -0700 Subject: [PATCH 051/126] Fix SDK constraint (dart-lang/fixnum#29) --- pkgs/fixnum/pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index a80a13ed..e415e6cf 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,9 +1,9 @@ name: fixnum -version: 0.10.6 +version: 0.10.7-dev author: Dart Team description: Library for 32- and 64-bit signed fixed-width integers. homepage: https://github.com/dart-lang/fixnum dev_dependencies: test: ^0.12.0 environment: - sdk: ">=1.8.3 <2.0.0-dev.infinity" + sdk: ">=1.8.3 <2.0.0" From ab446689db31c9ec72799fb50c4c88a673ea3aa8 Mon Sep 17 00:00:00 2001 From: "Nam T. Nguyen" Date: Fri, 12 Jan 2018 12:55:19 -0800 Subject: [PATCH 052/126] Fix dart-lang/fixnum#31: Make shifts work at width boundaries. --- pkgs/fixnum/lib/src/int32.dart | 12 +++++++++--- pkgs/fixnum/lib/src/int64.dart | 12 +++++++++--- pkgs/fixnum/test/int32_test.dart | 10 ++++++++++ pkgs/fixnum/test/int64_test.dart | 6 ++++++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index 562ff0c2..db8ecd0f 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -239,7 +239,9 @@ class Int32 implements IntX { if (n < 0) { throw new ArgumentError(n); } - n &= 31; + if (n >= 32) { + return ZERO; + } return new Int32(_i << n); } @@ -247,7 +249,9 @@ class Int32 implements IntX { if (n < 0) { throw new ArgumentError(n); } - n &= 31; + if (n >= 32) { + return isNegative ? const Int32._internal(-1) : ZERO; + } int value; if (_i >= 0) { value = _i >> n; @@ -261,7 +265,9 @@ class Int32 implements IntX { if (n < 0) { throw new ArgumentError(n); } - n &= 31; + if (n >= 32) { + return ZERO; + } int value; if (_i >= 0) { value = _i >> n; diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index c25b8fa5..a84cbd98 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -343,7 +343,9 @@ class Int64 implements IntX { if (n < 0) { throw new ArgumentError.value(n); } - n &= 63; + if (n >= 64) { + return ZERO; + } int res0, res1, res2; if (n < _BITS) { @@ -367,7 +369,9 @@ class Int64 implements IntX { if (n < 0) { throw new ArgumentError.value(n); } - n &= 63; + if (n >= 64) { + return isNegative ? const Int64._bits(_MASK, _MASK, _MASK2) : ZERO; + } int res0, res1, res2; @@ -410,7 +414,9 @@ class Int64 implements IntX { if (n < 0) { throw new ArgumentError.value(n); } - n &= 63; + if (n >= 64) { + return ZERO; + } int res0, res1, res2; int a2 = _MASK2 & _h; // Ensure a2 is positive. diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 63149cf8..afa7eeb9 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -294,12 +294,18 @@ void main() { group("bitshift operators", () { test("<<", () { expect(new Int32(0x12345678) << 7, new Int32(0x12345678 << 7)); + expect(new Int32(0x12345678) << 32, Int32.ZERO); + expect(new Int32(0x12345678) << 33, Int32.ZERO); expect(() => new Int32(17) << -1, throwsArgumentError); expect(() => new Int32(17) << null, throwsNoSuchMethodError); }); test(">>", () { expect(new Int32(0x12345678) >> 7, new Int32(0x12345678 >> 7)); + expect(new Int32(0x12345678) >> 32, Int32.ZERO); + expect(new Int32(0x12345678) >> 33, Int32.ZERO); + expect(new Int32(-42) >> 32, new Int32(-1)); + expect(new Int32(-42) >> 33, new Int32(-1)); expect(() => new Int32(17) >> -1, throwsArgumentError); expect(() => new Int32(17) >> null, throwsNoSuchMethodError); }); @@ -307,6 +313,10 @@ void main() { test("shiftRightUnsigned", () { expect(new Int32(0x12345678).shiftRightUnsigned(7), new Int32(0x12345678 >> 7)); + expect(new Int32(0x12345678).shiftRightUnsigned(32), Int32.ZERO); + expect(new Int32(0x12345678).shiftRightUnsigned(33), Int32.ZERO); + expect(new Int32(-42).shiftRightUnsigned(32), Int32.ZERO); + expect(new Int32(-42).shiftRightUnsigned(33), Int32.ZERO); expect(() => (new Int32(17).shiftRightUnsigned(-1)), throwsArgumentError); expect(() => (new Int32(17).shiftRightUnsigned(null)), throwsNoSuchMethodError); diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index fbd008d7..8106c2eb 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -494,6 +494,8 @@ void main() { new Int64.fromInts(0xd048d115, 0x9d159c00)); expect(new Int64(-1) << 5, new Int64(-32)); expect(new Int64(-1) << 0, new Int64(-1)); + expect(new Int64(42) << 64, Int64.ZERO); + expect(new Int64(42) << 65, Int64.ZERO); expect(() => new Int64(17) << -1, throwsArgumentError); expect(() => new Int64(17) << null, throwsNoSuchMethodError); }); @@ -506,6 +508,8 @@ void main() { new Int64.fromInts(0xffe48d04, 0x8d1159d1)); expect( new Int64.fromInts(0xFFFFFFF, 0xFFFFFFFF) >> 34, new Int64(67108863)); + expect(new Int64(42) >> 64, Int64.ZERO); + expect(new Int64(42) >> 65, Int64.ZERO); for (int n = 0; n <= 66; n++) { expect(new Int64(-1) >> n, new Int64(-1)); } @@ -590,6 +594,8 @@ void main() { new Int64.fromInts(0x00000000, 0x00092345)); expect(new Int64.fromInts(0x00000000, 0x00009234), new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48)); + expect(new Int64(-1).shiftRightUnsigned(64), Int64.ZERO); + expect(new Int64(1).shiftRightUnsigned(64), Int64.ZERO); expect(() => new Int64(17).shiftRightUnsigned(-1), throwsArgumentError); expect(() => new Int64(17).shiftRightUnsigned(null), throwsNoSuchMethodError); From e20672c525b69e6ebd81830800d4ef05b4275fff Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 6 Feb 2018 15:20:10 -0800 Subject: [PATCH 053/126] Version 0.10.7 (dart-lang/fixnum#34) --- pkgs/fixnum/CHANGELOG.md | 7 +++++++ pkgs/fixnum/pubspec.yaml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 228c9975..3a427acd 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.10.7 + +* Bugfix: Make bitshifts work at bitwidth boundaries. Previously, + `new Int64(3) << 64 == Int64(3)`. This ensures that the result is 0 in such + cases. +* Updated maximum SDK constraint from 2.0.0-dev.infinity to 2.0.0. + ## 0.10.6 * Fix `Int64([int value])` constructor to avoid rounding error on intermediate diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index e415e6cf..d794eb1d 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 0.10.7-dev +version: 0.10.7 author: Dart Team description: Library for 32- and 64-bit signed fixed-width integers. homepage: https://github.com/dart-lang/fixnum From cf9b71fd4bc15ad0cffee22c224721c12305d8d6 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 16 Mar 2018 08:42:43 -0700 Subject: [PATCH 054/126] Delete PATENTS Approved by Google OSS --- pkgs/fixnum/PATENTS | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 pkgs/fixnum/PATENTS diff --git a/pkgs/fixnum/PATENTS b/pkgs/fixnum/PATENTS deleted file mode 100644 index 39b78bab..00000000 --- a/pkgs/fixnum/PATENTS +++ /dev/null @@ -1,23 +0,0 @@ -Additional IP Rights Grant (Patents) - -"This implementation" means the copyrightable works distributed by -Google as part of the Dart Project. - -Google hereby grants to you a perpetual, worldwide, non-exclusive, -no-charge, royalty-free, irrevocable (except as stated in this -section) patent license to make, have made, use, offer to sell, sell, -import, transfer, and otherwise run, modify and propagate the contents -of this implementation of Dart, where such license applies only to -those patent claims, both currently owned by Google and acquired in -the future, licensable by Google that are necessarily infringed by -this implementation of Dart. This grant does not include claims that -would be infringed only as a consequence of further modification of -this implementation. If you or your agent or exclusive licensee -institute or order or agree to the institution of patent litigation -against any entity (including a cross-claim or counterclaim in a -lawsuit) alleging that this implementation of Dart or any code -incorporated within this implementation of Dart constitutes direct or -contributory patent infringement, or inducement of patent -infringement, then any patent rights granted to you under this License -for this implementation of Dart shall terminate as of the date such -litigation is filed. \ No newline at end of file From 1099fbd9095fc71e52801abe3f1b6a5a8baaf20f Mon Sep 17 00:00:00 2001 From: BC Ko Date: Tue, 10 Jul 2018 11:30:50 -0700 Subject: [PATCH 055/126] Update .gitignore to new `dart_tool` pub cache (dart-lang/fixnum#40) See dart-lang/sdkdart-lang/fixnum#32030 --- pkgs/fixnum/.gitignore | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pkgs/fixnum/.gitignore b/pkgs/fixnum/.gitignore index 0dceb6e0..49ce72d7 100644 --- a/pkgs/fixnum/.gitignore +++ b/pkgs/fixnum/.gitignore @@ -1,7 +1,3 @@ -*.sw? -.idea -.pub -build -packages +.dart_tool/ .packages pubspec.lock From ff72a6fcac4d5f655a0ddcadf5133c296b4d7ffa Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 10 Jul 2018 12:07:48 -0700 Subject: [PATCH 056/126] misc: small fix to changelog --- pkgs/fixnum/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 3a427acd..3212e344 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.10.7 -* Bugfix: Make bitshifts work at bitwidth boundaries. Previously, +* Bug fix: Make bit shifts work at bitwidth boundaries. Previously, `new Int64(3) << 64 == Int64(3)`. This ensures that the result is 0 in such cases. * Updated maximum SDK constraint from 2.0.0-dev.infinity to 2.0.0. From 353ee48018459219d7d7bdadfcdd87bb538aae59 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 10 Jul 2018 12:09:30 -0700 Subject: [PATCH 057/126] fix: go Dart-2 only, update dependencies, update deprecated test usage --- pkgs/fixnum/.travis.yml | 8 +------- pkgs/fixnum/CHANGELOG.md | 4 ++++ pkgs/fixnum/analysis_options.yaml | 2 -- pkgs/fixnum/pubspec.yaml | 10 ++++++---- pkgs/fixnum/test/int32_test.dart | 5 ++--- pkgs/fixnum/test/int64_test.dart | 7 +++---- 6 files changed, 16 insertions(+), 20 deletions(-) delete mode 100644 pkgs/fixnum/analysis_options.yaml diff --git a/pkgs/fixnum/.travis.yml b/pkgs/fixnum/.travis.yml index c2842f8d..dc9b4590 100644 --- a/pkgs/fixnum/.travis.yml +++ b/pkgs/fixnum/.travis.yml @@ -1,20 +1,14 @@ language: dart -sudo: false dart: - dev - - stable dart_task: - test: --platform vm xvfb: false - test: --platform firefox -j 1 - dartanalyzer --fatal-warnings - -matrix: - include: - - dart: stable - dart_task: dartfmt + - dartfmt # Only building master means that we don't run two builds for each pull request. branches: diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 3212e344..40f4156c 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.10.8 + +* Require Dart `>=2.0.0-dev.65`. + ## 0.10.7 * Bug fix: Make bit shifts work at bitwidth boundaries. Previously, diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml deleted file mode 100644 index a10d4c5a..00000000 --- a/pkgs/fixnum/analysis_options.yaml +++ /dev/null @@ -1,2 +0,0 @@ -analyzer: - strong-mode: true diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index d794eb1d..ad53ed47 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,9 +1,11 @@ name: fixnum -version: 0.10.7 +version: 0.10.8-dev author: Dart Team description: Library for 32- and 64-bit signed fixed-width integers. homepage: https://github.com/dart-lang/fixnum -dev_dependencies: - test: ^0.12.0 + environment: - sdk: ">=1.8.3 <2.0.0" + sdk: ">=2.0.0-dev.65 <2.0.0" + +dev_dependencies: + test: ^1.2.0 diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index afa7eeb9..55986381 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -108,7 +108,7 @@ void main() { () => new Int32(17) ~/ Int32.ZERO, // with dart2js, `UnsupportedError` is thrown // on the VM: IntegerDivisionByZeroException - throwsA(anyOf(new isInstanceOf(), + throwsA(anyOf(new TypeMatcher(), isUnsupportedError))); expect(() => new Int32(17) ~/ null, throwsArgumentError); }); @@ -383,8 +383,7 @@ void main() { checkInt(4294967295); checkInt(4294967296); expect(() => Int32.parseRadix('xyzzy', -1), throwsArgumentError); - expect(() => Int32.parseRadix('plugh', 10), - throwsA(new isInstanceOf())); + expect(() => Int32.parseRadix('plugh', 10), throwsFormatException); }); test("parseRadix", () { diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 8106c2eb..51f268da 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -227,13 +227,13 @@ void main() { expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461)); expect(new Int64(829893893) ~/ 1919, new Int32(432461)); expect(() => new Int64(1) ~/ Int64.ZERO, - throwsA(new isInstanceOf())); + throwsA(new TypeMatcher())); expect(Int64.MIN_VALUE ~/ new Int64(2), new Int64.fromInts(0xc0000000, 0x00000000)); expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE); expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE); expect(() => new Int64(17) ~/ Int64.ZERO, - throwsA(new isInstanceOf())); + throwsA(new TypeMatcher())); argumentErrorTest("~/", (a, b) => a ~/ b); }); @@ -788,8 +788,7 @@ void main() { checkInt(-4294967295); checkInt(-4294967296); expect(() => Int64.parseRadix('xyzzy', -1), throwsArgumentError); - expect(() => Int64.parseRadix('plugh', 10), - throwsA(new isInstanceOf())); + expect(() => Int64.parseRadix('plugh', 10), throwsFormatException); }); test("parseHex", () { From f1e7a4f5928e547d16f906ca2d6f09097f783cb3 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 10 Jul 2018 12:33:09 -0700 Subject: [PATCH 058/126] test: move tests requiring the VM to their own test file Fixes https://github.com/dart-lang/fixnum/issues/41 --- pkgs/fixnum/test/int64_test.dart | 20 ------------ pkgs/fixnum/test/int_64_vm_test.dart | 47 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 pkgs/fixnum/test/int_64_vm_test.dart diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 51f268da..2c6f3cad 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -689,24 +689,6 @@ void main() { expect(new Int64(4503599627370496).toInt(), 4503599627370496); expect(new Int64(-4503599627370495).toInt(), -4503599627370495); expect(new Int64(-4503599627370496).toInt(), -4503599627370496); - expect(Int64.parseInt("-10000000000000000").toInt(), - same(-10000000000000000)); - expect(Int64.parseInt("-10000000000000001").toInt(), - same(-10000000000000001)); - expect(Int64.parseInt("-10000000000000002").toInt(), - same(-10000000000000002)); - expect(Int64.parseInt("-10000000000000003").toInt(), - same(-10000000000000003)); - expect(Int64.parseInt("-10000000000000004").toInt(), - same(-10000000000000004)); - expect(Int64.parseInt("-10000000000000005").toInt(), - same(-10000000000000005)); - expect(Int64.parseInt("-10000000000000006").toInt(), - same(-10000000000000006)); - expect(Int64.parseInt("-10000000000000007").toInt(), - same(-10000000000000007)); - expect(Int64.parseInt("-10000000000000008").toInt(), - same(-10000000000000008)); }); test("toInt32", () { @@ -763,8 +745,6 @@ void main() { check(10); check(1000000000000000000); check(9223372000000000000); // near Int64.MAX_VALUE, has exact double value - check(9223372036854775807); // Int64.MAX_VALUE, rounds up to -MIN_VALUE - check(-9223372036854775808); // Int64.MIN_VALUE }); group("parse", () { diff --git a/pkgs/fixnum/test/int_64_vm_test.dart b/pkgs/fixnum/test/int_64_vm_test.dart new file mode 100644 index 00000000..549d3650 --- /dev/null +++ b/pkgs/fixnum/test/int_64_vm_test.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +@TestOn('vm') + +import 'package:fixnum/fixnum.dart'; +import 'package:test/test.dart'; + +void main() { + group("conversions", () { + test("toInt", () { + expect(Int64.parseInt("-10000000000000000").toInt(), + same(-10000000000000000)); + expect(Int64.parseInt("-10000000000000001").toInt(), + same(-10000000000000001)); + expect(Int64.parseInt("-10000000000000002").toInt(), + same(-10000000000000002)); + expect(Int64.parseInt("-10000000000000003").toInt(), + same(-10000000000000003)); + expect(Int64.parseInt("-10000000000000004").toInt(), + same(-10000000000000004)); + expect(Int64.parseInt("-10000000000000005").toInt(), + same(-10000000000000005)); + expect(Int64.parseInt("-10000000000000006").toInt(), + same(-10000000000000006)); + expect(Int64.parseInt("-10000000000000007").toInt(), + same(-10000000000000007)); + expect(Int64.parseInt("-10000000000000008").toInt(), + same(-10000000000000008)); + }); + }); + + test("", () { + check(int n) { + // Sign change should commute with conversion. + expect(-new Int64(-n), new Int64(n)); + expect(new Int64(-n), -new Int64(n)); + } + + check(10); + check(1000000000000000000); + check(9223372000000000000); // near Int64.MAX_VALUE, has exact double value + check(9223372036854775807); // Int64.MAX_VALUE, rounds up to -MIN_VALUE + check(-9223372036854775808); // Int64.MIN_VALUE + }); +} From 56e875ad4318f24c45debffc55fe4a3278f9d503 Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Wed, 18 Jul 2018 13:10:32 -0400 Subject: [PATCH 059/126] chore: set max SDK version to <3.0.0 (dart-lang/fixnum#43) --- pkgs/fixnum/.travis.yml | 2 +- pkgs/fixnum/CHANGELOG.md | 2 +- pkgs/fixnum/pubspec.yaml | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkgs/fixnum/.travis.yml b/pkgs/fixnum/.travis.yml index dc9b4590..c22b6306 100644 --- a/pkgs/fixnum/.travis.yml +++ b/pkgs/fixnum/.travis.yml @@ -7,7 +7,7 @@ dart_task: - test: --platform vm xvfb: false - test: --platform firefox -j 1 - - dartanalyzer --fatal-warnings + - dartanalyzer: --fatal-warnings . - dartfmt # Only building master means that we don't run two builds for each pull request. diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 40f4156c..9c978a55 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.10.8 -* Require Dart `>=2.0.0-dev.65`. +* Set SDK version constraint to `>=2.0.0-dev.65 <3.0.0`. ## 0.10.7 diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index ad53ed47..d8f523db 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,11 +1,12 @@ name: fixnum -version: 0.10.8-dev -author: Dart Team +version: 0.10.8 + description: Library for 32- and 64-bit signed fixed-width integers. +author: Dart Team homepage: https://github.com/dart-lang/fixnum environment: - sdk: ">=2.0.0-dev.65 <2.0.0" + sdk: '>=2.0.0-dev.65 <3.0.0' dev_dependencies: test: ^1.2.0 From ea85c72d9ae6ef1f02bd888d23da2e68dfbf255e Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Tue, 6 Nov 2018 17:51:24 -0800 Subject: [PATCH 060/126] Add toStringUnsigned() method (dart-lang/fixnum#44) * Update int64.dart * Update int64_test.dart * Update int64_test.dart * Update pubspec.yaml * Update int64.dart * Update int64.dart * Update int64_test.dart * Update int64.dart * Update CHANGELOG.md * Update int64_test.dart * Update int64.dart --- pkgs/fixnum/CHANGELOG.md | 4 ++++ pkgs/fixnum/lib/src/int64.dart | 21 +++++++++++++++++++-- pkgs/fixnum/pubspec.yaml | 2 +- pkgs/fixnum/test/int64_test.dart | 24 ++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 9c978a55..796f6c63 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.10.9 + +* Add `Int64.toStringUnsigned()` method. + ## 0.10.8 * Set SDK version constraint to `>=2.0.0-dev.65 <3.0.0`. diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index a84cbd98..ead89fe0 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -668,6 +668,19 @@ class Int64 implements IntX { return hexStr; } + /** + * Returns the digits of [this] when interpreted as an unsigned 64-bit value. + */ + @pragma('dart2js:noInline') + String toStringUnsigned() { + return _toRadixStringUnsigned(10, _l, _m, _h, ''); + } + + @pragma('dart2js:noInline') + String toRadixStringUnsigned(int radix) { + return _toRadixStringUnsigned(Int32._validateRadix(radix), _l, _m, _h, ''); + } + String toRadixString(int radix) { return _toRadixString(Int32._validateRadix(radix)); } @@ -677,8 +690,6 @@ class Int64 implements IntX { int d1 = _m; int d2 = _h; - if (d0 == 0 && d1 == 0 && d2 == 0) return '0'; - String sign = ''; if ((d2 & _SIGN_BIT_MASK) != 0) { sign = '-'; @@ -695,6 +706,12 @@ class Int64 implements IntX { // d2, d1, d0 now are an unsigned 64 bit integer for MIN_VALUE and an // unsigned 63 bit integer for other values. } + return _toRadixStringUnsigned(radix, d0, d1, d2, sign); + } + + static String _toRadixStringUnsigned( + int radix, int d0, int d1, int d2, String sign) { + if (d0 == 0 && d1 == 0 && d2 == 0) return '0'; // Rearrange components into five components where all but the most // significant are 10 bits wide. diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index d8f523db..ff06246f 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 0.10.8 +version: 0.10.9 description: Library for 32- and 64-bit signed fixed-width integers. author: Dart Team diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 2c6f3cad..0fc2085f 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -888,5 +888,29 @@ void main() { expect(() => new Int64(42).toRadixString(0), throwsArgumentError); expect(() => new Int64(42).toRadixString(37), throwsArgumentError); }); + + test("toStringUnsigned", () { + List values = []; + for (int high = 0; high < 16; high++) { + for (int low = -2; low <= 2; low++) { + values.add((Int64(high) << (64 - 4)) + Int64(low)); + } + } + + for (Int64 value in values) { + for (int radix = 2; radix <= 36; radix++) { + String s1 = value.toRadixStringUnsigned(radix); + Int64 v2 = Int64.parseRadix(s1, radix); + expect(v2, value); + String s2 = v2.toRadixStringUnsigned(radix); + expect(s2, s1); + } + String s3 = value.toStringUnsigned(); + Int64 v4 = Int64.parseInt(s3); + expect(v4, value); + String s4 = v4.toStringUnsigned(); + expect(s4, s3); + } + }); }); } From 0f00289a788ac4f90c846e1aa172cb63f220bce9 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 6 Nov 2018 18:11:13 -0800 Subject: [PATCH 061/126] Enable and fix a number of lints (dart-lang/fixnum#45) Almost entirely `dartfmt --fix -w .` --- pkgs/fixnum/analysis_options.yaml | 58 ++ pkgs/fixnum/lib/fixnum.dart | 18 +- pkgs/fixnum/lib/src/int32.dart | 134 ++--- pkgs/fixnum/lib/src/int64.dart | 154 ++--- pkgs/fixnum/lib/src/intx.dart | 246 ++++---- pkgs/fixnum/pubspec.yaml | 3 +- pkgs/fixnum/test/int32_test.dart | 399 +++++++------ pkgs/fixnum/test/int64_test.dart | 839 +++++++++++++-------------- pkgs/fixnum/test/int_64_vm_test.dart | 4 +- 9 files changed, 895 insertions(+), 960 deletions(-) create mode 100644 pkgs/fixnum/analysis_options.yaml diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml new file mode 100644 index 00000000..8ef67de5 --- /dev/null +++ b/pkgs/fixnum/analysis_options.yaml @@ -0,0 +1,58 @@ +include: package:pedantic/analysis_options.yaml +linter: + rules: + #- annotate_overrides + - avoid_function_literals_in_foreach_calls + - avoid_init_to_null + - avoid_null_checks_in_equality_operators + - avoid_relative_lib_imports + - avoid_returning_null + - avoid_unused_constructor_parameters + - await_only_futures + - camel_case_types + - cancel_subscriptions + - comment_references + #- constant_identifier_names + - control_flow_in_finally + - directives_ordering + - empty_catches + - empty_constructor_bodies + - empty_statements + - hash_and_equals + - implementation_imports + - invariant_booleans + - iterable_contains_unrelated_type + - library_names + - library_prefixes + - list_remove_unrelated_type + - no_adjacent_strings_in_list + - non_constant_identifier_names + #- omit_local_variable_types + - only_throw_errors + - overridden_fields + - package_api_docs + - package_names + - package_prefixed_library_names + - prefer_adjacent_string_concatenation + - prefer_collection_literals + - prefer_conditional_assignment + - prefer_const_constructors + - prefer_final_fields + - prefer_initializing_formals + - prefer_interpolation_to_compose_strings + #- prefer_single_quotes + - prefer_typing_uninitialized_variables + - slash_for_doc_comments + - test_types_in_equals + - super_goes_last + - test_types_in_equals + - throw_in_finally + - type_init_formals + - unnecessary_brace_in_string_interps + - unnecessary_const + - unnecessary_getters_setters + - unnecessary_lambdas + - unnecessary_new + - unnecessary_null_aware_assignments + - unnecessary_statements + #- unnecessary_this diff --git a/pkgs/fixnum/lib/fixnum.dart b/pkgs/fixnum/lib/fixnum.dart index fe21c479..6d08ba86 100644 --- a/pkgs/fixnum/lib/fixnum.dart +++ b/pkgs/fixnum/lib/fixnum.dart @@ -2,16 +2,14 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/** - * Signed 32- and 64-bit integer support. - * - * The integer implementations in this library are designed to work - * identically whether executed on the Dart VM or compiled to JavaScript. - * - * For information on installing and importing this library, see the - * [fixnum package on pub.dartlang.org] - * (http://pub.dartlang.org/packages/fixnum). - */ +/// Signed 32- and 64-bit integer support. +/// +/// The integer implementations in this library are designed to work +/// identically whether executed on the Dart VM or compiled to JavaScript. +/// +/// For information on installing and importing this library, see the +/// [fixnum package on pub.dartlang.org] +/// (http://pub.dartlang.org/packages/fixnum). library fixnum; part 'src/intx.dart'; diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index db8ecd0f..f3cc72c8 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -4,37 +4,25 @@ part of fixnum; -/** - * An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1]. - * Arithmetic operations may overflow in order to maintain this range. - */ +/// An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1]. +/// Arithmetic operations may overflow in order to maintain this range. class Int32 implements IntX { - /** - * The maximum positive value attainable by an [Int32], namely - * 2147483647. - */ - static const Int32 MAX_VALUE = const Int32._internal(0x7FFFFFFF); - - /** - * The minimum positive value attainable by an [Int32], namely - * -2147483648. - */ - static const Int32 MIN_VALUE = const Int32._internal(-0x80000000); - - /** - * An [Int32] constant equal to 0. - */ - static const Int32 ZERO = const Int32._internal(0); - - /** - * An [Int32] constant equal to 1. - */ - static const Int32 ONE = const Int32._internal(1); - - /** - * An [Int32] constant equal to 2. - */ - static const Int32 TWO = const Int32._internal(2); + /// The maximum positive value attainable by an [Int32], namely + /// 2147483647. + static const Int32 MAX_VALUE = Int32._internal(0x7FFFFFFF); + + /// The minimum positive value attainable by an [Int32], namely + /// -2147483648. + static const Int32 MIN_VALUE = Int32._internal(-0x80000000); + + /// An [Int32] constant equal to 0. + static const Int32 ZERO = Int32._internal(0); + + /// An [Int32] constant equal to 1. + static const Int32 ONE = Int32._internal(1); + + /// An [Int32] constant equal to 2. + static const Int32 TWO = Int32._internal(2); // Hex digit char codes static const int _CC_0 = 48; // '0'.codeUnitAt(0) @@ -58,13 +46,11 @@ class Int32 implements IntX { static int _validateRadix(int radix) { if (2 <= radix && radix <= 36) return radix; - throw new RangeError.range(radix, 2, 36, 'radix'); + throw RangeError.range(radix, 2, 36, 'radix'); } - /** - * Parses a [String] in a given [radix] between 2 and 16 and returns an - * [Int32]. - */ + /// Parses a [String] in a given [radix] between 2 and 16 and returns an + /// [Int32]. // TODO(rice) - Make this faster by converting several digits at once. static Int32 parseRadix(String s, int radix) { _validateRadix(radix); @@ -73,21 +59,17 @@ class Int32 implements IntX { int c = s.codeUnitAt(i); int digit = _decodeDigit(c); if (digit < 0 || digit >= radix) { - throw new FormatException("Non-radix code unit: $c"); + throw FormatException("Non-radix code unit: $c"); } x = (x * radix) + digit; } return x; } - /** - * Parses a decimal [String] and returns an [Int32]. - */ - static Int32 parseInt(String s) => new Int32(int.parse(s)); + /// Parses a decimal [String] and returns an [Int32]. + static Int32 parseInt(String s) => Int32(int.parse(s)); - /** - * Parses a hexadecimal [String] and returns an [Int32]. - */ + /// Parses a hexadecimal [String] and returns an [Int32]. static Int32 parseHex(String s) => parseRadix(s, 16); // Assumes i is <= 32-bit. @@ -134,10 +116,8 @@ class Int32 implements IntX { const Int32._internal(int i) : _i = i; - /** - * Constructs an [Int32] from an [int]. Only the low 32 bits of the input - * are used. - */ + /// Constructs an [Int32] from an [int]. Only the low 32 bits of the input + /// are used. Int32([int i = 0]) : _i = (i & 0x7fffffff) - (i & 0x80000000); // Returns the [int] representation of the specified value. Throws @@ -148,7 +128,7 @@ class Int32 implements IntX { } else if (val is int) { return val; } - throw new ArgumentError(val); + throw ArgumentError(val); } // The +, -, * , &, |, and ^ operaters deal with types as follows: @@ -169,17 +149,17 @@ class Int32 implements IntX { if (other is Int64) { return this.toInt64() + other; } - return new Int32(_i + _toInt(other)); + return Int32(_i + _toInt(other)); } IntX operator -(other) { if (other is Int64) { return this.toInt64() - other; } - return new Int32(_i - _toInt(other)); + return Int32(_i - _toInt(other)); } - Int32 operator -() => new Int32(-_i); + Int32 operator -() => Int32(-_i); IntX operator *(other) { if (other is Int64) { @@ -194,14 +174,14 @@ class Int32 implements IntX { // Result will be Int32 return (this.toInt64() % other).toInt32(); } - return new Int32(_i % _toInt(other)); + return Int32(_i % _toInt(other)); } Int32 operator ~/(other) { if (other is Int64) { return (this.toInt64() ~/ other).toInt32(); } - return new Int32(_i ~/ _toInt(other)); + return Int32(_i ~/ _toInt(other)); } Int32 remainder(other) { @@ -216,38 +196,38 @@ class Int32 implements IntX { if (other is Int64) { return (this.toInt64() & other).toInt32(); } - return new Int32(_i & _toInt(other)); + return Int32(_i & _toInt(other)); } Int32 operator |(other) { if (other is Int64) { return (this.toInt64() | other).toInt32(); } - return new Int32(_i | _toInt(other)); + return Int32(_i | _toInt(other)); } Int32 operator ^(other) { if (other is Int64) { return (this.toInt64() ^ other).toInt32(); } - return new Int32(_i ^ _toInt(other)); + return Int32(_i ^ _toInt(other)); } - Int32 operator ~() => new Int32(~_i); + Int32 operator ~() => Int32(~_i); Int32 operator <<(int n) { if (n < 0) { - throw new ArgumentError(n); + throw ArgumentError(n); } if (n >= 32) { return ZERO; } - return new Int32(_i << n); + return Int32(_i << n); } Int32 operator >>(int n) { if (n < 0) { - throw new ArgumentError(n); + throw ArgumentError(n); } if (n >= 32) { return isNegative ? const Int32._internal(-1) : ZERO; @@ -258,12 +238,12 @@ class Int32 implements IntX { } else { value = (_i >> n) | (0xffffffff << (32 - n)); } - return new Int32(value); + return Int32(value); } Int32 shiftRightUnsigned(int n) { if (n < 0) { - throw new ArgumentError(n); + throw ArgumentError(n); } if (n >= 32) { return ZERO; @@ -274,13 +254,11 @@ class Int32 implements IntX { } else { value = (_i >> n) & ((1 << (32 - n)) - 1); } - return new Int32(value); + return Int32(value); } - /** - * Returns [:true:] if this [Int32] has the same numeric value as the - * given object. The argument may be an [int] or an [IntX]. - */ + /// Returns [:true:] if this [Int32] has the same numeric value as the + /// given object. The argument may be an [int] or an [IntX]. bool operator ==(other) { if (other is Int32) { return _i == other._i; @@ -337,17 +315,17 @@ class Int32 implements IntX { int get hashCode => _i; - Int32 abs() => _i < 0 ? new Int32(-_i) : this; + Int32 abs() => _i < 0 ? Int32(-_i) : this; Int32 clamp(lowerLimit, upperLimit) { if (this < lowerLimit) { if (lowerLimit is IntX) return lowerLimit.toInt32(); - if (lowerLimit is int) return new Int32(lowerLimit); - throw new ArgumentError(lowerLimit); + if (lowerLimit is int) return Int32(lowerLimit); + throw ArgumentError(lowerLimit); } else if (this > upperLimit) { if (upperLimit is IntX) return upperLimit.toInt32(); - if (upperLimit is int) return new Int32(upperLimit); - throw new ArgumentError(upperLimit); + if (upperLimit is int) return Int32(upperLimit); + throw ArgumentError(upperLimit); } return this; } @@ -356,17 +334,17 @@ class Int32 implements IntX { int numberOfTrailingZeros() => _numberOfTrailingZeros(_i); Int32 toSigned(int width) { - if (width < 1 || width > 32) throw new RangeError.range(width, 1, 32); - return new Int32(_i.toSigned(width)); + if (width < 1 || width > 32) throw RangeError.range(width, 1, 32); + return Int32(_i.toSigned(width)); } Int32 toUnsigned(int width) { - if (width < 0 || width > 32) throw new RangeError.range(width, 0, 32); - return new Int32(_i.toUnsigned(width)); + if (width < 0 || width > 32) throw RangeError.range(width, 0, 32); + return Int32(_i.toUnsigned(width)); } List toBytes() { - List result = new List(4); + List result = List(4); result[0] = _i & 0xff; result[1] = (_i >> 8) & 0xff; result[2] = (_i >> 16) & 0xff; @@ -377,7 +355,7 @@ class Int32 implements IntX { double toDouble() => _i.toDouble(); int toInt() => _i; Int32 toInt32() => this; - Int64 toInt64() => new Int64(_i); + Int64 toInt64() => Int64(_i); String toString() => _i.toString(); String toHexString() => _i.toRadixString(16); diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index ead89fe0..a1109c03 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -4,10 +4,8 @@ part of fixnum; -/** - * An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1]. - * Arithmetic operations may overflow in order to maintain this range. - */ +/// An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1]. +/// Arithmetic operations may overflow in order to maintain this range. class Int64 implements IntX { // A 64-bit integer is represented internally as three non-negative // integers, storing the 22 low, 22 middle, and 20 high bits of the @@ -31,43 +29,29 @@ class Int64 implements IntX { static const int _SIGN_BIT = 19; // _BITS2 - 1 static const int _SIGN_BIT_MASK = 1 << _SIGN_BIT; - /** - * The maximum positive value attainable by an [Int64], namely - * 9,223,372,036,854,775,807. - */ - static const Int64 MAX_VALUE = const Int64._bits(_MASK, _MASK, _MASK2 >> 1); - - /** - * The minimum positive value attainable by an [Int64], namely - * -9,223,372,036,854,775,808. - */ - static const Int64 MIN_VALUE = const Int64._bits(0, 0, _SIGN_BIT_MASK); - - /** - * An [Int64] constant equal to 0. - */ - static const Int64 ZERO = const Int64._bits(0, 0, 0); - - /** - * An [Int64] constant equal to 1. - */ - static const Int64 ONE = const Int64._bits(1, 0, 0); - - /** - * An [Int64] constant equal to 2. - */ - static const Int64 TWO = const Int64._bits(2, 0, 0); - - /** - * Constructs an [Int64] with a given bitwise representation. No validation - * is performed. - */ + /// The maximum positive value attainable by an [Int64], namely + /// 9,223,372,036,854,775,807. + static const Int64 MAX_VALUE = Int64._bits(_MASK, _MASK, _MASK2 >> 1); + + /// The minimum positive value attainable by an [Int64], namely + /// -9,223,372,036,854,775,808. + static const Int64 MIN_VALUE = Int64._bits(0, 0, _SIGN_BIT_MASK); + + /// An [Int64] constant equal to 0. + static const Int64 ZERO = Int64._bits(0, 0, 0); + + /// An [Int64] constant equal to 1. + static const Int64 ONE = Int64._bits(1, 0, 0); + + /// An [Int64] constant equal to 2. + static const Int64 TWO = Int64._bits(2, 0, 0); + + /// Constructs an [Int64] with a given bitwise representation. No validation + /// is performed. const Int64._bits(this._l, this._m, this._h); - /** - * Parses a [String] in a given [radix] between 2 and 36 and returns an - * [Int64]. - */ + /// Parses a [String] in a given [radix] between 2 and 36 and returns an + /// [Int64]. static Int64 parseRadix(String s, int radix) { return _parseRadix(s, Int32._validateRadix(radix)); } @@ -84,7 +68,7 @@ class Int64 implements IntX { int c = s.codeUnitAt(i); int digit = Int32._decodeDigit(c); if (digit < 0 || digit >= radix) { - throw new FormatException("Non-radix char code: $c"); + throw FormatException("Non-radix char code: $c"); } // [radix] and [digit] are at most 6 bits, component is 22, so we can @@ -106,23 +90,17 @@ class Int64 implements IntX { return Int64._masked(d0, d1, d2); } - /** - * Parses a decimal [String] and returns an [Int64]. - */ + /// Parses a decimal [String] and returns an [Int64]. static Int64 parseInt(String s) => _parseRadix(s, 10); - /** - * Parses a hexadecimal [String] and returns an [Int64]. - */ + /// Parses a hexadecimal [String] and returns an [Int64]. static Int64 parseHex(String s) => _parseRadix(s, 16); // // Public constructors // - /** - * Constructs an [Int64] with a given [int] value; zero by default. - */ + /// Constructs an [Int64] with a given [int] value; zero by default. factory Int64([int value = 0]) { int v0 = 0, v1 = 0, v2 = 0; bool negative = false; @@ -160,7 +138,7 @@ class Int64 implements IntX { bottom <<= 8; bottom |= bytes[0] & 0xff; - return new Int64.fromInts(top, bottom); + return Int64.fromInts(top, bottom); } factory Int64.fromBytesBigEndian(List bytes) { @@ -180,13 +158,11 @@ class Int64 implements IntX { bottom <<= 8; bottom |= bytes[7] & 0xff; - return new Int64.fromInts(top, bottom); + return Int64.fromInts(top, bottom); } - /** - * Constructs an [Int64] from a pair of 32-bit integers having the value - * [:((top & 0xffffffff) << 32) | (bottom & 0xffffffff):]. - */ + /// Constructs an [Int64] from a pair of 32-bit integers having the value + /// [:((top & 0xffffffff) << 32) | (bottom & 0xffffffff):]. factory Int64.fromInts(int top, int bottom) { top &= 0xffffffff; bottom &= 0xffffffff; @@ -202,11 +178,11 @@ class Int64 implements IntX { if (value is Int64) { return value; } else if (value is int) { - return new Int64(value); + return Int64(value); } else if (value is Int32) { return value.toInt64(); } - throw new ArgumentError.value(value); + throw ArgumentError.value(value); } Int64 operator +(other) { @@ -341,7 +317,7 @@ class Int64 implements IntX { Int64 operator <<(int n) { if (n < 0) { - throw new ArgumentError.value(n); + throw ArgumentError.value(n); } if (n >= 64) { return ZERO; @@ -367,7 +343,7 @@ class Int64 implements IntX { Int64 operator >>(int n) { if (n < 0) { - throw new ArgumentError.value(n); + throw ArgumentError.value(n); } if (n >= 64) { return isNegative ? const Int64._bits(_MASK, _MASK, _MASK2) : ZERO; @@ -412,7 +388,7 @@ class Int64 implements IntX { Int64 shiftRightUnsigned(int n) { if (n < 0) { - throw new ArgumentError.value(n); + throw ArgumentError.value(n); } if (n >= 64) { return ZERO; @@ -437,10 +413,8 @@ class Int64 implements IntX { return Int64._masked(res0, res1, res2); } - /** - * Returns [:true:] if this [Int64] has the same numeric value as the - * given object. The argument may be an [int] or an [IntX]. - */ + /// Returns [:true:] if this [Int64] has the same numeric value as the + /// given object. The argument may be an [int] or an [IntX]. bool operator ==(other) { Int64 o; if (other is Int64) { @@ -450,7 +424,7 @@ class Int64 implements IntX { // Since we know one of [_h] or [_m] is non-zero, if [other] fits in the // low word then it can't be numerically equal. if ((_MASK & other) == other) return false; - o = new Int64(other); + o = Int64(other); } else if (other is Int32) { o = other.toInt64(); } @@ -512,9 +486,7 @@ class Int64 implements IntX { return a0.bitLength; } - /** - * Returns a hash code based on all the bits of this [Int64]. - */ + /// Returns a hash code based on all the bits of this [Int64]. int get hashCode { // TODO(sra): Should we ensure that hashCode values match corresponding int? // i.e. should `new Int64(x).hashCode == x.hashCode`? @@ -535,10 +507,8 @@ class Int64 implements IntX { return this; } - /** - * Returns the number of leading zeros in this [Int64] as an [int] - * between 0 and 64. - */ + /// Returns the number of leading zeros in this [Int64] as an [int] + /// between 0 and 64. int numberOfLeadingZeros() { int b2 = Int32._numberOfLeadingZeros(_h); if (b2 == 32) { @@ -553,10 +523,8 @@ class Int64 implements IntX { } } - /** - * Returns the number of trailing zeros in this [Int64] as an [int] - * between 0 and 64. - */ + /// Returns the number of trailing zeros in this [Int64] as an [int] + /// between 0 and 64. int numberOfTrailingZeros() { int zeros = Int32._numberOfTrailingZeros(_l); if (zeros < 32) { @@ -577,7 +545,7 @@ class Int64 implements IntX { } Int64 toSigned(int width) { - if (width < 1 || width > 64) throw new RangeError.range(width, 1, 64); + if (width < 1 || width > 64) throw RangeError.range(width, 1, 64); if (width > _BITS01) { return Int64._masked(_l, _m, _h.toSigned(width - _BITS01)); } else if (width > _BITS) { @@ -594,7 +562,7 @@ class Int64 implements IntX { } Int64 toUnsigned(int width) { - if (width < 0 || width > 64) throw new RangeError.range(width, 0, 64); + if (width < 0 || width > 64) throw RangeError.range(width, 0, 64); if (width > _BITS01) { int h = _h.toUnsigned(width - _BITS01); return Int64._masked(_l, _m, h); @@ -608,7 +576,7 @@ class Int64 implements IntX { } List toBytes() { - List result = new List(8); + List result = List(8); result[0] = _l & 0xff; result[1] = (_l >> 8) & 0xff; result[2] = ((_m << 6) & 0xfc) | ((_l >> 16) & 0x3f); @@ -638,21 +606,15 @@ class Int64 implements IntX { } } - /** - * Returns an [Int32] containing the low 32 bits of this [Int64]. - */ + /// Returns an [Int32] containing the low 32 bits of this [Int64]. Int32 toInt32() { - return new Int32(((_m & 0x3ff) << _BITS) | _l); + return Int32(((_m & 0x3ff) << _BITS) | _l); } - /** - * Returns [this]. - */ + /// Returns `this`. Int64 toInt64() => this; - /** - * Returns the value of this [Int64] as a decimal [String]. - */ + /// Returns the value of this [Int64] as a decimal [String]. String toString() => _toRadixString(10); // TODO(rice) - Make this faster by avoiding arithmetic. @@ -668,9 +630,7 @@ class Int64 implements IntX { return hexStr; } - /** - * Returns the digits of [this] when interpreted as an unsigned 64-bit value. - */ + /// Returns the digits of `this` when interpreted as an unsigned 64-bit value. @pragma('dart2js:noInline') String toStringUnsigned() { return _toRadixStringUnsigned(10, _l, _m, _h, ''); @@ -787,7 +747,7 @@ class Int64 implements IntX { // Table of 'fat' radix values. Each entry for index `i` is the largest power // of `i` whose remainder fits in 20 bits. - static const _fatRadixTable = const [ + static const _fatRadixTable = [ 0, 0, 2 * @@ -851,7 +811,7 @@ class Int64 implements IntX { } static Int64 _masked(int a0, int a1, int a2) => - new Int64._bits(_MASK & a0, _MASK & a1, _MASK2 & a2); + Int64._bits(_MASK & a0, _MASK & a1, _MASK2 & a2); static Int64 _sub(int a0, int a1, int a2, int b0, int b1, int b2) { int diff0 = a0 - b0; @@ -884,7 +844,7 @@ class Int64 implements IntX { static Int64 _divide(Int64 a, other, int what) { Int64 b = _promote(other); if (b.isZero) { - throw new IntegerDivisionByZeroException(); + throw const IntegerDivisionByZeroException(); } if (a.isZero) return ZERO; @@ -1014,9 +974,9 @@ class Int64 implements IntX { } // 0 <= R < B - assert(Int64.ZERO <= new Int64._bits(r0, r1, r2)); + assert(Int64.ZERO <= Int64._bits(r0, r1, r2)); assert(r2 < b2 || // Handles case where B = -(MIN_VALUE) - new Int64._bits(r0, r1, r2) < new Int64._bits(b0, b1, b2)); + Int64._bits(r0, r1, r2) < Int64._bits(b0, b1, b2)); assert(what == _RETURN_DIV || what == _RETURN_MOD || what == _RETURN_REM); if (what == _RETURN_DIV) { diff --git a/pkgs/fixnum/lib/src/intx.dart b/pkgs/fixnum/lib/src/intx.dart index 3c2207da..cdc4b05f 100644 --- a/pkgs/fixnum/lib/src/intx.dart +++ b/pkgs/fixnum/lib/src/intx.dart @@ -4,233 +4,189 @@ part of fixnum; -/** - * A fixed-precision integer. - */ +/// A fixed-precision integer. abstract class IntX implements Comparable { - /** Addition operator. */ + /// Addition operator. IntX operator +(other); - /** Subtraction operator. */ + /// Subtraction operator. IntX operator -(other); - /** - * Negate operator. - * - * Note that `-MIN_VALUE` is equal to `MIN_VALUE` due to overflow. - */ + /// Negate operator. + /// + /// Note that `-MIN_VALUE` is equal to `MIN_VALUE` due to overflow. IntX operator -(); - /** Multiplication operator. */ + /// Multiplication operator. IntX operator *(other); - /** - * Euclidean modulo operator. - * - * Returns the remainder of the euclidean division. The euclidean division - * of two integers `a` and `b` yields two integers `q` and `r` such that - * `a == b * q + r` and `0 <= r < a.abs()`. - */ + /// Euclidean modulo operator. + /// + /// Returns the remainder of the euclidean division. The euclidean division + /// of two integers `a` and `b` yields two integers `q` and `r` such that + /// `a == b * q + r` and `0 <= r < a.abs()`. IntX operator %(other); - /** Truncating division operator. */ + /// Truncating division operator. IntX operator ~/(other); - /** - * Returns the remainder of the truncating division of this integer by - * [other]. - */ + /// Returns the remainder of the truncating division of this integer by + /// [other]. IntX remainder(other); - /** Bitwise and operator. */ + /// Bitwise and operator. IntX operator &(other); - /** Bitwise or operator. */ + /// Bitwise or operator. IntX operator |(other); - /** Bitwise xor operator. */ + /// Bitwise xor operator. IntX operator ^(other); - /** Bitwise negate operator. */ + /// Bitwise negate operator. IntX operator ~(); - /** - * Left bit-shift operator. - * - * Returns the result of shifting the bits of this integer by [shiftAmount] - * bits to the left. Low-order bits are filled with zeros. - */ + /// Left bit-shift operator. + /// + /// Returns the result of shifting the bits of this integer by [shiftAmount] + /// bits to the left. Low-order bits are filled with zeros. IntX operator <<(int shiftAmount); - /** - * Right bit-shift operator. - * - * Returns the result of shifting the bits of this integer by [shiftAmount] - * bits to the right. High-order bits are filled with zero in the case where - * this integer is positive, or one in the case where it is negative. - */ + /// Right bit-shift operator. + /// + /// Returns the result of shifting the bits of this integer by [shiftAmount] + /// bits to the right. High-order bits are filled with zero in the case where + /// this integer is positive, or one in the case where it is negative. IntX operator >>(int shiftAmount); - /** - * Unsigned right-shift operator. - * - * Returns the result of shifting the bits of this integer by [shiftAmount] - * bits to the right. High-order bits are filled with zeros. - */ + /// Unsigned right-shift operator. + /// + /// Returns the result of shifting the bits of this integer by [shiftAmount] + /// bits to the right. High-order bits are filled with zeros. IntX shiftRightUnsigned(int shiftAmount); int compareTo(other); - /** - * Returns `true` if and only if [other] is an int or IntX equal in - * value to this integer. - */ + /// Returns `true` if and only if [other] is an int or IntX equal in + /// value to this integer. bool operator ==(other); - /** Relational less than operator. */ + /// Relational less than operator. bool operator <(other); - /** Relational less than or equal to operator. */ + /// Relational less than or equal to operator. bool operator <=(other); - /** Relational greater than operator. */ + /// Relational greater than operator. bool operator >(other); - /** Relational greater than or equal to operator. */ + /// Relational greater than or equal to operator. bool operator >=(other); - /** Returns `true` if and only if this integer is even. */ + /// Returns `true` if and only if this integer is even. bool get isEven; - /** - * Returns `true` if and only if this integer is the maximum signed value - * that can be represented within its bit size. - */ + /// Returns `true` if and only if this integer is the maximum signed value + /// that can be represented within its bit size. bool get isMaxValue; - /** - * Returns `true` if and only if this integer is the minimum signed value - * that can be represented within its bit size. - */ + /// Returns `true` if and only if this integer is the minimum signed value + /// that can be represented within its bit size. bool get isMinValue; - /** Returns `true` if and only if this integer is less than zero. */ + /// Returns `true` if and only if this integer is less than zero. bool get isNegative; - /** Returns `true` if and only if this integer is odd. */ + /// Returns `true` if and only if this integer is odd. bool get isOdd; - /** Returns `true` if and only if this integer is zero. */ + /// Returns `true` if and only if this integer is zero. bool get isZero; int get hashCode; - /** Returns the absolute value of this integer. */ + /// Returns the absolute value of this integer. IntX abs(); - /** Clamps this integer to be in the range [lowerLimit] - [upperLimit]. */ + /// Clamps this integer to be in the range [lowerLimit] - [upperLimit]. IntX clamp(lowerLimit, upperLimit); - /** - * Returns the minimum number of bits required to store this integer. - * - * The number of bits excludes the sign bit, which gives the natural length - * for non-negative (unsigned) values. Negative values are complemented to - * return the bit position of the first bit that differs from the sign bit. - * - * To find the the number of bits needed to store the value as a signed value, - * add one, i.e. use `x.bitLength + 1`. - */ + /// Returns the minimum number of bits required to store this integer. + /// + /// The number of bits excludes the sign bit, which gives the natural length + /// for non-negative (unsigned) values. Negative values are complemented to + /// return the bit position of the first bit that differs from the sign bit. + /// + /// To find the the number of bits needed to store the value as a signed value, + /// add one, i.e. use `x.bitLength + 1`. int get bitLength; - /** - * Returns the number of high-order zeros in this integer's bit - * representation. - */ + /// Returns the number of high-order zeros in this integer's bit + /// representation. int numberOfLeadingZeros(); - /** - * Returns the number of low-order zeros in this integer's bit representation. - */ + /// Returns the number of low-order zeros in this integer's bit representation. int numberOfTrailingZeros(); - /** - * Returns the least significant [width] bits of this integer, extending the - * highest retained bit to the sign. This is the same as truncating the value - * to fit in [width] bits using an signed 2-s complement representation. The - * returned value has the same bit value in all positions higher than [width]. - * - * If the input value fits in [width] bits without truncation, the result is - * the same as the input. The minimum width needed to avoid truncation of `x` - * is `x.bitLength + 1`, i.e. - * - * x == x.toSigned(x.bitLength + 1); - */ + /// Returns the least significant [width] bits of this integer, extending the + /// highest retained bit to the sign. This is the same as truncating the value + /// to fit in [width] bits using an signed 2-s complement representation. The + /// returned value has the same bit value in all positions higher than [width]. + /// + /// If the input value fits in [width] bits without truncation, the result is + /// the same as the input. The minimum width needed to avoid truncation of `x` + /// is `x.bitLength + 1`, i.e. + /// + /// x == x.toSigned(x.bitLength + 1); IntX toSigned(int width); - /** - * Returns the least significant [width] bits of this integer as a - * non-negative number (i.e. unsigned representation). The returned value has - * zeros in all bit positions higher than [width]. - * - * If the input fits in [width] bits without truncation, the result is the - * same as the input. The minimum width needed to avoid truncation of `x` is - * given by `x.bitLength`, i.e. - * - * x == x.toUnsigned(x.bitLength); - */ + /// Returns the least significant [width] bits of this integer as a + /// non-negative number (i.e. unsigned representation). The returned value has + /// zeros in all bit positions higher than [width]. + /// + /// If the input fits in [width] bits without truncation, the result is the + /// same as the input. The minimum width needed to avoid truncation of `x` is + /// given by `x.bitLength`, i.e. + /// + /// x == x.toUnsigned(x.bitLength); IntX toUnsigned(int width); - /** - * Returns a byte-sequence representation of this integer. - * - * Returns a list of int, starting with the least significant byte. - */ + /// Returns a byte-sequence representation of this integer. + /// + /// Returns a list of int, starting with the least significant byte. List toBytes(); - /** - * Returns the double representation of this integer. - * - * On some platforms, inputs with large absolute values (i.e., > 2^52) may - * lose some of their low-order bits. - */ + /// Returns the double representation of this integer. + /// + /// On some platforms, inputs with large absolute values (i.e., > 2^52) may + /// lose some of their low-order bits. double toDouble(); - /** - * Returns the int representation of this integer. - * - * On some platforms, inputs with large absolute values (i.e., > 2^52) may - * lose some of their low-order bits. - */ + /// Returns the int representation of this integer. + /// + /// On some platforms, inputs with large absolute values (i.e., > 2^52) may + /// lose some of their low-order bits. int toInt(); - /** - * Returns an Int32 representation of this integer. - * - * Narrower values are sign-extended and wider values have their high bits - * truncated. - */ + /// Returns an Int32 representation of this integer. + /// + /// Narrower values are sign-extended and wider values have their high bits + /// truncated. Int32 toInt32(); - /** Returns an Int64 representation of this integer. */ + /// Returns an Int64 representation of this integer. Int64 toInt64(); - /** - * Returns a string representing the value of this integer in decimal - * notation; example: `'13'`. - */ + /// Returns a string representing the value of this integer in decimal + /// notation; example: `'13'`. String toString(); - /** - * Returns a string representing the value of this integer in hexadecimal - * notation; example: `'0xd'`. - */ + /// Returns a string representing the value of this integer in hexadecimal + /// notation; example: `'0xd'`. String toHexString(); - /** - * Returns a string representing the value of this integer in the given radix. - * - * [radix] must be an integer in the range 2 .. 16, inclusive. - */ + /// Returns a string representing the value of this integer in the given radix. + /// + /// [radix] must be an integer in the range 2 .. 16, inclusive. String toRadixString(int radix); } diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index ff06246f..db003b83 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -6,7 +6,8 @@ author: Dart Team homepage: https://github.com/dart-lang/fixnum environment: - sdk: '>=2.0.0-dev.65 <3.0.0' + sdk: '>=2.0.0 <3.0.0' dev_dependencies: + pedantic: ^1.3.0 test: ^1.2.0 diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 55986381..e76a0dc9 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -library Int32test; - import 'package:fixnum/fixnum.dart'; import 'package:test/test.dart'; @@ -42,123 +40,117 @@ void main() { expect(Int32.MAX_VALUE.isZero, false); }); test("bitLength", () { - expect(new Int32(-2).bitLength, 1); + expect(Int32(-2).bitLength, 1); expect((-Int32.ONE).bitLength, 0); expect(Int32.ZERO.bitLength, 0); expect(Int32.ONE.bitLength, 1); - expect(new Int32(2).bitLength, 2); + expect(Int32(2).bitLength, 2); expect(Int32.MAX_VALUE.bitLength, 31); expect(Int32.MIN_VALUE.bitLength, 31); }); }); group("arithmetic operators", () { - Int32 n1 = new Int32(1234); - Int32 n2 = new Int32(9876); - Int32 n3 = new Int32(-1234); - Int32 n4 = new Int32(-9876); + Int32 n1 = Int32(1234); + Int32 n2 = Int32(9876); + Int32 n3 = Int32(-1234); + Int32 n4 = Int32(-9876); test("+", () { - expect(n1 + n2, new Int32(11110)); - expect(n3 + n2, new Int32(8642)); - expect(n3 + n4, new Int32(-11110)); - expect(n3 + new Int64(1), new Int64(-1233)); + expect(n1 + n2, Int32(11110)); + expect(n3 + n2, Int32(8642)); + expect(n3 + n4, Int32(-11110)); + expect(n3 + Int64(1), Int64(-1233)); expect(Int32.MAX_VALUE + 1, Int32.MIN_VALUE); - expect(() => new Int32(17) + null, throwsArgumentError); + expect(() => Int32(17) + null, throwsArgumentError); }); test("-", () { - expect(n1 - n2, new Int32(-8642)); - expect(n3 - n2, new Int32(-11110)); - expect(n3 - n4, new Int32(8642)); - expect(n3 - new Int64(1), new Int64(-1235)); + expect(n1 - n2, Int32(-8642)); + expect(n3 - n2, Int32(-11110)); + expect(n3 - n4, Int32(8642)); + expect(n3 - Int64(1), Int64(-1235)); expect(Int32.MIN_VALUE - 1, Int32.MAX_VALUE); - expect(() => new Int32(17) - null, throwsArgumentError); + expect(() => Int32(17) - null, throwsArgumentError); }); test("unary -", () { - expect(-n1, new Int32(-1234)); + expect(-n1, Int32(-1234)); expect(-Int32.ZERO, Int32.ZERO); }); test("*", () { - expect(n1 * n2, new Int32(12186984)); - expect(n2 * n3, new Int32(-12186984)); - expect(n3 * n3, new Int32(1522756)); - expect(n3 * n2, new Int32(-12186984)); - expect( - new Int32(0x12345678) * new Int32(0x22222222), new Int32(-899716112)); - expect( - (new Int32(123456789) * new Int32(987654321)), new Int32(-67153019)); - expect(new Int32(0x12345678) * new Int64(0x22222222), - new Int64.fromInts(0x026D60DC, 0xCA5F6BF0)); - expect((new Int32(123456789) * 987654321), new Int32(-67153019)); - expect(() => new Int32(17) * null, throwsArgumentError); + expect(n1 * n2, Int32(12186984)); + expect(n2 * n3, Int32(-12186984)); + expect(n3 * n3, Int32(1522756)); + expect(n3 * n2, Int32(-12186984)); + expect(Int32(0x12345678) * Int32(0x22222222), Int32(-899716112)); + expect((Int32(123456789) * Int32(987654321)), Int32(-67153019)); + expect(Int32(0x12345678) * Int64(0x22222222), + Int64.fromInts(0x026D60DC, 0xCA5F6BF0)); + expect((Int32(123456789) * 987654321), Int32(-67153019)); + expect(() => Int32(17) * null, throwsArgumentError); }); test("~/", () { - expect(new Int32(829893893) ~/ new Int32(1919), new Int32(432461)); - expect(new Int32(0x12345678) ~/ new Int32(0x22), - new Int32(0x12345678 ~/ 0x22)); - expect(new Int32(829893893) ~/ new Int64(1919), new Int32(432461)); - expect(new Int32(0x12345678) ~/ new Int64(0x22), - new Int32(0x12345678 ~/ 0x22)); - expect(new Int32(829893893) ~/ 1919, new Int32(432461)); + expect(Int32(829893893) ~/ Int32(1919), Int32(432461)); + expect(Int32(0x12345678) ~/ Int32(0x22), Int32(0x12345678 ~/ 0x22)); + expect(Int32(829893893) ~/ Int64(1919), Int32(432461)); + expect(Int32(0x12345678) ~/ Int64(0x22), Int32(0x12345678 ~/ 0x22)); + expect(Int32(829893893) ~/ 1919, Int32(432461)); expect( - () => new Int32(17) ~/ Int32.ZERO, + () => Int32(17) ~/ Int32.ZERO, // with dart2js, `UnsupportedError` is thrown // on the VM: IntegerDivisionByZeroException - throwsA(anyOf(new TypeMatcher(), + throwsA(anyOf(const TypeMatcher(), isUnsupportedError))); - expect(() => new Int32(17) ~/ null, throwsArgumentError); + expect(() => Int32(17) ~/ null, throwsArgumentError); }); test("%", () { - expect(new Int32(0x12345678) % new Int32(0x22), - new Int32(0x12345678 % 0x22)); - expect(new Int32(0x12345678) % new Int64(0x22), - new Int32(0x12345678 % 0x22)); - expect(() => new Int32(17) % null, throwsArgumentError); + expect(Int32(0x12345678) % Int32(0x22), Int32(0x12345678 % 0x22)); + expect(Int32(0x12345678) % Int64(0x22), Int32(0x12345678 % 0x22)); + expect(() => Int32(17) % null, throwsArgumentError); }); test("remainder", () { - expect(new Int32(0x12345678).remainder(new Int32(0x22)), - new Int32(0x12345678.remainder(0x22))); - expect(new Int32(0x12345678).remainder(new Int32(-0x22)), - new Int32(0x12345678.remainder(-0x22))); - expect(new Int32(-0x12345678).remainder(new Int32(-0x22)), - new Int32(-0x12345678.remainder(-0x22))); - expect(new Int32(-0x12345678).remainder(new Int32(0x22)), - new Int32(-0x12345678.remainder(0x22))); - expect(new Int32(0x12345678).remainder(new Int64(0x22)), - new Int32(0x12345678.remainder(0x22))); - expect(() => new Int32(17).remainder(null), throwsArgumentError); + expect(Int32(0x12345678).remainder(Int32(0x22)), + Int32(0x12345678.remainder(0x22))); + expect(Int32(0x12345678).remainder(Int32(-0x22)), + Int32(0x12345678.remainder(-0x22))); + expect(Int32(-0x12345678).remainder(Int32(-0x22)), + Int32(-0x12345678.remainder(-0x22))); + expect(Int32(-0x12345678).remainder(Int32(0x22)), + Int32(-0x12345678.remainder(0x22))); + expect(Int32(0x12345678).remainder(Int64(0x22)), + Int32(0x12345678.remainder(0x22))); + expect(() => Int32(17).remainder(null), throwsArgumentError); }); test("abs", () { // NOTE: Int32.MIN_VALUE.abs() is undefined expect((Int32.MIN_VALUE + 1).abs(), Int32.MAX_VALUE); - expect(new Int32(-1).abs(), new Int32(1)); - expect(new Int32(0).abs(), new Int32(0)); - expect(new Int32(1).abs(), new Int32(1)); + expect(Int32(-1).abs(), Int32(1)); + expect(Int32(0).abs(), Int32(0)); + expect(Int32(1).abs(), Int32(1)); expect(Int32.MAX_VALUE.abs(), Int32.MAX_VALUE); }); test("clamp", () { - Int32 val = new Int32(17); - expect(val.clamp(20, 30), new Int32(20)); - expect(val.clamp(10, 20), new Int32(17)); - expect(val.clamp(10, 15), new Int32(15)); + Int32 val = Int32(17); + expect(val.clamp(20, 30), Int32(20)); + expect(val.clamp(10, 20), Int32(17)); + expect(val.clamp(10, 15), Int32(15)); - expect(val.clamp(new Int32(20), new Int32(30)), new Int32(20)); - expect(val.clamp(new Int32(10), new Int32(20)), new Int32(17)); - expect(val.clamp(new Int32(10), new Int32(15)), new Int32(15)); + expect(val.clamp(Int32(20), Int32(30)), Int32(20)); + expect(val.clamp(Int32(10), Int32(20)), Int32(17)); + expect(val.clamp(Int32(10), Int32(15)), Int32(15)); - expect(val.clamp(new Int64(20), new Int64(30)), new Int32(20)); - expect(val.clamp(new Int64(10), new Int64(20)), new Int32(17)); - expect(val.clamp(new Int64(10), new Int64(15)), new Int32(15)); - expect(val.clamp(Int64.MIN_VALUE, new Int64(30)), new Int32(17)); - expect(val.clamp(new Int64(10), Int64.MAX_VALUE), new Int32(17)); + expect(val.clamp(Int64(20), Int64(30)), Int32(20)); + expect(val.clamp(Int64(10), Int64(20)), Int32(17)); + expect(val.clamp(Int64(10), Int64(15)), Int32(15)); + expect(val.clamp(Int64.MIN_VALUE, Int64(30)), Int32(17)); + expect(val.clamp(Int64(10), Int64.MAX_VALUE), Int32(17)); expect(() => val.clamp(30.5, 40.5), throwsArgumentError); expect(() => val.clamp(5.5, 10.5), throwsArgumentError); @@ -170,156 +162,155 @@ void main() { group("leading/trailing zeros", () { test("numberOfLeadingZeros", () { - expect(new Int32(0).numberOfLeadingZeros(), 32); - expect(new Int32(1).numberOfLeadingZeros(), 31); - expect(new Int32(0xffff).numberOfLeadingZeros(), 16); - expect(new Int32(-1).numberOfLeadingZeros(), 0); + expect(Int32(0).numberOfLeadingZeros(), 32); + expect(Int32(1).numberOfLeadingZeros(), 31); + expect(Int32(0xffff).numberOfLeadingZeros(), 16); + expect(Int32(-1).numberOfLeadingZeros(), 0); }); test("numberOfTrailingZeros", () { - expect(new Int32(0).numberOfTrailingZeros(), 32); - expect(new Int32(0x80000000).numberOfTrailingZeros(), 31); - expect(new Int32(1).numberOfTrailingZeros(), 0); - expect(new Int32(0x10000).numberOfTrailingZeros(), 16); + expect(Int32(0).numberOfTrailingZeros(), 32); + expect(Int32(0x80000000).numberOfTrailingZeros(), 31); + expect(Int32(1).numberOfTrailingZeros(), 0); + expect(Int32(0x10000).numberOfTrailingZeros(), 16); }); }); group("comparison operators", () { test("compareTo", () { - expect(new Int32(0).compareTo(-1), 1); - expect(new Int32(0).compareTo(0), 0); - expect(new Int32(0).compareTo(1), -1); - expect(new Int32(0).compareTo(new Int32(-1)), 1); - expect(new Int32(0).compareTo(new Int32(0)), 0); - expect(new Int32(0).compareTo(new Int32(1)), -1); - expect(new Int32(0).compareTo(new Int64(-1)), 1); - expect(new Int32(0).compareTo(new Int64(0)), 0); - expect(new Int32(0).compareTo(new Int64(1)), -1); + expect(Int32(0).compareTo(-1), 1); + expect(Int32(0).compareTo(0), 0); + expect(Int32(0).compareTo(1), -1); + expect(Int32(0).compareTo(Int32(-1)), 1); + expect(Int32(0).compareTo(Int32(0)), 0); + expect(Int32(0).compareTo(Int32(1)), -1); + expect(Int32(0).compareTo(Int64(-1)), 1); + expect(Int32(0).compareTo(Int64(0)), 0); + expect(Int32(0).compareTo(Int64(1)), -1); }); test("<", () { - expect(new Int32(17) < new Int32(18), true); - expect(new Int32(17) < new Int32(17), false); - expect(new Int32(17) < new Int32(16), false); - expect(new Int32(17) < new Int64(18), true); - expect(new Int32(17) < new Int64(17), false); - expect(new Int32(17) < new Int64(16), false); + expect(Int32(17) < Int32(18), true); + expect(Int32(17) < Int32(17), false); + expect(Int32(17) < Int32(16), false); + expect(Int32(17) < Int64(18), true); + expect(Int32(17) < Int64(17), false); + expect(Int32(17) < Int64(16), false); expect(Int32.MIN_VALUE < Int32.MAX_VALUE, true); expect(Int32.MAX_VALUE < Int32.MIN_VALUE, false); - expect(() => new Int32(17) < null, throwsArgumentError); + expect(() => Int32(17) < null, throwsArgumentError); }); test("<=", () { - expect(new Int32(17) <= new Int32(18), true); - expect(new Int32(17) <= new Int32(17), true); - expect(new Int32(17) <= new Int32(16), false); - expect(new Int32(17) <= new Int64(18), true); - expect(new Int32(17) <= new Int64(17), true); - expect(new Int32(17) <= new Int64(16), false); + expect(Int32(17) <= Int32(18), true); + expect(Int32(17) <= Int32(17), true); + expect(Int32(17) <= Int32(16), false); + expect(Int32(17) <= Int64(18), true); + expect(Int32(17) <= Int64(17), true); + expect(Int32(17) <= Int64(16), false); expect(Int32.MIN_VALUE <= Int32.MAX_VALUE, true); expect(Int32.MAX_VALUE <= Int32.MIN_VALUE, false); - expect(() => new Int32(17) <= null, throwsArgumentError); + expect(() => Int32(17) <= null, throwsArgumentError); }); test("==", () { - expect(new Int32(17) == new Int32(18), false); - expect(new Int32(17) == new Int32(17), true); - expect(new Int32(17) == new Int32(16), false); - expect(new Int32(17) == new Int64(18), false); - expect(new Int32(17) == new Int64(17), true); - expect(new Int32(17) == new Int64(16), false); + expect(Int32(17) == Int32(18), false); + expect(Int32(17) == Int32(17), true); + expect(Int32(17) == Int32(16), false); + expect(Int32(17) == Int64(18), false); + expect(Int32(17) == Int64(17), true); + expect(Int32(17) == Int64(16), false); expect(Int32.MIN_VALUE == Int32.MAX_VALUE, false); - expect(new Int32(17) == 18, false); - expect(new Int32(17) == 17, true); - expect(new Int32(17) == 16, false); - expect(new Int32(17) == new Object(), false); - expect(new Int32(17) == null, false); + expect(Int32(17) == 18, false); + expect(Int32(17) == 17, true); + expect(Int32(17) == 16, false); + expect(Int32(17) == Object(), false); + expect(Int32(17) == null, false); }); test(">=", () { - expect(new Int32(17) >= new Int32(18), false); - expect(new Int32(17) >= new Int32(17), true); - expect(new Int32(17) >= new Int32(16), true); - expect(new Int32(17) >= new Int64(18), false); - expect(new Int32(17) >= new Int64(17), true); - expect(new Int32(17) >= new Int64(16), true); + expect(Int32(17) >= Int32(18), false); + expect(Int32(17) >= Int32(17), true); + expect(Int32(17) >= Int32(16), true); + expect(Int32(17) >= Int64(18), false); + expect(Int32(17) >= Int64(17), true); + expect(Int32(17) >= Int64(16), true); expect(Int32.MIN_VALUE >= Int32.MAX_VALUE, false); expect(Int32.MAX_VALUE >= Int32.MIN_VALUE, true); - expect(() => new Int32(17) >= null, throwsArgumentError); + expect(() => Int32(17) >= null, throwsArgumentError); }); test(">", () { - expect(new Int32(17) > new Int32(18), false); - expect(new Int32(17) > new Int32(17), false); - expect(new Int32(17) > new Int32(16), true); - expect(new Int32(17) > new Int64(18), false); - expect(new Int32(17) > new Int64(17), false); - expect(new Int32(17) > new Int64(16), true); + expect(Int32(17) > Int32(18), false); + expect(Int32(17) > Int32(17), false); + expect(Int32(17) > Int32(16), true); + expect(Int32(17) > Int64(18), false); + expect(Int32(17) > Int64(17), false); + expect(Int32(17) > Int64(16), true); expect(Int32.MIN_VALUE > Int32.MAX_VALUE, false); expect(Int32.MAX_VALUE > Int32.MIN_VALUE, true); - expect(() => new Int32(17) > null, throwsArgumentError); + expect(() => Int32(17) > null, throwsArgumentError); }); }); group("bitwise operators", () { test("&", () { - expect(new Int32(0x12345678) & new Int32(0x22222222), - new Int32(0x12345678 & 0x22222222)); - expect(new Int32(0x12345678) & new Int64(0x22222222), - new Int64(0x12345678 & 0x22222222)); - expect(() => new Int32(17) & null, throwsArgumentError); + expect(Int32(0x12345678) & Int32(0x22222222), + Int32(0x12345678 & 0x22222222)); + expect(Int32(0x12345678) & Int64(0x22222222), + Int64(0x12345678 & 0x22222222)); + expect(() => Int32(17) & null, throwsArgumentError); }); test("|", () { - expect(new Int32(0x12345678) | new Int32(0x22222222), - new Int32(0x12345678 | 0x22222222)); - expect(new Int32(0x12345678) | new Int64(0x22222222), - new Int64(0x12345678 | 0x22222222)); - expect(() => new Int32(17) | null, throwsArgumentError); + expect(Int32(0x12345678) | Int32(0x22222222), + Int32(0x12345678 | 0x22222222)); + expect(Int32(0x12345678) | Int64(0x22222222), + Int64(0x12345678 | 0x22222222)); + expect(() => Int32(17) | null, throwsArgumentError); }); test("^", () { - expect(new Int32(0x12345678) ^ new Int32(0x22222222), - new Int32(0x12345678 ^ 0x22222222)); - expect(new Int32(0x12345678) ^ new Int64(0x22222222), - new Int64(0x12345678 ^ 0x22222222)); - expect(() => new Int32(17) ^ null, throwsArgumentError); + expect(Int32(0x12345678) ^ Int32(0x22222222), + Int32(0x12345678 ^ 0x22222222)); + expect(Int32(0x12345678) ^ Int64(0x22222222), + Int64(0x12345678 ^ 0x22222222)); + expect(() => Int32(17) ^ null, throwsArgumentError); }); test("~", () { - expect(~(new Int32(0x12345678)), new Int32(~0x12345678)); - expect(-(new Int32(0x12345678)), new Int64(-0x12345678)); + expect(~(Int32(0x12345678)), Int32(~0x12345678)); + expect(-(Int32(0x12345678)), Int64(-0x12345678)); }); }); group("bitshift operators", () { test("<<", () { - expect(new Int32(0x12345678) << 7, new Int32(0x12345678 << 7)); - expect(new Int32(0x12345678) << 32, Int32.ZERO); - expect(new Int32(0x12345678) << 33, Int32.ZERO); - expect(() => new Int32(17) << -1, throwsArgumentError); - expect(() => new Int32(17) << null, throwsNoSuchMethodError); + expect(Int32(0x12345678) << 7, Int32(0x12345678 << 7)); + expect(Int32(0x12345678) << 32, Int32.ZERO); + expect(Int32(0x12345678) << 33, Int32.ZERO); + expect(() => Int32(17) << -1, throwsArgumentError); + expect(() => Int32(17) << null, throwsNoSuchMethodError); }); test(">>", () { - expect(new Int32(0x12345678) >> 7, new Int32(0x12345678 >> 7)); - expect(new Int32(0x12345678) >> 32, Int32.ZERO); - expect(new Int32(0x12345678) >> 33, Int32.ZERO); - expect(new Int32(-42) >> 32, new Int32(-1)); - expect(new Int32(-42) >> 33, new Int32(-1)); - expect(() => new Int32(17) >> -1, throwsArgumentError); - expect(() => new Int32(17) >> null, throwsNoSuchMethodError); + expect(Int32(0x12345678) >> 7, Int32(0x12345678 >> 7)); + expect(Int32(0x12345678) >> 32, Int32.ZERO); + expect(Int32(0x12345678) >> 33, Int32.ZERO); + expect(Int32(-42) >> 32, Int32(-1)); + expect(Int32(-42) >> 33, Int32(-1)); + expect(() => Int32(17) >> -1, throwsArgumentError); + expect(() => Int32(17) >> null, throwsNoSuchMethodError); }); test("shiftRightUnsigned", () { - expect(new Int32(0x12345678).shiftRightUnsigned(7), - new Int32(0x12345678 >> 7)); - expect(new Int32(0x12345678).shiftRightUnsigned(32), Int32.ZERO); - expect(new Int32(0x12345678).shiftRightUnsigned(33), Int32.ZERO); - expect(new Int32(-42).shiftRightUnsigned(32), Int32.ZERO); - expect(new Int32(-42).shiftRightUnsigned(33), Int32.ZERO); - expect(() => (new Int32(17).shiftRightUnsigned(-1)), throwsArgumentError); - expect(() => (new Int32(17).shiftRightUnsigned(null)), - throwsNoSuchMethodError); + expect(Int32(0x12345678).shiftRightUnsigned(7), Int32(0x12345678 >> 7)); + expect(Int32(0x12345678).shiftRightUnsigned(32), Int32.ZERO); + expect(Int32(0x12345678).shiftRightUnsigned(33), Int32.ZERO); + expect(Int32(-42).shiftRightUnsigned(32), Int32.ZERO); + expect(Int32(-42).shiftRightUnsigned(33), Int32.ZERO); + expect(() => (Int32(17).shiftRightUnsigned(-1)), throwsArgumentError); + expect( + () => (Int32(17).shiftRightUnsigned(null)), throwsNoSuchMethodError); }); }); @@ -345,33 +336,33 @@ void main() { expect(() => Int32.ONE.toUnsigned(33), throwsRangeError); }); test("toDouble", () { - expect(new Int32(17).toDouble(), same(17.0)); - expect(new Int32(-17).toDouble(), same(-17.0)); + expect(Int32(17).toDouble(), same(17.0)); + expect(Int32(-17).toDouble(), same(-17.0)); }); test("toInt", () { - expect(new Int32(17).toInt(), 17); - expect(new Int32(-17).toInt(), -17); + expect(Int32(17).toInt(), 17); + expect(Int32(-17).toInt(), -17); }); test("toInt32", () { - expect(new Int32(17).toInt32(), new Int32(17)); - expect(new Int32(-17).toInt32(), new Int32(-17)); + expect(Int32(17).toInt32(), Int32(17)); + expect(Int32(-17).toInt32(), Int32(-17)); }); test("toInt64", () { - expect(new Int32(17).toInt64(), new Int64(17)); - expect(new Int32(-17).toInt64(), new Int64(-17)); + expect(Int32(17).toInt64(), Int64(17)); + expect(Int32(-17).toInt64(), Int64(-17)); }); test("toBytes", () { - expect(new Int32(0).toBytes(), [0, 0, 0, 0]); - expect(new Int32(0x01020304).toBytes(), [4, 3, 2, 1]); - expect(new Int32(0x04030201).toBytes(), [1, 2, 3, 4]); - expect(new Int32(-1).toBytes(), [0xff, 0xff, 0xff, 0xff]); + expect(Int32(0).toBytes(), [0, 0, 0, 0]); + expect(Int32(0x01020304).toBytes(), [4, 3, 2, 1]); + expect(Int32(0x04030201).toBytes(), [1, 2, 3, 4]); + expect(Int32(-1).toBytes(), [0xff, 0xff, 0xff, 0xff]); }); }); group("parse", () { test("base 10", () { checkInt(int x) { - expect(Int32.parseRadix('$x', 10), new Int32(x)); + expect(Int32.parseRadix('$x', 10), Int32(x)); } checkInt(0); @@ -396,49 +387,49 @@ void main() { }); test("parseInt", () { - expect(Int32.parseInt('0'), new Int32(0)); - expect(Int32.parseInt('1000'), new Int32(1000)); - expect(Int32.parseInt('4294967296'), new Int32(4294967296)); + expect(Int32.parseInt('0'), Int32(0)); + expect(Int32.parseInt('1000'), Int32(1000)); + expect(Int32.parseInt('4294967296'), Int32(4294967296)); }); test("parseHex", () { - expect(Int32.parseHex('deadbeef'), new Int32(0xdeadbeef)); - expect(Int32.parseHex('cafebabe'), new Int32(0xcafebabe)); - expect(Int32.parseHex('8badf00d'), new Int32(0x8badf00d)); + expect(Int32.parseHex('deadbeef'), Int32(0xdeadbeef)); + expect(Int32.parseHex('cafebabe'), Int32(0xcafebabe)); + expect(Int32.parseHex('8badf00d'), Int32(0x8badf00d)); }); }); group("string representation", () { test("toString", () { - expect(new Int32(0).toString(), "0"); - expect(new Int32(1).toString(), "1"); - expect(new Int32(-1).toString(), "-1"); - expect(new Int32(1000).toString(), "1000"); - expect(new Int32(-1000).toString(), "-1000"); - expect(new Int32(123456789).toString(), "123456789"); - expect(new Int32(2147483647).toString(), "2147483647"); - expect(new Int32(2147483648).toString(), "-2147483648"); - expect(new Int32(2147483649).toString(), "-2147483647"); - expect(new Int32(2147483650).toString(), "-2147483646"); - expect(new Int32(-2147483648).toString(), "-2147483648"); - expect(new Int32(-2147483649).toString(), "2147483647"); - expect(new Int32(-2147483650).toString(), "2147483646"); + expect(Int32(0).toString(), "0"); + expect(Int32(1).toString(), "1"); + expect(Int32(-1).toString(), "-1"); + expect(Int32(1000).toString(), "1000"); + expect(Int32(-1000).toString(), "-1000"); + expect(Int32(123456789).toString(), "123456789"); + expect(Int32(2147483647).toString(), "2147483647"); + expect(Int32(2147483648).toString(), "-2147483648"); + expect(Int32(2147483649).toString(), "-2147483647"); + expect(Int32(2147483650).toString(), "-2147483646"); + expect(Int32(-2147483648).toString(), "-2147483648"); + expect(Int32(-2147483649).toString(), "2147483647"); + expect(Int32(-2147483650).toString(), "2147483646"); }); }); group("toHexString", () { test("returns hexadecimal string representation", () { - expect(new Int32(-1).toHexString(), "-1"); - expect((new Int32(-1) >> 8).toHexString(), "-1"); - expect((new Int32(-1) << 8).toHexString(), "-100"); - expect(new Int32(123456789).toHexString(), "75bcd15"); - expect(new Int32(-1).shiftRightUnsigned(8).toHexString(), "ffffff"); + expect(Int32(-1).toHexString(), "-1"); + expect((Int32(-1) >> 8).toHexString(), "-1"); + expect((Int32(-1) << 8).toHexString(), "-100"); + expect(Int32(123456789).toHexString(), "75bcd15"); + expect(Int32(-1).shiftRightUnsigned(8).toHexString(), "ffffff"); }); }); group("toRadixString", () { test("returns base n string representation", () { - expect(new Int32(123456789).toRadixString(5), "223101104124"); + expect(Int32(123456789).toRadixString(5), "223101104124"); }); }); } diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 0fc2085f..ac6b6b08 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -11,7 +11,7 @@ void main() { group("fromBytes", () { test("fromBytes", () { checkBytes(List bytes, int h, int l) { - expect(new Int64.fromBytes(bytes), new Int64.fromInts(h, l)); + expect(Int64.fromBytes(bytes), Int64.fromInts(h, l)); } checkBytes([0, 0, 0, 0, 0, 0, 0, 0], 0, 0); @@ -24,7 +24,7 @@ void main() { }); test("fromBytesBigEndian", () { checkBytes(List bytes, int h, int l) { - expect(new Int64.fromBytesBigEndian(bytes), new Int64.fromInts(h, l)); + expect(Int64.fromBytesBigEndian(bytes), Int64.fromInts(h, l)); } checkBytes([0, 0, 0, 0, 0, 0, 0, 0], 0, 0); @@ -79,219 +79,218 @@ void main() { expect(Int64.MAX_VALUE.isZero, false); }); test("bitLength", () { - expect(new Int64(-2).bitLength, 1); + expect(Int64(-2).bitLength, 1); expect((-Int64.ONE).bitLength, 0); expect(Int64.ZERO.bitLength, 0); expect((Int64.ONE << 21).bitLength, 22); expect((Int64.ONE << 22).bitLength, 23); expect((Int64.ONE << 43).bitLength, 44); expect((Int64.ONE << 44).bitLength, 45); - expect(new Int64(2).bitLength, 2); + expect(Int64(2).bitLength, 2); expect(Int64.MAX_VALUE.bitLength, 63); expect(Int64.MIN_VALUE.bitLength, 63); }); }); group("arithmetic operators", () { - Int64 n1 = new Int64(1234); - Int64 n2 = new Int64(9876); - Int64 n3 = new Int64(-1234); - Int64 n4 = new Int64(-9876); - Int64 n5 = new Int64.fromInts(0x12345678, 0xabcdabcd); - Int64 n6 = new Int64.fromInts(0x77773333, 0x22224444); + Int64 n1 = Int64(1234); + Int64 n2 = Int64(9876); + Int64 n3 = Int64(-1234); + Int64 n4 = Int64(-9876); + Int64 n5 = Int64.fromInts(0x12345678, 0xabcdabcd); + Int64 n6 = Int64.fromInts(0x77773333, 0x22224444); test("+", () { - expect(n1 + n2, new Int64(11110)); - expect(n3 + n2, new Int64(8642)); - expect(n3 + n4, new Int64(-11110)); - expect(n5 + n6, new Int64.fromInts(0x89ab89ab, 0xcdeff011)); + expect(n1 + n2, Int64(11110)); + expect(n3 + n2, Int64(8642)); + expect(n3 + n4, Int64(-11110)); + expect(n5 + n6, Int64.fromInts(0x89ab89ab, 0xcdeff011)); expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE); argumentErrorTest("+", (a, b) => a + b); }); test("-", () { - expect(n1 - n2, new Int64(-8642)); - expect(n3 - n2, new Int64(-11110)); - expect(n3 - n4, new Int64(8642)); - expect(n5 - n6, new Int64.fromInts(0x9abd2345, 0x89ab6789)); + expect(n1 - n2, Int64(-8642)); + expect(n3 - n2, Int64(-11110)); + expect(n3 - n4, Int64(8642)); + expect(n5 - n6, Int64.fromInts(0x9abd2345, 0x89ab6789)); expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE); argumentErrorTest("-", (a, b) => a - b); }); test("unary -", () { - expect(-n1, new Int64(-1234)); + expect(-n1, Int64(-1234)); expect(-Int64.ZERO, Int64.ZERO); }); test("*", () { - expect(new Int64(1111) * new Int64(3), new Int64(3333)); - expect(new Int64(1111) * new Int64(-3), new Int64(-3333)); - expect(new Int64(-1111) * new Int64(3), new Int64(-3333)); - expect(new Int64(-1111) * new Int64(-3), new Int64(3333)); - expect(new Int64(100) * Int64.ZERO, Int64.ZERO); + expect(Int64(1111) * Int64(3), Int64(3333)); + expect(Int64(1111) * Int64(-3), Int64(-3333)); + expect(Int64(-1111) * Int64(3), Int64(-3333)); + expect(Int64(-1111) * Int64(-3), Int64(3333)); + expect(Int64(100) * Int64.ZERO, Int64.ZERO); expect( - new Int64.fromInts(0x12345678, 0x12345678) * - new Int64.fromInts(0x1234, 0x12345678), - new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); + Int64.fromInts(0x12345678, 0x12345678) * + Int64.fromInts(0x1234, 0x12345678), + Int64.fromInts(0x7ff63f7c, 0x1df4d840)); expect( - new Int64.fromInts(0xf2345678, 0x12345678) * - new Int64.fromInts(0x1234, 0x12345678), - new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); + Int64.fromInts(0xf2345678, 0x12345678) * + Int64.fromInts(0x1234, 0x12345678), + Int64.fromInts(0x7ff63f7c, 0x1df4d840)); expect( - new Int64.fromInts(0xf2345678, 0x12345678) * - new Int64.fromInts(0xffff1234, 0x12345678), - new Int64.fromInts(0x297e3f7c, 0x1df4d840)); + Int64.fromInts(0xf2345678, 0x12345678) * + Int64.fromInts(0xffff1234, 0x12345678), + Int64.fromInts(0x297e3f7c, 0x1df4d840)); // RHS Int32 - expect((new Int64(123456789) * new Int32(987654321)), - new Int64.fromInts(0x1b13114, 0xfbff5385)); - expect((new Int64(123456789) * new Int32(987654321)), - new Int64.fromInts(0x1b13114, 0xfbff5385)); + expect((Int64(123456789) * Int32(987654321)), + Int64.fromInts(0x1b13114, 0xfbff5385)); + expect((Int64(123456789) * Int32(987654321)), + Int64.fromInts(0x1b13114, 0xfbff5385)); // Wraparound - expect((new Int64(123456789) * new Int64(987654321)), - new Int64.fromInts(0x1b13114, 0xfbff5385)); + expect((Int64(123456789) * Int64(987654321)), + Int64.fromInts(0x1b13114, 0xfbff5385)); - expect(Int64.MIN_VALUE * new Int64(2), Int64.ZERO); - expect(Int64.MIN_VALUE * new Int64(1), Int64.MIN_VALUE); - expect(Int64.MIN_VALUE * new Int64(-1), Int64.MIN_VALUE); + expect(Int64.MIN_VALUE * Int64(2), Int64.ZERO); + expect(Int64.MIN_VALUE * Int64(1), Int64.MIN_VALUE); + expect(Int64.MIN_VALUE * Int64(-1), Int64.MIN_VALUE); argumentErrorTest("*", (a, b) => a * b); }); test("~/", () { - Int64 deadBeef = new Int64.fromInts(0xDEADBEEF, 0xDEADBEEF); - Int64 ten = new Int64(10); + Int64 deadBeef = Int64.fromInts(0xDEADBEEF, 0xDEADBEEF); + Int64 ten = Int64(10); - expect(deadBeef ~/ ten, new Int64.fromInts(0xfcaaf97e, 0x63115fe5)); + expect(deadBeef ~/ ten, Int64.fromInts(0xfcaaf97e, 0x63115fe5)); expect(Int64.ONE ~/ Int64.TWO, Int64.ZERO); - expect(Int64.MAX_VALUE ~/ Int64.TWO, - new Int64.fromInts(0x3fffffff, 0xffffffff)); - expect(Int64.ZERO ~/ new Int64(1000), Int64.ZERO); + expect( + Int64.MAX_VALUE ~/ Int64.TWO, Int64.fromInts(0x3fffffff, 0xffffffff)); + expect(Int64.ZERO ~/ Int64(1000), Int64.ZERO); expect(Int64.MIN_VALUE ~/ Int64.MIN_VALUE, Int64.ONE); - expect(new Int64(1000) ~/ Int64.MIN_VALUE, Int64.ZERO); - expect(Int64.MIN_VALUE ~/ new Int64(8192), new Int64(-1125899906842624)); - expect(Int64.MIN_VALUE ~/ new Int64(8193), new Int64(-1125762484664320)); - expect(new Int64(-1000) ~/ new Int64(8192), Int64.ZERO); - expect(new Int64(-1000) ~/ new Int64(8193), Int64.ZERO); - expect(new Int64(-1000000000) ~/ new Int64(8192), new Int64(-122070)); - expect(new Int64(-1000000000) ~/ new Int64(8193), new Int64(-122055)); - expect(new Int64(1000000000) ~/ new Int64(8192), new Int64(122070)); - expect(new Int64(1000000000) ~/ new Int64(8193), new Int64(122055)); - expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00000400), - new Int64.fromInts(0x1fffff, 0xffffffff)); - expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00040000), - new Int64.fromInts(0x1fff, 0xffffffff)); - expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x04000000), - new Int64.fromInts(0x1f, 0xffffffff)); - expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000004, 0x00000000), - new Int64(536870911)); - expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000400, 0x00000000), - new Int64(2097151)); - expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00040000, 0x00000000), - new Int64(8191)); - expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x04000000, 0x00000000), - new Int64(31)); - expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00000300), - new Int64.fromInts(0x2AAAAA, 0xAAAAAAAA)); - expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x30000000), - new Int64.fromInts(0x2, 0xAAAAAAAA)); - expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00300000, 0x00000000), - new Int64(0x2AA)); - expect(Int64.MAX_VALUE ~/ new Int64(0x123456), - new Int64.fromInts(0x708, 0x002E9501)); - expect(Int64.MAX_VALUE % new Int64(0x123456), new Int64(0x3BDA9)); - expect(new Int64(5) ~/ new Int64(5), Int64.ONE); - expect(new Int64(1000) ~/ new Int64(3), new Int64(333)); - expect(new Int64(1000) ~/ new Int64(-3), new Int64(-333)); - expect(new Int64(-1000) ~/ new Int64(3), new Int64(-333)); - expect(new Int64(-1000) ~/ new Int64(-3), new Int64(333)); - expect(new Int64(3) ~/ new Int64(1000), Int64.ZERO); + expect(Int64(1000) ~/ Int64.MIN_VALUE, Int64.ZERO); + expect(Int64.MIN_VALUE ~/ Int64(8192), Int64(-1125899906842624)); + expect(Int64.MIN_VALUE ~/ Int64(8193), Int64(-1125762484664320)); + expect(Int64(-1000) ~/ Int64(8192), Int64.ZERO); + expect(Int64(-1000) ~/ Int64(8193), Int64.ZERO); + expect(Int64(-1000000000) ~/ Int64(8192), Int64(-122070)); + expect(Int64(-1000000000) ~/ Int64(8193), Int64(-122055)); + expect(Int64(1000000000) ~/ Int64(8192), Int64(122070)); + expect(Int64(1000000000) ~/ Int64(8193), Int64(122055)); + expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000000, 0x00000400), + Int64.fromInts(0x1fffff, 0xffffffff)); + expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000000, 0x00040000), + Int64.fromInts(0x1fff, 0xffffffff)); + expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000000, 0x04000000), + Int64.fromInts(0x1f, 0xffffffff)); + expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000004, 0x00000000), + Int64(536870911)); + expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000400, 0x00000000), + Int64(2097151)); + expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00040000, 0x00000000), + Int64(8191)); + expect( + Int64.MAX_VALUE ~/ Int64.fromInts(0x04000000, 0x00000000), Int64(31)); + expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000000, 0x00000300), + Int64.fromInts(0x2AAAAA, 0xAAAAAAAA)); + expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000000, 0x30000000), + Int64.fromInts(0x2, 0xAAAAAAAA)); + expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00300000, 0x00000000), + Int64(0x2AA)); + expect(Int64.MAX_VALUE ~/ Int64(0x123456), + Int64.fromInts(0x708, 0x002E9501)); + expect(Int64.MAX_VALUE % Int64(0x123456), Int64(0x3BDA9)); + expect(Int64(5) ~/ Int64(5), Int64.ONE); + expect(Int64(1000) ~/ Int64(3), Int64(333)); + expect(Int64(1000) ~/ Int64(-3), Int64(-333)); + expect(Int64(-1000) ~/ Int64(3), Int64(-333)); + expect(Int64(-1000) ~/ Int64(-3), Int64(333)); + expect(Int64(3) ~/ Int64(1000), Int64.ZERO); expect( - new Int64.fromInts(0x12345678, 0x12345678) ~/ - new Int64.fromInts(0x0, 0x123), - new Int64.fromInts(0x1003d0, 0xe84f5ae8)); + Int64.fromInts(0x12345678, 0x12345678) ~/ Int64.fromInts(0x0, 0x123), + Int64.fromInts(0x1003d0, 0xe84f5ae8)); expect( - new Int64.fromInts(0x12345678, 0x12345678) ~/ - new Int64.fromInts(0x1234, 0x12345678), - new Int64.fromInts(0x0, 0x10003)); + Int64.fromInts(0x12345678, 0x12345678) ~/ + Int64.fromInts(0x1234, 0x12345678), + Int64.fromInts(0x0, 0x10003)); expect( - new Int64.fromInts(0xf2345678, 0x12345678) ~/ - new Int64.fromInts(0x1234, 0x12345678), - new Int64.fromInts(0xffffffff, 0xffff3dfe)); + Int64.fromInts(0xf2345678, 0x12345678) ~/ + Int64.fromInts(0x1234, 0x12345678), + Int64.fromInts(0xffffffff, 0xffff3dfe)); expect( - new Int64.fromInts(0xf2345678, 0x12345678) ~/ - new Int64.fromInts(0xffff1234, 0x12345678), - new Int64.fromInts(0x0, 0xeda)); - expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461)); - expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461)); - expect(new Int64(829893893) ~/ 1919, new Int32(432461)); - expect(() => new Int64(1) ~/ Int64.ZERO, - throwsA(new TypeMatcher())); - expect(Int64.MIN_VALUE ~/ new Int64(2), - new Int64.fromInts(0xc0000000, 0x00000000)); - expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE); - expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE); - expect(() => new Int64(17) ~/ Int64.ZERO, - throwsA(new TypeMatcher())); + Int64.fromInts(0xf2345678, 0x12345678) ~/ + Int64.fromInts(0xffff1234, 0x12345678), + Int64.fromInts(0x0, 0xeda)); + expect(Int64(829893893) ~/ Int32(1919), Int32(432461)); + expect(Int64(829893893) ~/ Int64(1919), Int32(432461)); + expect(Int64(829893893) ~/ 1919, Int32(432461)); + expect(() => Int64(1) ~/ Int64.ZERO, + throwsA(const TypeMatcher())); + expect( + Int64.MIN_VALUE ~/ Int64(2), Int64.fromInts(0xc0000000, 0x00000000)); + expect(Int64.MIN_VALUE ~/ Int64(1), Int64.MIN_VALUE); + expect(Int64.MIN_VALUE ~/ Int64(-1), Int64.MIN_VALUE); + expect(() => Int64(17) ~/ Int64.ZERO, + throwsA(const TypeMatcher())); argumentErrorTest("~/", (a, b) => a ~/ b); }); test("%", () { // Define % as Euclidean mod, with positive result for all arguments - expect(Int64.ZERO % new Int64(1000), Int64.ZERO); + expect(Int64.ZERO % Int64(1000), Int64.ZERO); expect(Int64.MIN_VALUE % Int64.MIN_VALUE, Int64.ZERO); - expect(new Int64(1000) % Int64.MIN_VALUE, new Int64(1000)); - expect(Int64.MIN_VALUE % new Int64(8192), Int64.ZERO); - expect(Int64.MIN_VALUE % new Int64(8193), new Int64(6145)); - expect(new Int64(-1000) % new Int64(8192), new Int64(7192)); - expect(new Int64(-1000) % new Int64(8193), new Int64(7193)); - expect(new Int64(-1000000000) % new Int64(8192), new Int64(5632)); - expect(new Int64(-1000000000) % new Int64(8193), new Int64(4808)); - expect(new Int64(1000000000) % new Int64(8192), new Int64(2560)); - expect(new Int64(1000000000) % new Int64(8193), new Int64(3385)); - expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x00000400), - new Int64.fromInts(0x0, 0x3ff)); - expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x00040000), - new Int64.fromInts(0x0, 0x3ffff)); - expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x04000000), - new Int64.fromInts(0x0, 0x3ffffff)); - expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000004, 0x00000000), - new Int64.fromInts(0x3, 0xffffffff)); - expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000400, 0x00000000), - new Int64.fromInts(0x3ff, 0xffffffff)); - expect(Int64.MAX_VALUE % new Int64.fromInts(0x00040000, 0x00000000), - new Int64.fromInts(0x3ffff, 0xffffffff)); - expect(Int64.MAX_VALUE % new Int64.fromInts(0x04000000, 0x00000000), - new Int64.fromInts(0x3ffffff, 0xffffffff)); - expect(new Int64(0x12345678).remainder(new Int64(0x22)), - new Int64(0x12345678.remainder(0x22))); - expect(new Int64(0x12345678).remainder(new Int64(-0x22)), - new Int64(0x12345678.remainder(-0x22))); - expect(new Int64(-0x12345678).remainder(new Int64(-0x22)), - new Int64(-0x12345678.remainder(-0x22))); - expect(new Int64(-0x12345678).remainder(new Int64(0x22)), - new Int64(-0x12345678.remainder(0x22))); - expect(new Int32(0x12345678).remainder(new Int64(0x22)), - new Int64(0x12345678.remainder(0x22))); + expect(Int64(1000) % Int64.MIN_VALUE, Int64(1000)); + expect(Int64.MIN_VALUE % Int64(8192), Int64.ZERO); + expect(Int64.MIN_VALUE % Int64(8193), Int64(6145)); + expect(Int64(-1000) % Int64(8192), Int64(7192)); + expect(Int64(-1000) % Int64(8193), Int64(7193)); + expect(Int64(-1000000000) % Int64(8192), Int64(5632)); + expect(Int64(-1000000000) % Int64(8193), Int64(4808)); + expect(Int64(1000000000) % Int64(8192), Int64(2560)); + expect(Int64(1000000000) % Int64(8193), Int64(3385)); + expect(Int64.MAX_VALUE % Int64.fromInts(0x00000000, 0x00000400), + Int64.fromInts(0x0, 0x3ff)); + expect(Int64.MAX_VALUE % Int64.fromInts(0x00000000, 0x00040000), + Int64.fromInts(0x0, 0x3ffff)); + expect(Int64.MAX_VALUE % Int64.fromInts(0x00000000, 0x04000000), + Int64.fromInts(0x0, 0x3ffffff)); + expect(Int64.MAX_VALUE % Int64.fromInts(0x00000004, 0x00000000), + Int64.fromInts(0x3, 0xffffffff)); + expect(Int64.MAX_VALUE % Int64.fromInts(0x00000400, 0x00000000), + Int64.fromInts(0x3ff, 0xffffffff)); + expect(Int64.MAX_VALUE % Int64.fromInts(0x00040000, 0x00000000), + Int64.fromInts(0x3ffff, 0xffffffff)); + expect(Int64.MAX_VALUE % Int64.fromInts(0x04000000, 0x00000000), + Int64.fromInts(0x3ffffff, 0xffffffff)); + expect(Int64(0x12345678).remainder(Int64(0x22)), + Int64(0x12345678.remainder(0x22))); + expect(Int64(0x12345678).remainder(Int64(-0x22)), + Int64(0x12345678.remainder(-0x22))); + expect(Int64(-0x12345678).remainder(Int64(-0x22)), + Int64(-0x12345678.remainder(-0x22))); + expect(Int64(-0x12345678).remainder(Int64(0x22)), + Int64(-0x12345678.remainder(0x22))); + expect(Int32(0x12345678).remainder(Int64(0x22)), + Int64(0x12345678.remainder(0x22))); argumentErrorTest("%", (a, b) => a % b); }); test("clamp", () { - Int64 val = new Int64(17); - expect(val.clamp(20, 30), new Int64(20)); - expect(val.clamp(10, 20), new Int64(17)); - expect(val.clamp(10, 15), new Int64(15)); + Int64 val = Int64(17); + expect(val.clamp(20, 30), Int64(20)); + expect(val.clamp(10, 20), Int64(17)); + expect(val.clamp(10, 15), Int64(15)); - expect(val.clamp(new Int32(20), new Int32(30)), new Int64(20)); - expect(val.clamp(new Int32(10), new Int32(20)), new Int64(17)); - expect(val.clamp(new Int32(10), new Int32(15)), new Int64(15)); + expect(val.clamp(Int32(20), Int32(30)), Int64(20)); + expect(val.clamp(Int32(10), Int32(20)), Int64(17)); + expect(val.clamp(Int32(10), Int32(15)), Int64(15)); - expect(val.clamp(new Int64(20), new Int64(30)), new Int64(20)); - expect(val.clamp(new Int64(10), new Int64(20)), new Int64(17)); - expect(val.clamp(new Int64(10), new Int64(15)), new Int64(15)); - expect(val.clamp(Int64.MIN_VALUE, new Int64(30)), new Int64(17)); - expect(val.clamp(new Int64(10), Int64.MAX_VALUE), new Int64(17)); + expect(val.clamp(Int64(20), Int64(30)), Int64(20)); + expect(val.clamp(Int64(10), Int64(20)), Int64(17)); + expect(val.clamp(Int64(10), Int64(15)), Int64(15)); + expect(val.clamp(Int64.MIN_VALUE, Int64(30)), Int64(17)); + expect(val.clamp(Int64(10), Int64.MAX_VALUE), Int64(17)); expect(() => val.clamp(1, 'b'), throwsA(isArgumentError)); expect(() => val.clamp('a', 1), throwsA(isArgumentError)); @@ -304,14 +303,14 @@ void main() { expect(value.numberOfLeadingZeros(), zeros); } - checkZeros(new Int64(0), 64); - checkZeros(new Int64(1), 63); - checkZeros(new Int64.fromInts(0x00000000, 0x003fffff), 42); - checkZeros(new Int64.fromInts(0x00000000, 0x00400000), 41); - checkZeros(new Int64.fromInts(0x00000fff, 0xffffffff), 20); - checkZeros(new Int64.fromInts(0x00001000, 0x00000000), 19); - checkZeros(new Int64.fromInts(0x7fffffff, 0xffffffff), 1); - checkZeros(new Int64(-1), 0); + checkZeros(Int64(0), 64); + checkZeros(Int64(1), 63); + checkZeros(Int64.fromInts(0x00000000, 0x003fffff), 42); + checkZeros(Int64.fromInts(0x00000000, 0x00400000), 41); + checkZeros(Int64.fromInts(0x00000fff, 0xffffffff), 20); + checkZeros(Int64.fromInts(0x00001000, 0x00000000), 19); + checkZeros(Int64.fromInts(0x7fffffff, 0xffffffff), 1); + checkZeros(Int64(-1), 0); }); test("numberOfTrailingZeros", () { @@ -319,31 +318,31 @@ void main() { expect(value.numberOfTrailingZeros(), zeros); } - checkZeros(new Int64(-1), 0); - checkZeros(new Int64(1), 0); - checkZeros(new Int64(2), 1); - checkZeros(new Int64.fromInts(0x00000000, 0x00200000), 21); - checkZeros(new Int64.fromInts(0x00000000, 0x00400000), 22); - checkZeros(new Int64.fromInts(0x00000800, 0x00000000), 43); - checkZeros(new Int64.fromInts(0x00001000, 0x00000000), 44); - checkZeros(new Int64.fromInts(0x80000000, 0x00000000), 63); - checkZeros(new Int64(0), 64); + checkZeros(Int64(-1), 0); + checkZeros(Int64(1), 0); + checkZeros(Int64(2), 1); + checkZeros(Int64.fromInts(0x00000000, 0x00200000), 21); + checkZeros(Int64.fromInts(0x00000000, 0x00400000), 22); + checkZeros(Int64.fromInts(0x00000800, 0x00000000), 43); + checkZeros(Int64.fromInts(0x00001000, 0x00000000), 44); + checkZeros(Int64.fromInts(0x80000000, 0x00000000), 63); + checkZeros(Int64(0), 64); }); }); group("comparison operators", () { - Int64 largeNeg = new Int64.fromInts(0x82341234, 0x0); - Int64 largePos = new Int64.fromInts(0x12341234, 0x0); - Int64 largePosPlusOne = largePos + new Int64(1); + Int64 largeNeg = Int64.fromInts(0x82341234, 0x0); + Int64 largePos = Int64.fromInts(0x12341234, 0x0); + Int64 largePosPlusOne = largePos + Int64(1); test("<", () { - expect(new Int64(10) < new Int64(11), true); - expect(new Int64(10) < new Int64(10), false); - expect(new Int64(10) < new Int64(9), false); - expect(new Int64(10) < new Int32(11), true); - expect(new Int64(10) < new Int32(10), false); - expect(new Int64(10) < new Int32(9), false); - expect(new Int64(-10) < new Int64(-11), false); + expect(Int64(10) < Int64(11), true); + expect(Int64(10) < Int64(10), false); + expect(Int64(10) < Int64(9), false); + expect(Int64(10) < Int32(11), true); + expect(Int64(10) < Int32(10), false); + expect(Int64(10) < Int32(9), false); + expect(Int64(-10) < Int64(-11), false); expect(Int64.MIN_VALUE < Int64.ZERO, true); expect(largeNeg < largePos, true); expect(largePos < largePosPlusOne, true); @@ -355,14 +354,14 @@ void main() { }); test("<=", () { - expect(new Int64(10) <= new Int64(11), true); - expect(new Int64(10) <= new Int64(10), true); - expect(new Int64(10) <= new Int64(9), false); - expect(new Int64(10) <= new Int32(11), true); - expect(new Int64(10) <= new Int32(10), true); - expect(new Int64(10) <= new Int64(9), false); - expect(new Int64(-10) <= new Int64(-11), false); - expect(new Int64(-10) <= new Int64(-10), true); + expect(Int64(10) <= Int64(11), true); + expect(Int64(10) <= Int64(10), true); + expect(Int64(10) <= Int64(9), false); + expect(Int64(10) <= Int32(11), true); + expect(Int64(10) <= Int32(10), true); + expect(Int64(10) <= Int64(9), false); + expect(Int64(-10) <= Int64(-11), false); + expect(Int64(-10) <= Int64(-10), true); expect(largeNeg <= largePos, true); expect(largePos <= largeNeg, false); expect(largePos <= largePosPlusOne, true); @@ -374,42 +373,42 @@ void main() { }); test("==", () { - expect(new Int64(0) == new Int64(0), true); - expect(new Int64(0) == new Int64(1), false); - expect(new Int64(0) == new Int32(0), true); - expect(new Int64(0) == new Int32(1), false); - expect(new Int64(0) == 0, true); - expect(new Int64(0) == 1, false); - expect(new Int64(10) == new Int64(11), false); - expect(new Int64(10) == new Int64(10), true); - expect(new Int64(10) == new Int64(9), false); - expect(new Int64(10) == new Int32(11), false); - expect(new Int64(10) == new Int32(10), true); - expect(new Int64(10) == new Int32(9), false); - expect(new Int64(10) == 11, false); - expect(new Int64(10) == 10, true); - expect(new Int64(10) == 9, false); - expect(new Int64(-10) == new Int64(-10), true); - expect(new Int64(-10) != new Int64(-10), false); - expect(new Int64(-10) == -10, true); - expect(new Int64(-10) == -9, false); + expect(Int64(0) == Int64(0), true); + expect(Int64(0) == Int64(1), false); + expect(Int64(0) == Int32(0), true); + expect(Int64(0) == Int32(1), false); + expect(Int64(0) == 0, true); + expect(Int64(0) == 1, false); + expect(Int64(10) == Int64(11), false); + expect(Int64(10) == Int64(10), true); + expect(Int64(10) == Int64(9), false); + expect(Int64(10) == Int32(11), false); + expect(Int64(10) == Int32(10), true); + expect(Int64(10) == Int32(9), false); + expect(Int64(10) == 11, false); + expect(Int64(10) == 10, true); + expect(Int64(10) == 9, false); + expect(Int64(-10) == Int64(-10), true); + expect(Int64(-10) != Int64(-10), false); + expect(Int64(-10) == -10, true); + expect(Int64(-10) == -9, false); expect(largePos == largePos, true); expect(largePos == largePosPlusOne, false); expect(largePosPlusOne == largePos, false); expect(Int64.MIN_VALUE == Int64.MAX_VALUE, false); - expect(new Int64(17) == new Object(), false); - expect(new Int64(17) == null, false); + expect(Int64(17) == Object(), false); + expect(Int64(17) == null, false); }); test(">=", () { - expect(new Int64(10) >= new Int64(11), false); - expect(new Int64(10) >= new Int64(10), true); - expect(new Int64(10) >= new Int64(9), true); - expect(new Int64(10) >= new Int32(11), false); - expect(new Int64(10) >= new Int32(10), true); - expect(new Int64(10) >= new Int32(9), true); - expect(new Int64(-10) >= new Int64(-11), true); - expect(new Int64(-10) >= new Int64(-10), true); + expect(Int64(10) >= Int64(11), false); + expect(Int64(10) >= Int64(10), true); + expect(Int64(10) >= Int64(9), true); + expect(Int64(10) >= Int32(11), false); + expect(Int64(10) >= Int32(10), true); + expect(Int64(10) >= Int32(9), true); + expect(Int64(-10) >= Int64(-11), true); + expect(Int64(-10) >= Int64(-10), true); expect(largePos >= largeNeg, true); expect(largeNeg >= largePos, false); expect(largePos >= largePosPlusOne, false); @@ -421,15 +420,15 @@ void main() { }); test(">", () { - expect(new Int64(10) > new Int64(11), false); - expect(new Int64(10) > new Int64(10), false); - expect(new Int64(10) > new Int64(9), true); - expect(new Int64(10) > new Int32(11), false); - expect(new Int64(10) > new Int32(10), false); - expect(new Int64(10) > new Int32(9), true); - expect(new Int64(-10) > new Int64(-11), true); - expect(new Int64(10) > new Int64(-11), true); - expect(new Int64(-10) > new Int64(11), false); + expect(Int64(10) > Int64(11), false); + expect(Int64(10) > Int64(10), false); + expect(Int64(10) > Int64(9), true); + expect(Int64(10) > Int32(11), false); + expect(Int64(10) > Int32(10), false); + expect(Int64(10) > Int32(9), true); + expect(Int64(-10) > Int64(-11), true); + expect(Int64(10) > Int64(-11), true); + expect(Int64(-10) > Int64(11), false); expect(largePos > largeNeg, true); expect(largeNeg > largePos, false); expect(largePos > largePosPlusOne, false); @@ -443,174 +442,171 @@ void main() { }); group("bitwise operators", () { - Int64 n1 = new Int64(1234); - Int64 n2 = new Int64(9876); - Int64 n3 = new Int64(-1234); - Int64 n4 = new Int64(0x1234) << 32; - Int64 n5 = new Int64(0x9876) << 32; + Int64 n1 = Int64(1234); + Int64 n2 = Int64(9876); + Int64 n3 = Int64(-1234); + Int64 n4 = Int64(0x1234) << 32; + Int64 n5 = Int64(0x9876) << 32; test("&", () { - expect(n1 & n2, new Int64(1168)); - expect(n3 & n2, new Int64(8708)); - expect(n4 & n5, new Int64(0x1034) << 32); + expect(n1 & n2, Int64(1168)); + expect(n3 & n2, Int64(8708)); + expect(n4 & n5, Int64(0x1034) << 32); expect(() => n1 & null, throwsArgumentError); argumentErrorTest("&", (a, b) => a & b); }); test("|", () { - expect(n1 | n2, new Int64(9942)); - expect(n3 | n2, new Int64(-66)); - expect(n4 | n5, new Int64(0x9a76) << 32); + expect(n1 | n2, Int64(9942)); + expect(n3 | n2, Int64(-66)); + expect(n4 | n5, Int64(0x9a76) << 32); expect(() => n1 | null, throwsArgumentError); argumentErrorTest("|", (a, b) => a | b); }); test("^", () { - expect(n1 ^ n2, new Int64(8774)); - expect(n3 ^ n2, new Int64(-8774)); - expect(n4 ^ n5, new Int64(0x8a42) << 32); + expect(n1 ^ n2, Int64(8774)); + expect(n3 ^ n2, Int64(-8774)); + expect(n4 ^ n5, Int64(0x8a42) << 32); expect(() => n1 ^ null, throwsArgumentError); argumentErrorTest("^", (a, b) => a ^ b); }); test("~", () { - expect(-new Int64(1), new Int64(-1)); - expect(-new Int64(-1), new Int64(1)); + expect(-Int64(1), Int64(-1)); + expect(-Int64(-1), Int64(1)); expect(-Int64.MIN_VALUE, Int64.MIN_VALUE); - expect(~n1, new Int64(-1235)); - expect(~n2, new Int64(-9877)); - expect(~n3, new Int64(1233)); - expect(~n4, new Int64.fromInts(0xffffedcb, 0xffffffff)); - expect(~n5, new Int64.fromInts(0xffff6789, 0xffffffff)); + expect(~n1, Int64(-1235)); + expect(~n2, Int64(-9877)); + expect(~n3, Int64(1233)); + expect(~n4, Int64.fromInts(0xffffedcb, 0xffffffff)); + expect(~n5, Int64.fromInts(0xffff6789, 0xffffffff)); }); }); group("bitshift operators", () { test("<<", () { - expect(new Int64.fromInts(0x12341234, 0x45674567) << 10, - new Int64.fromInts(0xd048d115, 0x9d159c00)); - expect(new Int64.fromInts(0x92341234, 0x45674567) << 10, - new Int64.fromInts(0xd048d115, 0x9d159c00)); - expect(new Int64(-1) << 5, new Int64(-32)); - expect(new Int64(-1) << 0, new Int64(-1)); - expect(new Int64(42) << 64, Int64.ZERO); - expect(new Int64(42) << 65, Int64.ZERO); - expect(() => new Int64(17) << -1, throwsArgumentError); - expect(() => new Int64(17) << null, throwsNoSuchMethodError); + expect(Int64.fromInts(0x12341234, 0x45674567) << 10, + Int64.fromInts(0xd048d115, 0x9d159c00)); + expect(Int64.fromInts(0x92341234, 0x45674567) << 10, + Int64.fromInts(0xd048d115, 0x9d159c00)); + expect(Int64(-1) << 5, Int64(-32)); + expect(Int64(-1) << 0, Int64(-1)); + expect(Int64(42) << 64, Int64.ZERO); + expect(Int64(42) << 65, Int64.ZERO); + expect(() => Int64(17) << -1, throwsArgumentError); + expect(() => Int64(17) << null, throwsNoSuchMethodError); }); test(">>", () { expect((Int64.MIN_VALUE >> 13).toString(), "-1125899906842624"); - expect(new Int64.fromInts(0x12341234, 0x45674567) >> 10, - new Int64.fromInts(0x48d04, 0x8d1159d1)); - expect(new Int64.fromInts(0x92341234, 0x45674567) >> 10, - new Int64.fromInts(0xffe48d04, 0x8d1159d1)); - expect( - new Int64.fromInts(0xFFFFFFF, 0xFFFFFFFF) >> 34, new Int64(67108863)); - expect(new Int64(42) >> 64, Int64.ZERO); - expect(new Int64(42) >> 65, Int64.ZERO); + expect(Int64.fromInts(0x12341234, 0x45674567) >> 10, + Int64.fromInts(0x48d04, 0x8d1159d1)); + expect(Int64.fromInts(0x92341234, 0x45674567) >> 10, + Int64.fromInts(0xffe48d04, 0x8d1159d1)); + expect(Int64.fromInts(0xFFFFFFF, 0xFFFFFFFF) >> 34, Int64(67108863)); + expect(Int64(42) >> 64, Int64.ZERO); + expect(Int64(42) >> 65, Int64.ZERO); for (int n = 0; n <= 66; n++) { - expect(new Int64(-1) >> n, new Int64(-1)); + expect(Int64(-1) >> n, Int64(-1)); } - expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 8, - new Int64.fromInts(0x00723456, 0x789abcde)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 16, - new Int64.fromInts(0x00007234, 0x56789abc)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 24, - new Int64.fromInts(0x00000072, 0x3456789a)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 28, - new Int64.fromInts(0x00000007, 0x23456789)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 32, - new Int64.fromInts(0x00000000, 0x72345678)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 36, - new Int64.fromInts(0x00000000, 0x07234567)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 40, - new Int64.fromInts(0x00000000, 0x00723456)); - expect(new Int64.fromInts(0x72345678, 0x9abcde00) >> 44, - new Int64.fromInts(0x00000000, 0x00072345)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 48, - new Int64.fromInts(0x00000000, 0x00007234)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 8, - new Int64.fromInts(0xff923456, 0x789abcde)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 16, - new Int64.fromInts(0xffff9234, 0x56789abc)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 24, - new Int64.fromInts(0xffffff92, 0x3456789a)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 28, - new Int64.fromInts(0xfffffff9, 0x23456789)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 32, - new Int64.fromInts(0xffffffff, 0x92345678)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 36, - new Int64.fromInts(0xffffffff, 0xf9234567)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 40, - new Int64.fromInts(0xffffffff, 0xff923456)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 44, - new Int64.fromInts(0xffffffff, 0xfff92345)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 48, - new Int64.fromInts(0xffffffff, 0xffff9234)); - expect(() => new Int64(17) >> -1, throwsArgumentError); - expect(() => new Int64(17) >> null, throwsNoSuchMethodError); + expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 8, + Int64.fromInts(0x00723456, 0x789abcde)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 16, + Int64.fromInts(0x00007234, 0x56789abc)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 24, + Int64.fromInts(0x00000072, 0x3456789a)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 28, + Int64.fromInts(0x00000007, 0x23456789)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 32, + Int64.fromInts(0x00000000, 0x72345678)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 36, + Int64.fromInts(0x00000000, 0x07234567)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 40, + Int64.fromInts(0x00000000, 0x00723456)); + expect(Int64.fromInts(0x72345678, 0x9abcde00) >> 44, + Int64.fromInts(0x00000000, 0x00072345)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 48, + Int64.fromInts(0x00000000, 0x00007234)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 8, + Int64.fromInts(0xff923456, 0x789abcde)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 16, + Int64.fromInts(0xffff9234, 0x56789abc)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 24, + Int64.fromInts(0xffffff92, 0x3456789a)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 28, + Int64.fromInts(0xfffffff9, 0x23456789)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 32, + Int64.fromInts(0xffffffff, 0x92345678)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 36, + Int64.fromInts(0xffffffff, 0xf9234567)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 40, + Int64.fromInts(0xffffffff, 0xff923456)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 44, + Int64.fromInts(0xffffffff, 0xfff92345)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 48, + Int64.fromInts(0xffffffff, 0xffff9234)); + expect(() => Int64(17) >> -1, throwsArgumentError); + expect(() => Int64(17) >> null, throwsNoSuchMethodError); }); test("shiftRightUnsigned", () { - expect(new Int64.fromInts(0x12341234, 0x45674567).shiftRightUnsigned(10), - new Int64.fromInts(0x48d04, 0x8d1159d1)); - expect(new Int64.fromInts(0x92341234, 0x45674567).shiftRightUnsigned(10), - new Int64.fromInts(0x248d04, 0x8d1159d1)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(8), - new Int64.fromInts(0x00723456, 0x789abcde)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(16), - new Int64.fromInts(0x00007234, 0x56789abc)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(24), - new Int64.fromInts(0x00000072, 0x3456789a)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(28), - new Int64.fromInts(0x00000007, 0x23456789)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(32), - new Int64.fromInts(0x00000000, 0x72345678)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(36), - new Int64.fromInts(0x00000000, 0x07234567)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(40), - new Int64.fromInts(0x00000000, 0x00723456)); - expect(new Int64.fromInts(0x72345678, 0x9abcde00).shiftRightUnsigned(44), - new Int64.fromInts(0x00000000, 0x00072345)); - expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(48), - new Int64.fromInts(0x00000000, 0x00007234)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(8), - new Int64.fromInts(0x00923456, 0x789abcde)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(16), - new Int64.fromInts(0x00009234, 0x56789abc)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(24), - new Int64.fromInts(0x00000092, 0x3456789a)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(28), - new Int64.fromInts(0x00000009, 0x23456789)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(32), - new Int64.fromInts(0x00000000, 0x92345678)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(36), - new Int64.fromInts(0x00000000, 0x09234567)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(40), - new Int64.fromInts(0x00000000, 0x00923456)); - expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(44), - new Int64.fromInts(0x00000000, 0x00092345)); - expect(new Int64.fromInts(0x00000000, 0x00009234), - new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48)); - expect(new Int64(-1).shiftRightUnsigned(64), Int64.ZERO); - expect(new Int64(1).shiftRightUnsigned(64), Int64.ZERO); - expect(() => new Int64(17).shiftRightUnsigned(-1), throwsArgumentError); - expect(() => new Int64(17).shiftRightUnsigned(null), - throwsNoSuchMethodError); + expect(Int64.fromInts(0x12341234, 0x45674567).shiftRightUnsigned(10), + Int64.fromInts(0x48d04, 0x8d1159d1)); + expect(Int64.fromInts(0x92341234, 0x45674567).shiftRightUnsigned(10), + Int64.fromInts(0x248d04, 0x8d1159d1)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(8), + Int64.fromInts(0x00723456, 0x789abcde)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(16), + Int64.fromInts(0x00007234, 0x56789abc)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(24), + Int64.fromInts(0x00000072, 0x3456789a)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(28), + Int64.fromInts(0x00000007, 0x23456789)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(32), + Int64.fromInts(0x00000000, 0x72345678)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(36), + Int64.fromInts(0x00000000, 0x07234567)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(40), + Int64.fromInts(0x00000000, 0x00723456)); + expect(Int64.fromInts(0x72345678, 0x9abcde00).shiftRightUnsigned(44), + Int64.fromInts(0x00000000, 0x00072345)); + expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(48), + Int64.fromInts(0x00000000, 0x00007234)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(8), + Int64.fromInts(0x00923456, 0x789abcde)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(16), + Int64.fromInts(0x00009234, 0x56789abc)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(24), + Int64.fromInts(0x00000092, 0x3456789a)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(28), + Int64.fromInts(0x00000009, 0x23456789)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(32), + Int64.fromInts(0x00000000, 0x92345678)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(36), + Int64.fromInts(0x00000000, 0x09234567)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(40), + Int64.fromInts(0x00000000, 0x00923456)); + expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(44), + Int64.fromInts(0x00000000, 0x00092345)); + expect(Int64.fromInts(0x00000000, 0x00009234), + Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48)); + expect(Int64(-1).shiftRightUnsigned(64), Int64.ZERO); + expect(Int64(1).shiftRightUnsigned(64), Int64.ZERO); + expect(() => Int64(17).shiftRightUnsigned(-1), throwsArgumentError); + expect(() => Int64(17).shiftRightUnsigned(null), throwsNoSuchMethodError); }); test("overflow", () { - expect((new Int64(1) << 63) >> 1, - -new Int64.fromInts(0x40000000, 0x00000000)); - expect((new Int64(-1) << 32) << 32, new Int64(0)); + expect((Int64(1) << 63) >> 1, -Int64.fromInts(0x40000000, 0x00000000)); + expect((Int64(-1) << 32) << 32, Int64(0)); expect(Int64.MIN_VALUE << 0, Int64.MIN_VALUE); - expect(Int64.MIN_VALUE << 1, new Int64(0)); - expect((-new Int64.fromInts(8, 0)) >> 1, - new Int64.fromInts(0xfffffffc, 0x00000000)); - expect((-new Int64.fromInts(8, 0)).shiftRightUnsigned(1), - new Int64.fromInts(0x7ffffffc, 0x0)); + expect(Int64.MIN_VALUE << 1, Int64(0)); + expect( + (-Int64.fromInts(8, 0)) >> 1, Int64.fromInts(0xfffffffc, 0x00000000)); + expect((-Int64.fromInts(8, 0)).shiftRightUnsigned(1), + Int64.fromInts(0x7ffffffc, 0x0)); }); }); @@ -644,19 +640,17 @@ void main() { expect(() => Int64.ONE.toUnsigned(65), throwsRangeError); }); test("toDouble", () { - expect(new Int64(0).toDouble(), same(0.0)); - expect(new Int64(100).toDouble(), same(100.0)); - expect(new Int64(-100).toDouble(), same(-100.0)); - expect(new Int64(2147483647).toDouble(), same(2147483647.0)); - expect(new Int64(2147483648).toDouble(), same(2147483648.0)); - expect(new Int64(-2147483647).toDouble(), same(-2147483647.0)); - expect(new Int64(-2147483648).toDouble(), same(-2147483648.0)); - expect(new Int64(4503599627370495).toDouble(), same(4503599627370495.0)); - expect(new Int64(4503599627370496).toDouble(), same(4503599627370496.0)); - expect( - new Int64(-4503599627370495).toDouble(), same(-4503599627370495.0)); - expect( - new Int64(-4503599627370496).toDouble(), same(-4503599627370496.0)); + expect(Int64(0).toDouble(), same(0.0)); + expect(Int64(100).toDouble(), same(100.0)); + expect(Int64(-100).toDouble(), same(-100.0)); + expect(Int64(2147483647).toDouble(), same(2147483647.0)); + expect(Int64(2147483648).toDouble(), same(2147483648.0)); + expect(Int64(-2147483647).toDouble(), same(-2147483647.0)); + expect(Int64(-2147483648).toDouble(), same(-2147483648.0)); + expect(Int64(4503599627370495).toDouble(), same(4503599627370495.0)); + expect(Int64(4503599627370496).toDouble(), same(4503599627370496.0)); + expect(Int64(-4503599627370495).toDouble(), same(-4503599627370495.0)); + expect(Int64(-4503599627370496).toDouble(), same(-4503599627370496.0)); expect(Int64.parseInt("-10000000000000000").toDouble().toStringAsFixed(1), "-10000000000000000.0"); expect(Int64.parseInt("-10000000000000001").toDouble().toStringAsFixed(1), @@ -678,40 +672,40 @@ void main() { }); test("toInt", () { - expect(new Int64(0).toInt(), 0); - expect(new Int64(100).toInt(), 100); - expect(new Int64(-100).toInt(), -100); - expect(new Int64(2147483647).toInt(), 2147483647); - expect(new Int64(2147483648).toInt(), 2147483648); - expect(new Int64(-2147483647).toInt(), -2147483647); - expect(new Int64(-2147483648).toInt(), -2147483648); - expect(new Int64(4503599627370495).toInt(), 4503599627370495); - expect(new Int64(4503599627370496).toInt(), 4503599627370496); - expect(new Int64(-4503599627370495).toInt(), -4503599627370495); - expect(new Int64(-4503599627370496).toInt(), -4503599627370496); + expect(Int64(0).toInt(), 0); + expect(Int64(100).toInt(), 100); + expect(Int64(-100).toInt(), -100); + expect(Int64(2147483647).toInt(), 2147483647); + expect(Int64(2147483648).toInt(), 2147483648); + expect(Int64(-2147483647).toInt(), -2147483647); + expect(Int64(-2147483648).toInt(), -2147483648); + expect(Int64(4503599627370495).toInt(), 4503599627370495); + expect(Int64(4503599627370496).toInt(), 4503599627370496); + expect(Int64(-4503599627370495).toInt(), -4503599627370495); + expect(Int64(-4503599627370496).toInt(), -4503599627370496); }); test("toInt32", () { - expect(new Int64(0).toInt32(), new Int32(0)); - expect(new Int64(1).toInt32(), new Int32(1)); - expect(new Int64(-1).toInt32(), new Int32(-1)); - expect(new Int64(2147483647).toInt32(), new Int32(2147483647)); - expect(new Int64(2147483648).toInt32(), new Int32(-2147483648)); - expect(new Int64(2147483649).toInt32(), new Int32(-2147483647)); - expect(new Int64(2147483650).toInt32(), new Int32(-2147483646)); - expect(new Int64(-2147483648).toInt32(), new Int32(-2147483648)); - expect(new Int64(-2147483649).toInt32(), new Int32(2147483647)); - expect(new Int64(-2147483650).toInt32(), new Int32(2147483646)); - expect(new Int64(-2147483651).toInt32(), new Int32(2147483645)); + expect(Int64(0).toInt32(), Int32(0)); + expect(Int64(1).toInt32(), Int32(1)); + expect(Int64(-1).toInt32(), Int32(-1)); + expect(Int64(2147483647).toInt32(), Int32(2147483647)); + expect(Int64(2147483648).toInt32(), Int32(-2147483648)); + expect(Int64(2147483649).toInt32(), Int32(-2147483647)); + expect(Int64(2147483650).toInt32(), Int32(-2147483646)); + expect(Int64(-2147483648).toInt32(), Int32(-2147483648)); + expect(Int64(-2147483649).toInt32(), Int32(2147483647)); + expect(Int64(-2147483650).toInt32(), Int32(2147483646)); + expect(Int64(-2147483651).toInt32(), Int32(2147483645)); }); test("toBytes", () { - expect(new Int64(0).toBytes(), [0, 0, 0, 0, 0, 0, 0, 0]); - expect(new Int64.fromInts(0x08070605, 0x04030201).toBytes(), + expect(Int64(0).toBytes(), [0, 0, 0, 0, 0, 0, 0, 0]); + expect(Int64.fromInts(0x08070605, 0x04030201).toBytes(), [1, 2, 3, 4, 5, 6, 7, 8]); - expect(new Int64.fromInts(0x01020304, 0x05060708).toBytes(), + expect(Int64.fromInts(0x01020304, 0x05060708).toBytes(), [8, 7, 6, 5, 4, 3, 2, 1]); - expect(new Int64(-1).toBytes(), + expect(Int64(-1).toBytes(), [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]); }); }); @@ -719,27 +713,27 @@ void main() { test("JavaScript 53-bit integer boundary", () { Int64 _factorial(Int64 n) { if (n.isZero) { - return new Int64(1); + return Int64(1); } else { - return n * _factorial(n - new Int64(1)); + return n * _factorial(n - Int64(1)); } } - Int64 fact18 = _factorial(new Int64(18)); - Int64 fact17 = _factorial(new Int64(17)); - expect(fact18 ~/ fact17, new Int64(18)); + Int64 fact18 = _factorial(Int64(18)); + Int64 fact17 = _factorial(Int64(17)); + expect(fact18 ~/ fact17, Int64(18)); }); test("min, max values", () { - expect(new Int64(1) << 63, Int64.MIN_VALUE); - expect(-(Int64.MIN_VALUE + new Int64(1)), Int64.MAX_VALUE); + expect(Int64(1) << 63, Int64.MIN_VALUE); + expect(-(Int64.MIN_VALUE + Int64(1)), Int64.MAX_VALUE); }); test("", () { check(int n) { // Sign change should commute with conversion. - expect(-new Int64(-n), new Int64(n)); - expect(new Int64(-n), -new Int64(n)); + expect(-Int64(-n), Int64(n)); + expect(Int64(-n), -Int64(n)); } check(10); @@ -750,7 +744,7 @@ void main() { group("parse", () { test("parseRadix10", () { checkInt(int x) { - expect(Int64.parseRadix('$x', 10), new Int64(x)); + expect(Int64.parseRadix('$x', 10), Int64(x)); } checkInt(0); @@ -773,7 +767,7 @@ void main() { test("parseHex", () { checkHex(String hexStr, int h, int l) { - expect(Int64.parseHex(hexStr), new Int64.fromInts(h, l)); + expect(Int64.parseHex(hexStr), Int64.fromInts(h, l)); } checkHex('0', 0, 0); @@ -821,33 +815,32 @@ void main() { group("string representation", () { test("toString", () { - expect(new Int64(0).toString(), "0"); - expect(new Int64(1).toString(), "1"); - expect(new Int64(-1).toString(), "-1"); - expect(new Int64(-10).toString(), "-10"); + expect(Int64(0).toString(), "0"); + expect(Int64(1).toString(), "1"); + expect(Int64(-1).toString(), "-1"); + expect(Int64(-10).toString(), "-10"); expect(Int64.MIN_VALUE.toString(), "-9223372036854775808"); expect(Int64.MAX_VALUE.toString(), "9223372036854775807"); int top = 922337201; int bottom = 967490662; - Int64 fullnum = - (new Int64(1000000000) * new Int64(top)) + new Int64(bottom); + Int64 fullnum = (Int64(1000000000) * Int64(top)) + Int64(bottom); expect(fullnum.toString(), "922337201967490662"); expect((-fullnum).toString(), "-922337201967490662"); - expect(new Int64(123456789).toString(), "123456789"); + expect(Int64(123456789).toString(), "123456789"); }); test("toHexString", () { - Int64 deadbeef12341234 = new Int64.fromInts(0xDEADBEEF, 0x12341234); + Int64 deadbeef12341234 = Int64.fromInts(0xDEADBEEF, 0x12341234); expect(Int64.ZERO.toHexString(), "0"); expect(deadbeef12341234.toHexString(), "DEADBEEF12341234"); - expect(new Int64.fromInts(0x17678A7, 0xDEF01234).toHexString(), + expect(Int64.fromInts(0x17678A7, 0xDEF01234).toHexString(), "17678A7DEF01234"); - expect(new Int64(123456789).toHexString(), "75BCD15"); + expect(Int64(123456789).toHexString(), "75BCD15"); }); test("toRadixString", () { - expect(new Int64(123456789).toRadixString(5), "223101104124"); + expect(Int64(123456789).toRadixString(5), "223101104124"); expect(Int64.MIN_VALUE.toRadixString(2), "-1000000000000000000000000000000000000000000000000000000000000000"); expect(Int64.MIN_VALUE.toRadixString(3), @@ -884,9 +877,9 @@ void main() { expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); - expect(() => new Int64(42).toRadixString(-1), throwsArgumentError); - expect(() => new Int64(42).toRadixString(0), throwsArgumentError); - expect(() => new Int64(42).toRadixString(37), throwsArgumentError); + expect(() => Int64(42).toRadixString(-1), throwsArgumentError); + expect(() => Int64(42).toRadixString(0), throwsArgumentError); + expect(() => Int64(42).toRadixString(37), throwsArgumentError); }); test("toStringUnsigned", () { diff --git a/pkgs/fixnum/test/int_64_vm_test.dart b/pkgs/fixnum/test/int_64_vm_test.dart index 549d3650..e5e1303a 100644 --- a/pkgs/fixnum/test/int_64_vm_test.dart +++ b/pkgs/fixnum/test/int_64_vm_test.dart @@ -34,8 +34,8 @@ void main() { test("", () { check(int n) { // Sign change should commute with conversion. - expect(-new Int64(-n), new Int64(n)); - expect(new Int64(-n), -new Int64(n)); + expect(-Int64(-n), Int64(n)); + expect(Int64(-n), -Int64(n)); } check(10); From c29132e729f5869f454b7c9c875f1e18826b8214 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 6 Nov 2018 19:07:00 -0800 Subject: [PATCH 062/126] fix some more lints --- pkgs/fixnum/.travis.yml | 5 ++-- pkgs/fixnum/test/int32_test.dart | 24 ++++++++-------- pkgs/fixnum/test/int64_test.dart | 48 ++++++++++++++++---------------- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/pkgs/fixnum/.travis.yml b/pkgs/fixnum/.travis.yml index c22b6306..7a04dbdc 100644 --- a/pkgs/fixnum/.travis.yml +++ b/pkgs/fixnum/.travis.yml @@ -1,13 +1,14 @@ language: dart dart: + - stable - dev dart_task: - test: --platform vm xvfb: false - - test: --platform firefox -j 1 - - dartanalyzer: --fatal-warnings . + - test: --platform chrome + - dartanalyzer: --fatal-warnings --fatal-infos . - dartfmt # Only building master means that we don't run two builds for each pull request. diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index e76a0dc9..52764b68 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -213,18 +213,18 @@ void main() { }); test("==", () { - expect(Int32(17) == Int32(18), false); - expect(Int32(17) == Int32(17), true); - expect(Int32(17) == Int32(16), false); - expect(Int32(17) == Int64(18), false); - expect(Int32(17) == Int64(17), true); - expect(Int32(17) == Int64(16), false); - expect(Int32.MIN_VALUE == Int32.MAX_VALUE, false); - expect(Int32(17) == 18, false); - expect(Int32(17) == 17, true); - expect(Int32(17) == 16, false); - expect(Int32(17) == Object(), false); - expect(Int32(17) == null, false); + expect(Int32(17), isNot(equals(Int32(18)))); + expect(Int32(17), equals(Int32(17))); + expect(Int32(17), isNot(equals(Int32(16)))); + expect(Int32(17), isNot(equals(Int64(18)))); + expect(Int32(17), equals(Int64(17))); + expect(Int32(17), isNot(equals(Int64(16)))); + expect(Int32.MIN_VALUE, isNot(equals(Int32.MAX_VALUE))); + expect(Int32(17), isNot(equals(18))); + expect(Int32(17) == 17, isTrue); + expect(Int32(17), isNot(equals(16))); + expect(Int32(17), isNot(equals(Object()))); + expect(Int32(17), isNot(equals(null))); }); test(">=", () { diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index ac6b6b08..baa2f14f 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -373,31 +373,31 @@ void main() { }); test("==", () { - expect(Int64(0) == Int64(0), true); - expect(Int64(0) == Int64(1), false); - expect(Int64(0) == Int32(0), true); - expect(Int64(0) == Int32(1), false); - expect(Int64(0) == 0, true); - expect(Int64(0) == 1, false); - expect(Int64(10) == Int64(11), false); - expect(Int64(10) == Int64(10), true); - expect(Int64(10) == Int64(9), false); - expect(Int64(10) == Int32(11), false); - expect(Int64(10) == Int32(10), true); - expect(Int64(10) == Int32(9), false); - expect(Int64(10) == 11, false); - expect(Int64(10) == 10, true); - expect(Int64(10) == 9, false); - expect(Int64(-10) == Int64(-10), true); + expect(Int64(0), equals(Int64(0))); + expect(Int64(0), isNot(equals(Int64(1)))); + expect(Int64(0), equals(Int32(0))); + expect(Int64(0), isNot(equals(Int32(1)))); + expect(Int64(0) == 0, isTrue); + expect(Int64(0), isNot(equals(1))); + expect(Int64(10), isNot(equals(Int64(11)))); + expect(Int64(10), equals(Int64(10))); + expect(Int64(10), isNot(equals(Int64(9)))); + expect(Int64(10), isNot(equals(Int32(11)))); + expect(Int64(10), equals(Int32(10))); + expect(Int64(10), isNot(equals(Int32(9)))); + expect(Int64(10), isNot(equals(11))); + expect(Int64(10) == 10, isTrue); + expect(Int64(10), isNot(equals(9))); + expect(Int64(-10), equals(Int64(-10))); expect(Int64(-10) != Int64(-10), false); - expect(Int64(-10) == -10, true); - expect(Int64(-10) == -9, false); - expect(largePos == largePos, true); - expect(largePos == largePosPlusOne, false); - expect(largePosPlusOne == largePos, false); - expect(Int64.MIN_VALUE == Int64.MAX_VALUE, false); - expect(Int64(17) == Object(), false); - expect(Int64(17) == null, false); + expect(Int64(-10) == -10, isTrue); + expect(Int64(-10), isNot(equals(-9))); + expect(largePos, equals(largePos)); + expect(largePos, isNot(equals(largePosPlusOne))); + expect(largePosPlusOne, isNot(equals(largePos))); + expect(Int64.MIN_VALUE, isNot(equals(Int64.MAX_VALUE))); + expect(Int64(17), isNot(equals(Object()))); + expect(Int64(17), isNot(equals(null))); }); test(">=", () { From e6b93deeea5c7571786e0e87f4626dea28a2062b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 6 Nov 2018 19:07:40 -0800 Subject: [PATCH 063/126] fix changelog --- pkgs/fixnum/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 796f6c63..9cfc5092 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.10.9 -* Add `Int64.toStringUnsigned()` method. +* Add `Int64.toStringUnsigned()` and `Int64.toRadixStringUnsigned()` functions. ## 0.10.8 From c21470ade8c22a0989e1aef392e17c94a2d5b40f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 29 Apr 2019 13:01:10 -0700 Subject: [PATCH 064/126] Update lints, test on oldest supported Dart SDK (dart-lang/fixnum#47) --- pkgs/fixnum/.travis.yml | 9 +++++++-- pkgs/fixnum/analysis_options.yaml | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkgs/fixnum/.travis.yml b/pkgs/fixnum/.travis.yml index 7a04dbdc..d1e3ba85 100644 --- a/pkgs/fixnum/.travis.yml +++ b/pkgs/fixnum/.travis.yml @@ -1,7 +1,7 @@ language: dart dart: - - stable + - 2.0.0 - dev dart_task: @@ -9,7 +9,12 @@ dart_task: xvfb: false - test: --platform chrome - dartanalyzer: --fatal-warnings --fatal-infos . - - dartfmt + +matrix: + include: + # Only validate formatting using the dev release + - dart: dev + dart_task: dartfmt # Only building master means that we don't run two builds for each pull request. branches: diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index 8ef67de5..6cd52307 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -38,14 +38,13 @@ linter: - prefer_conditional_assignment - prefer_const_constructors - prefer_final_fields + - prefer_generic_function_type_aliases - prefer_initializing_formals - prefer_interpolation_to_compose_strings #- prefer_single_quotes - prefer_typing_uninitialized_variables - slash_for_doc_comments - test_types_in_equals - - super_goes_last - - test_types_in_equals - throw_in_finally - type_init_formals - unnecessary_brace_in_string_interps From 19af1aa33493c6bb5fdf4ab44640779d23346f89 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 31 Jul 2019 21:16:52 -0700 Subject: [PATCH 065/126] Delete codereview.settings --- pkgs/fixnum/codereview.settings | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 pkgs/fixnum/codereview.settings diff --git a/pkgs/fixnum/codereview.settings b/pkgs/fixnum/codereview.settings deleted file mode 100644 index 25faff74..00000000 --- a/pkgs/fixnum/codereview.settings +++ /dev/null @@ -1,3 +0,0 @@ -CODE_REVIEW_SERVER: http://codereview.chromium.org/ -VIEW_VC: https://github.com/dart-lang/fixnum/commit/ -CC_LIST: reviews@dartlang.org From 6fc8bab9cb1dfa66adadfaebe5d1dbf7f2f1d76e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 20 Aug 2019 10:03:59 -0700 Subject: [PATCH 066/126] Fix outdated pub site URLs --- pkgs/fixnum/README.md | 7 ++----- pkgs/fixnum/lib/fixnum.dart | 4 ---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index 3e6af187..cfb31648 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -1,6 +1,3 @@ -Fixnum -====== - A fixed-width 32- and 64- bit integer library for Dart. [![Build Status](https://travis-ci.org/dart-lang/fixnum.svg?branch=master)](https://travis-ci.org/dart-lang/fixnum) @@ -13,5 +10,5 @@ The integer implementations in this library are designed to work identically whether executed on the Dart VM or compiled to JavaScript. For more information, see the -[fixnum package](http://pub.dartlang.org/packages/fixnum) on -[pub.dartlang.org](http://pub.dartlang.org). +[fixnum package](https://pub.dev/packages/fixnum) on +[pub.dev](https://pub.dev/). diff --git a/pkgs/fixnum/lib/fixnum.dart b/pkgs/fixnum/lib/fixnum.dart index 6d08ba86..72f97421 100644 --- a/pkgs/fixnum/lib/fixnum.dart +++ b/pkgs/fixnum/lib/fixnum.dart @@ -6,10 +6,6 @@ /// /// The integer implementations in this library are designed to work /// identically whether executed on the Dart VM or compiled to JavaScript. -/// -/// For information on installing and importing this library, see the -/// [fixnum package on pub.dartlang.org] -/// (http://pub.dartlang.org/packages/fixnum). library fixnum; part 'src/intx.dart'; From 87cba38a2978a96dbbddfff9b7204c7da5dd60e9 Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Mon, 7 Oct 2019 13:12:33 -0700 Subject: [PATCH 067/126] Fix Int64._parseRadix (dart-lang/fixnum#49) * Fix Int64._parseRadix * Update changelog * Fix lint warning * code review suggestions * code review suggestions --- pkgs/fixnum/CHANGELOG.md | 6 ++++++ pkgs/fixnum/lib/src/int64.dart | 9 ++++++++- pkgs/fixnum/pubspec.yaml | 2 +- pkgs/fixnum/test/int64_test.dart | 6 +++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 9cfc5092..14334c54 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.10.10 + +* Fix `Int64` parsing to throw `FormatException` on an empty string or single + minus sign. Previous incorrect behaviour was to throw a `RangeError` or + silently return zero. + ## 0.10.9 * Add `Int64.toStringUnsigned()` and `Int64.toRadixStringUnsigned()` functions. diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index a1109c03..3453a093 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -59,10 +59,17 @@ class Int64 implements IntX { static Int64 _parseRadix(String s, int radix) { int i = 0; bool negative = false; - if (s[0] == '-') { + if (i < s.length && s[0] == '-') { negative = true; i++; } + + // TODO(https://github.com/dart-lang/sdk/issues/38728). Replace with "if (i + // >= s.length)". + if (!(i < s.length)) { + throw FormatException("No digits in '$s'"); + } + int d0 = 0, d1 = 0, d2 = 0; // low, middle, high components. for (; i < s.length; i++) { int c = s.codeUnitAt(i); diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index db003b83..25e3f70b 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 0.10.9 +version: 0.10.10 description: Library for 32- and 64-bit signed fixed-width integers. author: Dart Team diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index baa2f14f..9c9e7ba2 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -729,7 +729,7 @@ void main() { expect(-(Int64.MIN_VALUE + Int64(1)), Int64.MAX_VALUE); }); - test("", () { + test("negation", () { check(int n) { // Sign change should commute with conversion. expect(-Int64(-n), Int64(n)); @@ -763,6 +763,8 @@ void main() { checkInt(-4294967296); expect(() => Int64.parseRadix('xyzzy', -1), throwsArgumentError); expect(() => Int64.parseRadix('plugh', 10), throwsFormatException); + expect(() => Int64.parseRadix('', 10), throwsFormatException); + expect(() => Int64.parseRadix('-', 10), throwsFormatException); }); test("parseHex", () { @@ -783,6 +785,8 @@ void main() { checkHex('FFFFFFFFFFF', 0xfff, 0xffffffff); checkHex('FFFFFFFFFFFFFFFE', 0xffffffff, 0xfffffffe); checkHex('FFFFFFFFFFFFFFFF', 0xffffffff, 0xffffffff); + expect(() => Int64.parseHex(''), throwsFormatException); + expect(() => Int64.parseHex('-'), throwsFormatException); }); test("parseRadix", () { From 4fb5a00751354f2daff88b401ccc121cb8f1139a Mon Sep 17 00:00:00 2001 From: Keerti Parthasarathy Date: Thu, 10 Oct 2019 08:24:54 -0700 Subject: [PATCH 068/126] Update to pedantic 1.8.0, also no implicit casts (dart-lang/fixnum#50) * Update to pedantic 1.8.0, also no implicit casts * format file * Update min SDK * Add a changelog entry --- pkgs/fixnum/.travis.yml | 2 +- pkgs/fixnum/CHANGELOG.md | 4 ++++ pkgs/fixnum/analysis_options.yaml | 3 +++ pkgs/fixnum/lib/src/int32.dart | 4 ++-- pkgs/fixnum/pubspec.yaml | 6 +++--- pkgs/fixnum/test/int32_test.dart | 10 +++++----- pkgs/fixnum/test/int64_test.dart | 10 +++++----- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pkgs/fixnum/.travis.yml b/pkgs/fixnum/.travis.yml index d1e3ba85..88939f9b 100644 --- a/pkgs/fixnum/.travis.yml +++ b/pkgs/fixnum/.travis.yml @@ -1,7 +1,7 @@ language: dart dart: - - 2.0.0 + - 2.1.1 - dev dart_task: diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 14334c54..7ed6bc6c 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.10.11-dev + +* Update minimum SDK constraint to version 2.1.1. + ## 0.10.10 * Fix `Int64` parsing to throw `FormatException` on an empty string or single diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index 6cd52307..6ddb1078 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -1,4 +1,7 @@ include: package:pedantic/analysis_options.yaml +analyzer: + strong-mode: + implicit-casts: false linter: rules: #- annotate_overrides diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index f3cc72c8..3a9d017b 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -61,7 +61,7 @@ class Int32 implements IntX { if (digit < 0 || digit >= radix) { throw FormatException("Non-radix code unit: $c"); } - x = (x * radix) + digit; + x = ((x * radix) + digit) as Int32; } return x; } @@ -189,7 +189,7 @@ class Int32 implements IntX { Int64 t = this.toInt64(); return (t - (t ~/ other) * other).toInt32(); } - return this - (this ~/ other) * other; + return (this - (this ~/ other) * other) as Int32; } Int32 operator &(other) { diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 25e3f70b..5864bc1c 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,13 +1,13 @@ name: fixnum -version: 0.10.10 +version: 0.10.11-dev description: Library for 32- and 64-bit signed fixed-width integers. author: Dart Team homepage: https://github.com/dart-lang/fixnum environment: - sdk: '>=2.0.0 <3.0.0' + sdk: '>=2.1.1 <3.0.0' dev_dependencies: - pedantic: ^1.3.0 + pedantic: ^1.8.0 test: ^1.2.0 diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 52764b68..b9ba31a6 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -115,15 +115,15 @@ void main() { test("remainder", () { expect(Int32(0x12345678).remainder(Int32(0x22)), - Int32(0x12345678.remainder(0x22))); + Int32(0x12345678.remainder(0x22) as int)); expect(Int32(0x12345678).remainder(Int32(-0x22)), - Int32(0x12345678.remainder(-0x22))); + Int32(0x12345678.remainder(-0x22) as int)); expect(Int32(-0x12345678).remainder(Int32(-0x22)), - Int32(-0x12345678.remainder(-0x22))); + Int32(-0x12345678.remainder(-0x22) as int)); expect(Int32(-0x12345678).remainder(Int32(0x22)), - Int32(-0x12345678.remainder(0x22))); + Int32(-0x12345678.remainder(0x22) as int)); expect(Int32(0x12345678).remainder(Int64(0x22)), - Int32(0x12345678.remainder(0x22))); + Int32(0x12345678.remainder(0x22) as int)); expect(() => Int32(17).remainder(null), throwsArgumentError); }); diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 9c9e7ba2..1acc3a4e 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -264,15 +264,15 @@ void main() { expect(Int64.MAX_VALUE % Int64.fromInts(0x04000000, 0x00000000), Int64.fromInts(0x3ffffff, 0xffffffff)); expect(Int64(0x12345678).remainder(Int64(0x22)), - Int64(0x12345678.remainder(0x22))); + Int64(0x12345678.remainder(0x22) as int)); expect(Int64(0x12345678).remainder(Int64(-0x22)), - Int64(0x12345678.remainder(-0x22))); + Int64(0x12345678.remainder(-0x22) as int)); expect(Int64(-0x12345678).remainder(Int64(-0x22)), - Int64(-0x12345678.remainder(-0x22))); + Int64(-0x12345678.remainder(-0x22) as int)); expect(Int64(-0x12345678).remainder(Int64(0x22)), - Int64(-0x12345678.remainder(0x22))); + Int64(-0x12345678.remainder(0x22) as int)); expect(Int32(0x12345678).remainder(Int64(0x22)), - Int64(0x12345678.remainder(0x22))); + Int64(0x12345678.remainder(0x22) as int)); argumentErrorTest("%", (a, b) => a % b); }); From dba55c7a631ea670802a3c863c07503cb40bcb02 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 28 Oct 2019 16:13:37 -0700 Subject: [PATCH 069/126] Version 0.10.11 --- pkgs/fixnum/CHANGELOG.md | 2 +- pkgs/fixnum/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 7ed6bc6c..3359d0a1 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.10.11-dev +## 0.10.11 * Update minimum SDK constraint to version 2.1.1. diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 5864bc1c..a08ee332 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 0.10.11-dev +version: 0.10.11 description: Library for 32- and 64-bit signed fixed-width integers. author: Dart Team From f315ad22eb6a2a032a1383f672015178f0b8c4f3 Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Tue, 10 Dec 2019 15:53:43 -0800 Subject: [PATCH 070/126] Address pedantic lints (dart-lang/fixnum#52) * Update int64.dart * Update analysis_options.yaml * Update int32.dart * Update int64.dart * Update int32.dart * Update int32.dart * Update intx.dart * Update int32.dart * Update all_tests.dart * Update int32_test.dart * Update pubspec.yaml * Update int_64_vm_test.dart * Update int64_test.dart * Update int64_test.dart * Update int64_test.dart --- pkgs/fixnum/analysis_options.yaml | 4 - pkgs/fixnum/lib/src/int32.dart | 98 +++++++-- pkgs/fixnum/lib/src/int64.dart | 75 ++++++- pkgs/fixnum/lib/src/intx.dart | 4 + pkgs/fixnum/pubspec.yaml | 2 +- pkgs/fixnum/test/all_tests.dart | 2 +- pkgs/fixnum/test/int32_test.dart | 164 +++++++------- pkgs/fixnum/test/int64_test.dart | 305 ++++++++++++++------------- pkgs/fixnum/test/int_64_vm_test.dart | 26 +-- 9 files changed, 397 insertions(+), 283 deletions(-) diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index 6ddb1078..628d93ed 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -4,7 +4,6 @@ analyzer: implicit-casts: false linter: rules: - #- annotate_overrides - avoid_function_literals_in_foreach_calls - avoid_init_to_null - avoid_null_checks_in_equality_operators @@ -30,7 +29,6 @@ linter: - list_remove_unrelated_type - no_adjacent_strings_in_list - non_constant_identifier_names - #- omit_local_variable_types - only_throw_errors - overridden_fields - package_api_docs @@ -44,7 +42,6 @@ linter: - prefer_generic_function_type_aliases - prefer_initializing_formals - prefer_interpolation_to_compose_strings - #- prefer_single_quotes - prefer_typing_uninitialized_variables - slash_for_doc_comments - test_types_in_equals @@ -57,4 +54,3 @@ linter: - unnecessary_new - unnecessary_null_aware_assignments - unnecessary_statements - #- unnecessary_this diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index 3a9d017b..ec31d9d3 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -54,12 +54,12 @@ class Int32 implements IntX { // TODO(rice) - Make this faster by converting several digits at once. static Int32 parseRadix(String s, int radix) { _validateRadix(radix); - Int32 x = ZERO; - for (int i = 0; i < s.length; i++) { - int c = s.codeUnitAt(i); - int digit = _decodeDigit(c); + var x = ZERO; + for (var i = 0; i < s.length; i++) { + var c = s.codeUnitAt(i); + var digit = _decodeDigit(c); if (digit < 0 || digit >= radix) { - throw FormatException("Non-radix code unit: $c"); + throw FormatException('Non-radix code unit: $c'); } x = ((x * radix) + digit) as Int32; } @@ -145,76 +145,88 @@ class Int32 implements IntX { // Int32 % Int32 => Int32 // Int32 % Int64 => Int32 + @override IntX operator +(other) { if (other is Int64) { - return this.toInt64() + other; + return toInt64() + other; } return Int32(_i + _toInt(other)); } + @override IntX operator -(other) { if (other is Int64) { - return this.toInt64() - other; + return toInt64() - other; } return Int32(_i - _toInt(other)); } + @override Int32 operator -() => Int32(-_i); + @override IntX operator *(other) { if (other is Int64) { - return this.toInt64() * other; + return toInt64() * other; } // TODO(rice) - optimize - return (this.toInt64() * other).toInt32(); + return (toInt64() * other).toInt32(); } + @override Int32 operator %(other) { if (other is Int64) { // Result will be Int32 - return (this.toInt64() % other).toInt32(); + return (toInt64() % other).toInt32(); } return Int32(_i % _toInt(other)); } + @override Int32 operator ~/(other) { if (other is Int64) { - return (this.toInt64() ~/ other).toInt32(); + return (toInt64() ~/ other).toInt32(); } return Int32(_i ~/ _toInt(other)); } + @override Int32 remainder(other) { if (other is Int64) { - Int64 t = this.toInt64(); + var t = toInt64(); return (t - (t ~/ other) * other).toInt32(); } return (this - (this ~/ other) * other) as Int32; } + @override Int32 operator &(other) { if (other is Int64) { - return (this.toInt64() & other).toInt32(); + return (toInt64() & other).toInt32(); } return Int32(_i & _toInt(other)); } + @override Int32 operator |(other) { if (other is Int64) { - return (this.toInt64() | other).toInt32(); + return (toInt64() | other).toInt32(); } return Int32(_i | _toInt(other)); } + @override Int32 operator ^(other) { if (other is Int64) { - return (this.toInt64() ^ other).toInt32(); + return (toInt64() ^ other).toInt32(); } return Int32(_i ^ _toInt(other)); } + @override Int32 operator ~() => Int32(~_i); + @override Int32 operator <<(int n) { if (n < 0) { throw ArgumentError(n); @@ -225,6 +237,7 @@ class Int32 implements IntX { return Int32(_i << n); } + @override Int32 operator >>(int n) { if (n < 0) { throw ArgumentError(n); @@ -241,6 +254,7 @@ class Int32 implements IntX { return Int32(value); } + @override Int32 shiftRightUnsigned(int n) { if (n < 0) { throw ArgumentError(n); @@ -259,64 +273,86 @@ class Int32 implements IntX { /// Returns [:true:] if this [Int32] has the same numeric value as the /// given object. The argument may be an [int] or an [IntX]. + @override bool operator ==(other) { if (other is Int32) { return _i == other._i; } else if (other is Int64) { - return this.toInt64() == other; + return toInt64() == other; } else if (other is int) { return _i == other; } return false; } + @override int compareTo(other) { if (other is Int64) { - return this.toInt64().compareTo(other); + return toInt64().compareTo(other); } return _i.compareTo(_toInt(other)); } + @override bool operator <(other) { if (other is Int64) { - return this.toInt64() < other; + return toInt64() < other; } return _i < _toInt(other); } + @override bool operator <=(other) { if (other is Int64) { - return this.toInt64() <= other; + return toInt64() <= other; } return _i <= _toInt(other); } + @override bool operator >(other) { if (other is Int64) { - return this.toInt64() > other; + return toInt64() > other; } return _i > _toInt(other); } + @override bool operator >=(other) { if (other is Int64) { - return this.toInt64() >= other; + return toInt64() >= other; } return _i >= _toInt(other); } + @override bool get isEven => (_i & 0x1) == 0; + + @override bool get isMaxValue => _i == 2147483647; + + @override bool get isMinValue => _i == -2147483648; + + @override bool get isNegative => _i < 0; + + @override bool get isOdd => (_i & 0x1) == 1; + + @override bool get isZero => _i == 0; + + @override int get bitLength => _i.bitLength; + @override int get hashCode => _i; + @override Int32 abs() => _i < 0 ? Int32(-_i) : this; + @override Int32 clamp(lowerLimit, upperLimit) { if (this < lowerLimit) { if (lowerLimit is IntX) return lowerLimit.toInt32(); @@ -330,21 +366,27 @@ class Int32 implements IntX { return this; } + @override int numberOfLeadingZeros() => _numberOfLeadingZeros(_i); + + @override int numberOfTrailingZeros() => _numberOfTrailingZeros(_i); + @override Int32 toSigned(int width) { if (width < 1 || width > 32) throw RangeError.range(width, 1, 32); return Int32(_i.toSigned(width)); } + @override Int32 toUnsigned(int width) { if (width < 0 || width > 32) throw RangeError.range(width, 0, 32); return Int32(_i.toUnsigned(width)); } + @override List toBytes() { - List result = List(4); + var result = List(4); result[0] = _i & 0xff; result[1] = (_i >> 8) & 0xff; result[2] = (_i >> 16) & 0xff; @@ -352,12 +394,24 @@ class Int32 implements IntX { return result; } + @override double toDouble() => _i.toDouble(); + + @override int toInt() => _i; + + @override Int32 toInt32() => this; + + @override Int64 toInt64() => Int64(_i); + @override String toString() => _i.toString(); + + @override String toHexString() => _i.toRadixString(16); + + @override String toRadixString(int radix) => _i.toRadixString(radix); } diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index 3453a093..d6240731 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -2,6 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// Many locals are declared as `int` or `double`. We keep local variable types +// because the types are critical to the efficiency of many operations. +// +// ignore_for_file: omit_local_variable_types + part of fixnum; /// An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1]. @@ -75,7 +80,7 @@ class Int64 implements IntX { int c = s.codeUnitAt(i); int digit = Int32._decodeDigit(c); if (digit < 0 || digit >= radix) { - throw FormatException("Non-radix char code: $c"); + throw FormatException('Non-radix char code: $c'); } // [radix] and [digit] are at most 6 bits, component is 22, so we can @@ -192,6 +197,7 @@ class Int64 implements IntX { throw ArgumentError.value(value); } + @override Int64 operator +(other) { Int64 o = _promote(other); int sum0 = _l + o._l; @@ -200,13 +206,16 @@ class Int64 implements IntX { return Int64._masked(sum0, sum1, sum2); } + @override Int64 operator -(other) { Int64 o = _promote(other); return _sub(_l, _m, _h, o._l, o._m, o._h); } + @override Int64 operator -() => _negate(_l, _m, _h); + @override Int64 operator *(other) { Int64 o = _promote(other); @@ -288,12 +297,16 @@ class Int64 implements IntX { return Int64._masked(c0, c1, c2); } + @override Int64 operator %(other) => _divide(this, other, _RETURN_MOD); + @override Int64 operator ~/(other) => _divide(this, other, _RETURN_DIV); + @override Int64 remainder(other) => _divide(this, other, _RETURN_REM); + @override Int64 operator &(other) { Int64 o = _promote(other); int a0 = _l & o._l; @@ -302,6 +315,7 @@ class Int64 implements IntX { return Int64._masked(a0, a1, a2); } + @override Int64 operator |(other) { Int64 o = _promote(other); int a0 = _l | o._l; @@ -310,6 +324,7 @@ class Int64 implements IntX { return Int64._masked(a0, a1, a2); } + @override Int64 operator ^(other) { Int64 o = _promote(other); int a0 = _l ^ o._l; @@ -318,10 +333,12 @@ class Int64 implements IntX { return Int64._masked(a0, a1, a2); } + @override Int64 operator ~() { return Int64._masked(~_l, ~_m, ~_h); } + @override Int64 operator <<(int n) { if (n < 0) { throw ArgumentError.value(n); @@ -348,6 +365,7 @@ class Int64 implements IntX { return Int64._masked(res0, res1, res2); } + @override Int64 operator >>(int n) { if (n < 0) { throw ArgumentError.value(n); @@ -393,6 +411,7 @@ class Int64 implements IntX { return Int64._masked(res0, res1, res2); } + @override Int64 shiftRightUnsigned(int n) { if (n < 0) { throw ArgumentError.value(n); @@ -422,6 +441,7 @@ class Int64 implements IntX { /// Returns [:true:] if this [Int64] has the same numeric value as the /// given object. The argument may be an [int] or an [IntX]. + @override bool operator ==(other) { Int64 o; if (other is Int64) { @@ -441,6 +461,7 @@ class Int64 implements IntX { return false; } + @override int compareTo(other) => _compareTo(other); int _compareTo(other) { @@ -468,18 +489,37 @@ class Int64 implements IntX { return 0; } + @override bool operator <(other) => _compareTo(other) < 0; + + @override bool operator <=(other) => _compareTo(other) <= 0; - bool operator >(other) => this._compareTo(other) > 0; + + @override + bool operator >(other) => _compareTo(other) > 0; + + @override bool operator >=(other) => _compareTo(other) >= 0; + @override bool get isEven => (_l & 0x1) == 0; + + @override bool get isMaxValue => (_h == _MASK2 >> 1) && _m == _MASK && _l == _MASK; + + @override bool get isMinValue => _h == _SIGN_BIT_MASK && _m == 0 && _l == 0; + + @override bool get isNegative => (_h & _SIGN_BIT_MASK) != 0; + + @override bool get isOdd => (_l & 0x1) == 1; + + @override bool get isZero => _h == 0 && _m == 0 && _l == 0; + @override int get bitLength { if (isZero) return 0; int a0 = _l, a1 = _m, a2 = _h; @@ -494,6 +534,7 @@ class Int64 implements IntX { } /// Returns a hash code based on all the bits of this [Int64]. + @override int get hashCode { // TODO(sra): Should we ensure that hashCode values match corresponding int? // i.e. should `new Int64(x).hashCode == x.hashCode`? @@ -502,10 +543,12 @@ class Int64 implements IntX { return bottom ^ top; } + @override Int64 abs() { - return this.isNegative ? -this : this; + return isNegative ? -this : this; } + @override Int64 clamp(lowerLimit, upperLimit) { Int64 lower = _promote(lowerLimit); Int64 upper = _promote(upperLimit); @@ -516,6 +559,7 @@ class Int64 implements IntX { /// Returns the number of leading zeros in this [Int64] as an [int] /// between 0 and 64. + @override int numberOfLeadingZeros() { int b2 = Int32._numberOfLeadingZeros(_h); if (b2 == 32) { @@ -532,6 +576,7 @@ class Int64 implements IntX { /// Returns the number of trailing zeros in this [Int64] as an [int] /// between 0 and 64. + @override int numberOfTrailingZeros() { int zeros = Int32._numberOfTrailingZeros(_l); if (zeros < 32) { @@ -551,6 +596,7 @@ class Int64 implements IntX { return 64; } + @override Int64 toSigned(int width) { if (width < 1 || width > 64) throw RangeError.range(width, 1, 64); if (width > _BITS01) { @@ -568,6 +614,7 @@ class Int64 implements IntX { } } + @override Int64 toUnsigned(int width) { if (width < 0 || width > 64) throw RangeError.range(width, 0, 64); if (width > _BITS01) { @@ -582,6 +629,7 @@ class Int64 implements IntX { } } + @override List toBytes() { List result = List(8); result[0] = _l & 0xff; @@ -595,8 +643,10 @@ class Int64 implements IntX { return result; } + @override double toDouble() => toInt().toDouble(); + @override int toInt() { int l = _l; int m = _m; @@ -614,24 +664,28 @@ class Int64 implements IntX { } /// Returns an [Int32] containing the low 32 bits of this [Int64]. + @override Int32 toInt32() { return Int32(((_m & 0x3ff) << _BITS) | _l); } /// Returns `this`. + @override Int64 toInt64() => this; /// Returns the value of this [Int64] as a decimal [String]. + @override String toString() => _toRadixString(10); // TODO(rice) - Make this faster by avoiding arithmetic. + @override String toHexString() { - if (isZero) return "0"; + if (isZero) return '0'; Int64 x = this; - String hexStr = ""; + String hexStr = ''; while (!x.isZero) { int digit = x._l & 0xf; - hexStr = "${_hexDigit(digit)}$hexStr"; + hexStr = '${_hexDigit(digit)}$hexStr'; x = x.shiftRightUnsigned(4); } return hexStr; @@ -648,6 +702,7 @@ class Int64 implements IntX { return _toRadixStringUnsigned(Int32._validateRadix(radix), _l, _m, _h, ''); } + @override String toRadixString(int radix) { return _toRadixString(Int32._validateRadix(radix)); } @@ -712,7 +767,7 @@ class Int64 implements IntX { // need only two chunks, but radix values 17-19 and 33-36 generate only 15 // or 16 bits per iteration, so sometimes the third chunk is needed. - String chunk1 = "", chunk2 = "", chunk3 = ""; + String chunk1 = '', chunk2 = '', chunk3 = ''; while (!(d4 == 0 && d3 == 0)) { int q = d4 ~/ fatRadix; @@ -739,7 +794,7 @@ class Int64 implements IntX { r = d0 - q * fatRadix; d0 = q; - assert(chunk3 == ""); + assert(chunk3 == ''); chunk3 = chunk2; chunk2 = chunk1; // Adding [fatRadix] Forces an extra digit which we discard to get a fixed @@ -814,7 +869,7 @@ class Int64 implements IntX { ]; String toDebugString() { - return "Int64[_l=$_l, _m=$_m, _h=$_h]"; + return 'Int64[_l=$_l, _m=$_m, _h=$_h]'; } static Int64 _masked(int a0, int a1, int a2) => @@ -831,7 +886,7 @@ class Int64 implements IntX { return _sub(0, 0, 0, b0, b1, b2); } - String _hexDigit(int digit) => "0123456789ABCDEF"[digit]; + String _hexDigit(int digit) => '0123456789ABCDEF'[digit]; // Work around dart2js bugs with negative arguments to '>>' operator. static int _shiftRight(int x, int n) { diff --git a/pkgs/fixnum/lib/src/intx.dart b/pkgs/fixnum/lib/src/intx.dart index cdc4b05f..e1c13425 100644 --- a/pkgs/fixnum/lib/src/intx.dart +++ b/pkgs/fixnum/lib/src/intx.dart @@ -65,10 +65,12 @@ abstract class IntX implements Comparable { /// bits to the right. High-order bits are filled with zeros. IntX shiftRightUnsigned(int shiftAmount); + @override int compareTo(other); /// Returns `true` if and only if [other] is an int or IntX equal in /// value to this integer. + @override bool operator ==(other); /// Relational less than operator. @@ -103,6 +105,7 @@ abstract class IntX implements Comparable { /// Returns `true` if and only if this integer is zero. bool get isZero; + @override int get hashCode; /// Returns the absolute value of this integer. @@ -179,6 +182,7 @@ abstract class IntX implements Comparable { /// Returns a string representing the value of this integer in decimal /// notation; example: `'13'`. + @override String toString(); /// Returns a string representing the value of this integer in hexadecimal diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index a08ee332..51c87080 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 0.10.11 +version: 0.10.12-dev description: Library for 32- and 64-bit signed fixed-width integers. author: Dart Team diff --git a/pkgs/fixnum/test/all_tests.dart b/pkgs/fixnum/test/all_tests.dart index a93d00b9..eb530b74 100644 --- a/pkgs/fixnum/test/all_tests.dart +++ b/pkgs/fixnum/test/all_tests.dart @@ -1,7 +1,7 @@ import 'int32_test.dart' as int32_test; import 'int64_test.dart' as int64_test; -main() { +void main() { int32_test.main(); int64_test.main(); } diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index b9ba31a6..db961237 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -6,40 +6,40 @@ import 'package:fixnum/fixnum.dart'; import 'package:test/test.dart'; void main() { - group("isX tests", () { - test("isEven", () { + group('isX tests', () { + test('isEven', () { expect((-Int32.ONE).isEven, false); expect(Int32.ZERO.isEven, true); expect(Int32.ONE.isEven, false); expect(Int32.TWO.isEven, true); }); - test("isMaxValue", () { + test('isMaxValue', () { expect(Int32.MIN_VALUE.isMaxValue, false); expect(Int32.ZERO.isMaxValue, false); expect(Int32.MAX_VALUE.isMaxValue, true); }); - test("isMinValue", () { + test('isMinValue', () { expect(Int32.MIN_VALUE.isMinValue, true); expect(Int32.ZERO.isMinValue, false); expect(Int32.MAX_VALUE.isMinValue, false); }); - test("isNegative", () { + test('isNegative', () { expect(Int32.MIN_VALUE.isNegative, true); expect(Int32.ZERO.isNegative, false); expect(Int32.ONE.isNegative, false); }); - test("isOdd", () { + test('isOdd', () { expect((-Int32.ONE).isOdd, true); expect(Int32.ZERO.isOdd, false); expect(Int32.ONE.isOdd, true); expect(Int32.TWO.isOdd, false); }); - test("isZero", () { + test('isZero', () { expect(Int32.MIN_VALUE.isZero, false); expect(Int32.ZERO.isZero, true); expect(Int32.MAX_VALUE.isZero, false); }); - test("bitLength", () { + test('bitLength', () { expect(Int32(-2).bitLength, 1); expect((-Int32.ONE).bitLength, 0); expect(Int32.ZERO.bitLength, 0); @@ -50,13 +50,13 @@ void main() { }); }); - group("arithmetic operators", () { - Int32 n1 = Int32(1234); - Int32 n2 = Int32(9876); - Int32 n3 = Int32(-1234); - Int32 n4 = Int32(-9876); + group('arithmetic operators', () { + var n1 = Int32(1234); + var n2 = Int32(9876); + var n3 = Int32(-1234); + var n4 = Int32(-9876); - test("+", () { + test('+', () { expect(n1 + n2, Int32(11110)); expect(n3 + n2, Int32(8642)); expect(n3 + n4, Int32(-11110)); @@ -65,7 +65,7 @@ void main() { expect(() => Int32(17) + null, throwsArgumentError); }); - test("-", () { + test('-', () { expect(n1 - n2, Int32(-8642)); expect(n3 - n2, Int32(-11110)); expect(n3 - n4, Int32(8642)); @@ -74,12 +74,12 @@ void main() { expect(() => Int32(17) - null, throwsArgumentError); }); - test("unary -", () { + test('unary -', () { expect(-n1, Int32(-1234)); expect(-Int32.ZERO, Int32.ZERO); }); - test("*", () { + test('*', () { expect(n1 * n2, Int32(12186984)); expect(n2 * n3, Int32(-12186984)); expect(n3 * n3, Int32(1522756)); @@ -92,7 +92,7 @@ void main() { expect(() => Int32(17) * null, throwsArgumentError); }); - test("~/", () { + test('~/', () { expect(Int32(829893893) ~/ Int32(1919), Int32(432461)); expect(Int32(0x12345678) ~/ Int32(0x22), Int32(0x12345678 ~/ 0x22)); expect(Int32(829893893) ~/ Int64(1919), Int32(432461)); @@ -107,13 +107,13 @@ void main() { expect(() => Int32(17) ~/ null, throwsArgumentError); }); - test("%", () { + test('%', () { expect(Int32(0x12345678) % Int32(0x22), Int32(0x12345678 % 0x22)); expect(Int32(0x12345678) % Int64(0x22), Int32(0x12345678 % 0x22)); expect(() => Int32(17) % null, throwsArgumentError); }); - test("remainder", () { + test('remainder', () { expect(Int32(0x12345678).remainder(Int32(0x22)), Int32(0x12345678.remainder(0x22) as int)); expect(Int32(0x12345678).remainder(Int32(-0x22)), @@ -127,7 +127,7 @@ void main() { expect(() => Int32(17).remainder(null), throwsArgumentError); }); - test("abs", () { + test('abs', () { // NOTE: Int32.MIN_VALUE.abs() is undefined expect((Int32.MIN_VALUE + 1).abs(), Int32.MAX_VALUE); expect(Int32(-1).abs(), Int32(1)); @@ -136,8 +136,8 @@ void main() { expect(Int32.MAX_VALUE.abs(), Int32.MAX_VALUE); }); - test("clamp", () { - Int32 val = Int32(17); + test('clamp', () { + var val = Int32(17); expect(val.clamp(20, 30), Int32(20)); expect(val.clamp(10, 20), Int32(17)); expect(val.clamp(10, 15), Int32(15)); @@ -160,14 +160,14 @@ void main() { }); }); - group("leading/trailing zeros", () { - test("numberOfLeadingZeros", () { + group('leading/trailing zeros', () { + test('numberOfLeadingZeros', () { expect(Int32(0).numberOfLeadingZeros(), 32); expect(Int32(1).numberOfLeadingZeros(), 31); expect(Int32(0xffff).numberOfLeadingZeros(), 16); expect(Int32(-1).numberOfLeadingZeros(), 0); }); - test("numberOfTrailingZeros", () { + test('numberOfTrailingZeros', () { expect(Int32(0).numberOfTrailingZeros(), 32); expect(Int32(0x80000000).numberOfTrailingZeros(), 31); expect(Int32(1).numberOfTrailingZeros(), 0); @@ -175,8 +175,8 @@ void main() { }); }); - group("comparison operators", () { - test("compareTo", () { + group('comparison operators', () { + test('compareTo', () { expect(Int32(0).compareTo(-1), 1); expect(Int32(0).compareTo(0), 0); expect(Int32(0).compareTo(1), -1); @@ -188,7 +188,7 @@ void main() { expect(Int32(0).compareTo(Int64(1)), -1); }); - test("<", () { + test('<', () { expect(Int32(17) < Int32(18), true); expect(Int32(17) < Int32(17), false); expect(Int32(17) < Int32(16), false); @@ -200,7 +200,7 @@ void main() { expect(() => Int32(17) < null, throwsArgumentError); }); - test("<=", () { + test('<=', () { expect(Int32(17) <= Int32(18), true); expect(Int32(17) <= Int32(17), true); expect(Int32(17) <= Int32(16), false); @@ -212,7 +212,7 @@ void main() { expect(() => Int32(17) <= null, throwsArgumentError); }); - test("==", () { + test('==', () { expect(Int32(17), isNot(equals(Int32(18)))); expect(Int32(17), equals(Int32(17))); expect(Int32(17), isNot(equals(Int32(16)))); @@ -227,7 +227,7 @@ void main() { expect(Int32(17), isNot(equals(null))); }); - test(">=", () { + test('>=', () { expect(Int32(17) >= Int32(18), false); expect(Int32(17) >= Int32(17), true); expect(Int32(17) >= Int32(16), true); @@ -239,7 +239,7 @@ void main() { expect(() => Int32(17) >= null, throwsArgumentError); }); - test(">", () { + test('>', () { expect(Int32(17) > Int32(18), false); expect(Int32(17) > Int32(17), false); expect(Int32(17) > Int32(16), true); @@ -252,8 +252,8 @@ void main() { }); }); - group("bitwise operators", () { - test("&", () { + group('bitwise operators', () { + test('&', () { expect(Int32(0x12345678) & Int32(0x22222222), Int32(0x12345678 & 0x22222222)); expect(Int32(0x12345678) & Int64(0x22222222), @@ -261,7 +261,7 @@ void main() { expect(() => Int32(17) & null, throwsArgumentError); }); - test("|", () { + test('|', () { expect(Int32(0x12345678) | Int32(0x22222222), Int32(0x12345678 | 0x22222222)); expect(Int32(0x12345678) | Int64(0x22222222), @@ -269,7 +269,7 @@ void main() { expect(() => Int32(17) | null, throwsArgumentError); }); - test("^", () { + test('^', () { expect(Int32(0x12345678) ^ Int32(0x22222222), Int32(0x12345678 ^ 0x22222222)); expect(Int32(0x12345678) ^ Int64(0x22222222), @@ -277,14 +277,14 @@ void main() { expect(() => Int32(17) ^ null, throwsArgumentError); }); - test("~", () { + test('~', () { expect(~(Int32(0x12345678)), Int32(~0x12345678)); expect(-(Int32(0x12345678)), Int64(-0x12345678)); }); }); - group("bitshift operators", () { - test("<<", () { + group('bitshift operators', () { + test('<<', () { expect(Int32(0x12345678) << 7, Int32(0x12345678 << 7)); expect(Int32(0x12345678) << 32, Int32.ZERO); expect(Int32(0x12345678) << 33, Int32.ZERO); @@ -292,7 +292,7 @@ void main() { expect(() => Int32(17) << null, throwsNoSuchMethodError); }); - test(">>", () { + test('>>', () { expect(Int32(0x12345678) >> 7, Int32(0x12345678 >> 7)); expect(Int32(0x12345678) >> 32, Int32.ZERO); expect(Int32(0x12345678) >> 33, Int32.ZERO); @@ -302,7 +302,7 @@ void main() { expect(() => Int32(17) >> null, throwsNoSuchMethodError); }); - test("shiftRightUnsigned", () { + test('shiftRightUnsigned', () { expect(Int32(0x12345678).shiftRightUnsigned(7), Int32(0x12345678 >> 7)); expect(Int32(0x12345678).shiftRightUnsigned(32), Int32.ZERO); expect(Int32(0x12345678).shiftRightUnsigned(33), Int32.ZERO); @@ -314,8 +314,8 @@ void main() { }); }); - group("conversions", () { - test("toSigned", () { + group('conversions', () { + test('toSigned', () { expect(Int32.ONE.toSigned(2), Int32.ONE); expect(Int32.ONE.toSigned(1), -Int32.ONE); expect(Int32.MAX_VALUE.toSigned(32), Int32.MAX_VALUE); @@ -325,7 +325,7 @@ void main() { expect(() => Int32.ONE.toSigned(0), throwsRangeError); expect(() => Int32.ONE.toSigned(33), throwsRangeError); }); - test("toUnsigned", () { + test('toUnsigned', () { expect(Int32.ONE.toUnsigned(1), Int32.ONE); expect(Int32.ONE.toUnsigned(0), Int32.ZERO); expect(Int32.MAX_VALUE.toUnsigned(32), Int32.MAX_VALUE); @@ -335,23 +335,23 @@ void main() { expect(() => Int32.ONE.toUnsigned(-1), throwsRangeError); expect(() => Int32.ONE.toUnsigned(33), throwsRangeError); }); - test("toDouble", () { + test('toDouble', () { expect(Int32(17).toDouble(), same(17.0)); expect(Int32(-17).toDouble(), same(-17.0)); }); - test("toInt", () { + test('toInt', () { expect(Int32(17).toInt(), 17); expect(Int32(-17).toInt(), -17); }); - test("toInt32", () { + test('toInt32', () { expect(Int32(17).toInt32(), Int32(17)); expect(Int32(-17).toInt32(), Int32(-17)); }); - test("toInt64", () { + test('toInt64', () { expect(Int32(17).toInt64(), Int64(17)); expect(Int32(-17).toInt64(), Int64(-17)); }); - test("toBytes", () { + test('toBytes', () { expect(Int32(0).toBytes(), [0, 0, 0, 0]); expect(Int32(0x01020304).toBytes(), [4, 3, 2, 1]); expect(Int32(0x04030201).toBytes(), [1, 2, 3, 4]); @@ -359,9 +359,9 @@ void main() { }); }); - group("parse", () { - test("base 10", () { - checkInt(int x) { + group('parse', () { + test('base 10', () { + void checkInt(int x) { expect(Int32.parseRadix('$x', 10), Int32(x)); } @@ -377,8 +377,8 @@ void main() { expect(() => Int32.parseRadix('plugh', 10), throwsFormatException); }); - test("parseRadix", () { - check(String s, int r, String x) { + test('parseRadix', () { + void check(String s, int r, String x) { expect(Int32.parseRadix(s, r).toString(), x); } @@ -386,50 +386,50 @@ void main() { check('95', 12, '113'); }); - test("parseInt", () { + test('parseInt', () { expect(Int32.parseInt('0'), Int32(0)); expect(Int32.parseInt('1000'), Int32(1000)); expect(Int32.parseInt('4294967296'), Int32(4294967296)); }); - test("parseHex", () { + test('parseHex', () { expect(Int32.parseHex('deadbeef'), Int32(0xdeadbeef)); expect(Int32.parseHex('cafebabe'), Int32(0xcafebabe)); expect(Int32.parseHex('8badf00d'), Int32(0x8badf00d)); }); }); - group("string representation", () { - test("toString", () { - expect(Int32(0).toString(), "0"); - expect(Int32(1).toString(), "1"); - expect(Int32(-1).toString(), "-1"); - expect(Int32(1000).toString(), "1000"); - expect(Int32(-1000).toString(), "-1000"); - expect(Int32(123456789).toString(), "123456789"); - expect(Int32(2147483647).toString(), "2147483647"); - expect(Int32(2147483648).toString(), "-2147483648"); - expect(Int32(2147483649).toString(), "-2147483647"); - expect(Int32(2147483650).toString(), "-2147483646"); - expect(Int32(-2147483648).toString(), "-2147483648"); - expect(Int32(-2147483649).toString(), "2147483647"); - expect(Int32(-2147483650).toString(), "2147483646"); + group('string representation', () { + test('toString', () { + expect(Int32(0).toString(), '0'); + expect(Int32(1).toString(), '1'); + expect(Int32(-1).toString(), '-1'); + expect(Int32(1000).toString(), '1000'); + expect(Int32(-1000).toString(), '-1000'); + expect(Int32(123456789).toString(), '123456789'); + expect(Int32(2147483647).toString(), '2147483647'); + expect(Int32(2147483648).toString(), '-2147483648'); + expect(Int32(2147483649).toString(), '-2147483647'); + expect(Int32(2147483650).toString(), '-2147483646'); + expect(Int32(-2147483648).toString(), '-2147483648'); + expect(Int32(-2147483649).toString(), '2147483647'); + expect(Int32(-2147483650).toString(), '2147483646'); }); }); - group("toHexString", () { - test("returns hexadecimal string representation", () { - expect(Int32(-1).toHexString(), "-1"); - expect((Int32(-1) >> 8).toHexString(), "-1"); - expect((Int32(-1) << 8).toHexString(), "-100"); - expect(Int32(123456789).toHexString(), "75bcd15"); - expect(Int32(-1).shiftRightUnsigned(8).toHexString(), "ffffff"); + group('toHexString', () { + test('returns hexadecimal string representation', () { + expect(Int32(-1).toHexString(), '-1'); + expect((Int32(-1) >> 8).toHexString(), '-1'); + expect((Int32(-1) << 8).toHexString(), '-100'); + expect(Int32(123456789).toHexString(), '75bcd15'); + expect(Int32(-1).shiftRightUnsigned(8).toHexString(), 'ffffff'); }); }); - group("toRadixString", () { - test("returns base n string representation", () { - expect(Int32(123456789).toRadixString(5), "223101104124"); + group('toRadixString', () { + test('returns base n string representation', () { + expect(Int32(123456789).toRadixString(5), '223101104124'); }); }); } diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 1acc3a4e..7994a8dd 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -2,15 +2,20 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// We permit local variable types in this test because they statically 'assert' +// that the operations have an expected type. +// +// ignore_for_file: omit_local_variable_types + library int64test; import 'package:fixnum/fixnum.dart'; import 'package:test/test.dart'; void main() { - group("fromBytes", () { - test("fromBytes", () { - checkBytes(List bytes, int h, int l) { + group('fromBytes', () { + test('fromBytes', () { + void checkBytes(List bytes, int h, int l) { expect(Int64.fromBytes(bytes), Int64.fromInts(h, l)); } @@ -22,8 +27,8 @@ void main() { checkBytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], 0xffffffff, 0xffffffff); }); - test("fromBytesBigEndian", () { - checkBytes(List bytes, int h, int l) { + test('fromBytesBigEndian', () { + void checkBytes(List bytes, int h, int l) { expect(Int64.fromBytesBigEndian(bytes), Int64.fromInts(h, l)); } @@ -37,48 +42,48 @@ void main() { }); }); - argumentErrorTest(name, op, [receiver = Int64.ONE]) { - throwsArgumentErrorMentioning(String substring) => + void argumentErrorTest(name, op, [receiver = Int64.ONE]) { + Matcher throwsArgumentErrorMentioning(String substring) => throwsA((e) => e is ArgumentError && '$e'.contains(substring)); expect(() => op(receiver, null), throwsArgumentErrorMentioning('null')); expect(() => op(receiver, 'foo'), throwsArgumentErrorMentioning(r'"foo"')); } - group("is-tests", () { - test("isEven", () { + group('is-tests', () { + test('isEven', () { expect((-Int64.ONE).isEven, false); expect(Int64.ZERO.isEven, true); expect(Int64.ONE.isEven, false); expect(Int64.TWO.isEven, true); }); - test("isMaxValue", () { + test('isMaxValue', () { expect(Int64.MIN_VALUE.isMaxValue, false); expect(Int64.ZERO.isMaxValue, false); expect(Int64.MAX_VALUE.isMaxValue, true); }); - test("isMinValue", () { + test('isMinValue', () { expect(Int64.MIN_VALUE.isMinValue, true); expect(Int64.ZERO.isMinValue, false); expect(Int64.MAX_VALUE.isMinValue, false); }); - test("isNegative", () { + test('isNegative', () { expect(Int64.MIN_VALUE.isNegative, true); expect(Int64.ZERO.isNegative, false); expect(Int64.ONE.isNegative, false); }); - test("isOdd", () { + test('isOdd', () { expect((-Int64.ONE).isOdd, true); expect(Int64.ZERO.isOdd, false); expect(Int64.ONE.isOdd, true); expect(Int64.TWO.isOdd, false); }); - test("isZero", () { + test('isZero', () { expect(Int64.MIN_VALUE.isZero, false); expect(Int64.ZERO.isZero, true); expect(Int64.MAX_VALUE.isZero, false); }); - test("bitLength", () { + test('bitLength', () { expect(Int64(-2).bitLength, 1); expect((-Int64.ONE).bitLength, 0); expect(Int64.ZERO.bitLength, 0); @@ -92,7 +97,7 @@ void main() { }); }); - group("arithmetic operators", () { + group('arithmetic operators', () { Int64 n1 = Int64(1234); Int64 n2 = Int64(9876); Int64 n3 = Int64(-1234); @@ -100,30 +105,30 @@ void main() { Int64 n5 = Int64.fromInts(0x12345678, 0xabcdabcd); Int64 n6 = Int64.fromInts(0x77773333, 0x22224444); - test("+", () { + test('+', () { expect(n1 + n2, Int64(11110)); expect(n3 + n2, Int64(8642)); expect(n3 + n4, Int64(-11110)); expect(n5 + n6, Int64.fromInts(0x89ab89ab, 0xcdeff011)); expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE); - argumentErrorTest("+", (a, b) => a + b); + argumentErrorTest('+', (a, b) => a + b); }); - test("-", () { + test('-', () { expect(n1 - n2, Int64(-8642)); expect(n3 - n2, Int64(-11110)); expect(n3 - n4, Int64(8642)); expect(n5 - n6, Int64.fromInts(0x9abd2345, 0x89ab6789)); expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE); - argumentErrorTest("-", (a, b) => a - b); + argumentErrorTest('-', (a, b) => a - b); }); - test("unary -", () { + test('unary -', () { expect(-n1, Int64(-1234)); expect(-Int64.ZERO, Int64.ZERO); }); - test("*", () { + test('*', () { expect(Int64(1111) * Int64(3), Int64(3333)); expect(Int64(1111) * Int64(-3), Int64(-3333)); expect(Int64(-1111) * Int64(3), Int64(-3333)); @@ -156,10 +161,10 @@ void main() { expect(Int64.MIN_VALUE * Int64(2), Int64.ZERO); expect(Int64.MIN_VALUE * Int64(1), Int64.MIN_VALUE); expect(Int64.MIN_VALUE * Int64(-1), Int64.MIN_VALUE); - argumentErrorTest("*", (a, b) => a * b); + argumentErrorTest('*', (a, b) => a * b); }); - test("~/", () { + test('~/', () { Int64 deadBeef = Int64.fromInts(0xDEADBEEF, 0xDEADBEEF); Int64 ten = Int64(10); @@ -233,10 +238,10 @@ void main() { expect(Int64.MIN_VALUE ~/ Int64(-1), Int64.MIN_VALUE); expect(() => Int64(17) ~/ Int64.ZERO, throwsA(const TypeMatcher())); - argumentErrorTest("~/", (a, b) => a ~/ b); + argumentErrorTest('~/', (a, b) => a ~/ b); }); - test("%", () { + test('%', () { // Define % as Euclidean mod, with positive result for all arguments expect(Int64.ZERO % Int64(1000), Int64.ZERO); expect(Int64.MIN_VALUE % Int64.MIN_VALUE, Int64.ZERO); @@ -273,10 +278,10 @@ void main() { Int64(-0x12345678.remainder(0x22) as int)); expect(Int32(0x12345678).remainder(Int64(0x22)), Int64(0x12345678.remainder(0x22) as int)); - argumentErrorTest("%", (a, b) => a % b); + argumentErrorTest('%', (a, b) => a % b); }); - test("clamp", () { + test('clamp', () { Int64 val = Int64(17); expect(val.clamp(20, 30), Int64(20)); expect(val.clamp(10, 20), Int64(17)); @@ -297,9 +302,9 @@ void main() { }); }); - group("leading/trailing zeros", () { - test("numberOfLeadingZeros", () { - checkZeros(Int64 value, int zeros) { + group('leading/trailing zeros', () { + test('numberOfLeadingZeros', () { + void checkZeros(Int64 value, int zeros) { expect(value.numberOfLeadingZeros(), zeros); } @@ -313,8 +318,8 @@ void main() { checkZeros(Int64(-1), 0); }); - test("numberOfTrailingZeros", () { - checkZeros(Int64 value, int zeros) { + test('numberOfTrailingZeros', () { + void checkZeros(Int64 value, int zeros) { expect(value.numberOfTrailingZeros(), zeros); } @@ -330,12 +335,12 @@ void main() { }); }); - group("comparison operators", () { + group('comparison operators', () { Int64 largeNeg = Int64.fromInts(0x82341234, 0x0); Int64 largePos = Int64.fromInts(0x12341234, 0x0); Int64 largePosPlusOne = largePos + Int64(1); - test("<", () { + test('<', () { expect(Int64(10) < Int64(11), true); expect(Int64(10) < Int64(10), false); expect(Int64(10) < Int64(9), false); @@ -350,10 +355,10 @@ void main() { expect(largePosPlusOne < largePos, false); expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true); expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false); - argumentErrorTest("<", (a, b) => a < b); + argumentErrorTest('<', (a, b) => a < b); }); - test("<=", () { + test('<=', () { expect(Int64(10) <= Int64(11), true); expect(Int64(10) <= Int64(10), true); expect(Int64(10) <= Int64(9), false); @@ -369,10 +374,10 @@ void main() { expect(largePosPlusOne <= largePos, false); expect(Int64.MIN_VALUE <= Int64.MAX_VALUE, true); expect(Int64.MAX_VALUE <= Int64.MIN_VALUE, false); - argumentErrorTest("<=", (a, b) => a <= b); + argumentErrorTest('<=', (a, b) => a <= b); }); - test("==", () { + test('==', () { expect(Int64(0), equals(Int64(0))); expect(Int64(0), isNot(equals(Int64(1)))); expect(Int64(0), equals(Int32(0))); @@ -400,7 +405,7 @@ void main() { expect(Int64(17), isNot(equals(null))); }); - test(">=", () { + test('>=', () { expect(Int64(10) >= Int64(11), false); expect(Int64(10) >= Int64(10), true); expect(Int64(10) >= Int64(9), true); @@ -416,10 +421,10 @@ void main() { expect(largePosPlusOne >= largePos, true); expect(Int64.MIN_VALUE >= Int64.MAX_VALUE, false); expect(Int64.MAX_VALUE >= Int64.MIN_VALUE, true); - argumentErrorTest(">=", (a, b) => a >= b); + argumentErrorTest('>=', (a, b) => a >= b); }); - test(">", () { + test('>', () { expect(Int64(10) > Int64(11), false); expect(Int64(10) > Int64(10), false); expect(Int64(10) > Int64(9), true); @@ -437,42 +442,42 @@ void main() { expect(Int64.ZERO > Int64.MIN_VALUE, true); expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false); expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true); - argumentErrorTest(">", (a, b) => a > b); + argumentErrorTest('>', (a, b) => a > b); }); }); - group("bitwise operators", () { + group('bitwise operators', () { Int64 n1 = Int64(1234); Int64 n2 = Int64(9876); Int64 n3 = Int64(-1234); Int64 n4 = Int64(0x1234) << 32; Int64 n5 = Int64(0x9876) << 32; - test("&", () { + test('&', () { expect(n1 & n2, Int64(1168)); expect(n3 & n2, Int64(8708)); expect(n4 & n5, Int64(0x1034) << 32); expect(() => n1 & null, throwsArgumentError); - argumentErrorTest("&", (a, b) => a & b); + argumentErrorTest('&', (a, b) => a & b); }); - test("|", () { + test('|', () { expect(n1 | n2, Int64(9942)); expect(n3 | n2, Int64(-66)); expect(n4 | n5, Int64(0x9a76) << 32); expect(() => n1 | null, throwsArgumentError); - argumentErrorTest("|", (a, b) => a | b); + argumentErrorTest('|', (a, b) => a | b); }); - test("^", () { + test('^', () { expect(n1 ^ n2, Int64(8774)); expect(n3 ^ n2, Int64(-8774)); expect(n4 ^ n5, Int64(0x8a42) << 32); expect(() => n1 ^ null, throwsArgumentError); - argumentErrorTest("^", (a, b) => a ^ b); + argumentErrorTest('^', (a, b) => a ^ b); }); - test("~", () { + test('~', () { expect(-Int64(1), Int64(-1)); expect(-Int64(-1), Int64(1)); expect(-Int64.MIN_VALUE, Int64.MIN_VALUE); @@ -485,8 +490,8 @@ void main() { }); }); - group("bitshift operators", () { - test("<<", () { + group('bitshift operators', () { + test('<<', () { expect(Int64.fromInts(0x12341234, 0x45674567) << 10, Int64.fromInts(0xd048d115, 0x9d159c00)); expect(Int64.fromInts(0x92341234, 0x45674567) << 10, @@ -499,8 +504,8 @@ void main() { expect(() => Int64(17) << null, throwsNoSuchMethodError); }); - test(">>", () { - expect((Int64.MIN_VALUE >> 13).toString(), "-1125899906842624"); + test('>>', () { + expect((Int64.MIN_VALUE >> 13).toString(), '-1125899906842624'); expect(Int64.fromInts(0x12341234, 0x45674567) >> 10, Int64.fromInts(0x48d04, 0x8d1159d1)); expect(Int64.fromInts(0x92341234, 0x45674567) >> 10, @@ -551,7 +556,7 @@ void main() { expect(() => Int64(17) >> null, throwsNoSuchMethodError); }); - test("shiftRightUnsigned", () { + test('shiftRightUnsigned', () { expect(Int64.fromInts(0x12341234, 0x45674567).shiftRightUnsigned(10), Int64.fromInts(0x48d04, 0x8d1159d1)); expect(Int64.fromInts(0x92341234, 0x45674567).shiftRightUnsigned(10), @@ -598,7 +603,7 @@ void main() { expect(() => Int64(17).shiftRightUnsigned(null), throwsNoSuchMethodError); }); - test("overflow", () { + test('overflow', () { expect((Int64(1) << 63) >> 1, -Int64.fromInts(0x40000000, 0x00000000)); expect((Int64(-1) << 32) << 32, Int64(0)); expect(Int64.MIN_VALUE << 0, Int64.MIN_VALUE); @@ -610,8 +615,8 @@ void main() { }); }); - group("conversions", () { - test("toSigned", () { + group('conversions', () { + test('toSigned', () { expect((Int64.ONE << 44).toSigned(46), Int64.ONE << 44); expect((Int64.ONE << 44).toSigned(45), -(Int64.ONE << 44)); expect((Int64.ONE << 22).toSigned(24), Int64.ONE << 22); @@ -625,7 +630,7 @@ void main() { expect(() => Int64.ONE.toSigned(0), throwsRangeError); expect(() => Int64.ONE.toSigned(65), throwsRangeError); }); - test("toUnsigned", () { + test('toUnsigned', () { expect((Int64.ONE << 44).toUnsigned(45), Int64.ONE << 44); expect((Int64.ONE << 44).toUnsigned(44), Int64.ZERO); expect((Int64.ONE << 22).toUnsigned(23), Int64.ONE << 22); @@ -639,7 +644,7 @@ void main() { expect(() => Int64.ONE.toUnsigned(-1), throwsRangeError); expect(() => Int64.ONE.toUnsigned(65), throwsRangeError); }); - test("toDouble", () { + test('toDouble', () { expect(Int64(0).toDouble(), same(0.0)); expect(Int64(100).toDouble(), same(100.0)); expect(Int64(-100).toDouble(), same(-100.0)); @@ -651,27 +656,27 @@ void main() { expect(Int64(4503599627370496).toDouble(), same(4503599627370496.0)); expect(Int64(-4503599627370495).toDouble(), same(-4503599627370495.0)); expect(Int64(-4503599627370496).toDouble(), same(-4503599627370496.0)); - expect(Int64.parseInt("-10000000000000000").toDouble().toStringAsFixed(1), - "-10000000000000000.0"); - expect(Int64.parseInt("-10000000000000001").toDouble().toStringAsFixed(1), - "-10000000000000000.0"); - expect(Int64.parseInt("-10000000000000002").toDouble().toStringAsFixed(1), - "-10000000000000002.0"); - expect(Int64.parseInt("-10000000000000003").toDouble().toStringAsFixed(1), - "-10000000000000004.0"); - expect(Int64.parseInt("-10000000000000004").toDouble().toStringAsFixed(1), - "-10000000000000004.0"); - expect(Int64.parseInt("-10000000000000005").toDouble().toStringAsFixed(1), - "-10000000000000004.0"); - expect(Int64.parseInt("-10000000000000006").toDouble().toStringAsFixed(1), - "-10000000000000006.0"); - expect(Int64.parseInt("-10000000000000007").toDouble().toStringAsFixed(1), - "-10000000000000008.0"); - expect(Int64.parseInt("-10000000000000008").toDouble().toStringAsFixed(1), - "-10000000000000008.0"); - }); - - test("toInt", () { + expect(Int64.parseInt('-10000000000000000').toDouble().toStringAsFixed(1), + '-10000000000000000.0'); + expect(Int64.parseInt('-10000000000000001').toDouble().toStringAsFixed(1), + '-10000000000000000.0'); + expect(Int64.parseInt('-10000000000000002').toDouble().toStringAsFixed(1), + '-10000000000000002.0'); + expect(Int64.parseInt('-10000000000000003').toDouble().toStringAsFixed(1), + '-10000000000000004.0'); + expect(Int64.parseInt('-10000000000000004').toDouble().toStringAsFixed(1), + '-10000000000000004.0'); + expect(Int64.parseInt('-10000000000000005').toDouble().toStringAsFixed(1), + '-10000000000000004.0'); + expect(Int64.parseInt('-10000000000000006').toDouble().toStringAsFixed(1), + '-10000000000000006.0'); + expect(Int64.parseInt('-10000000000000007').toDouble().toStringAsFixed(1), + '-10000000000000008.0'); + expect(Int64.parseInt('-10000000000000008').toDouble().toStringAsFixed(1), + '-10000000000000008.0'); + }); + + test('toInt', () { expect(Int64(0).toInt(), 0); expect(Int64(100).toInt(), 100); expect(Int64(-100).toInt(), -100); @@ -685,7 +690,7 @@ void main() { expect(Int64(-4503599627370496).toInt(), -4503599627370496); }); - test("toInt32", () { + test('toInt32', () { expect(Int64(0).toInt32(), Int32(0)); expect(Int64(1).toInt32(), Int32(1)); expect(Int64(-1).toInt32(), Int32(-1)); @@ -699,7 +704,7 @@ void main() { expect(Int64(-2147483651).toInt32(), Int32(2147483645)); }); - test("toBytes", () { + test('toBytes', () { expect(Int64(0).toBytes(), [0, 0, 0, 0, 0, 0, 0, 0]); expect(Int64.fromInts(0x08070605, 0x04030201).toBytes(), [1, 2, 3, 4, 5, 6, 7, 8]); @@ -710,7 +715,7 @@ void main() { }); }); - test("JavaScript 53-bit integer boundary", () { + test('JavaScript 53-bit integer boundary', () { Int64 _factorial(Int64 n) { if (n.isZero) { return Int64(1); @@ -724,13 +729,13 @@ void main() { expect(fact18 ~/ fact17, Int64(18)); }); - test("min, max values", () { + test('min, max values', () { expect(Int64(1) << 63, Int64.MIN_VALUE); expect(-(Int64.MIN_VALUE + Int64(1)), Int64.MAX_VALUE); }); - test("negation", () { - check(int n) { + test('negation', () { + void check(int n) { // Sign change should commute with conversion. expect(-Int64(-n), Int64(n)); expect(Int64(-n), -Int64(n)); @@ -741,9 +746,9 @@ void main() { check(9223372000000000000); // near Int64.MAX_VALUE, has exact double value }); - group("parse", () { - test("parseRadix10", () { - checkInt(int x) { + group('parse', () { + test('parseRadix10', () { + void checkInt(int x) { expect(Int64.parseRadix('$x', 10), Int64(x)); } @@ -767,8 +772,8 @@ void main() { expect(() => Int64.parseRadix('-', 10), throwsFormatException); }); - test("parseHex", () { - checkHex(String hexStr, int h, int l) { + test('parseHex', () { + void checkHex(String hexStr, int h, int l) { expect(Int64.parseHex(hexStr), Int64.fromInts(h, l)); } @@ -789,18 +794,18 @@ void main() { expect(() => Int64.parseHex('-'), throwsFormatException); }); - test("parseRadix", () { - check(String s, int r, String x) { + test('parseRadix', () { + void check(String s, int r, String x) { expect(Int64.parseRadix(s, r).toString(), x); } check('ghoul', 36, '27699213'); check('ghoul', 35, '24769346'); // Min and max value. - check("-9223372036854775808", 10, "-9223372036854775808"); - check("9223372036854775807", 10, "9223372036854775807"); + check('-9223372036854775808', 10, '-9223372036854775808'); + check('9223372036854775807', 10, '9223372036854775807'); // Overflow during parsing. - check("9223372036854775808", 10, "-9223372036854775808"); + check('9223372036854775808', 10, '-9223372036854775808'); expect(() => Int64.parseRadix('0', 1), throwsRangeError); expect(() => Int64.parseRadix('0', 37), throwsRangeError); @@ -808,85 +813,85 @@ void main() { expect(() => Int64.parseRadix('xyzzy', 10), throwsFormatException); }); - test("parseRadixN", () { - check(String s, int r) { + test('parseRadixN', () { + void check(String s, int r) { expect(Int64.parseRadix(s, r).toRadixString(r), s); } - check("2ppp111222333", 33); // This value & radix requires three chunks. + check('2ppp111222333', 33); // This value & radix requires three chunks. }); }); - group("string representation", () { - test("toString", () { - expect(Int64(0).toString(), "0"); - expect(Int64(1).toString(), "1"); - expect(Int64(-1).toString(), "-1"); - expect(Int64(-10).toString(), "-10"); - expect(Int64.MIN_VALUE.toString(), "-9223372036854775808"); - expect(Int64.MAX_VALUE.toString(), "9223372036854775807"); + group('string representation', () { + test('toString', () { + expect(Int64(0).toString(), '0'); + expect(Int64(1).toString(), '1'); + expect(Int64(-1).toString(), '-1'); + expect(Int64(-10).toString(), '-10'); + expect(Int64.MIN_VALUE.toString(), '-9223372036854775808'); + expect(Int64.MAX_VALUE.toString(), '9223372036854775807'); int top = 922337201; int bottom = 967490662; Int64 fullnum = (Int64(1000000000) * Int64(top)) + Int64(bottom); - expect(fullnum.toString(), "922337201967490662"); - expect((-fullnum).toString(), "-922337201967490662"); - expect(Int64(123456789).toString(), "123456789"); + expect(fullnum.toString(), '922337201967490662'); + expect((-fullnum).toString(), '-922337201967490662'); + expect(Int64(123456789).toString(), '123456789'); }); - test("toHexString", () { + test('toHexString', () { Int64 deadbeef12341234 = Int64.fromInts(0xDEADBEEF, 0x12341234); - expect(Int64.ZERO.toHexString(), "0"); - expect(deadbeef12341234.toHexString(), "DEADBEEF12341234"); + expect(Int64.ZERO.toHexString(), '0'); + expect(deadbeef12341234.toHexString(), 'DEADBEEF12341234'); expect(Int64.fromInts(0x17678A7, 0xDEF01234).toHexString(), - "17678A7DEF01234"); - expect(Int64(123456789).toHexString(), "75BCD15"); + '17678A7DEF01234'); + expect(Int64(123456789).toHexString(), '75BCD15'); }); - test("toRadixString", () { - expect(Int64(123456789).toRadixString(5), "223101104124"); + test('toRadixString', () { + expect(Int64(123456789).toRadixString(5), '223101104124'); expect(Int64.MIN_VALUE.toRadixString(2), - "-1000000000000000000000000000000000000000000000000000000000000000"); + '-1000000000000000000000000000000000000000000000000000000000000000'); expect(Int64.MIN_VALUE.toRadixString(3), - "-2021110011022210012102010021220101220222"); + '-2021110011022210012102010021220101220222'); expect(Int64.MIN_VALUE.toRadixString(4), - "-20000000000000000000000000000000"); - expect(Int64.MIN_VALUE.toRadixString(5), "-1104332401304422434310311213"); - expect(Int64.MIN_VALUE.toRadixString(6), "-1540241003031030222122212"); - expect(Int64.MIN_VALUE.toRadixString(7), "-22341010611245052052301"); - expect(Int64.MIN_VALUE.toRadixString(8), "-1000000000000000000000"); - expect(Int64.MIN_VALUE.toRadixString(9), "-67404283172107811828"); - expect(Int64.MIN_VALUE.toRadixString(10), "-9223372036854775808"); - expect(Int64.MIN_VALUE.toRadixString(11), "-1728002635214590698"); - expect(Int64.MIN_VALUE.toRadixString(12), "-41a792678515120368"); - expect(Int64.MIN_VALUE.toRadixString(13), "-10b269549075433c38"); - expect(Int64.MIN_VALUE.toRadixString(14), "-4340724c6c71dc7a8"); - expect(Int64.MIN_VALUE.toRadixString(15), "-160e2ad3246366808"); - expect(Int64.MIN_VALUE.toRadixString(16), "-8000000000000000"); + '-20000000000000000000000000000000'); + expect(Int64.MIN_VALUE.toRadixString(5), '-1104332401304422434310311213'); + expect(Int64.MIN_VALUE.toRadixString(6), '-1540241003031030222122212'); + expect(Int64.MIN_VALUE.toRadixString(7), '-22341010611245052052301'); + expect(Int64.MIN_VALUE.toRadixString(8), '-1000000000000000000000'); + expect(Int64.MIN_VALUE.toRadixString(9), '-67404283172107811828'); + expect(Int64.MIN_VALUE.toRadixString(10), '-9223372036854775808'); + expect(Int64.MIN_VALUE.toRadixString(11), '-1728002635214590698'); + expect(Int64.MIN_VALUE.toRadixString(12), '-41a792678515120368'); + expect(Int64.MIN_VALUE.toRadixString(13), '-10b269549075433c38'); + expect(Int64.MIN_VALUE.toRadixString(14), '-4340724c6c71dc7a8'); + expect(Int64.MIN_VALUE.toRadixString(15), '-160e2ad3246366808'); + expect(Int64.MIN_VALUE.toRadixString(16), '-8000000000000000'); expect(Int64.MAX_VALUE.toRadixString(2), - "111111111111111111111111111111111111111111111111111111111111111"); + '111111111111111111111111111111111111111111111111111111111111111'); expect(Int64.MAX_VALUE.toRadixString(3), - "2021110011022210012102010021220101220221"); + '2021110011022210012102010021220101220221'); expect( - Int64.MAX_VALUE.toRadixString(4), "13333333333333333333333333333333"); - expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212"); - expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211"); - expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300"); - expect(Int64.MAX_VALUE.toRadixString(8), "777777777777777777777"); - expect(Int64.MAX_VALUE.toRadixString(9), "67404283172107811827"); - expect(Int64.MAX_VALUE.toRadixString(10), "9223372036854775807"); - expect(Int64.MAX_VALUE.toRadixString(11), "1728002635214590697"); - expect(Int64.MAX_VALUE.toRadixString(12), "41a792678515120367"); - expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37"); - expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); - expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); - expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); + Int64.MAX_VALUE.toRadixString(4), '13333333333333333333333333333333'); + expect(Int64.MAX_VALUE.toRadixString(5), '1104332401304422434310311212'); + expect(Int64.MAX_VALUE.toRadixString(6), '1540241003031030222122211'); + expect(Int64.MAX_VALUE.toRadixString(7), '22341010611245052052300'); + expect(Int64.MAX_VALUE.toRadixString(8), '777777777777777777777'); + expect(Int64.MAX_VALUE.toRadixString(9), '67404283172107811827'); + expect(Int64.MAX_VALUE.toRadixString(10), '9223372036854775807'); + expect(Int64.MAX_VALUE.toRadixString(11), '1728002635214590697'); + expect(Int64.MAX_VALUE.toRadixString(12), '41a792678515120367'); + expect(Int64.MAX_VALUE.toRadixString(13), '10b269549075433c37'); + expect(Int64.MAX_VALUE.toRadixString(14), '4340724c6c71dc7a7'); + expect(Int64.MAX_VALUE.toRadixString(15), '160e2ad3246366807'); + expect(Int64.MAX_VALUE.toRadixString(16), '7fffffffffffffff'); expect(() => Int64(42).toRadixString(-1), throwsArgumentError); expect(() => Int64(42).toRadixString(0), throwsArgumentError); expect(() => Int64(42).toRadixString(37), throwsArgumentError); }); - test("toStringUnsigned", () { + test('toStringUnsigned', () { List values = []; for (int high = 0; high < 16; high++) { for (int low = -2; low <= 2; low++) { diff --git a/pkgs/fixnum/test/int_64_vm_test.dart b/pkgs/fixnum/test/int_64_vm_test.dart index e5e1303a..2ab161e2 100644 --- a/pkgs/fixnum/test/int_64_vm_test.dart +++ b/pkgs/fixnum/test/int_64_vm_test.dart @@ -8,31 +8,31 @@ import 'package:fixnum/fixnum.dart'; import 'package:test/test.dart'; void main() { - group("conversions", () { - test("toInt", () { - expect(Int64.parseInt("-10000000000000000").toInt(), + group('conversions', () { + test('toInt', () { + expect(Int64.parseInt('-10000000000000000').toInt(), same(-10000000000000000)); - expect(Int64.parseInt("-10000000000000001").toInt(), + expect(Int64.parseInt('-10000000000000001').toInt(), same(-10000000000000001)); - expect(Int64.parseInt("-10000000000000002").toInt(), + expect(Int64.parseInt('-10000000000000002').toInt(), same(-10000000000000002)); - expect(Int64.parseInt("-10000000000000003").toInt(), + expect(Int64.parseInt('-10000000000000003').toInt(), same(-10000000000000003)); - expect(Int64.parseInt("-10000000000000004").toInt(), + expect(Int64.parseInt('-10000000000000004').toInt(), same(-10000000000000004)); - expect(Int64.parseInt("-10000000000000005").toInt(), + expect(Int64.parseInt('-10000000000000005').toInt(), same(-10000000000000005)); - expect(Int64.parseInt("-10000000000000006").toInt(), + expect(Int64.parseInt('-10000000000000006').toInt(), same(-10000000000000006)); - expect(Int64.parseInt("-10000000000000007").toInt(), + expect(Int64.parseInt('-10000000000000007').toInt(), same(-10000000000000007)); - expect(Int64.parseInt("-10000000000000008").toInt(), + expect(Int64.parseInt('-10000000000000008').toInt(), same(-10000000000000008)); }); }); - test("", () { - check(int n) { + test('', () { + void check(int n) { // Sign change should commute with conversion. expect(-Int64(-n), Int64(n)); expect(Int64(-n), -Int64(n)); From 67692d59bb244c3e986b7d9be574c42b699bc0c4 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 26 Mar 2020 09:11:17 -0700 Subject: [PATCH 071/126] readme pubspec cleanup --- pkgs/fixnum/README.md | 9 ++------- pkgs/fixnum/pubspec.yaml | 5 +++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index cfb31648..e6ef057d 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -1,14 +1,9 @@ A fixed-width 32- and 64- bit integer library for Dart. +[![Pub](https://img.shields.io/pub/v/fixnum.svg)](https://pub.dev/packages/fixnum) [![Build Status](https://travis-ci.org/dart-lang/fixnum.svg?branch=master)](https://travis-ci.org/dart-lang/fixnum) [![Coverage Status](https://img.shields.io/coveralls/dart-lang/fixnum.svg)](https://coveralls.io/r/dart-lang/fixnum) -## Documentation - -The fixnum package provides data types for signed 32- and 64-bit integers. +Provides data types for signed 32- and 64-bit integers. The integer implementations in this library are designed to work identically whether executed on the Dart VM or compiled to JavaScript. - -For more information, see the -[fixnum package](https://pub.dev/packages/fixnum) on -[pub.dev](https://pub.dev/). diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 51c87080..8dd0d45e 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,8 +1,9 @@ name: fixnum version: 0.10.12-dev -description: Library for 32- and 64-bit signed fixed-width integers. -author: Dart Team +description: >- + Library for 32- and 64-bit signed fixed-width integers with consistent + behavior between native and JS runtimes. homepage: https://github.com/dart-lang/fixnum environment: From aaf8cc0f9d0a3942e9fb579f4d76c5cc0989586a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 26 Mar 2020 09:12:09 -0700 Subject: [PATCH 072/126] remove lints duplicated by pedantic --- pkgs/fixnum/analysis_options.yaml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index 628d93ed..a934097e 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -5,9 +5,6 @@ analyzer: linter: rules: - avoid_function_literals_in_foreach_calls - - avoid_init_to_null - - avoid_null_checks_in_equality_operators - - avoid_relative_lib_imports - avoid_returning_null - avoid_unused_constructor_parameters - await_only_futures @@ -17,15 +14,11 @@ linter: #- constant_identifier_names - control_flow_in_finally - directives_ordering - - empty_catches - - empty_constructor_bodies - empty_statements - hash_and_equals - implementation_imports - invariant_booleans - iterable_contains_unrelated_type - - library_names - - library_prefixes - list_remove_unrelated_type - no_adjacent_strings_in_list - non_constant_identifier_names @@ -34,23 +27,14 @@ linter: - package_api_docs - package_names - package_prefixed_library_names - - prefer_adjacent_string_concatenation - - prefer_collection_literals - - prefer_conditional_assignment - prefer_const_constructors - - prefer_final_fields - - prefer_generic_function_type_aliases - prefer_initializing_formals - prefer_interpolation_to_compose_strings - prefer_typing_uninitialized_variables - - slash_for_doc_comments - test_types_in_equals - throw_in_finally - - type_init_formals - unnecessary_brace_in_string_interps - - unnecessary_const - unnecessary_getters_setters - unnecessary_lambdas - - unnecessary_new - unnecessary_null_aware_assignments - unnecessary_statements From e3869f971af122e1b754c8bc61d39945cd7b75d8 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Wed, 10 Jun 2020 08:46:49 -0700 Subject: [PATCH 073/126] Merge null safety branch into master (dart-lang/fixnum#56) * migrate fixnum to null safety (dart-lang/fixnum#55) Primarily this is just removing a bunch of dynamic params and converting them to Object, and then removing some of the explicit tests around null args that are no longer valid statically in the test. Note that the runtime argument errors are still present, and I left the tests in for argumentErrorTest which effectively validates the non-opted in users calling these functions still get the same behavior. We could restore some of the other tests that I deleted to do a similar thing, if we think its worth while. --- pkgs/fixnum/.travis.yml | 38 +++++++++---- pkgs/fixnum/CHANGELOG.md | 7 +++ pkgs/fixnum/analysis_options.yaml | 3 + pkgs/fixnum/lib/src/int32.dart | 36 ++++++------ pkgs/fixnum/lib/src/int64.dart | 38 ++++++------- pkgs/fixnum/lib/src/intx.dart | 34 +++++------ pkgs/fixnum/pubspec.yaml | 94 ++++++++++++++++++++++++++++++- pkgs/fixnum/test/int32_test.dart | 17 ------ pkgs/fixnum/test/int64_test.dart | 11 ++-- 9 files changed, 186 insertions(+), 92 deletions(-) diff --git a/pkgs/fixnum/.travis.yml b/pkgs/fixnum/.travis.yml index 88939f9b..27b7cf7c 100644 --- a/pkgs/fixnum/.travis.yml +++ b/pkgs/fixnum/.travis.yml @@ -1,20 +1,34 @@ language: dart dart: - - 2.1.1 - - dev + - be/raw/latest -dart_task: - - test: --platform vm - xvfb: false - - test: --platform chrome - - dartanalyzer: --fatal-warnings --fatal-infos . - -matrix: +jobs: include: - # Only validate formatting using the dev release - - dart: dev - dart_task: dartfmt + - stage: analyze_and_format + name: "Analyzer" + dart: be/raw/latest + os: linux + script: dartanalyzer --enable-experiment=non-nullable --fatal-warnings --fatal-infos . + - stage: analyze_and_format + name: "Format" + dart: be/raw/latest + os: linux + script: dartfmt -n --set-exit-if-changed . + - stage: test + name: "Vm Tests" + dart: be/raw/latest + os: linux + script: pub run --enable-experiment=non-nullable test -p vm + - stage: test + name: "Web Tests" + dart: be/raw/latest + os: linux + script: pub run --enable-experiment=non-nullable test -p chrome + +stages: + - analyze_and_format + - test # Only building master means that we don't run two builds for each pull request. branches: diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 3359d0a1..071d86c5 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.0.0-dev + +* Migrate to null safety. + * This is meant to be mostly non-breaking, for opted in users runtime errors + will be promoted to static errors. For non-opted in users the runtime + errors are still present in their original form. + ## 0.10.11 * Update minimum SDK constraint to version 2.1.1. diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index a934097e..447aba85 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -2,6 +2,9 @@ include: package:pedantic/analysis_options.yaml analyzer: strong-mode: implicit-casts: false + enable-experiment: + - non-nullable + linter: rules: - avoid_function_literals_in_foreach_calls diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index ec31d9d3..664fc179 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -122,7 +122,7 @@ class Int32 implements IntX { // Returns the [int] representation of the specified value. Throws // [ArgumentError] for non-integer arguments. - int _toInt(val) { + int _toInt(Object val) { if (val is Int32) { return val._i; } else if (val is int) { @@ -146,7 +146,7 @@ class Int32 implements IntX { // Int32 % Int64 => Int32 @override - IntX operator +(other) { + IntX operator +(Object other) { if (other is Int64) { return toInt64() + other; } @@ -154,7 +154,7 @@ class Int32 implements IntX { } @override - IntX operator -(other) { + IntX operator -(Object other) { if (other is Int64) { return toInt64() - other; } @@ -165,7 +165,7 @@ class Int32 implements IntX { Int32 operator -() => Int32(-_i); @override - IntX operator *(other) { + IntX operator *(Object other) { if (other is Int64) { return toInt64() * other; } @@ -174,7 +174,7 @@ class Int32 implements IntX { } @override - Int32 operator %(other) { + Int32 operator %(Object other) { if (other is Int64) { // Result will be Int32 return (toInt64() % other).toInt32(); @@ -183,7 +183,7 @@ class Int32 implements IntX { } @override - Int32 operator ~/(other) { + Int32 operator ~/(Object other) { if (other is Int64) { return (toInt64() ~/ other).toInt32(); } @@ -191,7 +191,7 @@ class Int32 implements IntX { } @override - Int32 remainder(other) { + Int32 remainder(Object other) { if (other is Int64) { var t = toInt64(); return (t - (t ~/ other) * other).toInt32(); @@ -200,7 +200,7 @@ class Int32 implements IntX { } @override - Int32 operator &(other) { + Int32 operator &(Object other) { if (other is Int64) { return (toInt64() & other).toInt32(); } @@ -208,7 +208,7 @@ class Int32 implements IntX { } @override - Int32 operator |(other) { + Int32 operator |(Object other) { if (other is Int64) { return (toInt64() | other).toInt32(); } @@ -216,7 +216,7 @@ class Int32 implements IntX { } @override - Int32 operator ^(other) { + Int32 operator ^(Object other) { if (other is Int64) { return (toInt64() ^ other).toInt32(); } @@ -274,7 +274,7 @@ class Int32 implements IntX { /// Returns [:true:] if this [Int32] has the same numeric value as the /// given object. The argument may be an [int] or an [IntX]. @override - bool operator ==(other) { + bool operator ==(Object other) { if (other is Int32) { return _i == other._i; } else if (other is Int64) { @@ -286,7 +286,7 @@ class Int32 implements IntX { } @override - int compareTo(other) { + int compareTo(Object other) { if (other is Int64) { return toInt64().compareTo(other); } @@ -294,7 +294,7 @@ class Int32 implements IntX { } @override - bool operator <(other) { + bool operator <(Object other) { if (other is Int64) { return toInt64() < other; } @@ -302,7 +302,7 @@ class Int32 implements IntX { } @override - bool operator <=(other) { + bool operator <=(Object other) { if (other is Int64) { return toInt64() <= other; } @@ -310,7 +310,7 @@ class Int32 implements IntX { } @override - bool operator >(other) { + bool operator >(Object other) { if (other is Int64) { return toInt64() > other; } @@ -318,7 +318,7 @@ class Int32 implements IntX { } @override - bool operator >=(other) { + bool operator >=(Object other) { if (other is Int64) { return toInt64() >= other; } @@ -353,7 +353,7 @@ class Int32 implements IntX { Int32 abs() => _i < 0 ? Int32(-_i) : this; @override - Int32 clamp(lowerLimit, upperLimit) { + Int32 clamp(Object lowerLimit, Object upperLimit) { if (this < lowerLimit) { if (lowerLimit is IntX) return lowerLimit.toInt32(); if (lowerLimit is int) return Int32(lowerLimit); @@ -386,7 +386,7 @@ class Int32 implements IntX { @override List toBytes() { - var result = List(4); + var result = List.filled(4, 0); result[0] = _i & 0xff; result[1] = (_i >> 8) & 0xff; result[2] = (_i >> 16) & 0xff; diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index d6240731..24de9d14 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -198,7 +198,7 @@ class Int64 implements IntX { } @override - Int64 operator +(other) { + Int64 operator +(Object other) { Int64 o = _promote(other); int sum0 = _l + o._l; int sum1 = _m + o._m + (sum0 >> _BITS); @@ -207,7 +207,7 @@ class Int64 implements IntX { } @override - Int64 operator -(other) { + Int64 operator -(Object other) { Int64 o = _promote(other); return _sub(_l, _m, _h, o._l, o._m, o._h); } @@ -216,7 +216,7 @@ class Int64 implements IntX { Int64 operator -() => _negate(_l, _m, _h); @override - Int64 operator *(other) { + Int64 operator *(Object other) { Int64 o = _promote(other); // Grab 13-bit chunks. @@ -298,16 +298,16 @@ class Int64 implements IntX { } @override - Int64 operator %(other) => _divide(this, other, _RETURN_MOD); + Int64 operator %(Object other) => _divide(this, other, _RETURN_MOD); @override - Int64 operator ~/(other) => _divide(this, other, _RETURN_DIV); + Int64 operator ~/(Object other) => _divide(this, other, _RETURN_DIV); @override - Int64 remainder(other) => _divide(this, other, _RETURN_REM); + Int64 remainder(Object other) => _divide(this, other, _RETURN_REM); @override - Int64 operator &(other) { + Int64 operator &(Object other) { Int64 o = _promote(other); int a0 = _l & o._l; int a1 = _m & o._m; @@ -316,7 +316,7 @@ class Int64 implements IntX { } @override - Int64 operator |(other) { + Int64 operator |(Object other) { Int64 o = _promote(other); int a0 = _l | o._l; int a1 = _m | o._m; @@ -325,7 +325,7 @@ class Int64 implements IntX { } @override - Int64 operator ^(other) { + Int64 operator ^(Object other) { Int64 o = _promote(other); int a0 = _l ^ o._l; int a1 = _m ^ o._m; @@ -442,8 +442,8 @@ class Int64 implements IntX { /// Returns [:true:] if this [Int64] has the same numeric value as the /// given object. The argument may be an [int] or an [IntX]. @override - bool operator ==(other) { - Int64 o; + bool operator ==(Object other) { + Int64? o; if (other is Int64) { o = other; } else if (other is int) { @@ -462,9 +462,9 @@ class Int64 implements IntX { } @override - int compareTo(other) => _compareTo(other); + int compareTo(Object other) => _compareTo(other); - int _compareTo(other) { + int _compareTo(Object other) { Int64 o = _promote(other); int signa = _h >> (_BITS2 - 1); int signb = o._h >> (_BITS2 - 1); @@ -490,16 +490,16 @@ class Int64 implements IntX { } @override - bool operator <(other) => _compareTo(other) < 0; + bool operator <(Object other) => _compareTo(other) < 0; @override - bool operator <=(other) => _compareTo(other) <= 0; + bool operator <=(Object other) => _compareTo(other) <= 0; @override - bool operator >(other) => _compareTo(other) > 0; + bool operator >(Object other) => _compareTo(other) > 0; @override - bool operator >=(other) => _compareTo(other) >= 0; + bool operator >=(Object other) => _compareTo(other) >= 0; @override bool get isEven => (_l & 0x1) == 0; @@ -549,7 +549,7 @@ class Int64 implements IntX { } @override - Int64 clamp(lowerLimit, upperLimit) { + Int64 clamp(Object lowerLimit, Object upperLimit) { Int64 lower = _promote(lowerLimit); Int64 upper = _promote(upperLimit); if (this < lower) return lower; @@ -631,7 +631,7 @@ class Int64 implements IntX { @override List toBytes() { - List result = List(8); + var result = List.filled(8, 0); result[0] = _l & 0xff; result[1] = (_l >> 8) & 0xff; result[2] = ((_m << 6) & 0xfc) | ((_l >> 16) & 0x3f); diff --git a/pkgs/fixnum/lib/src/intx.dart b/pkgs/fixnum/lib/src/intx.dart index e1c13425..4c0dd61d 100644 --- a/pkgs/fixnum/lib/src/intx.dart +++ b/pkgs/fixnum/lib/src/intx.dart @@ -5,12 +5,12 @@ part of fixnum; /// A fixed-precision integer. -abstract class IntX implements Comparable { +abstract class IntX implements Comparable { /// Addition operator. - IntX operator +(other); + IntX operator +(Object other); /// Subtraction operator. - IntX operator -(other); + IntX operator -(Object other); /// Negate operator. /// @@ -18,30 +18,30 @@ abstract class IntX implements Comparable { IntX operator -(); /// Multiplication operator. - IntX operator *(other); + IntX operator *(Object other); /// Euclidean modulo operator. /// /// Returns the remainder of the euclidean division. The euclidean division /// of two integers `a` and `b` yields two integers `q` and `r` such that /// `a == b * q + r` and `0 <= r < a.abs()`. - IntX operator %(other); + IntX operator %(Object other); /// Truncating division operator. - IntX operator ~/(other); + IntX operator ~/(Object other); /// Returns the remainder of the truncating division of this integer by /// [other]. - IntX remainder(other); + IntX remainder(Object other); /// Bitwise and operator. - IntX operator &(other); + IntX operator &(Object other); /// Bitwise or operator. - IntX operator |(other); + IntX operator |(Object other); /// Bitwise xor operator. - IntX operator ^(other); + IntX operator ^(Object other); /// Bitwise negate operator. IntX operator ~(); @@ -66,24 +66,24 @@ abstract class IntX implements Comparable { IntX shiftRightUnsigned(int shiftAmount); @override - int compareTo(other); + int compareTo(Object other); /// Returns `true` if and only if [other] is an int or IntX equal in /// value to this integer. @override - bool operator ==(other); + bool operator ==(Object other); /// Relational less than operator. - bool operator <(other); + bool operator <(Object other); /// Relational less than or equal to operator. - bool operator <=(other); + bool operator <=(Object other); /// Relational greater than operator. - bool operator >(other); + bool operator >(Object other); /// Relational greater than or equal to operator. - bool operator >=(other); + bool operator >=(Object other); /// Returns `true` if and only if this integer is even. bool get isEven; @@ -112,7 +112,7 @@ abstract class IntX implements Comparable { IntX abs(); /// Clamps this integer to be in the range [lowerLimit] - [upperLimit]. - IntX clamp(lowerLimit, upperLimit); + IntX clamp(Object lowerLimit, Object upperLimit); /// Returns the minimum number of bits required to store this integer. /// diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 8dd0d45e..015ed4cb 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,14 +1,104 @@ name: fixnum -version: 0.10.12-dev +version: 1.0.0-dev description: >- Library for 32- and 64-bit signed fixed-width integers with consistent behavior between native and JS runtimes. homepage: https://github.com/dart-lang/fixnum +# We are not ready to publish NNBD packages yet. +publish_to: none + environment: - sdk: '>=2.1.1 <3.0.0' + sdk: '>=2.9.0-1 <3.0.0' dev_dependencies: pedantic: ^1.8.0 test: ^1.2.0 + +dependency_overrides: + test: + git: + url: git://github.com/dart-lang/test.git + ref: null_safety + path: pkgs/test + test_api: + git: + url: git://github.com/dart-lang/test.git + ref: null_safety + path: pkgs/test_api + test_core: + git: + url: git://github.com/dart-lang/test.git + ref: null_safety + path: pkgs/test_core + async: + git: + url: git://github.com/dart-lang/async.git + ref: null_safety + boolean_selector: + git: + url: git://github.com/dart-lang/boolean_selector.git + ref: null_safety + charcode: + git: + url: git://github.com/dart-lang/charcode.git + ref: null_safety + collection: + git: + url: git://github.com/dart-lang/collection.git + ref: null_safety + js: + git: + url: git://github.com/dart-lang/sdk.git + ref: null_safety-pkgs + path: pkg/js + matcher: + git: + url: git://github.com/dart-lang/matcher.git + ref: null_safety + meta: + git: + url: git://github.com/dart-lang/sdk.git + ref: null_safety-pkgs + path: pkg/meta + path: + git: + url: git://github.com/dart-lang/path.git + ref: null_safety + pedantic: + git: + url: git://github.com/dart-lang/pedantic.git + ref: null_safety + pool: + git: + url: git://github.com/dart-lang/pool.git + ref: null_safety + source_maps: + git: + url: git://github.com/dart-lang/source_maps.git + ref: null_safety + source_map_stack_trace: + git: + url: git://github.com/dart-lang/source_map_stack_trace.git + ref: null_safety + source_span: + git: + url: git://github.com/dart-lang/source_span.git + ref: null_safety + stack_trace: + git: + url: git://github.com/dart-lang/stack_trace.git + ref: null_safety + stream_channel: + git: + url: git://github.com/dart-lang/stream_channel.git + ref: null_safety + string_scanner: + git: + url: git://github.com/dart-lang/string_scanner.git + ref: null_safety + term_glyph: + git: + url: git://github.com/dart-lang/term_glyph.git + ref: null_safety diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index db961237..8313f0b8 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -62,7 +62,6 @@ void main() { expect(n3 + n4, Int32(-11110)); expect(n3 + Int64(1), Int64(-1233)); expect(Int32.MAX_VALUE + 1, Int32.MIN_VALUE); - expect(() => Int32(17) + null, throwsArgumentError); }); test('-', () { @@ -71,7 +70,6 @@ void main() { expect(n3 - n4, Int32(8642)); expect(n3 - Int64(1), Int64(-1235)); expect(Int32.MIN_VALUE - 1, Int32.MAX_VALUE); - expect(() => Int32(17) - null, throwsArgumentError); }); test('unary -', () { @@ -89,7 +87,6 @@ void main() { expect(Int32(0x12345678) * Int64(0x22222222), Int64.fromInts(0x026D60DC, 0xCA5F6BF0)); expect((Int32(123456789) * 987654321), Int32(-67153019)); - expect(() => Int32(17) * null, throwsArgumentError); }); test('~/', () { @@ -104,13 +101,11 @@ void main() { // on the VM: IntegerDivisionByZeroException throwsA(anyOf(const TypeMatcher(), isUnsupportedError))); - expect(() => Int32(17) ~/ null, throwsArgumentError); }); test('%', () { expect(Int32(0x12345678) % Int32(0x22), Int32(0x12345678 % 0x22)); expect(Int32(0x12345678) % Int64(0x22), Int32(0x12345678 % 0x22)); - expect(() => Int32(17) % null, throwsArgumentError); }); test('remainder', () { @@ -124,7 +119,6 @@ void main() { Int32(-0x12345678.remainder(0x22) as int)); expect(Int32(0x12345678).remainder(Int64(0x22)), Int32(0x12345678.remainder(0x22) as int)); - expect(() => Int32(17).remainder(null), throwsArgumentError); }); test('abs', () { @@ -197,7 +191,6 @@ void main() { expect(Int32(17) < Int64(16), false); expect(Int32.MIN_VALUE < Int32.MAX_VALUE, true); expect(Int32.MAX_VALUE < Int32.MIN_VALUE, false); - expect(() => Int32(17) < null, throwsArgumentError); }); test('<=', () { @@ -209,7 +202,6 @@ void main() { expect(Int32(17) <= Int64(16), false); expect(Int32.MIN_VALUE <= Int32.MAX_VALUE, true); expect(Int32.MAX_VALUE <= Int32.MIN_VALUE, false); - expect(() => Int32(17) <= null, throwsArgumentError); }); test('==', () { @@ -236,7 +228,6 @@ void main() { expect(Int32(17) >= Int64(16), true); expect(Int32.MIN_VALUE >= Int32.MAX_VALUE, false); expect(Int32.MAX_VALUE >= Int32.MIN_VALUE, true); - expect(() => Int32(17) >= null, throwsArgumentError); }); test('>', () { @@ -248,7 +239,6 @@ void main() { expect(Int32(17) > Int64(16), true); expect(Int32.MIN_VALUE > Int32.MAX_VALUE, false); expect(Int32.MAX_VALUE > Int32.MIN_VALUE, true); - expect(() => Int32(17) > null, throwsArgumentError); }); }); @@ -258,7 +248,6 @@ void main() { Int32(0x12345678 & 0x22222222)); expect(Int32(0x12345678) & Int64(0x22222222), Int64(0x12345678 & 0x22222222)); - expect(() => Int32(17) & null, throwsArgumentError); }); test('|', () { @@ -266,7 +255,6 @@ void main() { Int32(0x12345678 | 0x22222222)); expect(Int32(0x12345678) | Int64(0x22222222), Int64(0x12345678 | 0x22222222)); - expect(() => Int32(17) | null, throwsArgumentError); }); test('^', () { @@ -274,7 +262,6 @@ void main() { Int32(0x12345678 ^ 0x22222222)); expect(Int32(0x12345678) ^ Int64(0x22222222), Int64(0x12345678 ^ 0x22222222)); - expect(() => Int32(17) ^ null, throwsArgumentError); }); test('~', () { @@ -289,7 +276,6 @@ void main() { expect(Int32(0x12345678) << 32, Int32.ZERO); expect(Int32(0x12345678) << 33, Int32.ZERO); expect(() => Int32(17) << -1, throwsArgumentError); - expect(() => Int32(17) << null, throwsNoSuchMethodError); }); test('>>', () { @@ -299,7 +285,6 @@ void main() { expect(Int32(-42) >> 32, Int32(-1)); expect(Int32(-42) >> 33, Int32(-1)); expect(() => Int32(17) >> -1, throwsArgumentError); - expect(() => Int32(17) >> null, throwsNoSuchMethodError); }); test('shiftRightUnsigned', () { @@ -309,8 +294,6 @@ void main() { expect(Int32(-42).shiftRightUnsigned(32), Int32.ZERO); expect(Int32(-42).shiftRightUnsigned(33), Int32.ZERO); expect(() => (Int32(17).shiftRightUnsigned(-1)), throwsArgumentError); - expect( - () => (Int32(17).shiftRightUnsigned(null)), throwsNoSuchMethodError); }); }); diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 7994a8dd..cace28da 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -46,7 +46,10 @@ void main() { Matcher throwsArgumentErrorMentioning(String substring) => throwsA((e) => e is ArgumentError && '$e'.contains(substring)); - expect(() => op(receiver, null), throwsArgumentErrorMentioning('null')); + expect( + () => op(receiver, null), + throwsA(isA().having( + (e) => e.toString(), 'should mention Null', contains('Null')))); expect(() => op(receiver, 'foo'), throwsArgumentErrorMentioning(r'"foo"')); } @@ -457,7 +460,6 @@ void main() { expect(n1 & n2, Int64(1168)); expect(n3 & n2, Int64(8708)); expect(n4 & n5, Int64(0x1034) << 32); - expect(() => n1 & null, throwsArgumentError); argumentErrorTest('&', (a, b) => a & b); }); @@ -465,7 +467,6 @@ void main() { expect(n1 | n2, Int64(9942)); expect(n3 | n2, Int64(-66)); expect(n4 | n5, Int64(0x9a76) << 32); - expect(() => n1 | null, throwsArgumentError); argumentErrorTest('|', (a, b) => a | b); }); @@ -473,7 +474,6 @@ void main() { expect(n1 ^ n2, Int64(8774)); expect(n3 ^ n2, Int64(-8774)); expect(n4 ^ n5, Int64(0x8a42) << 32); - expect(() => n1 ^ null, throwsArgumentError); argumentErrorTest('^', (a, b) => a ^ b); }); @@ -501,7 +501,6 @@ void main() { expect(Int64(42) << 64, Int64.ZERO); expect(Int64(42) << 65, Int64.ZERO); expect(() => Int64(17) << -1, throwsArgumentError); - expect(() => Int64(17) << null, throwsNoSuchMethodError); }); test('>>', () { @@ -553,7 +552,6 @@ void main() { expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 48, Int64.fromInts(0xffffffff, 0xffff9234)); expect(() => Int64(17) >> -1, throwsArgumentError); - expect(() => Int64(17) >> null, throwsNoSuchMethodError); }); test('shiftRightUnsigned', () { @@ -600,7 +598,6 @@ void main() { expect(Int64(-1).shiftRightUnsigned(64), Int64.ZERO); expect(Int64(1).shiftRightUnsigned(64), Int64.ZERO); expect(() => Int64(17).shiftRightUnsigned(-1), throwsArgumentError); - expect(() => Int64(17).shiftRightUnsigned(null), throwsNoSuchMethodError); }); test('overflow', () { From 6da639491f4a8ece85a425627c1ebe9459e30709 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Tue, 21 Jul 2020 19:42:13 -0700 Subject: [PATCH 074/126] update for the 2.10 dev sdk (dart-lang/fixnum#62) This is in preparation for the actual 2.10 dev sdk release. --- pkgs/fixnum/.travis.yml | 10 ++--- pkgs/fixnum/CHANGELOG.md | 2 +- pkgs/fixnum/pubspec.yaml | 96 ++++++++++++++-------------------------- 3 files changed, 39 insertions(+), 69 deletions(-) diff --git a/pkgs/fixnum/.travis.yml b/pkgs/fixnum/.travis.yml index 27b7cf7c..ba73a2a2 100644 --- a/pkgs/fixnum/.travis.yml +++ b/pkgs/fixnum/.travis.yml @@ -1,28 +1,28 @@ language: dart dart: - - be/raw/latest + - preview/raw/2.10.0-0.2-dev jobs: include: - stage: analyze_and_format name: "Analyzer" - dart: be/raw/latest + dart: preview/raw/2.10.0-0.2-dev os: linux script: dartanalyzer --enable-experiment=non-nullable --fatal-warnings --fatal-infos . - stage: analyze_and_format name: "Format" - dart: be/raw/latest + dart: preview/raw/2.10.0-0.2-dev os: linux script: dartfmt -n --set-exit-if-changed . - stage: test name: "Vm Tests" - dart: be/raw/latest + dart: preview/raw/2.10.0-0.2-dev os: linux script: pub run --enable-experiment=non-nullable test -p vm - stage: test name: "Web Tests" - dart: be/raw/latest + dart: preview/raw/2.10.0-0.2-dev os: linux script: pub run --enable-experiment=non-nullable test -p chrome diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 071d86c5..6db0fc01 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.0.0-dev +## 1.0.0-nullsafety * Migrate to null safety. * This is meant to be mostly non-breaking, for opted in users runtime errors diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 015ed4cb..080836b1 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 1.0.0-dev +version: 1.0.0-nullsafety description: >- Library for 32- and 64-bit signed fixed-width integers with consistent @@ -10,95 +10,65 @@ homepage: https://github.com/dart-lang/fixnum publish_to: none environment: - sdk: '>=2.9.0-1 <3.0.0' + # This must remain a tight constraint until nnbd is stable + sdk: '>=2.10.0-0 <2.10.0' dev_dependencies: pedantic: ^1.8.0 test: ^1.2.0 dependency_overrides: - test: - git: - url: git://github.com/dart-lang/test.git - ref: null_safety - path: pkgs/test - test_api: - git: - url: git://github.com/dart-lang/test.git - ref: null_safety - path: pkgs/test_api - test_core: - git: - url: git://github.com/dart-lang/test.git - ref: null_safety - path: pkgs/test_core async: - git: - url: git://github.com/dart-lang/async.git - ref: null_safety + git: git://github.com/dart-lang/async.git boolean_selector: - git: - url: git://github.com/dart-lang/boolean_selector.git - ref: null_safety + git: git://github.com/dart-lang/boolean_selector.git charcode: - git: - url: git://github.com/dart-lang/charcode.git - ref: null_safety + git: git://github.com/dart-lang/charcode.git collection: - git: - url: git://github.com/dart-lang/collection.git - ref: null_safety + git: git://github.com/dart-lang/collection.git js: git: url: git://github.com/dart-lang/sdk.git - ref: null_safety-pkgs path: pkg/js + ref: 2-10-pkgs matcher: - git: - url: git://github.com/dart-lang/matcher.git - ref: null_safety + git: git://github.com/dart-lang/matcher.git meta: git: url: git://github.com/dart-lang/sdk.git - ref: null_safety-pkgs path: pkg/meta + ref: 2-10-pkgs path: - git: - url: git://github.com/dart-lang/path.git - ref: null_safety + git: git://github.com/dart-lang/path.git pedantic: - git: - url: git://github.com/dart-lang/pedantic.git - ref: null_safety + git: git://github.com/dart-lang/pedantic.git pool: - git: - url: git://github.com/dart-lang/pool.git - ref: null_safety + git: git://github.com/dart-lang/pool.git source_maps: - git: - url: git://github.com/dart-lang/source_maps.git - ref: null_safety + git: git://github.com/dart-lang/source_maps.git source_map_stack_trace: - git: - url: git://github.com/dart-lang/source_map_stack_trace.git - ref: null_safety + git: git://github.com/dart-lang/source_map_stack_trace.git source_span: - git: - url: git://github.com/dart-lang/source_span.git - ref: null_safety + git: git://github.com/dart-lang/source_span.git stack_trace: - git: - url: git://github.com/dart-lang/stack_trace.git - ref: null_safety + git: git://github.com/dart-lang/stack_trace.git stream_channel: - git: - url: git://github.com/dart-lang/stream_channel.git - ref: null_safety + git: git://github.com/dart-lang/stream_channel.git string_scanner: - git: - url: git://github.com/dart-lang/string_scanner.git - ref: null_safety + git: git://github.com/dart-lang/string_scanner.git term_glyph: + git: git://github.com/dart-lang/term_glyph.git + test_api: + git: + url: git://github.com/dart-lang/test.git + path: pkgs/test_api + test_core: git: - url: git://github.com/dart-lang/term_glyph.git - ref: null_safety + url: git://github.com/dart-lang/test.git + path: pkgs/test_core + test: + git: + url: git://github.com/dart-lang/test.git + path: pkgs/test + typed_data: + git: git://github.com/dart-lang/typed_data.git From b5977a18db881b3b21881033a21d5ce2692f5587 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 23 Jul 2020 07:28:07 -0700 Subject: [PATCH 075/126] CI: Test on dev branch (dart-lang/fixnum#63) --- pkgs/fixnum/.travis.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pkgs/fixnum/.travis.yml b/pkgs/fixnum/.travis.yml index ba73a2a2..f35514ea 100644 --- a/pkgs/fixnum/.travis.yml +++ b/pkgs/fixnum/.travis.yml @@ -1,28 +1,24 @@ language: dart dart: - - preview/raw/2.10.0-0.2-dev + - dev jobs: include: - stage: analyze_and_format name: "Analyzer" - dart: preview/raw/2.10.0-0.2-dev os: linux script: dartanalyzer --enable-experiment=non-nullable --fatal-warnings --fatal-infos . - stage: analyze_and_format name: "Format" - dart: preview/raw/2.10.0-0.2-dev os: linux script: dartfmt -n --set-exit-if-changed . - stage: test name: "Vm Tests" - dart: preview/raw/2.10.0-0.2-dev os: linux script: pub run --enable-experiment=non-nullable test -p vm - stage: test name: "Web Tests" - dart: preview/raw/2.10.0-0.2-dev os: linux script: pub run --enable-experiment=non-nullable test -p chrome From a1b6f4f4141ab183037990b3959c0c202bb193a1 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Fri, 28 Aug 2020 13:04:05 -0700 Subject: [PATCH 076/126] remove some unnecessary casts from tests (dart-lang/fixnum#65) * remove some unnecessary casts from tests * update pubspec/changelog for next dev release --- pkgs/fixnum/CHANGELOG.md | 2 ++ pkgs/fixnum/pubspec.yaml | 2 +- pkgs/fixnum/test/int32_test.dart | 10 +++++----- pkgs/fixnum/test/int64_test.dart | 10 +++++----- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 6db0fc01..232ee74a 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,3 +1,5 @@ +## 1.0.0-nullsafety.1-dev + ## 1.0.0-nullsafety * Migrate to null safety. diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 080836b1..6cc6ebfc 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 1.0.0-nullsafety +version: 1.0.0-nullsafety.1-dev description: >- Library for 32- and 64-bit signed fixed-width integers with consistent diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 8313f0b8..d6761115 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -110,15 +110,15 @@ void main() { test('remainder', () { expect(Int32(0x12345678).remainder(Int32(0x22)), - Int32(0x12345678.remainder(0x22) as int)); + Int32(0x12345678.remainder(0x22))); expect(Int32(0x12345678).remainder(Int32(-0x22)), - Int32(0x12345678.remainder(-0x22) as int)); + Int32(0x12345678.remainder(-0x22))); expect(Int32(-0x12345678).remainder(Int32(-0x22)), - Int32(-0x12345678.remainder(-0x22) as int)); + Int32(-0x12345678.remainder(-0x22))); expect(Int32(-0x12345678).remainder(Int32(0x22)), - Int32(-0x12345678.remainder(0x22) as int)); + Int32(-0x12345678.remainder(0x22))); expect(Int32(0x12345678).remainder(Int64(0x22)), - Int32(0x12345678.remainder(0x22) as int)); + Int32(0x12345678.remainder(0x22))); }); test('abs', () { diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index cace28da..cd2f89bf 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -272,15 +272,15 @@ void main() { expect(Int64.MAX_VALUE % Int64.fromInts(0x04000000, 0x00000000), Int64.fromInts(0x3ffffff, 0xffffffff)); expect(Int64(0x12345678).remainder(Int64(0x22)), - Int64(0x12345678.remainder(0x22) as int)); + Int64(0x12345678.remainder(0x22))); expect(Int64(0x12345678).remainder(Int64(-0x22)), - Int64(0x12345678.remainder(-0x22) as int)); + Int64(0x12345678.remainder(-0x22))); expect(Int64(-0x12345678).remainder(Int64(-0x22)), - Int64(-0x12345678.remainder(-0x22) as int)); + Int64(-0x12345678.remainder(-0x22))); expect(Int64(-0x12345678).remainder(Int64(0x22)), - Int64(-0x12345678.remainder(0x22) as int)); + Int64(-0x12345678.remainder(0x22))); expect(Int32(0x12345678).remainder(Int64(0x22)), - Int64(0x12345678.remainder(0x22) as int)); + Int64(0x12345678.remainder(0x22))); argumentErrorTest('%', (a, b) => a % b); }); From f6f57c01ee6eab284675d4895f1c24a02ac46948 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Tue, 29 Sep 2020 10:29:38 -0700 Subject: [PATCH 077/126] expand the sdk constraint to allow the 2.11 dev sdk (dart-lang/fixnum#66) * expand the sdk constraint to allow the 2.11 dev sdk * use published deps, force lang version of tests to work around sdk issue --- pkgs/fixnum/CHANGELOG.md | 2 + pkgs/fixnum/pubspec.yaml | 62 ++-------------------------- pkgs/fixnum/test/all_tests.dart | 7 ++++ pkgs/fixnum/test/int32_test.dart | 3 ++ pkgs/fixnum/test/int64_test.dart | 3 ++ pkgs/fixnum/test/int_64_vm_test.dart | 3 ++ 6 files changed, 21 insertions(+), 59 deletions(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 232ee74a..f0a73375 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,5 +1,7 @@ ## 1.0.0-nullsafety.1-dev +* Expand sdk constraint to allow the 2.11 dev sdk. + ## 1.0.0-nullsafety * Migrate to null safety. diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 6cc6ebfc..ab994847 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -11,64 +11,8 @@ publish_to: none environment: # This must remain a tight constraint until nnbd is stable - sdk: '>=2.10.0-0 <2.10.0' + sdk: '>=2.10.0-0 <2.11.0' dev_dependencies: - pedantic: ^1.8.0 - test: ^1.2.0 - -dependency_overrides: - async: - git: git://github.com/dart-lang/async.git - boolean_selector: - git: git://github.com/dart-lang/boolean_selector.git - charcode: - git: git://github.com/dart-lang/charcode.git - collection: - git: git://github.com/dart-lang/collection.git - js: - git: - url: git://github.com/dart-lang/sdk.git - path: pkg/js - ref: 2-10-pkgs - matcher: - git: git://github.com/dart-lang/matcher.git - meta: - git: - url: git://github.com/dart-lang/sdk.git - path: pkg/meta - ref: 2-10-pkgs - path: - git: git://github.com/dart-lang/path.git - pedantic: - git: git://github.com/dart-lang/pedantic.git - pool: - git: git://github.com/dart-lang/pool.git - source_maps: - git: git://github.com/dart-lang/source_maps.git - source_map_stack_trace: - git: git://github.com/dart-lang/source_map_stack_trace.git - source_span: - git: git://github.com/dart-lang/source_span.git - stack_trace: - git: git://github.com/dart-lang/stack_trace.git - stream_channel: - git: git://github.com/dart-lang/stream_channel.git - string_scanner: - git: git://github.com/dart-lang/string_scanner.git - term_glyph: - git: git://github.com/dart-lang/term_glyph.git - test_api: - git: - url: git://github.com/dart-lang/test.git - path: pkgs/test_api - test_core: - git: - url: git://github.com/dart-lang/test.git - path: pkgs/test_core - test: - git: - url: git://github.com/dart-lang/test.git - path: pkgs/test - typed_data: - git: git://github.com/dart-lang/typed_data.git + pedantic: ^1.10.0-nullsafety + test: ^1.16.0-nullsafety diff --git a/pkgs/fixnum/test/all_tests.dart b/pkgs/fixnum/test/all_tests.dart index eb530b74..3a1ca1ba 100644 --- a/pkgs/fixnum/test/all_tests.dart +++ b/pkgs/fixnum/test/all_tests.dart @@ -1,3 +1,10 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +// +// TODO: Remove https://github.com/dart-lang/sdk/issues/43605 +// @dart=2.11 + import 'int32_test.dart' as int32_test; import 'int64_test.dart' as int64_test; diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index d6761115..2e14da94 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -1,6 +1,9 @@ // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// +// TODO: Remove https://github.com/dart-lang/sdk/issues/43605 +// @dart=2.11 import 'package:fixnum/fixnum.dart'; import 'package:test/test.dart'; diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index cd2f89bf..e5073c54 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -1,6 +1,9 @@ // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// +// TODO: Remove https://github.com/dart-lang/sdk/issues/43605 +// @dart=2.11 // We permit local variable types in this test because they statically 'assert' // that the operations have an expected type. diff --git a/pkgs/fixnum/test/int_64_vm_test.dart b/pkgs/fixnum/test/int_64_vm_test.dart index 2ab161e2..52b96bd0 100644 --- a/pkgs/fixnum/test/int_64_vm_test.dart +++ b/pkgs/fixnum/test/int_64_vm_test.dart @@ -1,6 +1,9 @@ // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// +// TODO: Remove https://github.com/dart-lang/sdk/issues/43605 +// @dart=2.11 @TestOn('vm') From ace8b3fde5a5e2e80a96d4bd655e4ad5c0d26486 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 3 Nov 2020 07:17:47 -0800 Subject: [PATCH 078/126] Support Dart 2.11 (dart-lang/fixnum#69) --- pkgs/fixnum/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index ab994847..eae6d51f 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -11,7 +11,7 @@ publish_to: none environment: # This must remain a tight constraint until nnbd is stable - sdk: '>=2.10.0-0 <2.11.0' + sdk: '>=2.10.0-0 <2.12.0' dev_dependencies: pedantic: ^1.10.0-nullsafety From e9435bef7d5939b6e6684f71c1786b6de858e354 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Tue, 10 Nov 2020 07:58:35 -0800 Subject: [PATCH 079/126] update for the null safety dev sdk release and eventual stable (dart-lang/fixnum#70) * update for the null safety dev sdk release and eventual stable * remove language version comments from tests * update version number --- pkgs/fixnum/.travis.yml | 6 +++--- pkgs/fixnum/CHANGELOG.md | 6 +----- pkgs/fixnum/pubspec.yaml | 8 ++------ pkgs/fixnum/test/int32_test.dart | 3 --- pkgs/fixnum/test/int64_test.dart | 3 --- pkgs/fixnum/test/int_64_vm_test.dart | 3 --- 6 files changed, 6 insertions(+), 23 deletions(-) diff --git a/pkgs/fixnum/.travis.yml b/pkgs/fixnum/.travis.yml index f35514ea..d2dcc4f4 100644 --- a/pkgs/fixnum/.travis.yml +++ b/pkgs/fixnum/.travis.yml @@ -8,7 +8,7 @@ jobs: - stage: analyze_and_format name: "Analyzer" os: linux - script: dartanalyzer --enable-experiment=non-nullable --fatal-warnings --fatal-infos . + script: dartanalyzer --fatal-warnings --fatal-infos . - stage: analyze_and_format name: "Format" os: linux @@ -16,11 +16,11 @@ jobs: - stage: test name: "Vm Tests" os: linux - script: pub run --enable-experiment=non-nullable test -p vm + script: pub run test -p vm - stage: test name: "Web Tests" os: linux - script: pub run --enable-experiment=non-nullable test -p chrome + script: pub run test -p chrome stages: - analyze_and_format diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index f0a73375..abd0bd81 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,8 +1,4 @@ -## 1.0.0-nullsafety.1-dev - -* Expand sdk constraint to allow the 2.11 dev sdk. - -## 1.0.0-nullsafety +## 1.0.0-nullsafety.0 * Migrate to null safety. * This is meant to be mostly non-breaking, for opted in users runtime errors diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index eae6d51f..1e232ce8 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,17 +1,13 @@ name: fixnum -version: 1.0.0-nullsafety.1-dev +version: 1.0.0-nullsafety.0 description: >- Library for 32- and 64-bit signed fixed-width integers with consistent behavior between native and JS runtimes. homepage: https://github.com/dart-lang/fixnum -# We are not ready to publish NNBD packages yet. -publish_to: none - environment: - # This must remain a tight constraint until nnbd is stable - sdk: '>=2.10.0-0 <2.12.0' + sdk: '>=2.12.0-0 <3.0.0' dev_dependencies: pedantic: ^1.10.0-nullsafety diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 2e14da94..d6761115 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -1,9 +1,6 @@ // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// -// TODO: Remove https://github.com/dart-lang/sdk/issues/43605 -// @dart=2.11 import 'package:fixnum/fixnum.dart'; import 'package:test/test.dart'; diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index e5073c54..cd2f89bf 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -1,9 +1,6 @@ // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// -// TODO: Remove https://github.com/dart-lang/sdk/issues/43605 -// @dart=2.11 // We permit local variable types in this test because they statically 'assert' // that the operations have an expected type. diff --git a/pkgs/fixnum/test/int_64_vm_test.dart b/pkgs/fixnum/test/int_64_vm_test.dart index 52b96bd0..2ab161e2 100644 --- a/pkgs/fixnum/test/int_64_vm_test.dart +++ b/pkgs/fixnum/test/int_64_vm_test.dart @@ -1,9 +1,6 @@ // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// -// TODO: Remove https://github.com/dart-lang/sdk/issues/43605 -// @dart=2.11 @TestOn('vm') From 868bc2c96f0a61dc5e24aab0feb277b244fdfadb Mon Sep 17 00:00:00 2001 From: Phil Quitslund Date: Thu, 12 Nov 2020 07:13:26 -0800 Subject: [PATCH 080/126] remove redundant experiment (dart-lang/fixnum#71) --- pkgs/fixnum/analysis_options.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index 447aba85..b459a9b8 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -2,8 +2,6 @@ include: package:pedantic/analysis_options.yaml analyzer: strong-mode: implicit-casts: false - enable-experiment: - - non-nullable linter: rules: From 2246dcb742515a7683a3651bbb45301c6e6bfa59 Mon Sep 17 00:00:00 2001 From: Alexander Thomas Date: Tue, 12 Jan 2021 18:11:21 +0100 Subject: [PATCH 081/126] Migrate to GitHub Actions (dart-lang/fixnum#72) * Migrate to GitHub Actions * Delete .travis.yml * Replace Travis badge --- .../fixnum/.github/workflows/test-package.yml | 64 +++++++++++++++++++ pkgs/fixnum/.travis.yml | 35 ---------- pkgs/fixnum/README.md | 2 +- 3 files changed, 65 insertions(+), 36 deletions(-) create mode 100644 pkgs/fixnum/.github/workflows/test-package.yml delete mode 100644 pkgs/fixnum/.travis.yml diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml new file mode 100644 index 00000000..e55702c2 --- /dev/null +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -0,0 +1,64 @@ +name: Dart CI + +on: + # Run on PRs and pushes to the default branch. + push: + branches: [ master ] + pull_request: + branches: [ master ] + schedule: + - cron: "0 0 * * 0" + +env: + PUB_ENVIRONMENT: bot.github + +jobs: + # Check code formatting and static analysis on a single OS (linux) + # against Dart dev. + analyze: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + sdk: [dev] + steps: + - uses: actions/checkout@v2 + - uses: dart-lang/setup-dart@v0.1 + with: + channel: ${{ matrix.sdk }} + - id: install + name: Install dependencies + run: dart pub get + - name: Check formatting + run: dart format --output=none --set-exit-if-changed . + if: always() && steps.install.outcome == 'success' + - name: Analyze code + run: dart analyze --fatal-infos + if: always() && steps.install.outcome == 'success' + + # Run tests on a matrix consisting of two dimensions: + # 1. OS: ubuntu-latest, (macos-latest, windows-latest) + # 2. release channel: dev + test: + needs: analyze + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + # Add macos-latest and/or windows-latest if relevant for this package. + os: [ubuntu-latest] + sdk: [dev] + steps: + - uses: actions/checkout@v2 + - uses: dart-lang/setup-dart@v0.1 + with: + channel: ${{ matrix.sdk }} + - id: install + name: Install dependencies + run: dart pub get + - name: Run VM tests + run: dart test --platform vm + if: always() && steps.install.outcome == 'success' + - name: Run Chrome tests + run: dart test --platform chrome + if: always() && steps.install.outcome == 'success' diff --git a/pkgs/fixnum/.travis.yml b/pkgs/fixnum/.travis.yml deleted file mode 100644 index d2dcc4f4..00000000 --- a/pkgs/fixnum/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -language: dart - -dart: - - dev - -jobs: - include: - - stage: analyze_and_format - name: "Analyzer" - os: linux - script: dartanalyzer --fatal-warnings --fatal-infos . - - stage: analyze_and_format - name: "Format" - os: linux - script: dartfmt -n --set-exit-if-changed . - - stage: test - name: "Vm Tests" - os: linux - script: pub run test -p vm - - stage: test - name: "Web Tests" - os: linux - script: pub run test -p chrome - -stages: - - analyze_and_format - - test - -# Only building master means that we don't run two builds for each pull request. -branches: - only: [master] - -cache: - directories: - - $HOME/.pub-cache diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index e6ef057d..2f79b60c 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -1,7 +1,7 @@ A fixed-width 32- and 64- bit integer library for Dart. [![Pub](https://img.shields.io/pub/v/fixnum.svg)](https://pub.dev/packages/fixnum) -[![Build Status](https://travis-ci.org/dart-lang/fixnum.svg?branch=master)](https://travis-ci.org/dart-lang/fixnum) +[![Dart CI](https://github.com/dart-lang/fixnum/workflows/Dart%20CI/badge.svg)](https://github.com/dart-lang/fixnum/actions?query=workflow%3A%22Dart+CI%22+branch%3Amaster) [![Coverage Status](https://img.shields.io/coveralls/dart-lang/fixnum.svg)](https://coveralls.io/r/dart-lang/fixnum) Provides data types for signed 32- and 64-bit integers. From 1e1ea3c3dd0eef536ac2693a33b4bb4edb7d681f Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Fri, 5 Feb 2021 11:03:55 -0800 Subject: [PATCH 082/126] stable null safety release (dart-lang/fixnum#73) --- pkgs/fixnum/CHANGELOG.md | 4 ++++ pkgs/fixnum/pubspec.yaml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index abd0bd81..5ee9ebb3 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.0 + +* Stable null safety release. + ## 1.0.0-nullsafety.0 * Migrate to null safety. diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 1e232ce8..7dc7da00 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 1.0.0-nullsafety.0 +version: 1.0.0 description: >- Library for 32- and 64-bit signed fixed-width integers with consistent @@ -10,5 +10,5 @@ environment: sdk: '>=2.12.0-0 <3.0.0' dev_dependencies: - pedantic: ^1.10.0-nullsafety + pedantic: ^1.10.0 test: ^1.16.0-nullsafety From fa7ecc1cbcfb2d62d9da25b3e70b968e163ff797 Mon Sep 17 00:00:00 2001 From: Franklin Yow <58489007+franklinyow@users.noreply.github.com> Date: Tue, 6 Apr 2021 15:15:21 -0700 Subject: [PATCH 083/126] Update LICENSE (dart-lang/fixnum#76) Changes to comply with internal review --- pkgs/fixnum/LICENSE | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/LICENSE b/pkgs/fixnum/LICENSE index 5c60afea..162572a4 100644 --- a/pkgs/fixnum/LICENSE +++ b/pkgs/fixnum/LICENSE @@ -1,4 +1,5 @@ -Copyright 2014, the Dart project authors. All rights reserved. +Copyright 2014, the Dart project authors. + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -9,7 +10,7 @@ met: copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. From 7cb79f12b13bb05a1819eb99e548f9d6ffac0f87 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 29 Apr 2021 09:47:32 -0700 Subject: [PATCH 084/126] Update test-package.yml (dart-lang/fixnum#77) --- pkgs/fixnum/.github/workflows/test-package.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index e55702c2..cdc25d95 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -23,9 +23,9 @@ jobs: sdk: [dev] steps: - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v0.1 + - uses: dart-lang/setup-dart@v1.0 with: - channel: ${{ matrix.sdk }} + sdk: ${{ matrix.sdk }} - id: install name: Install dependencies run: dart pub get @@ -47,12 +47,12 @@ jobs: matrix: # Add macos-latest and/or windows-latest if relevant for this package. os: [ubuntu-latest] - sdk: [dev] + sdk: [2.12.0, dev] steps: - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v0.1 + - uses: dart-lang/setup-dart@v1.0 with: - channel: ${{ matrix.sdk }} + sdk: ${{ matrix.sdk }} - id: install name: Install dependencies run: dart pub get From 60cdc19437423d75052ed9f8e4817507531adf4a Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 27 Jul 2021 11:03:58 -0700 Subject: [PATCH 085/126] Move from pedantic to lints package (dart-lang/fixnum#82) --- pkgs/fixnum/CHANGELOG.md | 2 ++ pkgs/fixnum/analysis_options.yaml | 2 +- pkgs/fixnum/lib/src/int32.dart | 2 ++ pkgs/fixnum/lib/src/int64.dart | 2 ++ pkgs/fixnum/pubspec.yaml | 8 ++++---- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 5ee9ebb3..faed6596 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,3 +1,5 @@ +## 1.0.1-dev + ## 1.0.0 * Stable null safety release. diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index b459a9b8..8083db4c 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -1,4 +1,4 @@ -include: package:pedantic/analysis_options.yaml +include: package:lints/recommended.yaml analyzer: strong-mode: implicit-casts: false diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index 664fc179..48263b7c 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -2,6 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// ignore_for_file: constant_identifier_names + part of fixnum; /// An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1]. diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index 24de9d14..ddd9751d 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -2,6 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// ignore_for_file: constant_identifier_names + // Many locals are declared as `int` or `double`. We keep local variable types // because the types are critical to the efficiency of many operations. // diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 7dc7da00..db8ca05a 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 1.0.0 +version: 1.0.1-dev description: >- Library for 32- and 64-bit signed fixed-width integers with consistent @@ -7,8 +7,8 @@ description: >- homepage: https://github.com/dart-lang/fixnum environment: - sdk: '>=2.12.0-0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dev_dependencies: - pedantic: ^1.10.0 - test: ^1.16.0-nullsafety + lints: ^1.0.0 + test: ^1.16.0 From 14aa32dbad3193ecb5f41229fb6a3a653a1531c7 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 4 Nov 2021 09:10:07 -0700 Subject: [PATCH 086/126] Ignore deprecations for IntegerDivisionByZeroException --- pkgs/fixnum/lib/src/int64.dart | 1 + pkgs/fixnum/test/int32_test.dart | 5 +++-- pkgs/fixnum/test/int64_test.dart | 6 ++++-- pkgs/fixnum/test/test_shared.dart | 8 ++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 pkgs/fixnum/test/test_shared.dart diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index ddd9751d..e9207d5d 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -908,6 +908,7 @@ class Int64 implements IntX { static Int64 _divide(Int64 a, other, int what) { Int64 b = _promote(other); if (b.isZero) { + // ignore: deprecated_member_use throw const IntegerDivisionByZeroException(); } if (a.isZero) return ZERO; diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index d6761115..23633130 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -5,6 +5,8 @@ import 'package:fixnum/fixnum.dart'; import 'package:test/test.dart'; +import 'test_shared.dart'; + void main() { group('isX tests', () { test('isEven', () { @@ -99,8 +101,7 @@ void main() { () => Int32(17) ~/ Int32.ZERO, // with dart2js, `UnsupportedError` is thrown // on the VM: IntegerDivisionByZeroException - throwsA(anyOf(const TypeMatcher(), - isUnsupportedError))); + throwsA(anyOf(isIntegerDivisionByZeroException, isUnsupportedError))); }); test('%', () { diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index cd2f89bf..01c8ecab 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -12,6 +12,8 @@ library int64test; import 'package:fixnum/fixnum.dart'; import 'package:test/test.dart'; +import 'test_shared.dart'; + void main() { group('fromBytes', () { test('fromBytes', () { @@ -234,13 +236,13 @@ void main() { expect(Int64(829893893) ~/ Int64(1919), Int32(432461)); expect(Int64(829893893) ~/ 1919, Int32(432461)); expect(() => Int64(1) ~/ Int64.ZERO, - throwsA(const TypeMatcher())); + throwsA(isIntegerDivisionByZeroException)); expect( Int64.MIN_VALUE ~/ Int64(2), Int64.fromInts(0xc0000000, 0x00000000)); expect(Int64.MIN_VALUE ~/ Int64(1), Int64.MIN_VALUE); expect(Int64.MIN_VALUE ~/ Int64(-1), Int64.MIN_VALUE); expect(() => Int64(17) ~/ Int64.ZERO, - throwsA(const TypeMatcher())); + throwsA(isIntegerDivisionByZeroException)); argumentErrorTest('~/', (a, b) => a ~/ b); }); diff --git a/pkgs/fixnum/test/test_shared.dart b/pkgs/fixnum/test/test_shared.dart new file mode 100644 index 00000000..e9345d07 --- /dev/null +++ b/pkgs/fixnum/test/test_shared.dart @@ -0,0 +1,8 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:test/test.dart'; + +// ignore: deprecated_member_use +final isIntegerDivisionByZeroException = isA(); From 6c82d8c147d0d8bc91be50eda22e59fad6e41dbb Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 4 Nov 2021 09:29:29 -0700 Subject: [PATCH 087/126] Enable and fix some lints --- pkgs/fixnum/analysis_options.yaml | 36 +++++++++++------------ pkgs/fixnum/lib/src/int32.dart | 14 ++++----- pkgs/fixnum/lib/src/int64.dart | 41 +++++++++----------------- pkgs/fixnum/lib/src/intx.dart | 23 ++++++++------- pkgs/fixnum/test/int32_test.dart | 10 +++---- pkgs/fixnum/test/int64_test.dart | 48 ++++++++++++++++--------------- 6 files changed, 81 insertions(+), 91 deletions(-) diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index 8083db4c..d24df6d7 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -5,37 +5,37 @@ analyzer: linter: rules: - - avoid_function_literals_in_foreach_calls + - avoid_catching_errors + - avoid_dynamic_calls + - avoid_private_typedef_functions - avoid_returning_null - avoid_unused_constructor_parameters - - await_only_futures - - camel_case_types - cancel_subscriptions + - cascade_invocations - comment_references - #- constant_identifier_names - - control_flow_in_finally - directives_ordering - - empty_statements - - hash_and_equals - - implementation_imports - invariant_booleans - - iterable_contains_unrelated_type - - list_remove_unrelated_type + - join_return_with_assignment + - lines_longer_than_80_chars + - missing_whitespace_between_adjacent_strings - no_adjacent_strings_in_list - - non_constant_identifier_names + - no_runtimeType_toString - only_throw_errors - - overridden_fields - package_api_docs - - package_names - - package_prefixed_library_names + - prefer_asserts_in_initializer_lists - prefer_const_constructors - - prefer_initializing_formals + - prefer_const_declarations + - prefer_expression_function_bodies - prefer_interpolation_to_compose_strings - - prefer_typing_uninitialized_variables + - prefer_relative_imports + - sort_pub_dependencies - test_types_in_equals - throw_in_finally - - unnecessary_brace_in_string_interps - - unnecessary_getters_setters + - type_annotate_public_apis - unnecessary_lambdas - unnecessary_null_aware_assignments + - unnecessary_parenthesis + - unnecessary_raw_strings - unnecessary_statements + - use_is_even_rather_than_modulo + - use_string_buffers diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index 48263b7c..760bc227 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -63,7 +63,7 @@ class Int32 implements IntX { if (digit < 0 || digit >= radix) { throw FormatException('Non-radix code unit: $c'); } - x = ((x * radix) + digit) as Int32; + x = (x * radix) + digit as Int32; } return x; } @@ -93,12 +93,12 @@ class Int32 implements IntX { // The code below removes unnecessary &'s and uses a // trick to remove one instruction in the first line. - i -= ((i >> 1) & 0x55555555); + i -= (i >> 1) & 0x55555555; i = (i & 0x33333333) + ((i >> 2) & 0x33333333); - i = ((i + (i >> 4)) & 0x0F0F0F0F); - i += (i >> 8); - i += (i >> 16); - return (i & 0x0000003F); + i = (i + (i >> 4)) & 0x0F0F0F0F; + i += i >> 8; + i += i >> 16; + return i & 0x0000003F; } // Assumes i is <= 32-bit @@ -198,7 +198,7 @@ class Int32 implements IntX { var t = toInt64(); return (t - (t ~/ other) * other).toInt32(); } - return (this - (this ~/ other) * other) as Int32; + return this - (this ~/ other) * other as Int32; } @override diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index e9207d5d..307a08f2 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -59,9 +59,8 @@ class Int64 implements IntX { /// Parses a [String] in a given [radix] between 2 and 36 and returns an /// [Int64]. - static Int64 parseRadix(String s, int radix) { - return _parseRadix(s, Int32._validateRadix(radix)); - } + static Int64 parseRadix(String s, int radix) => + _parseRadix(s, Int32._validateRadix(radix)); static Int64 _parseRadix(String s, int radix) { int i = 0; @@ -336,9 +335,7 @@ class Int64 implements IntX { } @override - Int64 operator ~() { - return Int64._masked(~_l, ~_m, ~_h); - } + Int64 operator ~() => Int64._masked(~_l, ~_m, ~_h); @override Int64 operator <<(int n) { @@ -384,7 +381,7 @@ class Int64 implements IntX { if (negative && _MASK > _MASK2) { // Add extra one bits on the left so the sign gets shifted into the wider // lower words. - a2 += (_MASK - _MASK2); + a2 += _MASK - _MASK2; } if (n < _BITS) { @@ -546,9 +543,7 @@ class Int64 implements IntX { } @override - Int64 abs() { - return isNegative ? -this : this; - } + Int64 abs() => isNegative ? -this : this; @override Int64 clamp(Object lowerLimit, Object upperLimit) { @@ -667,9 +662,7 @@ class Int64 implements IntX { /// Returns an [Int32] containing the low 32 bits of this [Int64]. @override - Int32 toInt32() { - return Int32(((_m & 0x3ff) << _BITS) | _l); - } + Int32 toInt32() => Int32(((_m & 0x3ff) << _BITS) | _l); /// Returns `this`. @override @@ -695,19 +688,15 @@ class Int64 implements IntX { /// Returns the digits of `this` when interpreted as an unsigned 64-bit value. @pragma('dart2js:noInline') - String toStringUnsigned() { - return _toRadixStringUnsigned(10, _l, _m, _h, ''); - } + String toStringUnsigned() => _toRadixStringUnsigned(10, _l, _m, _h, ''); @pragma('dart2js:noInline') - String toRadixStringUnsigned(int radix) { - return _toRadixStringUnsigned(Int32._validateRadix(radix), _l, _m, _h, ''); - } + String toRadixStringUnsigned(int radix) => + _toRadixStringUnsigned(Int32._validateRadix(radix), _l, _m, _h, ''); @override - String toRadixString(int radix) { - return _toRadixString(Int32._validateRadix(radix)); - } + String toRadixString(int radix) => + _toRadixString(Int32._validateRadix(radix)); String _toRadixString(int radix) { int d0 = _l; @@ -870,9 +859,7 @@ class Int64 implements IntX { 36 * 36 * 36 ]; - String toDebugString() { - return 'Int64[_l=$_l, _m=$_m, _h=$_h]'; - } + String toDebugString() => 'Int64[_l=$_l, _m=$_m, _h=$_h]'; static Int64 _masked(int a0, int a1, int a2) => Int64._bits(_MASK & a0, _MASK & a1, _MASK2 & a2); @@ -884,9 +871,7 @@ class Int64 implements IntX { return _masked(diff0, diff1, diff2); } - static Int64 _negate(int b0, int b1, int b2) { - return _sub(0, 0, 0, b0, b1, b2); - } + static Int64 _negate(int b0, int b1, int b2) => _sub(0, 0, 0, b0, b1, b2); String _hexDigit(int digit) => '0123456789ABCDEF'[digit]; diff --git a/pkgs/fixnum/lib/src/intx.dart b/pkgs/fixnum/lib/src/intx.dart index 4c0dd61d..bedb3e1a 100644 --- a/pkgs/fixnum/lib/src/intx.dart +++ b/pkgs/fixnum/lib/src/intx.dart @@ -120,31 +120,33 @@ abstract class IntX implements Comparable { /// for non-negative (unsigned) values. Negative values are complemented to /// return the bit position of the first bit that differs from the sign bit. /// - /// To find the the number of bits needed to store the value as a signed value, - /// add one, i.e. use `x.bitLength + 1`. + /// To find the the number of bits needed to store the value as a signed + /// value, add one, i.e. use `x.bitLength + 1`. int get bitLength; /// Returns the number of high-order zeros in this integer's bit /// representation. int numberOfLeadingZeros(); - /// Returns the number of low-order zeros in this integer's bit representation. + /// Returns the number of low-order zeros in this integer's bit + /// representation. int numberOfTrailingZeros(); /// Returns the least significant [width] bits of this integer, extending the - /// highest retained bit to the sign. This is the same as truncating the value - /// to fit in [width] bits using an signed 2-s complement representation. The - /// returned value has the same bit value in all positions higher than [width]. + /// highest retained bit to the sign. This is the same as truncating the + /// value to fit in [width] bits using an signed 2-s complement + /// representation. The returned value has the same bit value in all positions + /// higher than [width]. /// /// If the input value fits in [width] bits without truncation, the result is - /// the same as the input. The minimum width needed to avoid truncation of `x` - /// is `x.bitLength + 1`, i.e. + /// the same as the input. The minimum width needed to avoid truncation of + /// `x` is `x.bitLength + 1`, i.e. /// /// x == x.toSigned(x.bitLength + 1); IntX toSigned(int width); /// Returns the least significant [width] bits of this integer as a - /// non-negative number (i.e. unsigned representation). The returned value has + /// non-negative number (i.e. unsigned representation). The returned value has /// zeros in all bit positions higher than [width]. /// /// If the input fits in [width] bits without truncation, the result is the @@ -189,7 +191,8 @@ abstract class IntX implements Comparable { /// notation; example: `'0xd'`. String toHexString(); - /// Returns a string representing the value of this integer in the given radix. + /// Returns a string representing the value of this integer in the given + /// radix. /// /// [radix] must be an integer in the range 2 .. 16, inclusive. String toRadixString(int radix); diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 23633130..5e72c7ba 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -85,10 +85,10 @@ void main() { expect(n3 * n3, Int32(1522756)); expect(n3 * n2, Int32(-12186984)); expect(Int32(0x12345678) * Int32(0x22222222), Int32(-899716112)); - expect((Int32(123456789) * Int32(987654321)), Int32(-67153019)); + expect(Int32(123456789) * Int32(987654321), Int32(-67153019)); expect(Int32(0x12345678) * Int64(0x22222222), Int64.fromInts(0x026D60DC, 0xCA5F6BF0)); - expect((Int32(123456789) * 987654321), Int32(-67153019)); + expect(Int32(123456789) * 987654321, Int32(-67153019)); }); test('~/', () { @@ -266,8 +266,8 @@ void main() { }); test('~', () { - expect(~(Int32(0x12345678)), Int32(~0x12345678)); - expect(-(Int32(0x12345678)), Int64(-0x12345678)); + expect(~Int32(0x12345678), Int32(~0x12345678)); + expect(-Int32(0x12345678), Int64(-0x12345678)); }); }); @@ -294,7 +294,7 @@ void main() { expect(Int32(0x12345678).shiftRightUnsigned(33), Int32.ZERO); expect(Int32(-42).shiftRightUnsigned(32), Int32.ZERO); expect(Int32(-42).shiftRightUnsigned(33), Int32.ZERO); - expect(() => (Int32(17).shiftRightUnsigned(-1)), throwsArgumentError); + expect(() => Int32(17).shiftRightUnsigned(-1), throwsArgumentError); }); }); diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 01c8ecab..ac952c10 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -44,15 +44,17 @@ void main() { }); }); - void argumentErrorTest(name, op, [receiver = Int64.ONE]) { - Matcher throwsArgumentErrorMentioning(String substring) => - throwsA((e) => e is ArgumentError && '$e'.contains(substring)); - + void argumentErrorTest( + Object Function(Int64, Object) op, [ + Int64 receiver = Int64.ONE, + ]) { expect( - () => op(receiver, null), - throwsA(isA().having( - (e) => e.toString(), 'should mention Null', contains('Null')))); - expect(() => op(receiver, 'foo'), throwsArgumentErrorMentioning(r'"foo"')); + () => op(receiver, 'foo'), + throwsA( + isA() + .having((p0) => p0.toString(), 'toString', contains('"foo"')), + ), + ); } group('is-tests', () { @@ -116,7 +118,7 @@ void main() { expect(n3 + n4, Int64(-11110)); expect(n5 + n6, Int64.fromInts(0x89ab89ab, 0xcdeff011)); expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE); - argumentErrorTest('+', (a, b) => a + b); + argumentErrorTest((a, b) => a + b); }); test('-', () { @@ -125,7 +127,7 @@ void main() { expect(n3 - n4, Int64(8642)); expect(n5 - n6, Int64.fromInts(0x9abd2345, 0x89ab6789)); expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE); - argumentErrorTest('-', (a, b) => a - b); + argumentErrorTest((a, b) => a - b); }); test('unary -', () { @@ -154,19 +156,19 @@ void main() { Int64.fromInts(0x297e3f7c, 0x1df4d840)); // RHS Int32 - expect((Int64(123456789) * Int32(987654321)), + expect(Int64(123456789) * Int32(987654321), Int64.fromInts(0x1b13114, 0xfbff5385)); - expect((Int64(123456789) * Int32(987654321)), + expect(Int64(123456789) * Int32(987654321), Int64.fromInts(0x1b13114, 0xfbff5385)); // Wraparound - expect((Int64(123456789) * Int64(987654321)), + expect(Int64(123456789) * Int64(987654321), Int64.fromInts(0x1b13114, 0xfbff5385)); expect(Int64.MIN_VALUE * Int64(2), Int64.ZERO); expect(Int64.MIN_VALUE * Int64(1), Int64.MIN_VALUE); expect(Int64.MIN_VALUE * Int64(-1), Int64.MIN_VALUE); - argumentErrorTest('*', (a, b) => a * b); + argumentErrorTest((a, b) => a * b); }); test('~/', () { @@ -243,7 +245,7 @@ void main() { expect(Int64.MIN_VALUE ~/ Int64(-1), Int64.MIN_VALUE); expect(() => Int64(17) ~/ Int64.ZERO, throwsA(isIntegerDivisionByZeroException)); - argumentErrorTest('~/', (a, b) => a ~/ b); + argumentErrorTest((a, b) => a ~/ b); }); test('%', () { @@ -283,7 +285,7 @@ void main() { Int64(-0x12345678.remainder(0x22))); expect(Int32(0x12345678).remainder(Int64(0x22)), Int64(0x12345678.remainder(0x22))); - argumentErrorTest('%', (a, b) => a % b); + argumentErrorTest((a, b) => a % b); }); test('clamp', () { @@ -360,7 +362,7 @@ void main() { expect(largePosPlusOne < largePos, false); expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true); expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false); - argumentErrorTest('<', (a, b) => a < b); + argumentErrorTest((a, b) => a < b); }); test('<=', () { @@ -379,7 +381,7 @@ void main() { expect(largePosPlusOne <= largePos, false); expect(Int64.MIN_VALUE <= Int64.MAX_VALUE, true); expect(Int64.MAX_VALUE <= Int64.MIN_VALUE, false); - argumentErrorTest('<=', (a, b) => a <= b); + argumentErrorTest((a, b) => a <= b); }); test('==', () { @@ -426,7 +428,7 @@ void main() { expect(largePosPlusOne >= largePos, true); expect(Int64.MIN_VALUE >= Int64.MAX_VALUE, false); expect(Int64.MAX_VALUE >= Int64.MIN_VALUE, true); - argumentErrorTest('>=', (a, b) => a >= b); + argumentErrorTest((a, b) => a >= b); }); test('>', () { @@ -447,7 +449,7 @@ void main() { expect(Int64.ZERO > Int64.MIN_VALUE, true); expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false); expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true); - argumentErrorTest('>', (a, b) => a > b); + argumentErrorTest((a, b) => a > b); }); }); @@ -462,21 +464,21 @@ void main() { expect(n1 & n2, Int64(1168)); expect(n3 & n2, Int64(8708)); expect(n4 & n5, Int64(0x1034) << 32); - argumentErrorTest('&', (a, b) => a & b); + argumentErrorTest((a, b) => a & b); }); test('|', () { expect(n1 | n2, Int64(9942)); expect(n3 | n2, Int64(-66)); expect(n4 | n5, Int64(0x9a76) << 32); - argumentErrorTest('|', (a, b) => a | b); + argumentErrorTest((a, b) => a | b); }); test('^', () { expect(n1 ^ n2, Int64(8774)); expect(n3 ^ n2, Int64(-8774)); expect(n4 ^ n5, Int64(0x8a42) << 32); - argumentErrorTest('^', (a, b) => a ^ b); + argumentErrorTest((a, b) => a ^ b); }); test('~', () { From 0aa99899cd53802d327526ba818b66f2919569ca Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Wed, 20 Apr 2022 14:44:58 -0700 Subject: [PATCH 088/126] Switch from homepage to repository in pubspec (dart-lang/fixnum#86) --- pkgs/fixnum/pubspec.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index db8ca05a..4bb77d21 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,10 +1,9 @@ name: fixnum version: 1.0.1-dev - description: >- Library for 32- and 64-bit signed fixed-width integers with consistent behavior between native and JS runtimes. -homepage: https://github.com/dart-lang/fixnum +repository: https://github.com/dart-lang/fixnum environment: sdk: '>=2.12.0 <3.0.0' From 092b10a558195e8c0a97b832214ee7c633b0d57a Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Thu, 12 May 2022 10:09:23 -0700 Subject: [PATCH 089/126] prep for publishing 1.0.1 (dart-lang/fixnum#89) --- pkgs/fixnum/CHANGELOG.md | 5 ++++- pkgs/fixnum/README.md | 8 ++++---- pkgs/fixnum/analysis_options.yaml | 1 + pkgs/fixnum/pubspec.yaml | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index faed6596..441c4665 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,4 +1,7 @@ -## 1.0.1-dev +## 1.0.1 + +* Switch to using `package:lints`. +* Populate the pubspec `repository` field. ## 1.0.0 diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index 2f79b60c..33bdcc0f 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -1,8 +1,8 @@ -A fixed-width 32- and 64- bit integer library for Dart. - +[![Dart CI](https://github.com/dart-lang/fixnum/actions/workflows/test-package.yml/badge.svg)](https://github.com/dart-lang/fixnum/actions/workflows/test-package.yml) [![Pub](https://img.shields.io/pub/v/fixnum.svg)](https://pub.dev/packages/fixnum) -[![Dart CI](https://github.com/dart-lang/fixnum/workflows/Dart%20CI/badge.svg)](https://github.com/dart-lang/fixnum/actions?query=workflow%3A%22Dart+CI%22+branch%3Amaster) -[![Coverage Status](https://img.shields.io/coveralls/dart-lang/fixnum.svg)](https://coveralls.io/r/dart-lang/fixnum) +[![package publisher](https://img.shields.io/pub/publisher/fixnum.svg)](https://pub.dev/packages/fixnum/publisher) + +A fixed-width 32- and 64- bit integer library for Dart. Provides data types for signed 32- and 64-bit integers. The integer implementations in this library are designed to work identically diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index d24df6d7..7b7d7ce5 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -1,4 +1,5 @@ include: package:lints/recommended.yaml + analyzer: strong-mode: implicit-casts: false diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 4bb77d21..73536360 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 1.0.1-dev +version: 1.0.1 description: >- Library for 32- and 64-bit signed fixed-width integers with consistent behavior between native and JS runtimes. From 339a9f35bc795fc897367ba08c0b4e12d2e51363 Mon Sep 17 00:00:00 2001 From: Michael Thomsen Date: Thu, 2 Jun 2022 16:12:44 +0200 Subject: [PATCH 090/126] Remove old language version markers (dart-lang/fixnum#90) --- pkgs/fixnum/test/all_tests.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkgs/fixnum/test/all_tests.dart b/pkgs/fixnum/test/all_tests.dart index 3a1ca1ba..a4e2e749 100644 --- a/pkgs/fixnum/test/all_tests.dart +++ b/pkgs/fixnum/test/all_tests.dart @@ -1,9 +1,6 @@ // Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// -// TODO: Remove https://github.com/dart-lang/sdk/issues/43605 -// @dart=2.11 import 'int32_test.dart' as int32_test; import 'int64_test.dart' as int64_test; From 81987c1a7fe9681c599145321cf6b691ac5dea76 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Mon, 25 Jul 2022 13:29:46 -0700 Subject: [PATCH 091/126] Remove deprecated experimental invariant_booleans lint rule (dart-lang/fixnum#91) --- pkgs/fixnum/analysis_options.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index 7b7d7ce5..51df836d 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -15,7 +15,6 @@ linter: - cascade_invocations - comment_references - directives_ordering - - invariant_booleans - join_return_with_assignment - lines_longer_than_80_chars - missing_whitespace_between_adjacent_strings From d147bb59072074f185ab6d65cc844bc5d65793a0 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Thu, 10 Nov 2022 09:45:50 -0800 Subject: [PATCH 092/126] blast_repo fixes (dart-lang/fixnum#94) Dependabot GitHub Action --- pkgs/fixnum/.github/dependabot.yml | 9 +++++++++ pkgs/fixnum/.github/workflows/test-package.yml | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 pkgs/fixnum/.github/dependabot.yml diff --git a/pkgs/fixnum/.github/dependabot.yml b/pkgs/fixnum/.github/dependabot.yml new file mode 100644 index 00000000..1603cdd9 --- /dev/null +++ b/pkgs/fixnum/.github/dependabot.yml @@ -0,0 +1,9 @@ +# Dependabot configuration file. +# See https://docs.github.com/en/code-security/dependabot/dependabot-version-updates +version: 2 + +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index cdc25d95..68f255c7 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,8 +22,8 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v1.0 + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: ${{ matrix.sdk }} - id: install @@ -49,8 +49,8 @@ jobs: os: [ubuntu-latest] sdk: [2.12.0, dev] steps: - - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v1.0 + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: ${{ matrix.sdk }} - id: install From d00e06a834dda33026344a4f1f69bc8ac65d6d9b Mon Sep 17 00:00:00 2001 From: "Lasse R.H. Nielsen" Date: Wed, 23 Nov 2022 17:29:06 +0100 Subject: [PATCH 093/126] Add `tryParse` methods. (dart-lang/fixnum#96) * Add `tryParse` methods. Optimize some methods that were not highly optimized, in particular ones related to parsing. --- pkgs/fixnum/CHANGELOG.md | 8 ++ pkgs/fixnum/lib/src/int32.dart | 177 ++++++++++++++++++++----- pkgs/fixnum/lib/src/int64.dart | 215 +++++++++++++++++++++---------- pkgs/fixnum/lib/src/intx.dart | 9 +- pkgs/fixnum/pubspec.yaml | 2 +- pkgs/fixnum/test/int64_test.dart | 22 +++- 6 files changed, 329 insertions(+), 104 deletions(-) diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 441c4665..b8b69ace 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,3 +1,11 @@ +## 1.1.0 + +* Add `tryParseRadix`, `tryParseInt` and `tryParseHex` static methods + to both `Int32` and `Int64`. +* Document exception and overflow behavior of parse functions, + and of `toHexString`. +* Make `Int32` parse functions consistent with documentation (accept + leading minus sign, do not accept empty inputs). ## 1.0.1 * Switch to using `package:lints`. diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index 760bc227..15e9f6f5 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -28,51 +28,164 @@ class Int32 implements IntX { // Hex digit char codes static const int _CC_0 = 48; // '0'.codeUnitAt(0) - static const int _CC_9 = 57; // '9'.codeUnitAt(0) static const int _CC_a = 97; // 'a'.codeUnitAt(0) - static const int _CC_z = 122; // 'z'.codeUnitAt(0) - static const int _CC_A = 65; // 'A'.codeUnitAt(0) - static const int _CC_Z = 90; // 'Z'.codeUnitAt(0) + // Mask to 32-bits. + static const int _MASK_U32 = 0xFFFFFFFF; + + /// Converts radix digits into their numeric values. + /// + /// Converts the characters `0`-`9` into the values 0 through 9, + /// and the letters `a`-`z` or `A`-`Z` into values 10 through 35, + /// and return that value. + /// Any other character returns a value above 35, which means it's + /// not a valid digit in any radix in the range 2 through 36. static int _decodeDigit(int c) { - if (c >= _CC_0 && c <= _CC_9) { - return c - _CC_0; - } else if (c >= _CC_a && c <= _CC_z) { - return c - _CC_a + 10; - } else if (c >= _CC_A && c <= _CC_Z) { - return c - _CC_A + 10; + int digit = c ^ _CC_0; + if (digit < 10) return digit; + int letter = (c | 0x20) - _CC_a; + if (letter >= 0) { + // Returns values above 36 for invalid digits. + // The value is checked against the actual radix where the return + // value is used, so this is safe. + return letter + 10; } else { - return -1; // bad char code + return 255; // Never a valid radix. } } - static int _validateRadix(int radix) { - if (2 <= radix && radix <= 36) return radix; - throw RangeError.range(radix, 2, 36, 'radix'); - } + static int _validateRadix(int radix) => + RangeError.checkValueInInterval(radix, 2, 36, 'radix'); + + /// Parses [source] in a given [radix] between 2 and 36. + /// + /// Returns an [Int32] with the numerical value of [source]. + /// If the numerical value of [source] does not fit + /// in a signed 32 bit integer, + /// the numerical value is truncated to the lowest 32 bits + /// of the value's binary representation, + /// interpreted as a 32-bit two's complement integer. + /// + /// The [source] string must contain a sequence of base-[radix] + /// digits (using letters from `a` to `z` as digits with values 10 through + /// 25 for radixes above 10), possibly prefixed by a `-` sign. + /// + /// Throws a [FormatException] if the input is not a valid + /// integer numeral in base [radix]. + static Int32 parseRadix(String source, int radix) => + _parseRadix(source, _validateRadix(radix), true)!; + + /// Parses [source] in a given [radix] between 2 and 36. + /// + /// Returns an [Int32] with the numerical value of [source]. + /// If the numerical value of [source] does not fit + /// in a signed 32 bit integer, + /// the numerical value is truncated to the lowest 32 bits + /// of the value's binary representation, + /// interpreted as a 32-bit two's complement integer. + /// + /// The [source] string must contain a sequence of base-[radix] + /// digits (using letters from `a` to `z` as digits with values 10 through + /// 25 for radixes above 10), possibly prefixed by a `-` sign. + /// + /// Throws a [FormatException] if the input is not a valid + /// integer numeral in base [radix]. + static Int32? tryParseRadix(String source, int radix) => + _parseRadix(source, _validateRadix(radix), false); - /// Parses a [String] in a given [radix] between 2 and 16 and returns an - /// [Int32]. // TODO(rice) - Make this faster by converting several digits at once. - static Int32 parseRadix(String s, int radix) { - _validateRadix(radix); - var x = ZERO; - for (var i = 0; i < s.length; i++) { - var c = s.codeUnitAt(i); + static Int32? _parseRadix(String s, int radix, bool throwOnError) { + var index = 0; + var negative = false; + if (s.startsWith('-')) { + negative = true; + index = 1; + } + if (index == s.length) { + if (!throwOnError) return null; + throw FormatException('No digits', s, index); + } + var result = 0; + for (; index < s.length; index++) { + var c = s.codeUnitAt(index); var digit = _decodeDigit(c); - if (digit < 0 || digit >= radix) { - throw FormatException('Non-radix code unit: $c'); + if (digit < radix) { + /// Doesn't matter whether the result is unsigned + /// or signed (as on the web), only the bits matter + /// to the [Int32.new] constructor. + result = (result * radix + digit) & _MASK_U32; + } else { + if (!throwOnError) return null; + throw FormatException('Non radix code unit', s, index); } - x = (x * radix) + digit as Int32; } - return x; + if (negative) result = -result; + return Int32(result); } - /// Parses a decimal [String] and returns an [Int32]. - static Int32 parseInt(String s) => Int32(int.parse(s)); - - /// Parses a hexadecimal [String] and returns an [Int32]. - static Int32 parseHex(String s) => parseRadix(s, 16); + /// Parses [source] as a decimal numeral. + /// + /// Returns an [Int32] with the numerical value of [source]. + /// If the numerical value of [source] does not fit + /// in a signed 32 bit integer, + /// the numerical value is truncated to the lowest 32 bits + /// of the value's binary representation, + /// interpreted as a 32-bit two's complement integer. + /// + /// The [source] string must contain a sequence of digits (`0`-`9`), + /// possibly prefixed by a `-` sign. + /// + /// Throws a [FormatException] if the input is not a valid + /// decimal integer numeral. + static Int32 parseInt(String source) => _parseRadix(source, 10, true)!; + + /// Parses [source] as a decimal numeral. + /// + /// Returns an [Int32] with the numerical value of [source]. + /// If the numerical value of [source] does not fit + /// in a signed 32 bit integer, + /// the numerical value is truncated to the lowest 32 bits + /// of the value's binary representation, + /// interpreted as a 32-bit two's complement integer. + /// + /// The [source] string must contain a sequence of digits (`0`-`9`), + /// possibly prefixed by a `-` sign. + /// + /// Throws a [FormatException] if the input is not a valid + /// decimal integer numeral. + static Int32? tryParseInt(String source) => _parseRadix(source, 10, false); + + /// Parses [source] as a hexadecimal numeral. + /// + /// Returns an [Int32] with the numerical value of [source]. + /// If the numerical value of [source] does not fit + /// in a signed 32 bit integer, + /// the numerical value is truncated to the lowest 32 bits + /// of the value's binary representation, + /// interpreted as a 32-bit two's complement integer. + /// + /// The [source] string must contain a sequence of hexadecimal + /// digits (`0`-`9`, `a`-`f` or `A`-`F`), possibly prefixed by a `-` sign. + /// + /// Returns `null` if the input is not a valid + /// hexadecimal integer numeral. + static Int32 parseHex(String source) => _parseRadix(source, 16, true)!; + + /// Parses [source] as a hexadecimal numeral. + /// + /// Returns an [Int32] with the numerical value of [source]. + /// If the numerical value of [source] does not fit + /// in a signed 32 bit integer, + /// the numerical value is truncated to the lowest 32 bits + /// of the value's binary representation, + /// interpreted as a 32-bit two's complement integer. + /// + /// The [source] string must contain a sequence of hexadecimal + /// digits (`0`-`9`, `a`-`f` or `A`-`F`), possibly prefixed by a `-` sign. + /// + /// Returns `null` if the input is not a valid + /// hexadecimal integer numeral. + static Int32? tryParseHex(String source) => _parseRadix(source, 16, false); // Assumes i is <= 32-bit. static int _bitCount(int i) { @@ -130,7 +243,7 @@ class Int32 implements IntX { } else if (val is int) { return val; } - throw ArgumentError(val); + throw ArgumentError.value(val, 'other', 'Not an int, Int32 or Int64'); } // The +, -, * , &, |, and ^ operaters deal with types as follows: diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index 307a08f2..23cb958b 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -57,45 +57,76 @@ class Int64 implements IntX { /// is performed. const Int64._bits(this._l, this._m, this._h); - /// Parses a [String] in a given [radix] between 2 and 36 and returns an - /// [Int64]. - static Int64 parseRadix(String s, int radix) => - _parseRadix(s, Int32._validateRadix(radix)); - - static Int64 _parseRadix(String s, int radix) { + /// Parses [source] in a given [radix] between 2 and 36. + /// + /// Returns an [Int64] with the numerical value of [source]. + /// If the numerical value of [source] does not fit + /// in a signed 64 bit integer, + /// the numerical value is truncated to the lowest 64 bits + /// of the value's binary representation, + /// interpreted as a 64-bit two's complement integer. + /// + /// The [source] string must contain a sequence of base-[radix] + /// digits (using letters from `a` to `z` as digits with values 10 through + /// 25 for radixes above 10), possibly prefixed by a `-` sign. + /// + /// Throws a [FormatException] if the input is not recognized as a valid + /// integer numeral. + static Int64 parseRadix(String source, int radix) => + _parseRadix(source, Int32._validateRadix(radix), true)!; + + /// Parses [source] in a given [radix] between 2 and 36. + /// + /// Returns an [Int64] with the numerical value of [source]. + /// If the numerical value of [source] does not fit + /// in a signed 64 bit integer, + /// the numerical value is truncated to the lowest 64 bits + /// of the value's binary representation, + /// interpreted as a 64-bit two's complement integer. + /// + /// The [source] string must contain a sequence of base-[radix] + /// digits (using letters from `a` to `z` as digits with values 10 through + /// 25 for radixes above 10), possibly prefixed by a `-` sign. + /// + /// Returns `null` if the input is not recognized as a valid + /// integer numeral. + static Int64? tryParseRadix(String source, int radix) => + _parseRadix(source, Int32._validateRadix(radix), false); + + static Int64? _parseRadix(String s, int radix, bool throwOnError) { int i = 0; bool negative = false; - if (i < s.length && s[0] == '-') { + if (s.startsWith('-')) { negative = true; i++; } - // TODO(https://github.com/dart-lang/sdk/issues/38728). Replace with "if (i - // >= s.length)". - if (!(i < s.length)) { - throw FormatException("No digits in '$s'"); + if (i >= s.length) { + if (!throwOnError) return null; + throw FormatException('No digits', s, i); } int d0 = 0, d1 = 0, d2 = 0; // low, middle, high components. for (; i < s.length; i++) { int c = s.codeUnitAt(i); int digit = Int32._decodeDigit(c); - if (digit < 0 || digit >= radix) { - throw FormatException('Non-radix char code: $c'); + if (digit < radix) { + // [radix] and [digit] are at most 6 bits, component is 22, so we can + // multiply and add within 30 bit temporary values. + d0 = d0 * radix + digit; + int carry = d0 >> _BITS; + d0 = _MASK & d0; + + d1 = d1 * radix + carry; + carry = d1 >> _BITS; + d1 = _MASK & d1; + + d2 = d2 * radix + carry; + d2 = _MASK2 & d2; + } else { + if (!throwOnError) return null; + throw FormatException('Not radix digit', s, i); } - - // [radix] and [digit] are at most 6 bits, component is 22, so we can - // multiply and add within 30 bit temporary values. - d0 = d0 * radix + digit; - int carry = d0 >> _BITS; - d0 = _MASK & d0; - - d1 = d1 * radix + carry; - carry = d1 >> _BITS; - d1 = _MASK & d1; - - d2 = d2 * radix + carry; - d2 = _MASK2 & d2; } if (negative) return _negate(d0, d1, d2); @@ -103,11 +134,69 @@ class Int64 implements IntX { return Int64._masked(d0, d1, d2); } - /// Parses a decimal [String] and returns an [Int64]. - static Int64 parseInt(String s) => _parseRadix(s, 10); - - /// Parses a hexadecimal [String] and returns an [Int64]. - static Int64 parseHex(String s) => _parseRadix(s, 16); + /// Parses [source] as a decimal numeral. + /// + /// Returns an [Int64] with the numerical value of [source]. + /// If the numerical value of [source] does not fit + /// in a signed 64 bit integer, + /// the numerical value is truncated to the lowest 64 bits + /// of the value's binary representation, + /// interpreted as a 64-bit two's complement integer. + /// + /// The [source] string must contain a sequence of digits (`0`-`9`), + /// possibly prefixed by a `-` sign. + /// + /// Throws a [FormatException] if the input is not a valid + /// decimal integer numeral. + static Int64 parseInt(String source) => _parseRadix(source, 10, true)!; + + /// Parses [source] as a decimal numeral. + /// + /// Returns an [Int64] with the numerical value of [source]. + /// If the numerical value of [source] does not fit + /// in a signed 64 bit integer, + /// the numerical value is truncated to the lowest 64 bits + /// of the value's binary representation, + /// interpreted as a 64-bit two's complement integer. + /// + /// The [source] string must contain a sequence of digits (`0`-`9`), + /// possibly prefixed by a `-` sign. + /// + /// Returns `null` if the input is not a valid + /// decimal integer numeral. + static Int64? tryParseInt(String source) => _parseRadix(source, 10, false); + + /// Parses [source] as a hexadecimal numeral. + /// + /// Returns an [Int64] with the numerical value of [source]. + /// If the numerical value of [source] does not fit + /// in a signed 64 bit integer, + /// the numerical value is truncated to the lowest 64 bits + /// of the value's binary representation, + /// interpreted as a 64-bit two's complement integer. + /// + /// The [source] string must contain a sequence of hexadecimal + /// digits (`0`-`9`, `a`-`f` or `A`-`F`), possibly prefixed by a `-` sign. + /// + /// Throws a [FormatException] if the input is not a valid + /// hexadecimal integer numeral. + static Int64 parseHex(String source) => _parseRadix(source, 16, true)!; + + /// Parses [source] as a hexadecimal numeral. + /// + /// Returns an [Int64] with the numerical value of [source]. + /// If the numerical value of [source] does not fit + /// in a signed 64 bit integer, + /// the numerical value is truncated to the lowest 64 bits + /// of the value's binary representation, + /// interpreted as a 64-bit two's complement integer. + /// + /// The [source] string must contain a sequence of hexadecimal + /// digits (`0`-`9`, `a`-`f` or `A`-`F`), possibly prefixed by a `-` sign. + /// + /// Returns `null` if the input is not a valid + /// hexadecimal integer numeral. + static Int64? tryParseHex(String source) => _parseRadix(source, 16, false); // // Public constructors @@ -135,43 +224,32 @@ class Int64 implements IntX { } factory Int64.fromBytes(List bytes) { - int top = bytes[7] & 0xff; - top <<= 8; - top |= bytes[6] & 0xff; - top <<= 8; - top |= bytes[5] & 0xff; - top <<= 8; - top |= bytes[4] & 0xff; - - int bottom = bytes[3] & 0xff; - bottom <<= 8; - bottom |= bytes[2] & 0xff; - bottom <<= 8; - bottom |= bytes[1] & 0xff; - bottom <<= 8; - bottom |= bytes[0] & 0xff; - - return Int64.fromInts(top, bottom); + // 20 bits into top, 22 into middle and bottom. + var split1 = bytes[5] & 0xFF; + var high = + ((bytes[7] & 0xFF) << 12) | ((bytes[6] & 0xFF) << 4) | (split1 >> 4); + var split2 = bytes[2] & 0xFF; + var middle = (split1 << 18) | + ((bytes[4] & 0xFF) << 10) | + ((bytes[3] & 0xFF) << 2) | + (split2 >> 6); + var low = (split2 << 16) | ((bytes[1] & 0xFF) << 8) | (bytes[0] & 0xFF); + // Top bits from above will be masked off here. + return Int64._masked(low, middle, high); } factory Int64.fromBytesBigEndian(List bytes) { - int top = bytes[0] & 0xff; - top <<= 8; - top |= bytes[1] & 0xff; - top <<= 8; - top |= bytes[2] & 0xff; - top <<= 8; - top |= bytes[3] & 0xff; - - int bottom = bytes[4] & 0xff; - bottom <<= 8; - bottom |= bytes[5] & 0xff; - bottom <<= 8; - bottom |= bytes[6] & 0xff; - bottom <<= 8; - bottom |= bytes[7] & 0xff; - - return Int64.fromInts(top, bottom); + var split1 = bytes[2] & 0xFF; + var high = + ((bytes[0] & 0xFF) << 12) | ((bytes[1] & 0xFF) << 4) | (split1 >> 4); + var split2 = bytes[5] & 0xFF; + var middle = (split1 << 18) | + ((bytes[3] & 0xFF) << 10) | + ((bytes[4] & 0xFF) << 2) | + (split2 >> 6); + var low = (split2 << 16) | ((bytes[6] & 0xFF) << 8) | (bytes[7] & 0xFF); + // Top bits from above will be masked off here. + return Int64._masked(low, middle, high); } /// Constructs an [Int64] from a pair of 32-bit integers having the value @@ -195,7 +273,7 @@ class Int64 implements IntX { } else if (value is Int32) { return value.toInt64(); } - throw ArgumentError.value(value); + throw ArgumentError.value(value, 'other', 'not an int, Int32 or Int64'); } @override @@ -672,7 +750,6 @@ class Int64 implements IntX { @override String toString() => _toRadixString(10); - // TODO(rice) - Make this faster by avoiding arithmetic. @override String toHexString() { if (isZero) return '0'; @@ -861,8 +938,8 @@ class Int64 implements IntX { String toDebugString() => 'Int64[_l=$_l, _m=$_m, _h=$_h]'; - static Int64 _masked(int a0, int a1, int a2) => - Int64._bits(_MASK & a0, _MASK & a1, _MASK2 & a2); + static Int64 _masked(int low, int medium, int high) => + Int64._bits(_MASK & low, _MASK & medium, _MASK2 & high); static Int64 _sub(int a0, int a1, int a2, int b0, int b1, int b2) { int diff0 = a0 - b0; diff --git a/pkgs/fixnum/lib/src/intx.dart b/pkgs/fixnum/lib/src/intx.dart index bedb3e1a..fc06895d 100644 --- a/pkgs/fixnum/lib/src/intx.dart +++ b/pkgs/fixnum/lib/src/intx.dart @@ -188,7 +188,14 @@ abstract class IntX implements Comparable { String toString(); /// Returns a string representing the value of this integer in hexadecimal - /// notation; example: `'0xd'`. + /// notation. + /// + /// Example: `Int64(0xf01d).toHexString()` returns `'F01D'`. + /// + /// The string may interprets the number as *unsigned*, and has no leading + /// minus, even if the value [isNegative]. + /// + /// Example: `Int64(-1).toHexString()` returns `'FFFFFFFFFFFFFFFF'`. String toHexString(); /// Returns a string representing the value of this integer in the given diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 73536360..76099381 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,5 +1,5 @@ name: fixnum -version: 1.0.1 +version: 1.1.0-dev description: >- Library for 32- and 64-bit signed fixed-width integers with consistent behavior between native and JS runtimes. diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index ac952c10..32d7ea9e 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -744,13 +744,15 @@ void main() { check(10); check(1000000000000000000); - check(9223372000000000000); // near Int64.MAX_VALUE, has exact double value + check(9223372036854774784); // Near Int64.MAX_VALUE with exact double value. + check(-9223372036854775808); // Int64.MIN_VALUE. Is exact double. }); group('parse', () { test('parseRadix10', () { void checkInt(int x) { expect(Int64.parseRadix('$x', 10), Int64(x)); + expect(Int64.tryParseRadix('$x', 10), Int64(x)); } checkInt(0); @@ -767,15 +769,22 @@ void main() { checkInt(4294967296); checkInt(-4294967295); checkInt(-4294967296); + expect(() => Int64.parseRadix('xyzzy', -1), throwsArgumentError); expect(() => Int64.parseRadix('plugh', 10), throwsFormatException); expect(() => Int64.parseRadix('', 10), throwsFormatException); expect(() => Int64.parseRadix('-', 10), throwsFormatException); + + expect(() => Int64.tryParseRadix('xyzzy', -1), throwsArgumentError); + expect(Int64.tryParseRadix('plugh', 10), null); + expect(Int64.tryParseRadix('', 10), null); + expect(Int64.tryParseRadix('-', 10), null); }); test('parseHex', () { void checkHex(String hexStr, int h, int l) { expect(Int64.parseHex(hexStr), Int64.fromInts(h, l)); + expect(Int64.tryParseHex(hexStr), Int64.fromInts(h, l)); } checkHex('0', 0, 0); @@ -791,13 +800,18 @@ void main() { checkHex('FFFFFFFFFFF', 0xfff, 0xffffffff); checkHex('FFFFFFFFFFFFFFFE', 0xffffffff, 0xfffffffe); checkHex('FFFFFFFFFFFFFFFF', 0xffffffff, 0xffffffff); + expect(() => Int64.parseHex(''), throwsFormatException); expect(() => Int64.parseHex('-'), throwsFormatException); + + expect(Int64.tryParseHex(''), null); + expect(Int64.tryParseHex('-'), null); }); test('parseRadix', () { void check(String s, int r, String x) { expect(Int64.parseRadix(s, r).toString(), x); + expect(Int64.tryParseRadix(s, r).toString(), x); } check('ghoul', 36, '27699213'); @@ -812,11 +826,17 @@ void main() { expect(() => Int64.parseRadix('0', 37), throwsRangeError); expect(() => Int64.parseRadix('xyzzy', -1), throwsRangeError); expect(() => Int64.parseRadix('xyzzy', 10), throwsFormatException); + + expect(() => Int64.tryParseRadix('0', 1), throwsRangeError); + expect(() => Int64.tryParseRadix('0', 37), throwsRangeError); + expect(() => Int64.tryParseRadix('xyzzy', -1), throwsRangeError); + expect(Int64.tryParseRadix('xyzzy', 10), null); }); test('parseRadixN', () { void check(String s, int r) { expect(Int64.parseRadix(s, r).toRadixString(r), s); + expect(Int64.tryParseRadix(s, r)!.toRadixString(r), s); } check('2ppp111222333', 33); // This value & radix requires three chunks. From 3fe3c3ecb4879dddb7999ac6df8b8bcc49d2a4fe Mon Sep 17 00:00:00 2001 From: "Lasse R.H. Nielsen" Date: Thu, 24 Nov 2022 14:48:06 +0100 Subject: [PATCH 094/126] Split into separate libraries instead of using parts. (dart-lang/fixnum#97) * Split into separate libraries instead of using parts. This is a step towards using conditional imports to have platform optimized implementations. --- pkgs/fixnum/lib/fixnum.dart | 6 +-- pkgs/fixnum/lib/src/int32.dart | 81 +++--------------------------- pkgs/fixnum/lib/src/int64.dart | 27 +++++----- pkgs/fixnum/lib/src/intx.dart | 3 +- pkgs/fixnum/lib/src/utilities.dart | 72 ++++++++++++++++++++++++++ pkgs/fixnum/test/int32_test.dart | 2 +- pkgs/fixnum/test/int64_test.dart | 7 +-- 7 files changed, 104 insertions(+), 94 deletions(-) create mode 100644 pkgs/fixnum/lib/src/utilities.dart diff --git a/pkgs/fixnum/lib/fixnum.dart b/pkgs/fixnum/lib/fixnum.dart index 72f97421..eeb6defe 100644 --- a/pkgs/fixnum/lib/fixnum.dart +++ b/pkgs/fixnum/lib/fixnum.dart @@ -8,6 +8,6 @@ /// identically whether executed on the Dart VM or compiled to JavaScript. library fixnum; -part 'src/intx.dart'; -part 'src/int32.dart'; -part 'src/int64.dart'; +export 'src/int32.dart'; +export 'src/int64.dart'; +export 'src/intx.dart'; diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index 15e9f6f5..8045bc1f 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart @@ -4,7 +4,9 @@ // ignore_for_file: constant_identifier_names -part of fixnum; +import 'int64.dart'; +import 'intx.dart'; +import 'utilities.dart' as u; /// An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1]. /// Arithmetic operations may overflow in order to maintain this range. @@ -26,37 +28,9 @@ class Int32 implements IntX { /// An [Int32] constant equal to 2. static const Int32 TWO = Int32._internal(2); - // Hex digit char codes - static const int _CC_0 = 48; // '0'.codeUnitAt(0) - static const int _CC_a = 97; // 'a'.codeUnitAt(0) - // Mask to 32-bits. static const int _MASK_U32 = 0xFFFFFFFF; - /// Converts radix digits into their numeric values. - /// - /// Converts the characters `0`-`9` into the values 0 through 9, - /// and the letters `a`-`z` or `A`-`Z` into values 10 through 35, - /// and return that value. - /// Any other character returns a value above 35, which means it's - /// not a valid digit in any radix in the range 2 through 36. - static int _decodeDigit(int c) { - int digit = c ^ _CC_0; - if (digit < 10) return digit; - int letter = (c | 0x20) - _CC_a; - if (letter >= 0) { - // Returns values above 36 for invalid digits. - // The value is checked against the actual radix where the return - // value is used, so this is safe. - return letter + 10; - } else { - return 255; // Never a valid radix. - } - } - - static int _validateRadix(int radix) => - RangeError.checkValueInInterval(radix, 2, 36, 'radix'); - /// Parses [source] in a given [radix] between 2 and 36. /// /// Returns an [Int32] with the numerical value of [source]. @@ -73,7 +47,7 @@ class Int32 implements IntX { /// Throws a [FormatException] if the input is not a valid /// integer numeral in base [radix]. static Int32 parseRadix(String source, int radix) => - _parseRadix(source, _validateRadix(radix), true)!; + _parseRadix(source, u.validateRadix(radix), true)!; /// Parses [source] in a given [radix] between 2 and 36. /// @@ -91,7 +65,7 @@ class Int32 implements IntX { /// Throws a [FormatException] if the input is not a valid /// integer numeral in base [radix]. static Int32? tryParseRadix(String source, int radix) => - _parseRadix(source, _validateRadix(radix), false); + _parseRadix(source, u.validateRadix(radix), false); // TODO(rice) - Make this faster by converting several digits at once. static Int32? _parseRadix(String s, int radix, bool throwOnError) { @@ -108,7 +82,7 @@ class Int32 implements IntX { var result = 0; for (; index < s.length; index++) { var c = s.codeUnitAt(index); - var digit = _decodeDigit(c); + var digit = u.decodeDigit(c); if (digit < radix) { /// Doesn't matter whether the result is unsigned /// or signed (as on the web), only the bits matter @@ -187,45 +161,6 @@ class Int32 implements IntX { /// hexadecimal integer numeral. static Int32? tryParseHex(String source) => _parseRadix(source, 16, false); - // Assumes i is <= 32-bit. - static int _bitCount(int i) { - // See "Hacker's Delight", section 5-1, "Counting 1-Bits". - - // The basic strategy is to use "divide and conquer" to - // add pairs (then quads, etc.) of bits together to obtain - // sub-counts. - // - // A straightforward approach would look like: - // - // i = (i & 0x55555555) + ((i >> 1) & 0x55555555); - // i = (i & 0x33333333) + ((i >> 2) & 0x33333333); - // i = (i & 0x0F0F0F0F) + ((i >> 4) & 0x0F0F0F0F); - // i = (i & 0x00FF00FF) + ((i >> 8) & 0x00FF00FF); - // i = (i & 0x0000FFFF) + ((i >> 16) & 0x0000FFFF); - // - // The code below removes unnecessary &'s and uses a - // trick to remove one instruction in the first line. - - i -= (i >> 1) & 0x55555555; - i = (i & 0x33333333) + ((i >> 2) & 0x33333333); - i = (i + (i >> 4)) & 0x0F0F0F0F; - i += i >> 8; - i += i >> 16; - return i & 0x0000003F; - } - - // Assumes i is <= 32-bit - static int _numberOfLeadingZeros(int i) { - i |= i >> 1; - i |= i >> 2; - i |= i >> 4; - i |= i >> 8; - i |= i >> 16; - return _bitCount(~i); - } - - static int _numberOfTrailingZeros(int i) => _bitCount((i & -i) - 1); - // The internal value, kept in the range [MIN_VALUE, MAX_VALUE]. final int _i; @@ -482,10 +417,10 @@ class Int32 implements IntX { } @override - int numberOfLeadingZeros() => _numberOfLeadingZeros(_i); + int numberOfLeadingZeros() => u.numberOfLeadingZeros(_i); @override - int numberOfTrailingZeros() => _numberOfTrailingZeros(_i); + int numberOfTrailingZeros() => u.numberOfTrailingZeros(_i); @override Int32 toSigned(int width) { diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index 23cb958b..b0485a18 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -9,7 +9,9 @@ // // ignore_for_file: omit_local_variable_types -part of fixnum; +import 'int32.dart'; +import 'intx.dart'; +import 'utilities.dart' as u; /// An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1]. /// Arithmetic operations may overflow in order to maintain this range. @@ -73,7 +75,7 @@ class Int64 implements IntX { /// Throws a [FormatException] if the input is not recognized as a valid /// integer numeral. static Int64 parseRadix(String source, int radix) => - _parseRadix(source, Int32._validateRadix(radix), true)!; + _parseRadix(source, u.validateRadix(radix), true)!; /// Parses [source] in a given [radix] between 2 and 36. /// @@ -91,7 +93,7 @@ class Int64 implements IntX { /// Returns `null` if the input is not recognized as a valid /// integer numeral. static Int64? tryParseRadix(String source, int radix) => - _parseRadix(source, Int32._validateRadix(radix), false); + _parseRadix(source, u.validateRadix(radix), false); static Int64? _parseRadix(String s, int radix, bool throwOnError) { int i = 0; @@ -109,7 +111,7 @@ class Int64 implements IntX { int d0 = 0, d1 = 0, d2 = 0; // low, middle, high components. for (; i < s.length; i++) { int c = s.codeUnitAt(i); - int digit = Int32._decodeDigit(c); + int digit = u.decodeDigit(c); if (digit < radix) { // [radix] and [digit] are at most 6 bits, component is 22, so we can // multiply and add within 30 bit temporary values. @@ -636,11 +638,11 @@ class Int64 implements IntX { /// between 0 and 64. @override int numberOfLeadingZeros() { - int b2 = Int32._numberOfLeadingZeros(_h); + int b2 = u.numberOfLeadingZeros(_h); if (b2 == 32) { - int b1 = Int32._numberOfLeadingZeros(_m); + int b1 = u.numberOfLeadingZeros(_m); if (b1 == 32) { - return Int32._numberOfLeadingZeros(_l) + 32; + return u.numberOfLeadingZeros(_l) + 32; } else { return b1 + _BITS2 - (32 - _BITS); } @@ -653,17 +655,17 @@ class Int64 implements IntX { /// between 0 and 64. @override int numberOfTrailingZeros() { - int zeros = Int32._numberOfTrailingZeros(_l); + int zeros = u.numberOfTrailingZeros(_l); if (zeros < 32) { return zeros; } - zeros = Int32._numberOfTrailingZeros(_m); + zeros = u.numberOfTrailingZeros(_m); if (zeros < 32) { return _BITS + zeros; } - zeros = Int32._numberOfTrailingZeros(_h); + zeros = u.numberOfTrailingZeros(_h); if (zeros < 32) { return _BITS01 + zeros; } @@ -769,11 +771,10 @@ class Int64 implements IntX { @pragma('dart2js:noInline') String toRadixStringUnsigned(int radix) => - _toRadixStringUnsigned(Int32._validateRadix(radix), _l, _m, _h, ''); + _toRadixStringUnsigned(u.validateRadix(radix), _l, _m, _h, ''); @override - String toRadixString(int radix) => - _toRadixString(Int32._validateRadix(radix)); + String toRadixString(int radix) => _toRadixString(u.validateRadix(radix)); String _toRadixString(int radix) { int d0 = _l; diff --git a/pkgs/fixnum/lib/src/intx.dart b/pkgs/fixnum/lib/src/intx.dart index fc06895d..d51a5835 100644 --- a/pkgs/fixnum/lib/src/intx.dart +++ b/pkgs/fixnum/lib/src/intx.dart @@ -2,7 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of fixnum; +import 'int32.dart'; +import 'int64.dart'; /// A fixed-precision integer. abstract class IntX implements Comparable { diff --git a/pkgs/fixnum/lib/src/utilities.dart b/pkgs/fixnum/lib/src/utilities.dart new file mode 100644 index 00000000..45207d7d --- /dev/null +++ b/pkgs/fixnum/lib/src/utilities.dart @@ -0,0 +1,72 @@ +// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Shared functionality used by multiple classes and their implementations. + +int validateRadix(int radix) => + RangeError.checkValueInInterval(radix, 2, 36, 'radix'); + +/// Converts radix digits into their numeric values. +/// +/// Converts the characters `0`-`9` into the values 0 through 9, +/// and the letters `a`-`z` or `A`-`Z` into values 10 through 35, +/// and return that value. +/// Any other character returns a value above 35, which means it's +/// not a valid digit in any radix in the range 2 through 36. +int decodeDigit(int c) { + // Hex digit char codes + const int _c0 = 48; // '0'.codeUnitAt(0) + const int _ca = 97; // 'a'.codeUnitAt(0) + + int digit = c ^ _c0; + if (digit < 10) return digit; + int letter = (c | 0x20) - _ca; + if (letter >= 0) { + // Returns values above 36 for invalid digits. + // The value is checked against the actual radix where the return + // value is used, so this is safe. + return letter + 10; + } else { + return 255; // Never a valid radix. + } +} + +// Assumes i is <= 32-bit +int numberOfLeadingZeros(int i) { + i |= i >> 1; + i |= i >> 2; + i |= i >> 4; + i |= i >> 8; + i |= i >> 16; + return bitCount(~i); +} + +int numberOfTrailingZeros(int i) => bitCount((i & -i) - 1); + +// Assumes i is <= 32-bit. +int bitCount(int i) { + // See "Hacker's Delight", section 5-1, "Counting 1-Bits". + + // The basic strategy is to use "divide and conquer" to + // add pairs (then quads, etc.) of bits together to obtain + // sub-counts. + // + // A straightforward approach would look like: + // + // i = (i & 0x55555555) + ((i >> 1) & 0x55555555); + // i = (i & 0x33333333) + ((i >> 2) & 0x33333333); + // i = (i & 0x0F0F0F0F) + ((i >> 4) & 0x0F0F0F0F); + // i = (i & 0x00FF00FF) + ((i >> 8) & 0x00FF00FF); + // i = (i & 0x0000FFFF) + ((i >> 16) & 0x0000FFFF); + // + // The code below removes unnecessary &'s and uses a + // trick to remove one instruction in the first line. + + i -= (i >> 1) & 0x55555555; + i = (i & 0x33333333) + ((i >> 2) & 0x33333333); + i = (i + (i >> 4)) & 0x0F0F0F0F; + i += i >> 8; + i += i >> 16; + return i & 0x0000003F; +} diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 5e72c7ba..12d86893 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -214,7 +214,7 @@ void main() { expect(Int32(17), isNot(equals(Int64(16)))); expect(Int32.MIN_VALUE, isNot(equals(Int32.MAX_VALUE))); expect(Int32(17), isNot(equals(18))); - expect(Int32(17) == 17, isTrue); + expect(Int32(17) == 17, isTrue); // ignore: unrelated_type_equality_checks expect(Int32(17), isNot(equals(16))); expect(Int32(17), isNot(equals(Object()))); expect(Int32(17), isNot(equals(null))); diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 32d7ea9e..2a64ac42 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -389,7 +389,7 @@ void main() { expect(Int64(0), isNot(equals(Int64(1)))); expect(Int64(0), equals(Int32(0))); expect(Int64(0), isNot(equals(Int32(1)))); - expect(Int64(0) == 0, isTrue); + expect(Int64(0) == 0, isTrue); // ignore: unrelated_type_equality_checks expect(Int64(0), isNot(equals(1))); expect(Int64(10), isNot(equals(Int64(11)))); expect(Int64(10), equals(Int64(10))); @@ -398,11 +398,12 @@ void main() { expect(Int64(10), equals(Int32(10))); expect(Int64(10), isNot(equals(Int32(9)))); expect(Int64(10), isNot(equals(11))); - expect(Int64(10) == 10, isTrue); + expect(Int64(10) == 10, isTrue); // ignore: unrelated_type_equality_checks expect(Int64(10), isNot(equals(9))); expect(Int64(-10), equals(Int64(-10))); expect(Int64(-10) != Int64(-10), false); - expect(Int64(-10) == -10, isTrue); + expect( + Int64(-10) == -10, isTrue); // ignore: unrelated_type_equality_checks expect(Int64(-10), isNot(equals(-9))); expect(largePos, equals(largePos)); expect(largePos, isNot(equals(largePosPlusOne))); From e39009c2ae8250b551c2b2839140b05bec2dfc3f Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Thu, 8 Dec 2022 07:38:44 -0800 Subject: [PATCH 095/126] rev the sdk min to 2.19.0-0 (dart-lang/fixnum#99) * rev the sdk min to 2.19.0-0 * remove localy use of ignore: unrelated_type_equality_checks * remove localy use of ignore: unrelated_type_equality_checks * Tweak constraint * Revert previous commit Co-authored-by: Michael Thomsen --- pkgs/fixnum/.github/workflows/test-package.yml | 3 ++- pkgs/fixnum/CHANGELOG.md | 4 +++- pkgs/fixnum/pubspec.yaml | 2 +- pkgs/fixnum/test/int32_test.dart | 2 +- pkgs/fixnum/test/int64_test.dart | 7 +++---- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 68f255c7..0fd8a5d6 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -47,7 +47,8 @@ jobs: matrix: # Add macos-latest and/or windows-latest if relevant for this package. os: [ubuntu-latest] - sdk: [2.12.0, dev] + # TODO(devoncarew): Add `2.19.0` to this once that release is stable + sdk: [dev] steps: - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index b8b69ace..a7fcd127 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.1.0 +## 1.1.0-dev * Add `tryParseRadix`, `tryParseInt` and `tryParseHex` static methods to both `Int32` and `Int64`. @@ -6,6 +6,8 @@ and of `toHexString`. * Make `Int32` parse functions consistent with documentation (accept leading minus sign, do not accept empty inputs). +* Update the minimum SDK constraint to 2.19. + ## 1.0.1 * Switch to using `package:lints`. diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 76099381..a380bb49 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -6,7 +6,7 @@ description: >- repository: https://github.com/dart-lang/fixnum environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.19.0-0 <3.0.0' dev_dependencies: lints: ^1.0.0 diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 12d86893..5e72c7ba 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -214,7 +214,7 @@ void main() { expect(Int32(17), isNot(equals(Int64(16)))); expect(Int32.MIN_VALUE, isNot(equals(Int32.MAX_VALUE))); expect(Int32(17), isNot(equals(18))); - expect(Int32(17) == 17, isTrue); // ignore: unrelated_type_equality_checks + expect(Int32(17) == 17, isTrue); expect(Int32(17), isNot(equals(16))); expect(Int32(17), isNot(equals(Object()))); expect(Int32(17), isNot(equals(null))); diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 2a64ac42..32d7ea9e 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -389,7 +389,7 @@ void main() { expect(Int64(0), isNot(equals(Int64(1)))); expect(Int64(0), equals(Int32(0))); expect(Int64(0), isNot(equals(Int32(1)))); - expect(Int64(0) == 0, isTrue); // ignore: unrelated_type_equality_checks + expect(Int64(0) == 0, isTrue); expect(Int64(0), isNot(equals(1))); expect(Int64(10), isNot(equals(Int64(11)))); expect(Int64(10), equals(Int64(10))); @@ -398,12 +398,11 @@ void main() { expect(Int64(10), equals(Int32(10))); expect(Int64(10), isNot(equals(Int32(9)))); expect(Int64(10), isNot(equals(11))); - expect(Int64(10) == 10, isTrue); // ignore: unrelated_type_equality_checks + expect(Int64(10) == 10, isTrue); expect(Int64(10), isNot(equals(9))); expect(Int64(-10), equals(Int64(-10))); expect(Int64(-10) != Int64(-10), false); - expect( - Int64(-10) == -10, isTrue); // ignore: unrelated_type_equality_checks + expect(Int64(-10) == -10, isTrue); expect(Int64(-10), isNot(equals(-9))); expect(largePos, equals(largePos)); expect(largePos, isNot(equals(largePosPlusOne))); From 783e06eb60d876930e86496e80bb7f1b6cce74c1 Mon Sep 17 00:00:00 2001 From: Michael Thomsen Date: Thu, 8 Dec 2022 17:13:54 +0100 Subject: [PATCH 096/126] Change IntegerDivisionByZeroException to UnsupportedError (dart-lang/fixnum#100) --- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- pkgs/fixnum/lib/src/int64.dart | 3 +-- pkgs/fixnum/test/int32_test.dart | 10 ++-------- pkgs/fixnum/test/int64_test.dart | 15 ++++++--------- pkgs/fixnum/test/test_shared.dart | 8 -------- 5 files changed, 11 insertions(+), 29 deletions(-) delete mode 100644 pkgs/fixnum/test/test_shared.dart diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 0fd8a5d6..92912582 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -20,7 +20,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [dev] + sdk: [dev, beta] steps: - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d @@ -48,7 +48,7 @@ jobs: # Add macos-latest and/or windows-latest if relevant for this package. os: [ubuntu-latest] # TODO(devoncarew): Add `2.19.0` to this once that release is stable - sdk: [dev] + sdk: [dev, beta] steps: - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index b0485a18..e4e2ba48 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -971,8 +971,7 @@ class Int64 implements IntX { static Int64 _divide(Int64 a, other, int what) { Int64 b = _promote(other); if (b.isZero) { - // ignore: deprecated_member_use - throw const IntegerDivisionByZeroException(); + throw UnsupportedError('Division by zero'); } if (a.isZero) return ZERO; diff --git a/pkgs/fixnum/test/int32_test.dart b/pkgs/fixnum/test/int32_test.dart index 5e72c7ba..5e6c36ad 100644 --- a/pkgs/fixnum/test/int32_test.dart +++ b/pkgs/fixnum/test/int32_test.dart @@ -5,8 +5,6 @@ import 'package:fixnum/fixnum.dart'; import 'package:test/test.dart'; -import 'test_shared.dart'; - void main() { group('isX tests', () { test('isEven', () { @@ -97,11 +95,7 @@ void main() { expect(Int32(829893893) ~/ Int64(1919), Int32(432461)); expect(Int32(0x12345678) ~/ Int64(0x22), Int32(0x12345678 ~/ 0x22)); expect(Int32(829893893) ~/ 1919, Int32(432461)); - expect( - () => Int32(17) ~/ Int32.ZERO, - // with dart2js, `UnsupportedError` is thrown - // on the VM: IntegerDivisionByZeroException - throwsA(anyOf(isIntegerDivisionByZeroException, isUnsupportedError))); + expect(() => Int32(17) ~/ Int32.ZERO, throwsA(isUnsupportedError)); }); test('%', () { @@ -214,7 +208,7 @@ void main() { expect(Int32(17), isNot(equals(Int64(16)))); expect(Int32.MIN_VALUE, isNot(equals(Int32.MAX_VALUE))); expect(Int32(17), isNot(equals(18))); - expect(Int32(17) == 17, isTrue); + expect(Int32(17) == 17, isTrue); // ignore: unrelated_type_equality_checks expect(Int32(17), isNot(equals(16))); expect(Int32(17), isNot(equals(Object()))); expect(Int32(17), isNot(equals(null))); diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 32d7ea9e..61fb6cfb 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -12,8 +12,6 @@ library int64test; import 'package:fixnum/fixnum.dart'; import 'package:test/test.dart'; -import 'test_shared.dart'; - void main() { group('fromBytes', () { test('fromBytes', () { @@ -237,14 +235,12 @@ void main() { expect(Int64(829893893) ~/ Int32(1919), Int32(432461)); expect(Int64(829893893) ~/ Int64(1919), Int32(432461)); expect(Int64(829893893) ~/ 1919, Int32(432461)); - expect(() => Int64(1) ~/ Int64.ZERO, - throwsA(isIntegerDivisionByZeroException)); + expect(() => Int64(1) ~/ Int64.ZERO, throwsA(isUnsupportedError)); expect( Int64.MIN_VALUE ~/ Int64(2), Int64.fromInts(0xc0000000, 0x00000000)); expect(Int64.MIN_VALUE ~/ Int64(1), Int64.MIN_VALUE); expect(Int64.MIN_VALUE ~/ Int64(-1), Int64.MIN_VALUE); - expect(() => Int64(17) ~/ Int64.ZERO, - throwsA(isIntegerDivisionByZeroException)); + expect(() => Int64(17) ~/ Int64.ZERO, throwsA(isUnsupportedError)); argumentErrorTest((a, b) => a ~/ b); }); @@ -389,7 +385,7 @@ void main() { expect(Int64(0), isNot(equals(Int64(1)))); expect(Int64(0), equals(Int32(0))); expect(Int64(0), isNot(equals(Int32(1)))); - expect(Int64(0) == 0, isTrue); + expect(Int64(0) == 0, isTrue); // ignore: unrelated_type_equality_checks expect(Int64(0), isNot(equals(1))); expect(Int64(10), isNot(equals(Int64(11)))); expect(Int64(10), equals(Int64(10))); @@ -398,11 +394,12 @@ void main() { expect(Int64(10), equals(Int32(10))); expect(Int64(10), isNot(equals(Int32(9)))); expect(Int64(10), isNot(equals(11))); - expect(Int64(10) == 10, isTrue); + expect(Int64(10) == 10, isTrue); // ignore: unrelated_type_equality_checks expect(Int64(10), isNot(equals(9))); expect(Int64(-10), equals(Int64(-10))); expect(Int64(-10) != Int64(-10), false); - expect(Int64(-10) == -10, isTrue); + expect( + Int64(-10) == -10, isTrue); // ignore: unrelated_type_equality_checks expect(Int64(-10), isNot(equals(-9))); expect(largePos, equals(largePos)); expect(largePos, isNot(equals(largePosPlusOne))); diff --git a/pkgs/fixnum/test/test_shared.dart b/pkgs/fixnum/test/test_shared.dart deleted file mode 100644 index e9345d07..00000000 --- a/pkgs/fixnum/test/test_shared.dart +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:test/test.dart'; - -// ignore: deprecated_member_use -final isIntegerDivisionByZeroException = isA(); From 97fa86110d161dfb8f9bf77a1b40be3c1a91ebc5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Jan 2023 09:27:52 -0800 Subject: [PATCH 097/126] Bump actions/checkout from 3.1.0 to 3.2.0 (dart-lang/fixnum#102) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.1.0 to 3.2.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8...755da8c3cf115ac066823e79a1e1788f8940201b) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 92912582..559b14f9 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev, beta] steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: ${{ matrix.sdk }} @@ -50,7 +50,7 @@ jobs: # TODO(devoncarew): Add `2.19.0` to this once that release is stable sdk: [dev, beta] steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: ${{ matrix.sdk }} From b9d030b38c5f102004539723a95adca4e96f70d8 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Mon, 9 Jan 2023 21:31:03 -0800 Subject: [PATCH 098/126] Migrate from no-implicit-casts to strict-casts (dart-lang/fixnum#103) --- pkgs/fixnum/analysis_options.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index 51df836d..2e3ed195 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -1,8 +1,8 @@ include: package:lints/recommended.yaml analyzer: - strong-mode: - implicit-casts: false + language: + strict-casts: true linter: rules: From 14b327257222376af156bcdeb26675f8aaf66eb6 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Mon, 30 Jan 2023 12:50:03 -0800 Subject: [PATCH 099/126] add a publish script; prep to publish 1.1.0 (dart-lang/fixnum#104) * blast_repo fixes auto-publish * rev to 1.1.0 * update the sdk to a stable release * update the sdks we test against --- pkgs/fixnum/.github/workflows/publish.yaml | 14 ++++++++++++++ pkgs/fixnum/.github/workflows/test-package.yml | 5 ++--- pkgs/fixnum/CHANGELOG.md | 3 ++- pkgs/fixnum/README.md | 5 +++++ pkgs/fixnum/lib/src/utilities.dart | 8 ++++---- pkgs/fixnum/pubspec.yaml | 6 +++--- pkgs/fixnum/test/int64_test.dart | 8 ++++---- 7 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 pkgs/fixnum/.github/workflows/publish.yaml diff --git a/pkgs/fixnum/.github/workflows/publish.yaml b/pkgs/fixnum/.github/workflows/publish.yaml new file mode 100644 index 00000000..fcb7ccb8 --- /dev/null +++ b/pkgs/fixnum/.github/workflows/publish.yaml @@ -0,0 +1,14 @@ +# A CI configuration to auto-publish pub packages. + +name: Publish + +on: + pull_request: + branches: [ master ] + push: + tags: [ 'v[0-9]+.[0-9]+.[0-9]+*' ] + +jobs: + publish: + if: ${{ github.repository_owner == 'dart-lang' }} + uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 559b14f9..26fffe21 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -20,7 +20,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [dev, beta] + sdk: [2.19.0, dev] steps: - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d @@ -47,8 +47,7 @@ jobs: matrix: # Add macos-latest and/or windows-latest if relevant for this package. os: [ubuntu-latest] - # TODO(devoncarew): Add `2.19.0` to this once that release is stable - sdk: [dev, beta] + sdk: [2.19.0, dev] steps: - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index a7fcd127..f7312960 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.1.0-dev +## 1.1.0 * Add `tryParseRadix`, `tryParseInt` and `tryParseHex` static methods to both `Int32` and `Int64`. @@ -7,6 +7,7 @@ * Make `Int32` parse functions consistent with documentation (accept leading minus sign, do not accept empty inputs). * Update the minimum SDK constraint to 2.19. +* Update to package:lints 2.0.0. ## 1.0.1 diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index 33bdcc0f..332d9001 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -7,3 +7,8 @@ A fixed-width 32- and 64- bit integer library for Dart. Provides data types for signed 32- and 64-bit integers. The integer implementations in this library are designed to work identically whether executed on the Dart VM or compiled to JavaScript. + +## Publishing automation + +For information about our publishing automation and release process, see +https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. diff --git a/pkgs/fixnum/lib/src/utilities.dart b/pkgs/fixnum/lib/src/utilities.dart index 45207d7d..d603b57f 100644 --- a/pkgs/fixnum/lib/src/utilities.dart +++ b/pkgs/fixnum/lib/src/utilities.dart @@ -16,12 +16,12 @@ int validateRadix(int radix) => /// not a valid digit in any radix in the range 2 through 36. int decodeDigit(int c) { // Hex digit char codes - const int _c0 = 48; // '0'.codeUnitAt(0) - const int _ca = 97; // 'a'.codeUnitAt(0) + const int c0 = 48; // '0'.codeUnitAt(0) + const int ca = 97; // 'a'.codeUnitAt(0) - int digit = c ^ _c0; + int digit = c ^ c0; if (digit < 10) return digit; - int letter = (c | 0x20) - _ca; + int letter = (c | 0x20) - ca; if (letter >= 0) { // Returns values above 36 for invalid digits. // The value is checked against the actual radix where the return diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index a380bb49..3180c25d 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,13 +1,13 @@ name: fixnum -version: 1.1.0-dev +version: 1.1.0 description: >- Library for 32- and 64-bit signed fixed-width integers with consistent behavior between native and JS runtimes. repository: https://github.com/dart-lang/fixnum environment: - sdk: '>=2.19.0-0 <3.0.0' + sdk: '>=2.19.0 <3.0.0' dev_dependencies: - lints: ^1.0.0 + lints: ^2.0.0 test: ^1.16.0 diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index 61fb6cfb..bb5ac7a7 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -714,16 +714,16 @@ void main() { }); test('JavaScript 53-bit integer boundary', () { - Int64 _factorial(Int64 n) { + Int64 factorial(Int64 n) { if (n.isZero) { return Int64(1); } else { - return n * _factorial(n - Int64(1)); + return n * factorial(n - Int64(1)); } } - Int64 fact18 = _factorial(Int64(18)); - Int64 fact17 = _factorial(Int64(17)); + Int64 fact18 = factorial(Int64(18)); + Int64 fact17 = factorial(Int64(17)); expect(fact18 ~/ fact17, Int64(18)); }); From 296435e4c227c21ca2852d9e045f58806256d113 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Feb 2023 08:33:21 -0800 Subject: [PATCH 100/126] Bump dart-lang/setup-dart from 1.3 to 1.4 (dart-lang/fixnum#106) Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.3 to 1.4. - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/6a218f2413a3e78e9087f638a238f6b40893203d...a57a6c04cf7d4840e88432aad6281d1e125f0d46) --- updated-dependencies: - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 26fffe21..5f24e9ab 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -23,7 +23,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: ${{ matrix.sdk }} - id: install @@ -50,7 +50,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: ${{ matrix.sdk }} - id: install From 95b1cf19b42ac952d42221d050a1944900c97eed Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Feb 2023 08:37:39 -0800 Subject: [PATCH 101/126] Bump actions/checkout from 3.2.0 to 3.3.0 (dart-lang/fixnum#105) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.2.0 to 3.3.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/755da8c3cf115ac066823e79a1e1788f8940201b...ac593985615ec2ede58e132d2e21d2b1cbd6127c) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 5f24e9ab..50824f00 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [2.19.0, dev] steps: - - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: ${{ matrix.sdk }} From e7bc391c24fa008a6fd6692626d0cd0c1e61bf78 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:36:22 -0700 Subject: [PATCH 102/126] Bump dart-lang/setup-dart from 1.4.0 to 1.5.0 (dart-lang/fixnum#109) Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.4.0 to 1.5.0. - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/a57a6c04cf7d4840e88432aad6281d1e125f0d46...d6a63dab3335f427404425de0fbfed4686d93c4f) --- updated-dependencies: - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 50824f00..918d1021 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -23,7 +23,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} - id: install @@ -50,7 +50,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} - id: install From 126c05a38625835333330f46b806145a0c811bd1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:57:43 -0700 Subject: [PATCH 103/126] Bump actions/checkout from 3.3.0 to 3.5.0 (dart-lang/fixnum#108) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.3.0 to 3.5.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/ac593985615ec2ede58e132d2e21d2b1cbd6127c...8f4b7f84864484a7bf31766abe9204da3cbe65b3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 918d1021..603b7737 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [2.19.0, dev] steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} From 08dfaa5214646c62533248152070a8d6e9cbb90c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 May 2023 12:24:26 -0700 Subject: [PATCH 104/126] Bump actions/checkout from 3.5.0 to 3.5.2 (dart-lang/fixnum#111) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.0 to 3.5.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/8f4b7f84864484a7bf31766abe9204da3cbe65b3...8e5e7e5ab8b370d6c329ec480221332ada57f0ab) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 603b7737..88404eb4 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [2.19.0, dev] steps: - - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} From 7affe57b0462fc930d560f381e60dc7e3dd17abe Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Wed, 17 May 2023 11:10:40 -0700 Subject: [PATCH 105/126] blast_repo fixes (dart-lang/fixnum#112) dependabot --- pkgs/fixnum/.github/dependabot.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/fixnum/.github/dependabot.yml b/pkgs/fixnum/.github/dependabot.yml index 1603cdd9..725f03af 100644 --- a/pkgs/fixnum/.github/dependabot.yml +++ b/pkgs/fixnum/.github/dependabot.yml @@ -3,7 +3,9 @@ version: 2 updates: - - package-ecosystem: "github-actions" - directory: "/" + - package-ecosystem: github-actions + directory: / schedule: - interval: "monthly" + interval: monthly + labels: + - autosubmit From 9ed8f67bf045a89b3b64849607ae70ee21ef8d08 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Jul 2023 14:24:21 +0000 Subject: [PATCH 106/126] Bump actions/checkout from 3.5.2 to 3.5.3 (dart-lang/fixnum#113) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.2 to 3.5.3.
Release notes

Sourced from actions/checkout's releases.

v3.5.3

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v3...v3.5.3

Changelog

Sourced from actions/checkout's changelog.

Changelog

v3.5.3

v3.5.2

v3.5.1

v3.5.0

v3.4.0

v3.3.0

v3.2.0

v3.1.0

v3.0.2

v3.0.1

v3.0.0

v2.3.1

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=3.5.2&new-version=3.5.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 88404eb4..872eebfa 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [2.19.0, dev] steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} From fa5a88c1ddaa54e1305392ceaec70f92300e07ca Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:30:52 +0000 Subject: [PATCH 107/126] Bump actions/checkout from 3.5.3 to 3.6.0 (dart-lang/fixnum#114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.3 to 3.6.0.
Release notes

Sourced from actions/checkout's releases.

v3.6.0

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v3.5.3...v3.6.0

Changelog

Sourced from actions/checkout's changelog.

Changelog

v3.6.0

v3.5.3

v3.5.2

v3.5.1

v3.5.0

v3.4.0

v3.3.0

v3.2.0

v3.1.0

v3.0.2

v3.0.1

v3.0.0

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=3.5.3&new-version=3.6.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 872eebfa..9f6bddfb 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [2.19.0, dev] steps: - - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} From 50fffa74b1a4a58030969d91b948d58ea61e0aed Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Oct 2023 14:03:51 +0000 Subject: [PATCH 108/126] Bump actions/checkout from 3.6.0 to 4.1.0 (dart-lang/fixnum#115) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 3.6.0 to 4.1.0.
Release notes

Sourced from actions/checkout's releases.

v4.1.0

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v4.0.0...v4.1.0

v4.0.0

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v3...v4.0.0

Changelog

Sourced from actions/checkout's changelog.

Changelog

v4.1.0

v4.0.0

v3.6.0

v3.5.3

v3.5.2

v3.5.1

v3.5.0

v3.4.0

v3.3.0

v3.2.0

v3.1.0

v3.0.2

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=3.6.0&new-version=4.1.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 9f6bddfb..38370760 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [2.19.0, dev] steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} From d3d8dae22cb0fa7a2097fecdc45f5c95e8db5fa8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 20:58:09 -0700 Subject: [PATCH 109/126] Bump dart-lang/setup-dart from 1.5.0 to 1.5.1 (dart-lang/fixnum#116) Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.5.0 to 1.5.1. - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/d6a63dab3335f427404425de0fbfed4686d93c4f...8a4b97ea2017cc079571daec46542f76189836b1) --- updated-dependencies: - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 38370760..a1668a5c 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -23,7 +23,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: ${{ matrix.sdk }} - id: install @@ -50,7 +50,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: ${{ matrix.sdk }} - id: install From 3b9fc6553d2a1d114a6abb9813c9a236cc00dd69 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Nov 2023 14:18:03 +0000 Subject: [PATCH 110/126] Bump actions/checkout from 4.1.0 to 4.1.1 (dart-lang/fixnum#121) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.0 to 4.1.1.
Release notes

Sourced from actions/checkout's releases.

v4.1.1

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v4.1.0...v4.1.1

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=4.1.0&new-version=4.1.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index a1668a5c..fad9190e 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [2.19.0, dev] steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: ${{ matrix.sdk }} From b122ef558483aa00b4f293ae404e1ca8f8938fa3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Nov 2023 14:27:54 +0000 Subject: [PATCH 111/126] Bump dart-lang/setup-dart from 1.5.1 to 1.6.0 (dart-lang/fixnum#120) Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.5.1 to 1.6.0.
Release notes

Sourced from dart-lang/setup-dart's releases.

v1.6.0

  • Enable provisioning of the latest Dart SDK patch release by specifying just the major and minor version (e.g. 3.2).
Changelog

Sourced from dart-lang/setup-dart's changelog.

v1.6.0

  • Enable provisioning of the latest Dart SDK patch release by specifying just the major and minor version (e.g. 3.2).

v1.5.1

  • No longer test the setup-dart action on pre-2.12 SDKs.
  • Upgrade JS interop code to use extension types (the new name for inline classes).
  • The upcoming rename of the be channel to main is now supported with forward compatibility that switches when the rename happens.

v1.5.0

  • Re-wrote the implementation of the action into Dart.
  • Auto-detect the platform architecture (x64, ia32, arm, arm64).
  • Improved the caching and download resilience of the sdk.
  • Added a new action output: dart-version - the installed version of the sdk.

v1.4.0

  • Automatically create OIDC token for pub.dev.
  • Add a reusable workflow for publishing.

v1.3.0

  • The install location of the Dart SDK is now available in an environment variable, DART_HOME (dart-lang/fixnum#43).
  • Fixed an issue where cached downloads could lead to unzip issues on self-hosted runners (dart-lang/fixnum#35).

v1.2.0

  • Fixed a path issue impacting git dependencies on Windows.

v1.1.0

  • Added a flavor option setup.sh to allow downloading unpublished builds.

v1.0.0

  • Promoted to 1.0 stable.

v0.5

  • Fixed a Windows pub global activate path issue.

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=dart-lang/setup-dart&package-manager=github_actions&previous-version=1.5.1&new-version=1.6.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index fad9190e..5f67d5b0 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -23,7 +23,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: ${{ matrix.sdk }} - id: install @@ -50,7 +50,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: ${{ matrix.sdk }} - id: install From 2afb3a7b2103eef8a135b58775de5802aaca8701 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 8 Nov 2023 11:05:52 -0800 Subject: [PATCH 112/126] Update to latest lints and fix (dart-lang/fixnum#122) Also bump min SDK to Dart 3.1 --- .../fixnum/.github/workflows/test-package.yml | 4 ++-- pkgs/fixnum/CHANGELOG.md | 4 ++++ pkgs/fixnum/analysis_options.yaml | 21 +------------------ pkgs/fixnum/lib/src/int64.dart | 4 ++-- pkgs/fixnum/lib/src/utilities.dart | 8 +++---- pkgs/fixnum/pubspec.yaml | 6 +++--- pkgs/fixnum/test/int64_test.dart | 2 -- pkgs/fixnum/test/int_64_vm_test.dart | 1 + 8 files changed, 17 insertions(+), 33 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 5f67d5b0..626b7094 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -20,7 +20,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [2.19.0, dev] + sdk: [3.1.0, dev] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d @@ -47,7 +47,7 @@ jobs: matrix: # Add macos-latest and/or windows-latest if relevant for this package. os: [ubuntu-latest] - sdk: [2.19.0, dev] + sdk: [3.1.0, dev] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index f7312960..36981452 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.1-wip + +* Require Dart `^3.1.0` + ## 1.1.0 * Add `tryParseRadix`, `tryParseInt` and `tryParseHex` static methods diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index 2e3ed195..76f6d6ab 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -1,4 +1,4 @@ -include: package:lints/recommended.yaml +include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: language: @@ -6,36 +6,17 @@ analyzer: linter: rules: - - avoid_catching_errors - - avoid_dynamic_calls - avoid_private_typedef_functions - avoid_returning_null - avoid_unused_constructor_parameters - cancel_subscriptions - cascade_invocations - - comment_references - - directives_ordering - join_return_with_assignment - - lines_longer_than_80_chars - missing_whitespace_between_adjacent_strings - no_adjacent_strings_in_list - no_runtimeType_toString - - only_throw_errors - package_api_docs - - prefer_asserts_in_initializer_lists - - prefer_const_constructors - prefer_const_declarations - prefer_expression_function_bodies - - prefer_interpolation_to_compose_strings - - prefer_relative_imports - - sort_pub_dependencies - - test_types_in_equals - - throw_in_finally - - type_annotate_public_apis - - unnecessary_lambdas - - unnecessary_null_aware_assignments - - unnecessary_parenthesis - unnecessary_raw_strings - - unnecessary_statements - - use_is_even_rather_than_modulo - use_string_buffers diff --git a/pkgs/fixnum/lib/src/int64.dart b/pkgs/fixnum/lib/src/int64.dart index e4e2ba48..bbfcbd91 100644 --- a/pkgs/fixnum/lib/src/int64.dart +++ b/pkgs/fixnum/lib/src/int64.dart @@ -267,7 +267,7 @@ class Int64 implements IntX { // Returns the [Int64] representation of the specified value. Throws // [ArgumentError] for non-integer arguments. - static Int64 _promote(value) { + static Int64 _promote(Object value) { if (value is Int64) { return value; } else if (value is int) { @@ -968,7 +968,7 @@ class Int64 implements IntX { // Implementation of '~/', '%' and 'remainder'. - static Int64 _divide(Int64 a, other, int what) { + static Int64 _divide(Int64 a, Object other, int what) { Int64 b = _promote(other); if (b.isZero) { throw UnsupportedError('Division by zero'); diff --git a/pkgs/fixnum/lib/src/utilities.dart b/pkgs/fixnum/lib/src/utilities.dart index d603b57f..8b3957cf 100644 --- a/pkgs/fixnum/lib/src/utilities.dart +++ b/pkgs/fixnum/lib/src/utilities.dart @@ -16,12 +16,12 @@ int validateRadix(int radix) => /// not a valid digit in any radix in the range 2 through 36. int decodeDigit(int c) { // Hex digit char codes - const int c0 = 48; // '0'.codeUnitAt(0) - const int ca = 97; // 'a'.codeUnitAt(0) + const c0 = 48; // '0'.codeUnitAt(0) + const ca = 97; // 'a'.codeUnitAt(0) - int digit = c ^ c0; + var digit = c ^ c0; if (digit < 10) return digit; - int letter = (c | 0x20) - ca; + var letter = (c | 0x20) - ca; if (letter >= 0) { // Returns values above 36 for invalid digits. // The value is checked against the actual radix where the return diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 3180c25d..76d5868b 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,13 +1,13 @@ name: fixnum -version: 1.1.0 +version: 1.1.1-wip description: >- Library for 32- and 64-bit signed fixed-width integers with consistent behavior between native and JS runtimes. repository: https://github.com/dart-lang/fixnum environment: - sdk: '>=2.19.0 <3.0.0' + sdk: ^3.1.0 dev_dependencies: - lints: ^2.0.0 + dart_flutter_team_lints: ^2.0.0 test: ^1.16.0 diff --git a/pkgs/fixnum/test/int64_test.dart b/pkgs/fixnum/test/int64_test.dart index bb5ac7a7..e74d8936 100644 --- a/pkgs/fixnum/test/int64_test.dart +++ b/pkgs/fixnum/test/int64_test.dart @@ -7,8 +7,6 @@ // // ignore_for_file: omit_local_variable_types -library int64test; - import 'package:fixnum/fixnum.dart'; import 'package:test/test.dart'; diff --git a/pkgs/fixnum/test/int_64_vm_test.dart b/pkgs/fixnum/test/int_64_vm_test.dart index 2ab161e2..2d28da3e 100644 --- a/pkgs/fixnum/test/int_64_vm_test.dart +++ b/pkgs/fixnum/test/int_64_vm_test.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') +library; import 'package:fixnum/fixnum.dart'; import 'package:test/test.dart'; From 4b1e4838c771a5543e6e80c4288105640f0bfdc7 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 4 Dec 2023 10:44:24 -0800 Subject: [PATCH 113/126] drop outdated lints (dart-lang/fixnum#123) --- pkgs/fixnum/analysis_options.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/fixnum/analysis_options.yaml b/pkgs/fixnum/analysis_options.yaml index 76f6d6ab..50e529cd 100644 --- a/pkgs/fixnum/analysis_options.yaml +++ b/pkgs/fixnum/analysis_options.yaml @@ -7,7 +7,6 @@ analyzer: linter: rules: - avoid_private_typedef_functions - - avoid_returning_null - avoid_unused_constructor_parameters - cancel_subscriptions - cascade_invocations From 15b4cfdad460d8eb96ee5c769d2c86ab51d2081f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Feb 2024 14:14:53 +0000 Subject: [PATCH 114/126] Bump dart-lang/setup-dart from 1.6.0 to 1.6.2 (dart-lang/fixnum#124) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.6.0 to 1.6.2.
Release notes

Sourced from dart-lang/setup-dart's releases.

v1.6.2

v1.6.1

  • Updated the google storage url for main channel releases.
Changelog

Sourced from dart-lang/setup-dart's changelog.

v1.6.2

v1.6.1

  • Updated the google storage url for main channel releases.

v1.6.0

  • Enable provisioning of the latest Dart SDK patch release by specifying just the major and minor version (e.g. 3.2).

v1.5.1

  • No longer test the setup-dart action on pre-2.12 SDKs.
  • Upgrade JS interop code to use extension types (the new name for inline classes).
  • The upcoming rename of the be channel to main is now supported with forward compatibility that switches when the rename happens.

v1.5.0

  • Re-wrote the implementation of the action into Dart.
  • Auto-detect the platform architecture (x64, ia32, arm, arm64).
  • Improved the caching and download resilience of the sdk.
  • Added a new action output: dart-version - the installed version of the sdk.

v1.4.0

  • Automatically create OIDC token for pub.dev.
  • Add a reusable workflow for publishing.

v1.3.0

  • The install location of the Dart SDK is now available in an environment variable, DART_HOME (dart-lang/fixnum#43).
  • Fixed an issue where cached downloads could lead to unzip issues on self-hosted runners (dart-lang/fixnum#35).

v1.2.0

  • Fixed a path issue impacting git dependencies on Windows.

v1.1.0

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=dart-lang/setup-dart&package-manager=github_actions&previous-version=1.6.0&new-version=1.6.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 626b7094..d404037c 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -23,7 +23,7 @@ jobs: sdk: [3.1.0, dev] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: ${{ matrix.sdk }} - id: install @@ -50,7 +50,7 @@ jobs: sdk: [3.1.0, dev] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: ${{ matrix.sdk }} - id: install From d1e462c4db2c5651434dbb72071852e9a6fa9342 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 14:46:05 +0000 Subject: [PATCH 115/126] Bump actions/checkout from 4.1.1 to 4.1.2 (dart-lang/fixnum#125) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.1 to 4.1.2.
Release notes

Sourced from actions/checkout's releases.

v4.1.2

We are investigating the following issue with this release and have rolled-back the v4 tag to point to v4.1.1

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v4.1.1...v4.1.2

Changelog

Sourced from actions/checkout's changelog.

Changelog

v4.1.2

v4.1.1

v4.1.0

v4.0.0

v3.6.0

v3.5.3

v3.5.2

v3.5.1

v3.5.0

v3.4.0

v3.3.0

v3.2.0

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=4.1.1&new-version=4.1.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index d404037c..346c0003 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [3.1.0, dev] steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [3.1.0, dev] steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: ${{ matrix.sdk }} From 7478039ac0b4c8584cba73b37429d439f3bc9de9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 14:50:04 +0000 Subject: [PATCH 116/126] Bump actions/checkout from 4.1.2 to 4.1.4 (dart-lang/fixnum#126) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.2 to 4.1.4.
Release notes

Sourced from actions/checkout's releases.

v4.1.4

What's Changed

Full Changelog: https://github.com/actions/checkout/compare/v4.1.3...v4.1.4

v4.1.3

What's Changed

Full Changelog: https://github.com/actions/checkout/compare/v4.1.2...v4.1.3

Changelog

Sourced from actions/checkout's changelog.

Changelog

v4.1.4

v4.1.3

v4.1.2

v4.1.1

v4.1.0

v4.0.0

v3.6.0

v3.5.3

v3.5.2

v3.5.1

v3.5.0

v3.4.0

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=4.1.2&new-version=4.1.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 346c0003..54d92654 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [3.1.0, dev] steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [3.1.0, dev] steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: ${{ matrix.sdk }} From e73b9796aa85d9c42e51041069dd58eb2e4c773a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 14:52:54 +0000 Subject: [PATCH 117/126] Bump dart-lang/setup-dart from 1.6.2 to 1.6.4 (dart-lang/fixnum#127) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.6.2 to 1.6.4.
Release notes

Sourced from dart-lang/setup-dart's releases.

v1.6.4

  • Rebuild JS code to include changes from v1.6.3

v1.6.3

Changelog

Sourced from dart-lang/setup-dart's changelog.

v1.6.4

  • Rebuild JS code.

v1.6.3

v1.6.2

v1.6.1

  • Updated the google storage url for main channel releases.

v1.6.0

  • Enable provisioning of the latest Dart SDK patch release by specifying just the major and minor version (e.g. 3.2).

v1.5.1

  • No longer test the setup-dart action on pre-2.12 SDKs.
  • Upgrade JS interop code to use extension types (the new name for inline classes).
  • The upcoming rename of the be channel to main is now supported with forward compatibility that switches when the rename happens.

v1.5.0

  • Re-wrote the implementation of the action into Dart.
  • Auto-detect the platform architecture (x64, ia32, arm, arm64).
  • Improved the caching and download resilience of the sdk.
  • Added a new action output: dart-version - the installed version of the sdk.

v1.4.0

  • Automatically create OIDC token for pub.dev.
  • Add a reusable workflow for publishing.

v1.3.0

  • The install location of the Dart SDK is now available

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=dart-lang/setup-dart&package-manager=github_actions&previous-version=1.6.2&new-version=1.6.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 54d92654..1b33ffb6 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -23,7 +23,7 @@ jobs: sdk: [3.1.0, dev] steps: - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b - - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: ${{ matrix.sdk }} - id: install @@ -50,7 +50,7 @@ jobs: sdk: [3.1.0, dev] steps: - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b - - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: ${{ matrix.sdk }} - id: install From f6b411bc6e8a64318a34a49b5dcfe0ba5a39a06b Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Mon, 6 May 2024 10:05:44 -0700 Subject: [PATCH 118/126] blast_repo fixes (dart-lang/fixnum#128) dependabot --- pkgs/fixnum/.github/dependabot.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/fixnum/.github/dependabot.yml b/pkgs/fixnum/.github/dependabot.yml index 725f03af..cde02ad6 100644 --- a/pkgs/fixnum/.github/dependabot.yml +++ b/pkgs/fixnum/.github/dependabot.yml @@ -9,3 +9,7 @@ updates: interval: monthly labels: - autosubmit + groups: + github-actions: + patterns: + - "*" From 7b1af9d873d92fbe5d98ec59949292470ba628f0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Jun 2024 14:42:13 +0000 Subject: [PATCH 119/126] Bump actions/checkout from 4.1.4 to 4.1.6 in the github-actions group (dart-lang/fixnum#130) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps the github-actions group with 1 update: [actions/checkout](https://github.com/actions/checkout). Updates `actions/checkout` from 4.1.4 to 4.1.6
Release notes

Sourced from actions/checkout's releases.

v4.1.6

What's Changed

Full Changelog: https://github.com/actions/checkout/compare/v4.1.5...v4.1.6

v4.1.5

What's Changed

Full Changelog: https://github.com/actions/checkout/compare/v4.1.4...v4.1.5

Changelog

Sourced from actions/checkout's changelog.

Changelog

v4.1.6

v4.1.5

v4.1.4

v4.1.3

v4.1.2

v4.1.1

v4.1.0

v4.0.0

v3.6.0

v3.5.3

v3.5.2

v3.5.1

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=4.1.4&new-version=4.1.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
--- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 1b33ffb6..3a5362fa 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [3.1.0, dev] steps: - - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [3.1.0, dev] steps: - - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: ${{ matrix.sdk }} From 50c7ea3e0636fb2dc25621e9092aa6e9307321af Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 27 Jun 2024 13:04:34 -0700 Subject: [PATCH 120/126] update lints (dart-lang/fixnum#131) --- pkgs/fixnum/lib/fixnum.dart | 2 +- pkgs/fixnum/pubspec.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/fixnum/lib/fixnum.dart b/pkgs/fixnum/lib/fixnum.dart index eeb6defe..69916452 100644 --- a/pkgs/fixnum/lib/fixnum.dart +++ b/pkgs/fixnum/lib/fixnum.dart @@ -6,7 +6,7 @@ /// /// The integer implementations in this library are designed to work /// identically whether executed on the Dart VM or compiled to JavaScript. -library fixnum; +library; export 'src/int32.dart'; export 'src/int64.dart'; diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 76d5868b..3c43b9a6 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -9,5 +9,5 @@ environment: sdk: ^3.1.0 dev_dependencies: - dart_flutter_team_lints: ^2.0.0 - test: ^1.16.0 + dart_flutter_team_lints: ^3.0.0 + test: ^1.16.6 From 88f9b4d14cfa4a74dd01408288ee0288ae3b6b41 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jul 2024 14:14:54 +0000 Subject: [PATCH 121/126] Bump the github-actions group with 2 updates (dart-lang/fixnum#132) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps the github-actions group with 2 updates: [actions/checkout](https://github.com/actions/checkout) and [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart). Updates `actions/checkout` from 4.1.6 to 4.1.7
Release notes

Sourced from actions/checkout's releases.

v4.1.7

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v4.1.6...v4.1.7

Changelog

Sourced from actions/checkout's changelog.

Changelog

v4.1.7

v4.1.6

v4.1.5

v4.1.4

v4.1.3

v4.1.2

v4.1.1

v4.1.0

v4.0.0

v3.6.0

v3.5.3

... (truncated)

Commits

Updates `dart-lang/setup-dart` from 1.6.4 to 1.6.5
Release notes

Sourced from dart-lang/setup-dart's releases.

v1.6.5

dart-lang/fixnum#118: dart-lang/setup-dartdart-lang/fixnum#118

Changelog

Sourced from dart-lang/setup-dart's changelog.

v1.6.5

dart-lang/fixnum#118: dart-lang/setup-dartdart-lang/fixnum#118

v1.6.4

  • Rebuild JS code.

v1.6.3

v1.6.2

v1.6.1

  • Updated the google storage url for main channel releases.

v1.6.0

  • Enable provisioning of the latest Dart SDK patch release by specifying just the major and minor version (e.g. 3.2).

v1.5.1

  • No longer test the setup-dart action on pre-2.12 SDKs.
  • Upgrade JS interop code to use extension types (the new name for inline classes).
  • The upcoming rename of the be channel to main is now supported with forward compatibility that switches when the rename happens.

v1.5.0

  • Re-wrote the implementation of the action into Dart.
  • Auto-detect the platform architecture (x64, ia32, arm, arm64).
  • Improved the caching and download resilience of the sdk.
  • Added a new action output: dart-version - the installed version of the sdk.

v1.4.0

... (truncated)

Commits

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
--- pkgs/fixnum/.github/workflows/test-package.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index 3a5362fa..d527f499 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,8 +22,8 @@ jobs: matrix: sdk: [3.1.0, dev] steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: ${{ matrix.sdk }} - id: install @@ -49,8 +49,8 @@ jobs: os: [ubuntu-latest] sdk: [3.1.0, dev] steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: ${{ matrix.sdk }} - id: install From d1f7c10102dc80bfd9ebc65be3e0b3119f24d763 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 1 Oct 2024 14:07:51 +0000 Subject: [PATCH 122/126] Bump actions/checkout from 4.1.7 to 4.2.0 in the github-actions group (dart-lang/fixnum#133) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps the github-actions group with 1 update: [actions/checkout](https://github.com/actions/checkout). Updates `actions/checkout` from 4.1.7 to 4.2.0
Release notes

Sourced from actions/checkout's releases.

v4.2.0

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v4.1.7...v4.2.0

Changelog

Sourced from actions/checkout's changelog.

Changelog

v4.2.0

v4.1.7

v4.1.6

v4.1.5

v4.1.4

v4.1.3

v4.1.2

v4.1.1

v4.1.0

v4.0.0

v3.6.0

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=4.1.7&new-version=4.2.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
--- pkgs/fixnum/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/pkgs/fixnum/.github/workflows/test-package.yml index d527f499..8c6de018 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/pkgs/fixnum/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [3.1.0, dev] steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [3.1.0, dev] steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: ${{ matrix.sdk }} From 61de93eb342f1ef8f938fefa7998d32616af1c9b Mon Sep 17 00:00:00 2001 From: Moritz Date: Tue, 15 Oct 2024 12:49:28 +0200 Subject: [PATCH 123/126] Moving fixes --- .github/labeler.yml | 4 ++++ .../workflows/fixnum.yaml | 17 +++++++++++++---- README.md | 1 + pkgs/fixnum/.github/dependabot.yml | 15 --------------- pkgs/fixnum/.github/workflows/publish.yaml | 14 -------------- pkgs/fixnum/CHANGELOG.md | 3 ++- pkgs/fixnum/README.md | 2 +- pkgs/fixnum/pubspec.yaml | 4 ++-- 8 files changed, 23 insertions(+), 37 deletions(-) rename pkgs/fixnum/.github/workflows/test-package.yml => .github/workflows/fixnum.yaml (85%) delete mode 100644 pkgs/fixnum/.github/dependabot.yml delete mode 100644 pkgs/fixnum/.github/workflows/publish.yaml diff --git a/.github/labeler.yml b/.github/labeler.yml index 62e1bfae..be3f9aff 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -3,3 +3,7 @@ "package-args": - changed-files: - any-glob-to-any-file: 'pkgs/args/**' + +"package-fixnum": + - changed-files: + - any-glob-to-any-file: 'pkgs/fixnum/**' diff --git a/pkgs/fixnum/.github/workflows/test-package.yml b/.github/workflows/fixnum.yaml similarity index 85% rename from pkgs/fixnum/.github/workflows/test-package.yml rename to .github/workflows/fixnum.yaml index 8c6de018..8f378d87 100644 --- a/pkgs/fixnum/.github/workflows/test-package.yml +++ b/.github/workflows/fixnum.yaml @@ -1,17 +1,26 @@ name: Dart CI on: - # Run on PRs and pushes to the default branch. + # Run CI on pushes to the main branch, and on PRs against main. push: - branches: [ master ] + branches: [ main ] + paths: + - '.github/workflows/fixnum.yaml' + - 'pkgs/fixnum/**' pull_request: - branches: [ master ] + branches: [ main ] + paths: + - '.github/workflows/fixnum.yaml' + - 'pkgs/fixnum/**' schedule: - cron: "0 0 * * 0" - env: PUB_ENVIRONMENT: bot.github +defaults: + run: + working-directory: pkgs/fixnum/ + jobs: # Check code formatting and static analysis on a single OS (linux) # against Dart dev. diff --git a/README.md b/README.md index 1205554f..90972ffd 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ This repository is home to various Dart packages under the [dart.dev](https://pu | Package | Description | Version | |---|---|---| | [args](pkgs/args/) | Library for defining parsers for parsing raw command-line arguments into a set of options and values. | [![pub package](https://img.shields.io/pub/v/args.svg)](https://pub.dev/packages/args) | +| [fixnum](pkgs/fixnum/) | Library for 32- and 64-bit signed fixed-width integers. | [![pub package](https://img.shields.io/pub/v/fixnum.svg)](https://pub.dev/packages/fixnum) | ## Publishing automation diff --git a/pkgs/fixnum/.github/dependabot.yml b/pkgs/fixnum/.github/dependabot.yml deleted file mode 100644 index cde02ad6..00000000 --- a/pkgs/fixnum/.github/dependabot.yml +++ /dev/null @@ -1,15 +0,0 @@ -# Dependabot configuration file. -# See https://docs.github.com/en/code-security/dependabot/dependabot-version-updates -version: 2 - -updates: - - package-ecosystem: github-actions - directory: / - schedule: - interval: monthly - labels: - - autosubmit - groups: - github-actions: - patterns: - - "*" diff --git a/pkgs/fixnum/.github/workflows/publish.yaml b/pkgs/fixnum/.github/workflows/publish.yaml deleted file mode 100644 index fcb7ccb8..00000000 --- a/pkgs/fixnum/.github/workflows/publish.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# A CI configuration to auto-publish pub packages. - -name: Publish - -on: - pull_request: - branches: [ master ] - push: - tags: [ 'v[0-9]+.[0-9]+.[0-9]+*' ] - -jobs: - publish: - if: ${{ github.repository_owner == 'dart-lang' }} - uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 36981452..f3e5c019 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md @@ -1,6 +1,7 @@ -## 1.1.1-wip +## 1.1.1 * Require Dart `^3.1.0` +* Move to `dart-lang/core` monorepo. ## 1.1.0 diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index 332d9001..1be07f37 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -1,4 +1,4 @@ -[![Dart CI](https://github.com/dart-lang/fixnum/actions/workflows/test-package.yml/badge.svg)](https://github.com/dart-lang/fixnum/actions/workflows/test-package.yml) +[![Dart CI](https://github.com/dart-lang/core/actions/workflows/fixnum.yaml/badge.svg)](https://github.com/dart-lang/core/actions/workflows/fixnum.yaml) [![Pub](https://img.shields.io/pub/v/fixnum.svg)](https://pub.dev/packages/fixnum) [![package publisher](https://img.shields.io/pub/publisher/fixnum.svg)](https://pub.dev/packages/fixnum/publisher) diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 3c43b9a6..149f2393 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -1,9 +1,9 @@ name: fixnum -version: 1.1.1-wip +version: 1.1.1 description: >- Library for 32- and 64-bit signed fixed-width integers with consistent behavior between native and JS runtimes. -repository: https://github.com/dart-lang/fixnum +repository: https://github.com/dart-lang/core/main/pkgs/fixnum environment: sdk: ^3.1.0 From ade36c475516e079434d7eefd32ff3397620c3cc Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 15 Oct 2024 21:59:08 +0200 Subject: [PATCH 124/126] Fix the repository URL in `pubspec.yaml` (#140) * Fix the repository URL in `pubspec.yaml` The branch name `main` must be preceded by `tree`. * Bump the version to 2.6.1-wip to add a changelog entry --- pkgs/args/CHANGELOG.md | 4 ++++ pkgs/args/pubspec.yaml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkgs/args/CHANGELOG.md b/pkgs/args/CHANGELOG.md index 15b392b1..03e693c5 100644 --- a/pkgs/args/CHANGELOG.md +++ b/pkgs/args/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.6.1-wip + +* Fix the reporitory URL in `pubspec.yaml`. + ## 2.6.0 * Added source argument when throwing a `ArgParserException`. diff --git a/pkgs/args/pubspec.yaml b/pkgs/args/pubspec.yaml index 859e1860..21c9389b 100644 --- a/pkgs/args/pubspec.yaml +++ b/pkgs/args/pubspec.yaml @@ -1,9 +1,9 @@ name: args -version: 2.6.0 +version: 2.6.1-wip description: >- Library for defining parsers for parsing raw command-line arguments into a set of options and values using GNU and POSIX style options. -repository: https://github.com/dart-lang/core/main/pkgs/args +repository: https://github.com/dart-lang/core/tree/main/pkgs/args topics: - cli From 80b3466aa52cc13b9d01ee702ac0550c94d8b739 Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 16 Oct 2024 09:11:42 +0200 Subject: [PATCH 125/126] Changes as per review --- .github/labeler.yml | 4 ++-- .github/workflows/fixnum.yaml | 2 +- pkgs/args/CHANGELOG.md | 4 ++++ pkgs/args/pubspec.yaml | 4 ++-- pkgs/fixnum/CONTRIBUTING.md | 10 ---------- pkgs/fixnum/README.md | 5 ----- pkgs/fixnum/pubspec.yaml | 2 +- 7 files changed, 10 insertions(+), 21 deletions(-) delete mode 100644 pkgs/fixnum/CONTRIBUTING.md diff --git a/.github/labeler.yml b/.github/labeler.yml index be3f9aff..c47b4254 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,9 +1,9 @@ # Configuration for .github/workflows/pull_request_label.yaml. -"package-args": +"package:args": - changed-files: - any-glob-to-any-file: 'pkgs/args/**' -"package-fixnum": +"package:fixnum": - changed-files: - any-glob-to-any-file: 'pkgs/fixnum/**' diff --git a/.github/workflows/fixnum.yaml b/.github/workflows/fixnum.yaml index 8f378d87..7ee55e50 100644 --- a/.github/workflows/fixnum.yaml +++ b/.github/workflows/fixnum.yaml @@ -1,4 +1,4 @@ -name: Dart CI +name: package:fixnum on: # Run CI on pushes to the main branch, and on PRs against main. diff --git a/pkgs/args/CHANGELOG.md b/pkgs/args/CHANGELOG.md index 15b392b1..2f24b6c0 100644 --- a/pkgs/args/CHANGELOG.md +++ b/pkgs/args/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.6.1 + +* Fix pubspec `repository` value. + ## 2.6.0 * Added source argument when throwing a `ArgParserException`. diff --git a/pkgs/args/pubspec.yaml b/pkgs/args/pubspec.yaml index 859e1860..6f18534a 100644 --- a/pkgs/args/pubspec.yaml +++ b/pkgs/args/pubspec.yaml @@ -1,9 +1,9 @@ name: args -version: 2.6.0 +version: 2.6.1 description: >- Library for defining parsers for parsing raw command-line arguments into a set of options and values using GNU and POSIX style options. -repository: https://github.com/dart-lang/core/main/pkgs/args +repository: https://github.com/dart-lang/core/tree/main/pkgs/args topics: - cli diff --git a/pkgs/fixnum/CONTRIBUTING.md b/pkgs/fixnum/CONTRIBUTING.md deleted file mode 100644 index 8dab68d0..00000000 --- a/pkgs/fixnum/CONTRIBUTING.md +++ /dev/null @@ -1,10 +0,0 @@ -# How to contribute - -### Sign our Contributor License Agreement (CLA) - -Even for small changes, we ask that you please sign the CLA electronically -[here](https://developers.google.com/open-source/cla/individual). -The CLA is necessary because you own the copyright to your changes, even -after your contribution becomes part of our codebase, so we need your permission -to use and distribute your code. You can find more details -[here](https://code.google.com/p/dart/wiki/Contributing). diff --git a/pkgs/fixnum/README.md b/pkgs/fixnum/README.md index 1be07f37..47aac7bb 100644 --- a/pkgs/fixnum/README.md +++ b/pkgs/fixnum/README.md @@ -7,8 +7,3 @@ A fixed-width 32- and 64- bit integer library for Dart. Provides data types for signed 32- and 64-bit integers. The integer implementations in this library are designed to work identically whether executed on the Dart VM or compiled to JavaScript. - -## Publishing automation - -For information about our publishing automation and release process, see -https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. diff --git a/pkgs/fixnum/pubspec.yaml b/pkgs/fixnum/pubspec.yaml index 149f2393..efa61eba 100644 --- a/pkgs/fixnum/pubspec.yaml +++ b/pkgs/fixnum/pubspec.yaml @@ -3,7 +3,7 @@ version: 1.1.1 description: >- Library for 32- and 64-bit signed fixed-width integers with consistent behavior between native and JS runtimes. -repository: https://github.com/dart-lang/core/main/pkgs/fixnum +repository: https://github.com/dart-lang/core/tree/main/pkgs/fixnum environment: sdk: ^3.1.0 From 7dff3843d15d4730258b0e0c53b318be4bc679d6 Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 16 Oct 2024 09:12:39 +0200 Subject: [PATCH 126/126] Revert changes to package args --- pkgs/args/CHANGELOG.md | 4 ---- pkgs/args/pubspec.yaml | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pkgs/args/CHANGELOG.md b/pkgs/args/CHANGELOG.md index 2f24b6c0..15b392b1 100644 --- a/pkgs/args/CHANGELOG.md +++ b/pkgs/args/CHANGELOG.md @@ -1,7 +1,3 @@ -## 2.6.1 - -* Fix pubspec `repository` value. - ## 2.6.0 * Added source argument when throwing a `ArgParserException`. diff --git a/pkgs/args/pubspec.yaml b/pkgs/args/pubspec.yaml index 6f18534a..859e1860 100644 --- a/pkgs/args/pubspec.yaml +++ b/pkgs/args/pubspec.yaml @@ -1,9 +1,9 @@ name: args -version: 2.6.1 +version: 2.6.0 description: >- Library for defining parsers for parsing raw command-line arguments into a set of options and values using GNU and POSIX style options. -repository: https://github.com/dart-lang/core/tree/main/pkgs/args +repository: https://github.com/dart-lang/core/main/pkgs/args topics: - cli