dart-sdk/tests/dart2js/operator3_test.dart
Joshua Litt f9f1ca6171 [dart2js] Create tests/dart2js for nnbd.
Change-Id: Ib8721cf976803d8d1b9d723b7e691e344c768b67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149881
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2020-06-09 16:53:15 +00:00

92 lines
1.3 KiB
Dart

// Copyright (c) 2011, 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:expect/expect.dart";
int zero() {
return 0;
}
int one() {
return 1;
}
int minus1() {
return 0 - 1;
}
int two() {
return 2;
}
int three() {
return 3;
}
int five() {
return 5;
}
int minus5() {
return 0 - 5;
}
int ninetyNine() {
return 99;
}
int four99() {
return 499;
}
int four99times99() {
return 499 * 99;
}
int four99times99plus1() {
return 499 * 99 + 1;
}
void postPlusPlusTest() {
var x = zero();
var y = x++;
Expect.equals(0, y);
Expect.equals(1, x);
Expect.equals(1, x++);
Expect.equals(2, x);
}
void prePlusPlusTest() {
var x = zero();
var y = ++x;
Expect.equals(1, x);
Expect.equals(1, y);
Expect.equals(2, ++x);
Expect.equals(2, ++y);
}
void postMinusMinusTest() {
var x = four99();
var y = x--;
Expect.equals(499, y);
Expect.equals(498, x);
Expect.equals(498, x--);
Expect.equals(497, x);
}
void preMinusMinusTest() {
var x = four99();
var y = --x;
Expect.equals(498, y);
Expect.equals(498, x);
Expect.equals(497, --x);
Expect.equals(497, x);
}
void main() {
postPlusPlusTest();
prePlusPlusTest();
postMinusMinusTest();
preMinusMinusTest();
}