Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 4 |
| 5 #include "vm/assembler.h" | 5 #include "vm/assembler.h" |
| 6 #include "vm/bigint_operations.h" | 6 #include "vm/bigint_operations.h" |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 EXPECT_EQ(Token::kLPAREN, iterator.CurrentTokenKind()); | 178 EXPECT_EQ(Token::kLPAREN, iterator.CurrentTokenKind()); |
| 179 iterator.Advance(); | 179 iterator.Advance(); |
| 180 iterator.Advance(); | 180 iterator.Advance(); |
| 181 iterator.Advance(); // Advance to '.' token. | 181 iterator.Advance(); // Advance to '.' token. |
| 182 EXPECT_EQ(Token::kPERIOD, iterator.CurrentTokenKind()); | 182 EXPECT_EQ(Token::kPERIOD, iterator.CurrentTokenKind()); |
| 183 iterator.Advance(); // Advance to end of stream. | 183 iterator.Advance(); // Advance to end of stream. |
| 184 EXPECT_EQ(Token::kEOS, iterator.CurrentTokenKind()); | 184 EXPECT_EQ(Token::kEOS, iterator.CurrentTokenKind()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 | 187 |
| 188 TEST_CASE(GenerateExactSource) { | |
| 189 // Verify the exact formatting of generated sources. | |
| 190 const char* kScriptChars = | |
| 191 "\n" | |
| 192 "class A {\n" | |
| 193 " static bar() { return 42; }\n" | |
| 194 " static fly() { return 5; }\n" | |
| 195 " void catcher(x) {\n" | |
| 196 " try {\n" | |
| 197 " if (x) {\n" | |
| 198 " fly();\n" | |
| 199 " } else {\n" | |
| 200 " !fly();\n" | |
| 201 " }\n" | |
| 202 " } on Blah catch (a) {\n" | |
| 203 " _print(17);\n" | |
| 204 " } catch (e, s) {\n" | |
|
kasperl
2014/03/12 09:20:17
Also test that it works with finally? There was a
| |
| 205 " bar()\n" | |
| 206 " }\n" | |
| 207 " }\n" | |
| 208 "}\n"; | |
| 209 | |
| 210 String& url = String::Handle(String::New("dart-test:GenerateExactSource")); | |
| 211 String& source = String::Handle(String::New(kScriptChars)); | |
| 212 Script& script = Script::Handle(Script::New(url, | |
| 213 source, | |
| 214 RawScript::kScriptTag)); | |
| 215 script.Tokenize(String::Handle(String::New(""))); | |
| 216 const TokenStream& tokens = TokenStream::Handle(script.tokens()); | |
| 217 const String& gen_source = String::Handle(tokens.GenerateSource()); | |
| 218 EXPECT_STREQ(source.ToCString(), gen_source.ToCString()); | |
| 219 } | |
| 220 | |
| 221 | |
| 188 TEST_CASE(InstanceClass) { | 222 TEST_CASE(InstanceClass) { |
| 189 // Allocate the class first. | 223 // Allocate the class first. |
| 190 String& class_name = String::Handle(Symbols::New("EmptyClass")); | 224 String& class_name = String::Handle(Symbols::New("EmptyClass")); |
| 191 Script& script = Script::Handle(); | 225 Script& script = Script::Handle(); |
| 192 const Class& empty_class = | 226 const Class& empty_class = |
| 193 Class::Handle(CreateDummyClass(class_name, script)); | 227 Class::Handle(CreateDummyClass(class_name, script)); |
| 194 | 228 |
| 195 // EmptyClass has no fields and no functions. | 229 // EmptyClass has no fields and no functions. |
| 196 EXPECT_EQ(Array::Handle(empty_class.fields()).Length(), 0); | 230 EXPECT_EQ(Array::Handle(empty_class.fields()).Length(), 0); |
| 197 EXPECT_EQ(Array::Handle(empty_class.functions()).Length(), 0); | 231 EXPECT_EQ(Array::Handle(empty_class.functions()).Length(), 0); |
| (...skipping 3820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4018 // Simple map. | 4052 // Simple map. |
| 4019 // | 4053 // |
| 4020 // TODO(turnidge): Consider showing something like: {1: 2, 2: 'otter'} | 4054 // TODO(turnidge): Consider showing something like: {1: 2, 2: 'otter'} |
| 4021 result = Dart_GetField(lib, NewString("simple_map")); | 4055 result = Dart_GetField(lib, NewString("simple_map")); |
| 4022 EXPECT_VALID(result); | 4056 EXPECT_VALID(result); |
| 4023 obj ^= Api::UnwrapHandle(result); | 4057 obj ^= Api::UnwrapHandle(result); |
| 4024 EXPECT_STREQ("Instance of '_LinkedHashMap'", obj.ToUserCString()); | 4058 EXPECT_STREQ("Instance of '_LinkedHashMap'", obj.ToUserCString()); |
| 4025 } | 4059 } |
| 4026 | 4060 |
| 4027 } // namespace dart | 4061 } // namespace dart |
| OLD | NEW |