Flutter Engine
The Flutter Engine
mixin_test.cc
Go to the documentation of this file.
1// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "include/dart_api.h"
6#include "vm/unit_test.h"
7
8namespace dart {
9
10#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
11
12TEST_CASE(Mixin_PrivateSuperResolution) {
13 // clang-format off
14 Dart_SourceFile sourcefiles[] = {
15 {
16 "file:///test-app.dart",
17 "class A {\n"
18 " _bar() => 42;\n"
19 "}\n"
20 "mixin M on A {\n"
21 " bar() => -1;\n"
22 "}\n"
23 "class B extends A {\n"
24 " foo() => 6;\n"
25 "}\n"
26 "class C extends B with M {\n"
27 " bar() => super._bar();\n"
28 "}\n"
29 "main() {\n"
30 " return new C().bar();\n"
31 "}\n",
32 }};
33 // clang-format on
34
36 sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles,
37 /* resolver= */ nullptr, /* finalize= */ true, /* incrementally= */ true);
38 EXPECT_VALID(lib);
39 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, nullptr);
40 int64_t value = 0;
43 EXPECT_EQ(42, value);
44}
45
46TEST_CASE(Mixin_PrivateSuperResolutionCrossLibraryShouldFail) {
47 // clang-format off
48 Dart_SourceFile sourcefiles[] = {
49 {
50 "file:///test-app.dart",
51 "import 'test-lib.dart';\n"
52 "class D extends B with M {\n"
53 " bar() => super._bar();\n"
54 "}\n"
55 "main() {\n"
56 " try {\n"
57 " return new D().bar();\n"
58 " } catch (e) {\n"
59 " return e.toString().split('\\n').first;\n"
60 " }\n"
61 "}\n",
62 },
63 {
64 "file:///test-lib.dart",
65 "class A {\n"
66 " foo() => 4;\n"
67 " _bar() => 42;\n"
68 "}\n"
69 "mixin M on A {\n"
70 " bar() => -1;\n"
71 "}\n"
72 "class B extends A {\n"
73 " foo() => 6;\n"
74 "}\n"
75 "class C extends B with M {\n"
76 " bar() => super._bar();\n"
77 "}\n"
78 },
79 {
80 "file:///.packages", "untitled:/"
81 }};
82 // clang-format on
83
85 sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles,
86 /* resolver= */ nullptr, /* finalize= */ true, /* incrementally= */ true);
87 EXPECT_ERROR(lib, "Error: Superclass has no method named '_bar'.");
88}
89#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
90
91} // namespace dart
static Dart_Handle LoadTestScriptWithDFE(int sourcefiles_count, Dart_SourceFile sourcefiles[], Dart_NativeEntryResolver resolver=nullptr, bool finalize=true, bool incrementally=true, bool allow_compile_errors=false, const char *entry_script_uri=nullptr, const char *multiroot_filepaths=nullptr, const char *multiroot_scheme=nullptr)
Definition: unit_test.cc:490
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
uint8_t value
GAsyncResult * result
Definition: dart_vm.cc:33
DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)
TEST_CASE(DirectoryCurrent)
Dart_Handle NewString(const char *str)
DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, int64_t *value)
#define EXPECT_ERROR(handle, substring)
Definition: unit_test.h:663
#define EXPECT_VALID(handle)
Definition: unit_test.h:643