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

Side by Side Diff: mojom/mojom_parser/parser/parser_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 unified diff | Download patch
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/lexer" 9 "mojom/mojom_parser/lexer"
10 "mojom/mojom_parser/mojom" 10 "mojom/mojom_parser/mojom"
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 struct Foo { 704 struct Foo {
705 uint8 x = 9999999999; 705 uint8 x = 9999999999;
706 }; 706 };
707 707
708 ` 708 `
709 expectError("Illegal assignment") 709 expectError("Illegal assignment")
710 expectError("Field x of type uint8 may not be assigned the value 9999999 999 of type int64.") 710 expectError("Field x of type uint8 may not be assigned the value 9999999 999 of type int64.")
711 endTestCase() 711 endTestCase()
712 712
713 //////////////////////////////////////////////////////////// 713 ////////////////////////////////////////////////////////////
714 // Test Case (Assign string to user-defined-type)
715 ////////////////////////////////////////////////////////////
716 startTestCase("")
717 cases[testCaseNum].mojomContents = `
718 struct Foo {
719 Foo x = "hello";
720 };
721
722 `
723 expectError("Illegal assignment")
724 expectError("Field x of type Foo may not be assigned the value \"hello\" of type string.")
725 endTestCase()
726
727 ////////////////////////////////////////////////////////////
728 // Test Case (Assign string to user-defined-type)
729 ////////////////////////////////////////////////////////////
730 startTestCase("")
731 cases[testCaseNum].mojomContents = `
732 struct Foo {
733 Foo x = "hello";
734 };
735
736 `
737 expectError("Illegal assignment")
738 expectError("Field x of type Foo may not be assigned the value \"hello\" of type string.")
739 endTestCase()
740
741 ////////////////////////////////////////////////////////////
742 // Group 2: Assign to constant. 714 // Group 2: Assign to constant.
743 //////////////////////////////////////////////////////////// 715 ////////////////////////////////////////////////////////////
744 716
745 //////////////////////////////////////////////////////////// 717 ////////////////////////////////////////////////////////////
746 // Test Case (Assign boolean to int32) 718 // Test Case (Assign boolean to int32)
747 //////////////////////////////////////////////////////////// 719 ////////////////////////////////////////////////////////////
748 startTestCase("") 720 startTestCase("")
749 cases[testCaseNum].mojomContents = ` 721 cases[testCaseNum].mojomContents = `
750 const int32 Foo = true; 722 const int32 Foo = true;
751 ` 723 `
752 expectError("Illegal assignment") 724 expectError("Illegal assignment")
753 expectError("Constant Foo of type int32 may not be assigned the value tr ue of type bool.") 725 expectError("Constant Foo of type int32 may not be assigned the value tr ue of type bool.")
754 endTestCase() 726 endTestCase()
755 727
756 //////////////////////////////////////////////////////////// 728 ////////////////////////////////////////////////////////////
757 // Test Case (Assign string to bool) 729 // Test Case (Assign string to bool)
758 //////////////////////////////////////////////////////////// 730 ////////////////////////////////////////////////////////////
759 startTestCase("") 731 startTestCase("")
760 cases[testCaseNum].mojomContents = ` 732 cases[testCaseNum].mojomContents = `
761 const bool Foo = "true"; 733 const bool Foo = "true";
762 ` 734 `
763 expectError("Illegal assignment") 735 expectError("Illegal assignment")
764 expectError("Constant Foo of type bool may not be assigned the value \"t rue\" of type string.") 736 expectError("Constant Foo of type bool may not be assigned the value \"t rue\" of type string.")
765 endTestCase() 737 endTestCase()
766 738
767 //////////////////////////////////////////////////////////// 739 ////////////////////////////////////////////////////////////
768 // Test Case (Assign boolean to user-defined type)
769 ////////////////////////////////////////////////////////////
770 startTestCase("")
771 cases[testCaseNum].mojomContents = `
772 const FooType Foo = true;
773 `
774 expectError("Illegal assignment")
775 expectError("Constant Foo of type FooType may not be assigned the value true of type bool.")
776 endTestCase()
777
778 ////////////////////////////////////////////////////////////
779 // Execute all of the test cases. 740 // Execute all of the test cases.
780 //////////////////////////////////////////////////////////// 741 ////////////////////////////////////////////////////////////
781 for i, c := range cases { 742 for i, c := range cases {
782 descriptor := mojom.NewMojomDescriptor() 743 descriptor := mojom.NewMojomDescriptor()
783 parser := MakeParser(c.fileName, c.mojomContents, descriptor, ni l) 744 parser := MakeParser(c.fileName, c.mojomContents, descriptor, ni l)
784 parser.Parse() 745 parser.Parse()
785 if parser.OK() { 746 if parser.OK() {
786 t.Errorf("Parsing was supposed to fail but did not for t est case %d", i) 747 t.Errorf("Parsing was supposed to fail but did not for t est case %d", i)
787 } else { 748 } else {
788 got := parser.GetError().Error() 749 got := parser.GetError().Error()
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 } else { 930 } else {
970 got := parser.GetError().Error() 931 got := parser.GetError().Error()
971 for _, expected := range c.expectedErrors { 932 for _, expected := range c.expectedErrors {
972 if !strings.Contains(got, expected) { 933 if !strings.Contains(got, expected) {
973 t.Errorf("%s:\n*****expected to contain: \n%s\n****actual\n%s", c.fileName, expected, got) 934 t.Errorf("%s:\n*****expected to contain: \n%s\n****actual\n%s", c.fileName, expected, got)
974 } 935 }
975 } 936 }
976 } 937 }
977 } 938 }
978 } 939 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/mojom/user_defined_types_test.go ('k') | mojom/mojom_parser/parser/resolution_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698