| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |