-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proto3 enums #137
Proto3 enums #137
Changes from all commits
8605326
176a5d5
bccef23
1d716f0
da6d4db
9d1a76d
eb4f5e4
2d0974b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,10 @@ message Foo { | |
Sub sub = 5; | ||
|
||
enum FooEnum { | ||
option allow_alias = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
Enum1 = 0; | ||
Enum2 = 1; | ||
Enum2 = 3; | ||
Enum2a = 3; | ||
} | ||
FooEnum enum = 6; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ import Proto.Proto3'Fields | |
) | ||
import Test.Framework (testGroup) | ||
import Test.Framework.Providers.HUnit (testCase) | ||
import Test.HUnit ((@=?)) | ||
import Test.HUnit ((@=?), assertBool) | ||
|
||
import Data.ProtoLens.TestUtil | ||
|
||
|
@@ -98,6 +98,26 @@ main = testMain | |
, testCase "string" $ (def :: Strings) @=? (def & string .~ "") | ||
, testCase "enum" $ (def :: Foo) @=? (def & enum .~ Foo'Enum1) | ||
] | ||
-- Enums are all pattern aliases | ||
, testGroup "enum" | ||
[ testCase "aliases are exported" $ Foo'Enum2 @=? Foo'Enum2a | ||
, testCase "enum values" $ do | ||
map toEnum [0, 3, 3] @=? [Foo'Enum1, Foo'Enum2, Foo'Enum2a] | ||
["Foo'Enum1", "Foo'Enum2", "Foo'Enum2", "toEnum 5"] | ||
@=? map show [Foo'Enum1, Foo'Enum2, Foo'Enum2a, toEnum 5] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're also exporting the newtype constructor itself. |
||
["Enum1", "Enum2", "Enum2", "6"] | ||
@=? map showEnum [Foo'Enum1, Foo'Enum2, Foo'Enum2a, toEnum 6] | ||
[Just Foo'Enum1, Just Foo'Enum2, Just Foo'Enum2, Nothing, Nothing] | ||
@=? map readEnum ["Enum1", "Enum2", "Enum2a", "4", "5"] | ||
, testCase "enum patterns" $ do | ||
assertBool "enum value" $ case toEnum 3 of | ||
Foo'Enum2 -> True | ||
_ -> False | ||
assertBool "enum alias" $ case toEnum 3 of | ||
Foo'Enum2a -> True | ||
_ -> False | ||
|
||
] | ||
-- Unset proto3 messages are different than the default value. | ||
, testGroup "submessage" | ||
[ testCase "Nothing" $ Nothing @=? ((def :: Foo) ^. maybe'sub) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3