Tests for passing falsy values to named arguments.

Fixes type error in previous version.

BUG=3530015
TEST=

Review URL: https://chromereviews.googleplex.com/3561022

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@260 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
sra@google.com 2011-10-07 20:55:07 +00:00
parent 015f74d3c1
commit 8af240c0cc
5 changed files with 173 additions and 0 deletions

View file

@ -78,6 +78,10 @@ NamedParameters2NegativeTest: Fail # Implementation in progress.
NamedParameters3NegativeTest: Fail # Implementation in progress.
NamedParameters4NegativeTest: Fail # Implementation in progress.
NamedParameters6NegativeTest: Crash # Implementation in progress.
NamedParametersPassingZeroTest: Fail # Bug
NamedParametersPassingNullTest: Fail # Bug
NamedParametersPassingFalseTest: Fail # Bug
NamedParametersPassingFalsyTest: Fail # Bug
InstFieldInitializerTest: Fail # Cannot deal with static final values in const expression.
RegExp3Test: Fail # 5299683
InterfaceFactory3NegativeTest: Fail # 5387405

View file

@ -0,0 +1,40 @@
// 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.
// Dart test program for testing named parameters with 'false' passed as an
// argument.
class TestClass {
TestClass();
bool method([bool value]) => value;
static bool staticMethod([bool value]) => value;
}
bool globalMethod([bool value]) => value;
main() {
var obj = new TestClass();
Expect.equals(null, obj.method());
Expect.equals(true, obj.method(true));
Expect.equals(true, obj.method(value: true));
Expect.equals(false, obj.method(false));
Expect.equals(false, obj.method(value: false));
Expect.equals(null, TestClass.staticMethod());
Expect.equals(true, TestClass.staticMethod(true));
Expect.equals(true, TestClass.staticMethod(value: true));
Expect.equals(false, TestClass.staticMethod(false));
Expect.equals(false, TestClass.staticMethod(value: false));
Expect.equals(null, globalMethod());
Expect.equals(true, globalMethod(true));
Expect.equals(true, globalMethod(value: true));
Expect.equals(false, globalMethod(false));
Expect.equals(false, globalMethod(value: false));
}

View file

@ -0,0 +1,49 @@
// 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.
// Dart test program for testing named parameters with various values that might
// be implemented as 'falsy' values in a JavaScript implementation.
class TestClass {
TestClass();
method([value = 100]) => value;
static staticMethod([value = 200]) => value;
}
globalMethod([value = 300]) => value;
final testValues = const [0, 0.0, '', false, null];
testFunction(f) {
Expect.isTrue(f() >= 100);
for (var v in testValues) {
Expect.equals(v, f(v));
Expect.equals(v, f(value: v));
}
}
main() {
var obj = new TestClass();
Expect.equals(100, obj.method());
Expect.equals(200, TestClass.staticMethod());
Expect.equals(300, globalMethod());
for (var v in testValues) {
Expect.equals(v, obj.method(v));
Expect.equals(v, obj.method(value: v));
Expect.equals(v, TestClass.staticMethod(v));
Expect.equals(v, TestClass.staticMethod(value: v));
Expect.equals(v, globalMethod(v));
Expect.equals(v, globalMethod(value: v));
}
// Test via indirect call.
testFunction(obj.method);
testFunction(TestClass.staticMethod);
testFunction(globalMethod);
}

View file

@ -0,0 +1,40 @@
// 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.
// Dart test program for testing named parameters with 'null' passed as an
// argument.
class TestClass {
TestClass();
num method([value = 100]) => value;
static num staticMethod([value = 200]) => value;
}
num globalMethod([value = 300]) => value;
main() {
var obj = new TestClass();
Expect.equals(100, obj.method());
Expect.equals(50, obj.method(50));
Expect.equals(50, obj.method(value: 50));
Expect.equals(null, obj.method(null));
Expect.equals(null, obj.method(value: null));
Expect.equals(200, TestClass.staticMethod());
Expect.equals(50, TestClass.staticMethod(50));
Expect.equals(50, TestClass.staticMethod(value: 50));
Expect.equals(null, TestClass.staticMethod(null));
Expect.equals(null, TestClass.staticMethod(value: null));
Expect.equals(300, globalMethod());
Expect.equals(50, globalMethod(50));
Expect.equals(50, globalMethod(value: 50));
Expect.equals(null, globalMethod(null));
Expect.equals(null, globalMethod(value: null));
}

View file

@ -0,0 +1,40 @@
// 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.
// Dart test program for testing named parameters with zero passed as an
// argument.
class TestClass {
TestClass();
num method([num value = 100]) => value;
static num staticMethod([num value = 200]) => value;
}
num globalMethod([num value = 300]) => value;
main() {
var obj = new TestClass();
Expect.equals(100, obj.method());
Expect.equals(7, obj.method(7));
Expect.equals(7, obj.method(value: 7));
Expect.equals(0, obj.method(0));
Expect.equals(0, obj.method(value: 0));
Expect.equals(200, TestClass.staticMethod());
Expect.equals(7, TestClass.staticMethod(7));
Expect.equals(7, TestClass.staticMethod(value: 7));
Expect.equals(0, TestClass.staticMethod(0));
Expect.equals(0, TestClass.staticMethod(value: 0));
Expect.equals(300, globalMethod());
Expect.equals(7, globalMethod(7));
Expect.equals(7, globalMethod(value: 7));
Expect.equals(0, globalMethod(0));
Expect.equals(0, globalMethod(value: 0));
}