Files
sdk/tests/language/src/AssertTest.dart
T
dgrove@google.com ebe439410d Initial checkin.
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@22 260f80e4-7a28-3924-810f-c04153c831b5
2011-10-05 06:22:36 +00:00

55 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() {
int i = 0;
try {
assert(false);
} catch (AssertError error) {
i = 1;
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("AssertTest.dart", subs);
Expect.equals(12, error.line);
Expect.equals(14, error.column);
}
return i;
}
static testClosure() {
int i = 0;
try {
assert(() => false);
} catch (AssertError error) {
i = 1;
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("AssertTest.dart", subs);
Expect.equals(30, error.line);
Expect.equals(14, error.column);
}
return i;
}
static testMain() {
Expect.equals(1, test());
Expect.equals(1, testClosure());
}
}
main() {
AssertTest.testMain();
}