| 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 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 }; | 820 }; |
| 821 | 821 |
| 822 const Hats MY_HAT = 1; | 822 const Hats MY_HAT = 1; |
| 823 ` | 823 ` |
| 824 test.addTestCase(contents, []string{ | 824 test.addTestCase(contents, []string{ |
| 825 "Illegal assignment", | 825 "Illegal assignment", |
| 826 "Const MY_HAT of type Hats may not be assigned the value
1 of type int8."}) | 826 "Const MY_HAT of type Hats may not be assigned the value
1 of type int8."}) |
| 827 } | 827 } |
| 828 | 828 |
| 829 //////////////////////////////////////////////////////////// | 829 //////////////////////////////////////////////////////////// |
| 830 // Group 3: Invalid use of interface request. |
| 831 //////////////////////////////////////////////////////////// |
| 832 |
| 833 //////////////////////////////////////////////////////////// |
| 834 // Test Case: Make an interface request out of a struct |
| 835 //////////////////////////////////////////////////////////// |
| 836 { |
| 837 contents := ` |
| 838 struct Foo{ |
| 839 }; |
| 840 |
| 841 struct Bar{ |
| 842 Foo& x; |
| 843 }; |
| 844 ` |
| 845 test.addTestCase(contents, []string{ |
| 846 "Invalid interface request specification", |
| 847 "Foo&. Foo is not an interface type"}) |
| 848 } |
| 849 |
| 850 //////////////////////////////////////////////////////////// |
| 851 // Test Case: Make a nullable interface request out of a struct |
| 852 //////////////////////////////////////////////////////////// |
| 853 { |
| 854 contents := ` |
| 855 struct Foo{ |
| 856 }; |
| 857 |
| 858 struct Bar{ |
| 859 Foo&? x; |
| 860 }; |
| 861 ` |
| 862 test.addTestCase(contents, []string{ |
| 863 "Invalid interface request specification", |
| 864 "Foo&?. Foo is not an interface type"}) |
| 865 } |
| 866 |
| 867 //////////////////////////////////////////////////////////// |
| 868 // Group 4: Invalid use of nullable |
| 869 //////////////////////////////////////////////////////////// |
| 870 |
| 871 //////////////////////////////////////////////////////////// |
| 872 // Test Case: Make nullable enum. |
| 873 //////////////////////////////////////////////////////////// |
| 874 { |
| 875 contents := ` |
| 876 enum Hats { |
| 877 COWBOY, |
| 878 TOP |
| 879 }; |
| 880 |
| 881 struct Bar{ |
| 882 Hats? my_hat; |
| 883 }; |
| 884 ` |
| 885 test.addTestCase(contents, []string{ |
| 886 "The type Hats? is invalid because Hats is an enum type
and these may not be made nullable."}) |
| 887 } |
| 888 |
| 889 //////////////////////////////////////////////////////////// |
| 830 // Execute all of the test cases. | 890 // Execute all of the test cases. |
| 831 //////////////////////////////////////////////////////////// | 891 //////////////////////////////////////////////////////////// |
| 832 for i, c := range test.cases { | 892 for i, c := range test.cases { |
| 833 // Parse and resolve the mojom input. | 893 // Parse and resolve the mojom input. |
| 834 descriptor := mojom.NewMojomDescriptor() | 894 descriptor := mojom.NewMojomDescriptor() |
| 835 parser := MakeParser(c.fileName, c.mojomContents, descriptor, c.
importedFrom) | 895 parser := MakeParser(c.fileName, c.mojomContents, descriptor, c.
importedFrom) |
| 836 parser.Parse() | 896 parser.Parse() |
| 837 if !parser.OK() { | 897 if !parser.OK() { |
| 838 t.Errorf("Parsing error for %s: %s", c.fileName, parser.
GetError().Error()) | 898 t.Errorf("Parsing error for %s: %s", c.fileName, parser.
GetError().Error()) |
| 839 continue | 899 continue |
| 840 } | 900 } |
| 841 err := descriptor.Resolve() | 901 err := descriptor.Resolve() |
| 842 if err == nil { | 902 if err == nil { |
| 843 t.Errorf("Resolution unexpectedly succeeded for test cas
e %d.", i) | 903 t.Errorf("Resolution unexpectedly succeeded for test cas
e %d.", i) |
| 844 continue | 904 continue |
| 845 } | 905 } |
| 846 got := err.Error() | 906 got := err.Error() |
| 847 for _, expected := range c.expectedErrors { | 907 for _, expected := range c.expectedErrors { |
| 848 if !strings.Contains(got, expected) { | 908 if !strings.Contains(got, expected) { |
| 849 t.Errorf("%s:\n*****expected to contain:\n%s\n**
**actual\n%s", c.fileName, expected, got) | 909 t.Errorf("%s:\n*****expected to contain:\n%s\n**
**actual\n%s", c.fileName, expected, got) |
| 850 } | 910 } |
| 851 } | 911 } |
| 852 | 912 |
| 853 } | 913 } |
| 854 } | 914 } |
| OLD | NEW |