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

Side by Side Diff: tests/compiler/dart2js/class_codegen_test.dart

Issue 11265020: Minifying renamer for classes, methods and instance variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 // Test that parameters keep their names in the output. 4 // Test that parameters keep their names in the output.
5 5
6 #import("compiler_helper.dart"); 6 #import("compiler_helper.dart");
7 #import("parser_helper.dart"); 7 #import("parser_helper.dart");
8 8
9 const String TEST_ONE = r""" 9 const String TEST_ONE = r"""
10 class A { } 10 class A { }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 class A { 55 class A {
56 var a; 56 var a;
57 A(a) : this.a = a {} 57 A(a) : this.a = a {}
58 } 58 }
59 59
60 main() { 60 main() {
61 new A(3); 61 new A(3);
62 } 62 }
63 """; 63 """;
64 64
65 twoClasses() { 65
66 String generated = compileAll(TEST_ONE); 66 String getClassName(String generated, int idx) {
floitsch 2012/10/25 12:58:38 index
67 Expect.isTrue(generated.contains('\$.A = {"": [],\n "super": "Object"')); 67 RegExp classNameRE = new RegExp(r'\$\$.([A-Za-z]) ?= ?\{"":');
68 Expect.isTrue(generated.contains('\$.B = {"": [],\n "super": "Object"')); 68 return classNameRE.allMatches(generated)[idx][1];
69 }
70
71 String classRE(className) {
72 return '\\\$.$className ?= ?\\{"":\\s*\\[\\],\\s*"super": ?"O(bject)?"';
69 } 73 }
70 74
71 subClass() { 75 subClass() {
72 checkOutput(String generated) { 76
73 Expect.isTrue(generated.contains('\$.A = {"": [],\n "super": "Object"')); 77 twoClasses() {
74 Expect.isTrue(generated.contains('\$.B = {"": [],\n "super": "A"')); 78 String generated = compileAll(TEST_ONE);
79 String className = getClassName(generated, 0);
80 String className2 = getClassName(generated, 1);
81 Expect.isFalse(className == className2);
82 Expect.isTrue(new RegExp(classRe(className)).hasMatch(generated));
83 Expect.isTrue(new RegExp(classRe(className2)).hasMatch(generated));
84 }
85
86 subClass() {
87 void checkForClass(String generated, String className, String superClass) {
88 RegExp re = new RegExp(
89 '\\\$\\.$className ?= ?\\{"":\\s*\\[\\],\\s*"super": ?"$superClass"');
floitsch 2012/10/25 12:58:38 Not sure if it's better, but it would get rid of s
90 Expect.isTrue(re.hasMatch(generated));
75 } 91 }
76 92
77 checkOutput(compileAll(TEST_TWO)); 93 checkOutput1(String generated) {
78 checkOutput(compileAll(TEST_THREE)); 94 String className = getClassName(generated, 0);
95 String className2 = getClassName(generated, 1);
96 checkForClass(generated, className, 'O(bject)?');
97 checkForClass(generated, className2, className);
98 }
99
100 checkOutput2(String generated) {
101 String className = getClassName(generated, 0);
102 String className2 = getClassName(generated, 1);
103 checkForClass(generated, className, className2);
104 checkForClass(generated, className2, 'O(bject)?');
105 }
106
107 checkOutput1(compileAll(TEST_TWO));
108 checkOutput2(compileAll(TEST_THREE));
79 } 109 }
80 110
81 fieldTest() { 111 fieldTest() {
82 String generated = compileAll(TEST_FOUR); 112 String generated = compileAll(TEST_FOUR);
83 Expect.isTrue(generated.contains(r""" 113 var className = getClassName(generated, 1);
84 $.B = {"": ["y", "z", "x"], 114 Expect.isTrue(generated.contains("""
115 \$.$className = {"":
116 ["y", "z", "x"],
85 "super": "A" 117 "super": "A"
86 }""")); 118 }"""));
87 } 119 }
88 120
89 constructor1() { 121 constructor1() {
90 String generated = compileAll(TEST_FIVE); 122 String generated = compileAll(TEST_FIVE);
91 Expect.isTrue(generated.contains(r"new $.A(a);")); 123 Expect.isTrue(generated.contains(r"new $.A(a);") ||
124 generated.contains(r"new $.S(a);"));
92 } 125 }
93 126
94 main() { 127 main() {
95 twoClasses(); 128 twoClasses();
96 subClass(); 129 subClass();
97 fieldTest(); 130 fieldTest();
98 constructor1(); 131 constructor1();
99 } 132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698