Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Commit

Permalink
fix Enum in message body error (#96)
Browse files Browse the repository at this point in the history
* Add a regression test for #93

* Move pField to end of choice list to allow other field types to be processed first

* Remove break
  • Loading branch information
7sharp9 authored and ctaggart committed Oct 9, 2018
1 parent 785ea27 commit 40a86c7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
46 changes: 44 additions & 2 deletions Parser.Test/TestParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,6 @@ module RegressionTests =

[<Fact>]
let ``proto3 oneof type doesn't parse (#88)`` () =
System.Diagnostics.Debugger.Break()
Parse.fromStringWithParser pProto """
syntax = "proto3";
Expand All @@ -1083,4 +1082,47 @@ module RegressionTests =
])

])
])
])

[<Fact>]
let ``proto3 message with enum type doesn't parse (#93)`` () =
Parse.fromStringWithParser pProto """
syntax = "proto3";
message SearchRequest {
string query = 1;
int32 page_number = 2;
int32 result_per_page = 3;
enum Corpus {
UNIVERSAL = 0;
WEB = 1;
IMAGES = 2;
LOCAL = 3;
NEWS = 4;
PRODUCTS = 5;
VIDEO = 6;
}
Corpus corpus = 4;
}
"""
|> should equal (
[
TSyntax TProto3
TMessage ("SearchRequest",
[
TField ("query",TOptional,TString,1u,[])
TField ("page_number",TOptional,TInt32,2u,[])
TField ("result_per_page",TOptional,TInt32,3u,[])
TMessageEnum("Corpus",
[
TEnumField ("UNIVERSAL",0,[])
TEnumField ("WEB",1,[])
TEnumField ("IMAGES",2,[])
TEnumField ("LOCAL",3,[])
TEnumField ("NEWS",4,[])
TEnumField ("PRODUCTS",5,[])
TEnumField ("VIDEO",6,[])
])
TField ("corpus", TOptional,TIdent "Corpus",4u,[])
])
])
2 changes: 1 addition & 1 deletion Parser/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -482,14 +482,14 @@ module Parse =
choice [
(isProto2 >>. pGroup) // must be parsed first to avoid confusion
pOneOf // must be parsed before pField, so 'oneof' isn't considered a type in Proto3
pField
pMessageEnum
pMessageMessage
(isProto2 >>. pMessageExtend)
(isProto2 >>. pExtensions)
pMessageOption
pMap
pReserved
pField
]

/// Parse message option: "option" (ident | "(" fullIdent ")" { "." ident }
Expand Down

0 comments on commit 40a86c7

Please sign in to comment.