mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:27:17 +00:00
8eb0b79ac1
Change-Id: I2c0182203d7566908a574208b7d8f10da08d7a43 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152043 Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com> Commit-Queue: Bob Nystrom <rnystrom@google.com>
62 lines
1.7 KiB
Dart
62 lines
1.7 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.
|
|
// Test for instance field initializer expressions.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
class Cheese {
|
|
static const mild = 1;
|
|
static const stinky = 2;
|
|
|
|
// Instance fields with initializer expression.
|
|
String name = "";
|
|
var smell = mild;
|
|
|
|
Cheese() {
|
|
Expect.equals("", this.name);
|
|
Expect.equals(Cheese.mild, this.smell);
|
|
}
|
|
|
|
Cheese.initInBlock(String s) {
|
|
Expect.equals("", this.name);
|
|
Expect.equals(Cheese.mild, this.smell);
|
|
this.name = s;
|
|
}
|
|
|
|
Cheese.initFieldParam(this.name, this.smell) {}
|
|
|
|
// Test that static const field Cheese.mild is not shadowed
|
|
// by the parameter mild when compiling the field initializer
|
|
// for instance field smell.
|
|
Cheese.hideAndSeek(var mild) : name = mild {
|
|
Expect.equals(mild, this.name);
|
|
Expect.equals(Cheese.mild, this.smell);
|
|
}
|
|
}
|
|
|
|
class HasNoExplicitConstructor {
|
|
String s = "Tilsiter";
|
|
}
|
|
|
|
main() {
|
|
var generic = new Cheese();
|
|
Expect.equals("", generic.name);
|
|
Expect.equals(Cheese.mild, generic.smell);
|
|
|
|
var gruyere = new Cheese.initInBlock("Gruyere");
|
|
Expect.equals("Gruyere", gruyere.name);
|
|
Expect.equals(Cheese.mild, gruyere.smell);
|
|
|
|
var munster = new Cheese.initFieldParam("Munster", Cheese.stinky);
|
|
Expect.equals("Munster", munster.name);
|
|
Expect.equals(Cheese.stinky, munster.smell);
|
|
|
|
var brie = new Cheese.hideAndSeek("Brie");
|
|
Expect.equals("Brie", brie.name);
|
|
Expect.equals(Cheese.mild, brie.smell);
|
|
|
|
var t = new HasNoExplicitConstructor();
|
|
Expect.equals("Tilsiter", t.s);
|
|
}
|