Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: frog/tests/frog_native/native_checked_fields_frog_test.dart

Issue 10536169: Move frog/tests/{leg,leg_only,frog_native} to tests/compiler/. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 // Test that type checks occur on assignment to fields of native methods.
6
7 class A native "*A" {
8 int foo;
9 }
10
11 class B native "*B" {
12 String foo;
13 }
14
15 A makeA() native { return new A(); }
16 B makeB() native { return new B(); }
17
18 void setup() native """
19 function A() {}
20
21 function B() {}
22
23 makeA = function(){return new A;};
24 makeB = function(){return new B;};
25 """;
26
27 expectThrows(action()) {
28 bool threw = false;
29 try {
30 action();
31 } catch (var e) {
32 threw = true;
33 }
34 Expect.isTrue(threw);
35 }
36
37 checkedModeTest() {
38 var things = [makeA(), makeB()];
39 var a = things[0];
40 var b = things[1];
41
42 a.foo = 123;
43 expectThrows(() => a.foo = 'xxx');
44 Expect.equals(123, a.foo);
45
46 b.foo = 'hello';
47 expectThrows(() => b.foo = 123);
48 Expect.equals('hello', b.foo);
49
50 // Check that we throw the same errors when the locals are typed.
51 A aa = things[0];
52 B bb = things[1];
53
54 aa.foo = 124;
55 expectThrows(() => aa.foo = 'xxx');
56 Expect.equals(124, aa.foo);
57
58 bb.foo = 'hello';
59 expectThrows(() => bb.foo = 124);
60 Expect.equals('hello', bb.foo);
61 }
62
63 uncheckedModeTest() {
64 var things = [makeA(), makeB()];
65 var a = things[0];
66 var b = things[1];
67
68 a.foo = 123;
69 Expect.equals(123, a.foo);
70 a.foo = 'xxx';
71 Expect.equals('xxx', a.foo);
72
73 b.foo = 'hello';
74 Expect.equals('hello', b.foo);
75 b.foo = 123;
76 Expect.equals(b.foo, 123);
77
78 // Check that we do not throw errors when the locals are typed.
79 A aa = things[0];
80 B bb = things[1];
81
82 aa.foo = 124;
83 Expect.equals(124, aa.foo);
84 a.foo = 'yyy';
85 Expect.equals('yyy', a.foo);
86
87 b.foo = 'hello';
88 Expect.equals('hello', b.foo);
89 b.foo = 124;
90 Expect.equals(b.foo, 124);
91 }
92
93 bool isCheckedMode() {
94 var stuff = [1, 'string'];
95 var a = stuff[0];
96 // Checked-mode detection.
97 try {
98 String s = a;
99 return false;
100 } catch (var e) { }
101 return true;
102 }
103
104 main() {
105 setup();
106
107 if (isCheckedMode()) {
108 checkedModeTest();
109 } else {
110 uncheckedModeTest();
111 }
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698