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

Unified Diff: mojom/mojom_parser/parser/resolution_test.go

Issue 1514173002: New Mojom parser: Don't allow enum variables to be assigned int values. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: working on stuff 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojom/mojom_parser/parser/parser_test.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/mojom_parser/parser/resolution_test.go
diff --git a/mojom/mojom_parser/parser/resolution_test.go b/mojom/mojom_parser/parser/resolution_test.go
index 57c0cb92e2e380f50e6326c5cebc6285c42d050a..1025231f632d1f7a4088ba91d9d68518bf98e877 100644
--- a/mojom/mojom_parser/parser/resolution_test.go
+++ b/mojom/mojom_parser/parser/resolution_test.go
@@ -642,6 +642,10 @@ func TestSingleFileTypeValidationErrors(t *testing.T) {
test := singleFileTest{}
////////////////////////////////////////////////////////////
+ // Group 1: Left-hand-side is a struct
+ ////////////////////////////////////////////////////////////
+
+ ////////////////////////////////////////////////////////////
// Test Case: Use struct as constant type
////////////////////////////////////////////////////////////
{
@@ -657,7 +661,7 @@ func TestSingleFileTypeValidationErrors(t *testing.T) {
}
////////////////////////////////////////////////////////////
- // Test Case: Assign struct as map key
+ // Test Case: Use struct as map key
////////////////////////////////////////////////////////////
{
contents := `
@@ -691,6 +695,46 @@ func TestSingleFileTypeValidationErrors(t *testing.T) {
}
////////////////////////////////////////////////////////////
+ // Group 2: Left-hand-side is an enum
+ ////////////////////////////////////////////////////////////
+
+ ////////////////////////////////////////////////////////////
+ // Test Case: Assign an integer to an enum variable in a struct field.
+ ////////////////////////////////////////////////////////////
+ {
+ contents := `
+ enum Hats {
+ COWBOY,
+ TOP
+ };
+
+ struct Bar{
+ Hats my_hat = 1;
+ };
+ `
+ test.addTestCase(contents, []string{
+ "Illegal assignment",
+ "Field my_hat of type Hats may not be assigned the value 1 of type int8."})
+ }
+
+ ////////////////////////////////////////////////////////////
+ // Test Case: Assign an integer to an enum variable in a constant.
+ ////////////////////////////////////////////////////////////
+ {
+ contents := `
+ enum Hats {
+ COWBOY,
+ TOP
+ };
+
+ const Hats MY_HAT = 1;
+ `
+ test.addTestCase(contents, []string{
+ "Illegal assignment",
+ "Const MY_HAT of type Hats may not be assigned the value 1 of type int8."})
+ }
+
+ ////////////////////////////////////////////////////////////
// Execute all of the test cases.
////////////////////////////////////////////////////////////
for i, c := range test.cases {
« no previous file with comments | « mojom/mojom_parser/parser/parser_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698