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

Side by Side Diff: mojom/mojom_parser/parser/resolution_test.go

Issue 1511353002: New Mojom parser: Fix error message for invalid enum value initailizers. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « mojom/mojom_parser/parser/parsing.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package parser 5 package parser
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "mojom/mojom_parser/mojom" 9 "mojom/mojom_parser/mojom"
10 "strings" 10 "strings"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 enum MyEnum { 238 enum MyEnum {
239 ONE, 239 ONE,
240 TWO, 240 TWO,
241 THREE 241 THREE
242 }; 242 };
243 243
244 const int32 Bar = MyEnum.TWO; 244 const int32 Bar = MyEnum.TWO;
245 ` 245 `
246 test.addTestCase(contents, []string{ 246 test.addTestCase(contents, []string{
247 "Illegal assignment", 247 "Illegal assignment",
248 » » » "The enum value MyEnum.TWO may not be assigned to Bar of type int32"}) 248 » » » "The enum value MyEnum.TWO of type MyEnum may not be ass igned to Bar of type int32"})
249 } 249 }
250 250
251 //////////////////////////////////////////////////////////// 251 ////////////////////////////////////////////////////////////
252 // Group 2: The left-hand-side is a string variable. 252 // Group 2: The left-hand-side is a string variable.
253 //////////////////////////////////////////////////////////// 253 ////////////////////////////////////////////////////////////
254 254
255 //////////////////////////////////////////////////////////// 255 ////////////////////////////////////////////////////////////
256 // Test Case: Assign constant of int32 type to string variable. 256 // Test Case: Assign constant of int32 type to string variable.
257 //////////////////////////////////////////////////////////// 257 ////////////////////////////////////////////////////////////
258 { 258 {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 enum MyEnum { 326 enum MyEnum {
327 ONE, 327 ONE,
328 TWO, 328 TWO,
329 THREE 329 THREE
330 }; 330 };
331 331
332 const string Bar = MyEnum.TWO; 332 const string Bar = MyEnum.TWO;
333 ` 333 `
334 test.addTestCase(contents, []string{ 334 test.addTestCase(contents, []string{
335 "Illegal assignment", 335 "Illegal assignment",
336 » » » "The enum value MyEnum.TWO may not be assigned to Bar of type string"}) 336 » » » "The enum value MyEnum.TWO of type MyEnum may not be ass igned to Bar of type string"})
337 } 337 }
338 338
339 //////////////////////////////////////////////////////////// 339 ////////////////////////////////////////////////////////////
340 // Group 3: The left-hand-side is an enum variable. 340 // Group 3: The left-hand-side is an enum variable.
341 //////////////////////////////////////////////////////////// 341 ////////////////////////////////////////////////////////////
342 342
343 //////////////////////////////////////////////////////////// 343 ////////////////////////////////////////////////////////////
344 // Test Case: Assign constant of bool type to an enum variable. 344 // Test Case: Assign constant of bool type to an enum variable.
345 //////////////////////////////////////////////////////////// 345 ////////////////////////////////////////////////////////////
346 { 346 {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 enum MyOtherEnum { 445 enum MyOtherEnum {
446 ONE, 446 ONE,
447 TWO, 447 TWO,
448 THREE 448 THREE
449 }; 449 };
450 450
451 const MyEnum Bar = MyOtherEnum.TWO; 451 const MyEnum Bar = MyOtherEnum.TWO;
452 ` 452 `
453 test.addTestCase(contents, []string{ 453 test.addTestCase(contents, []string{
454 "Illegal assignment", 454 "Illegal assignment",
455 » » » "The enum value MyOtherEnum.TWO may not be assigned to B ar of type MyEnum"}) 455 » » » "The enum value MyOtherEnum.TWO of type MyOtherEnum may not be assigned to Bar of type MyEnum"})
456 } 456 }
457 457
458 //////////////////////////////////////////////////////////// 458 ////////////////////////////////////////////////////////////
459 // Test Case: Use an enum value from a different enum as an enum value i nitializer.
460 ////////////////////////////////////////////////////////////
461 {
462 contents := `
463 enum MyEnum {
464 ONE,
465 TWO,
466 THREE
467 };
468
469 enum MyOtherEnum {
470 ONE,
471 TWO = MyEnum.TWO,
472 THREE
473 };
474 `
475 test.addTestCase(contents, []string{
476 "Illegal assignment",
477 "The enum value MyEnum.TWO of type MyEnum may not be use d as an initializer for TWO of type MyOtherEnum."})
478 }
479
480 ////////////////////////////////////////////////////////////
481 // Test Case: Use an enum value from a different enum as an enum value i nitializer.
482 ////////////////////////////////////////////////////////////
483 {
484 contents := `
485 enum MyEnum {
486 ONE,
487 TWO,
488 THREE
489 };
490
491 const MyEnum Bar = MyEnum.TWO;
492
493 enum MyOtherEnum {
494 ONE,
495 TWO = Bar,
496 THREE
497 };
498 `
499 test.addTestCase(contents, []string{
500 "Illegal assignment",
501 "Bar with the value MyEnum.TWO may not be used as an ini tializer for TWO of type MyOtherEnum."})
502 }
503
504 ////////////////////////////////////////////////////////////
459 // Group 4: Multiple indirection 505 // Group 4: Multiple indirection
460 //////////////////////////////////////////////////////////// 506 ////////////////////////////////////////////////////////////
461 507
462 //////////////////////////////////////////////////////////// 508 ////////////////////////////////////////////////////////////
463 // Test Case: Assign doubly-indirected constant of bool type to int32 va riable. 509 // Test Case: Assign doubly-indirected constant of bool type to int32 va riable.
464 //////////////////////////////////////////////////////////// 510 ////////////////////////////////////////////////////////////
465 { 511 {
466 contents := ` 512 contents := `
467 const bool Bar = true; 513 const bool Bar = true;
468 const bool Baz = Bar; 514 const bool Baz = Bar;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 } 709 }
664 got := err.Error() 710 got := err.Error()
665 for _, expected := range c.expectedErrors { 711 for _, expected := range c.expectedErrors {
666 if !strings.Contains(got, expected) { 712 if !strings.Contains(got, expected) {
667 t.Errorf("%s:\n*****expected to contain:\n%s\n** **actual\n%s", c.fileName, expected, got) 713 t.Errorf("%s:\n*****expected to contain:\n%s\n** **actual\n%s", c.fileName, expected, got)
668 } 714 }
669 } 715 }
670 716
671 } 717 }
672 } 718 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/parser/parsing.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698