Files
sdk/tests/standalone/assert_test.dart
T
lrn@google.com be2453bae1 Removed/moved "assert" function to core_patch.dart as "_assert".
Changed resolution of assert to only accepting assert in a statement position.
Added more assert tests.

Review URL: https://chromiumcodereview.appspot.com//10915083

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@12026 260f80e4-7a28-3924-810f-c04153c831b5
2012-09-07 12:45:02 +00:00

51 lines
1.5 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.
// VMOptions=--enable_asserts
//
// Dart test program testing assert statements.
class AssertTest {
static test() {
try {
assert(false);
Expect.fail("Assertion 'false' didn't fail.");
} on AssertionError catch (error) {
Expect.equals("false", error.failedAssertion);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("assert_test.dart", subs);
Expect.equals(11, error.line);
Expect.equals(14, error.column);
}
}
static testClosure() {
try {
assert(() => false);
Expect.fail("Assertion '() => false' didn't fail.");
} on AssertionError catch (error) {
Expect.equals("() => false", error.failedAssertion);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("assert_test.dart", subs);
Expect.equals(27, error.line);
Expect.equals(14, error.column);
}
}
static testMain() {
test();
testClosure();
}
}
main() {
AssertTest.testMain();
}