diff --git a/protoc-gen-elm/go_tests/main_test.go b/protoc-gen-elm/go_tests/main_test.go index 295f985..1e6c21d 100644 --- a/protoc-gen-elm/go_tests/main_test.go +++ b/protoc-gen-elm/go_tests/main_test.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "io/ioutil" "os" "os/exec" @@ -21,21 +22,23 @@ func TestDiff(t *testing.T) { continue } - dir := filepath.Join(td, fi.Name()) - actualOutputDir := filepath.Join(dir, "actual_output") + t.Run(fmt.Sprintf("generating in directory %s", fi.Name()), func (t *testing.T) { + dir := filepath.Join(td, fi.Name()) + actualOutputDir := filepath.Join(dir, "actual_output") - err := os.RemoveAll(actualOutputDir) - if err != nil { - t.Fatal(err) - } + err := os.RemoveAll(actualOutputDir) + if err != nil { + t.Fatal(err) + } - err = os.MkdirAll(actualOutputDir, 0777) - if err != nil { - t.Fatal(err) - } + err = os.MkdirAll(actualOutputDir, 0777) + if err != nil { + t.Fatal(err) + } - runProto(t, dir) - runDiff(t, dir) + runProto(t, dir) + runDiff(t, dir) + }) } } diff --git a/protoc-gen-elm/go_tests/testdata/oneof/expected_output/Oneof.elm b/protoc-gen-elm/go_tests/testdata/oneof/expected_output/Oneof.elm index d4f7ad6..ad59767 100644 --- a/protoc-gen-elm/go_tests/testdata/oneof/expected_output/Oneof.elm +++ b/protoc-gen-elm/go_tests/testdata/oneof/expected_output/Oneof.elm @@ -27,7 +27,7 @@ firstOneofDecoder : JD.Decoder FirstOneof firstOneofDecoder = JD.lazy <| \_ -> JD.oneOf [ JD.map StringField (JD.field "stringField" JD.string) - , JD.map IntField (JD.field "intField" JD.int) + , JD.map IntField (JD.field "intField" intDecoder) , JD.succeed FirstOneofUnspecified ] diff --git a/protoc-gen-elm/go_tests/testdata/repeated/expected_output/Repeated.elm b/protoc-gen-elm/go_tests/testdata/repeated/expected_output/Repeated.elm index 81f3ca0..6f5150a 100644 --- a/protoc-gen-elm/go_tests/testdata/repeated/expected_output/Repeated.elm +++ b/protoc-gen-elm/go_tests/testdata/repeated/expected_output/Repeated.elm @@ -74,7 +74,7 @@ type alias SubMessage = subMessageDecoder : JD.Decoder SubMessage subMessageDecoder = JD.lazy <| \_ -> decode SubMessage - |> required "int32Field" JD.int 0 + |> required "int32Field" intDecoder 0 subMessageEncoder : SubMessage -> JE.Value @@ -117,21 +117,21 @@ fooDecoder = JD.lazy <| \_ -> decode Foo |> required "doubleField" JD.float 0.0 |> required "floatField" JD.float 0.0 - |> required "int32Field" JD.int 0 - |> required "int64Field" JD.int 0 - |> required "uint32Field" JD.int 0 - |> required "uint64Field" JD.int 0 - |> required "sint32Field" JD.int 0 - |> required "sint64Field" JD.int 0 - |> required "fixed32Field" JD.int 0 - |> required "fixed64Field" JD.int 0 - |> required "sfixed32Field" JD.int 0 - |> required "sfixed64Field" JD.int 0 + |> required "int32Field" intDecoder 0 + |> required "int64Field" intDecoder 0 + |> required "uint32Field" intDecoder 0 + |> required "uint64Field" intDecoder 0 + |> required "sint32Field" intDecoder 0 + |> required "sint64Field" intDecoder 0 + |> required "fixed32Field" intDecoder 0 + |> required "fixed64Field" intDecoder 0 + |> required "sfixed32Field" intDecoder 0 + |> required "sfixed64Field" intDecoder 0 |> required "boolField" JD.bool False |> required "stringField" JD.string "" |> required "enumField" enumDecoder enumDefault |> optional "subMessage" subMessageDecoder - |> repeated "repeatedInt64Field" JD.int + |> repeated "repeatedInt64Field" intDecoder |> repeated "repeatedEnumField" enumDecoder |> optional "nestedMessageField" foo_NestedMessageDecoder |> required "nestedEnumField" foo_NestedEnumDecoder foo_NestedEnumDefault @@ -161,20 +161,20 @@ fooEncoder v = [ (requiredFieldEncoder "doubleField" JE.float 0.0 v.doubleField) , (requiredFieldEncoder "floatField" JE.float 0.0 v.floatField) , (requiredFieldEncoder "int32Field" JE.int 0 v.int32Field) - , (requiredFieldEncoder "int64Field" JE.int 0 v.int64Field) + , (requiredFieldEncoder "int64Field" numericStringEncoder 0 v.int64Field) , (requiredFieldEncoder "uint32Field" JE.int 0 v.uint32Field) - , (requiredFieldEncoder "uint64Field" JE.int 0 v.uint64Field) + , (requiredFieldEncoder "uint64Field" numericStringEncoder 0 v.uint64Field) , (requiredFieldEncoder "sint32Field" JE.int 0 v.sint32Field) - , (requiredFieldEncoder "sint64Field" JE.int 0 v.sint64Field) + , (requiredFieldEncoder "sint64Field" numericStringEncoder 0 v.sint64Field) , (requiredFieldEncoder "fixed32Field" JE.int 0 v.fixed32Field) - , (requiredFieldEncoder "fixed64Field" JE.int 0 v.fixed64Field) + , (requiredFieldEncoder "fixed64Field" numericStringEncoder 0 v.fixed64Field) , (requiredFieldEncoder "sfixed32Field" JE.int 0 v.sfixed32Field) - , (requiredFieldEncoder "sfixed64Field" JE.int 0 v.sfixed64Field) + , (requiredFieldEncoder "sfixed64Field" numericStringEncoder 0 v.sfixed64Field) , (requiredFieldEncoder "boolField" JE.bool False v.boolField) , (requiredFieldEncoder "stringField" JE.string "" v.stringField) , (requiredFieldEncoder "enumField" enumEncoder enumDefault v.enumField) , (optionalEncoder "subMessage" subMessageEncoder v.subMessage) - , (repeatedFieldEncoder "repeatedInt64Field" JE.int v.repeatedInt64Field) + , (repeatedFieldEncoder "repeatedInt64Field" numericStringEncoder v.repeatedInt64Field) , (repeatedFieldEncoder "repeatedEnumField" enumEncoder v.repeatedEnumField) , (optionalEncoder "nestedMessageField" foo_NestedMessageEncoder v.nestedMessageField) , (requiredFieldEncoder "nestedEnumField" foo_NestedEnumEncoder foo_NestedEnumDefault v.nestedEnumField) @@ -201,7 +201,7 @@ type alias Foo_NestedMessage = foo_NestedMessageDecoder : JD.Decoder Foo_NestedMessage foo_NestedMessageDecoder = JD.lazy <| \_ -> decode Foo_NestedMessage - |> required "int32Field" JD.int 0 + |> required "int32Field" intDecoder 0 foo_NestedMessageEncoder : Foo_NestedMessage -> JE.Value @@ -219,7 +219,7 @@ type alias Foo_NestedMessage_NestedNestedMessage = foo_NestedMessage_NestedNestedMessageDecoder : JD.Decoder Foo_NestedMessage_NestedNestedMessage foo_NestedMessage_NestedNestedMessageDecoder = JD.lazy <| \_ -> decode Foo_NestedMessage_NestedNestedMessage - |> required "int32Field" JD.int 0 + |> required "int32Field" intDecoder 0 foo_NestedMessage_NestedNestedMessageEncoder : Foo_NestedMessage_NestedNestedMessage -> JE.Value @@ -254,16 +254,16 @@ fooRepeatedDecoder = JD.lazy <| \_ -> decode FooRepeated |> repeated "doubleField" JD.float |> repeated "floatField" JD.float - |> repeated "int32Field" JD.int - |> repeated "int64Field" JD.int - |> repeated "uint32Field" JD.int - |> repeated "uint64Field" JD.int - |> repeated "sint32Field" JD.int - |> repeated "sint64Field" JD.int - |> repeated "fixed32Field" JD.int - |> repeated "fixed64Field" JD.int - |> repeated "sfixed32Field" JD.int - |> repeated "sfixed64Field" JD.int + |> repeated "int32Field" intDecoder + |> repeated "int64Field" intDecoder + |> repeated "uint32Field" intDecoder + |> repeated "uint64Field" intDecoder + |> repeated "sint32Field" intDecoder + |> repeated "sint64Field" intDecoder + |> repeated "fixed32Field" intDecoder + |> repeated "fixed64Field" intDecoder + |> repeated "sfixed32Field" intDecoder + |> repeated "sfixed64Field" intDecoder |> repeated "boolField" JD.bool |> repeated "stringField" JD.string |> repeated "enumField" enumDecoder @@ -276,15 +276,15 @@ fooRepeatedEncoder v = [ (repeatedFieldEncoder "doubleField" JE.float v.doubleField) , (repeatedFieldEncoder "floatField" JE.float v.floatField) , (repeatedFieldEncoder "int32Field" JE.int v.int32Field) - , (repeatedFieldEncoder "int64Field" JE.int v.int64Field) + , (repeatedFieldEncoder "int64Field" numericStringEncoder v.int64Field) , (repeatedFieldEncoder "uint32Field" JE.int v.uint32Field) - , (repeatedFieldEncoder "uint64Field" JE.int v.uint64Field) + , (repeatedFieldEncoder "uint64Field" numericStringEncoder v.uint64Field) , (repeatedFieldEncoder "sint32Field" JE.int v.sint32Field) - , (repeatedFieldEncoder "sint64Field" JE.int v.sint64Field) + , (repeatedFieldEncoder "sint64Field" numericStringEncoder v.sint64Field) , (repeatedFieldEncoder "fixed32Field" JE.int v.fixed32Field) - , (repeatedFieldEncoder "fixed64Field" JE.int v.fixed64Field) + , (repeatedFieldEncoder "fixed64Field" numericStringEncoder v.fixed64Field) , (repeatedFieldEncoder "sfixed32Field" JE.int v.sfixed32Field) - , (repeatedFieldEncoder "sfixed64Field" JE.int v.sfixed64Field) + , (repeatedFieldEncoder "sfixed64Field" numericStringEncoder v.sfixed64Field) , (repeatedFieldEncoder "boolField" JE.bool v.boolField) , (repeatedFieldEncoder "stringField" JE.string v.stringField) , (repeatedFieldEncoder "enumField" enumEncoder v.enumField) diff --git a/protoc-gen-elm/go_tests/testdata/well_known_types/expected_output/Google/Protobuf/Empty.elm b/protoc-gen-elm/go_tests/testdata/well_known_types/expected_output/Google/Protobuf/Empty.elm new file mode 100644 index 0000000..9b43168 --- /dev/null +++ b/protoc-gen-elm/go_tests/testdata/well_known_types/expected_output/Google/Protobuf/Empty.elm @@ -0,0 +1,28 @@ +module Google.Protobuf.Empty exposing (..) + +-- DO NOT EDIT +-- AUTOGENERATED BY THE ELM PROTOCOL BUFFER COMPILER +-- https://github.com/tiziano88/elm-protobuf +-- source file: google/protobuf/empty.proto + +import Protobuf exposing (..) + +import Json.Decode as JD +import Json.Encode as JE + + +type alias Empty = + { + } + + +emptyDecoder : JD.Decoder Empty +emptyDecoder = + JD.lazy <| \_ -> decode Empty + + +emptyEncoder : Empty -> JE.Value +emptyEncoder v = + JE.object <| List.filterMap identity <| + [ + ] diff --git a/protoc-gen-elm/go_tests/testdata/well_known_types/expected_output/Google/Protobuf/Wrappers.elm b/protoc-gen-elm/go_tests/testdata/well_known_types/expected_output/Google/Protobuf/Wrappers.elm deleted file mode 100644 index e581ea9..0000000 --- a/protoc-gen-elm/go_tests/testdata/well_known_types/expected_output/Google/Protobuf/Wrappers.elm +++ /dev/null @@ -1,237 +0,0 @@ -module Google.Protobuf.Wrappers exposing (..) - - -import Json.Decode as JD exposing ((:=)) -import Json.Encode as JE - - -(<$>) : (a -> b) -> JD.Decoder a -> JD.Decoder b -(<$>) = - JD.map - - -(<*>) : JD.Decoder (a -> b) -> JD.Decoder a -> JD.Decoder b -(<*>) f v = - f `JD.andThen` \x -> x <$> v - - -optionalDecoder : JD.Decoder a -> JD.Decoder (Maybe a) -optionalDecoder decoder = - JD.oneOf - [ JD.map Just decoder - , JD.succeed Nothing - ] - - -requiredFieldDecoder : String -> a -> JD.Decoder a -> JD.Decoder a -requiredFieldDecoder name default decoder = - withDefault default (name := decoder) - - -optionalFieldDecoder : String -> JD.Decoder a -> JD.Decoder (Maybe a) -optionalFieldDecoder name decoder = - optionalDecoder (name := decoder) - - -repeatedFieldDecoder : String -> JD.Decoder a -> JD.Decoder (List a) -repeatedFieldDecoder name decoder = - withDefault [] (name := (JD.list decoder)) - - -withDefault : a -> JD.Decoder a -> JD.Decoder a -withDefault default decoder = - JD.oneOf - [ decoder - , JD.succeed default - ] - - -optionalEncoder : String -> (a -> JE.Value) -> Maybe a -> Maybe (String, JE.Value) -optionalEncoder name encoder v = - case v of - Just x -> - Just (name, encoder x) - - Nothing -> - Nothing - - -requiredFieldEncoder : String -> (a -> JE.Value) -> a -> a -> Maybe (String, JE.Value) -requiredFieldEncoder name encoder default v = - if - v == default - then - Nothing - else - Just (name, encoder v) - - -repeatedFieldEncoder : String -> (a -> JE.Value) -> List a -> Maybe (String, JE.Value) -repeatedFieldEncoder name encoder v = - case v of - [] -> - Nothing - _ -> - Just (name, JE.list <| List.map encoder v) - - -type alias DoubleValue = - { value : Float -- 1 - } - - -doubleValueDecoder : JD.Decoder DoubleValue -doubleValueDecoder = - DoubleValue - <$> (requiredFieldDecoder "value" 0.0 JD.float) - - -doubleValueEncoder : DoubleValue -> JE.Value -doubleValueEncoder v = - JE.object <| List.filterMap identity <| - [ (requiredFieldEncoder "value" JE.float 0.0 v.value) - ] - - -type alias FloatValue = - { value : Float -- 1 - } - - -floatValueDecoder : JD.Decoder FloatValue -floatValueDecoder = - FloatValue - <$> (requiredFieldDecoder "value" 0.0 JD.float) - - -floatValueEncoder : FloatValue -> JE.Value -floatValueEncoder v = - JE.object <| List.filterMap identity <| - [ (requiredFieldEncoder "value" JE.float 0.0 v.value) - ] - - -type alias Int64Value = - { value : Int -- 1 - } - - -int64ValueDecoder : JD.Decoder Int64Value -int64ValueDecoder = - Int64Value - <$> (requiredFieldDecoder "value" 0 JD.int) - - -int64ValueEncoder : Int64Value -> JE.Value -int64ValueEncoder v = - JE.object <| List.filterMap identity <| - [ (requiredFieldEncoder "value" JE.int 0 v.value) - ] - - -type alias UInt64Value = - { value : Int -- 1 - } - - -uInt64ValueDecoder : JD.Decoder UInt64Value -uInt64ValueDecoder = - UInt64Value - <$> (requiredFieldDecoder "value" 0 JD.int) - - -uInt64ValueEncoder : UInt64Value -> JE.Value -uInt64ValueEncoder v = - JE.object <| List.filterMap identity <| - [ (requiredFieldEncoder "value" JE.int 0 v.value) - ] - - -type alias Int32Value = - { value : Int -- 1 - } - - -int32ValueDecoder : JD.Decoder Int32Value -int32ValueDecoder = - Int32Value - <$> (requiredFieldDecoder "value" 0 JD.int) - - -int32ValueEncoder : Int32Value -> JE.Value -int32ValueEncoder v = - JE.object <| List.filterMap identity <| - [ (requiredFieldEncoder "value" JE.int 0 v.value) - ] - - -type alias UInt32Value = - { value : Int -- 1 - } - - -uInt32ValueDecoder : JD.Decoder UInt32Value -uInt32ValueDecoder = - UInt32Value - <$> (requiredFieldDecoder "value" 0 JD.int) - - -uInt32ValueEncoder : UInt32Value -> JE.Value -uInt32ValueEncoder v = - JE.object <| List.filterMap identity <| - [ (requiredFieldEncoder "value" JE.int 0 v.value) - ] - - -type alias BoolValue = - { value : Bool -- 1 - } - - -boolValueDecoder : JD.Decoder BoolValue -boolValueDecoder = - BoolValue - <$> (requiredFieldDecoder "value" False JD.bool) - - -boolValueEncoder : BoolValue -> JE.Value -boolValueEncoder v = - JE.object <| List.filterMap identity <| - [ (requiredFieldEncoder "value" JE.bool False v.value) - ] - - -type alias StringValue = - { value : String -- 1 - } - - -stringValueDecoder : JD.Decoder StringValue -stringValueDecoder = - StringValue - <$> (requiredFieldDecoder "value" "" JD.string) - - -stringValueEncoder : StringValue -> JE.Value -stringValueEncoder v = - JE.object <| List.filterMap identity <| - [ (requiredFieldEncoder "value" JE.string "" v.value) - ] - - -type alias BytesValue = - { value : Bytes -- 1 - } - - -bytesValueDecoder : JD.Decoder BytesValue -bytesValueDecoder = - BytesValue - <$> (requiredFieldDecoder "value" xxx bytesFieldDecoder) - - -bytesValueEncoder : BytesValue -> JE.Value -bytesValueEncoder v = - JE.object <| List.filterMap identity <| - [ (requiredFieldEncoder "value" bytesFieldDecoder xxx v.value) - ] diff --git a/protoc-gen-elm/go_tests/testdata/well_known_types/expected_output/Well_known_types.elm b/protoc-gen-elm/go_tests/testdata/well_known_types/expected_output/Well_known_types.elm index 431b498..dedb803 100644 --- a/protoc-gen-elm/go_tests/testdata/well_known_types/expected_output/Well_known_types.elm +++ b/protoc-gen-elm/go_tests/testdata/well_known_types/expected_output/Well_known_types.elm @@ -9,10 +9,12 @@ import Protobuf exposing (..) import Json.Decode as JD import Json.Encode as JE +import Google.Protobuf.Empty exposing (..) type alias Message = { doubleValueField : Maybe Float -- 1 + , empty : Maybe Empty -- 2 } @@ -20,10 +22,12 @@ messageDecoder : JD.Decoder Message messageDecoder = JD.lazy <| \_ -> decode Message |> optional "doubleValueField" floatValueDecoder + |> optional "empty" emptyDecoder messageEncoder : Message -> JE.Value messageEncoder v = JE.object <| List.filterMap identity <| [ (optionalEncoder "doubleValueField" floatValueEncoder v.doubleValueField) + , (optionalEncoder "empty" emptyEncoder v.empty) ] diff --git a/protoc-gen-elm/go_tests/testdata/well_known_types/input/well_known_types.proto b/protoc-gen-elm/go_tests/testdata/well_known_types/input/well_known_types.proto index e7aaf79..479f840 100644 --- a/protoc-gen-elm/go_tests/testdata/well_known_types/input/well_known_types.proto +++ b/protoc-gen-elm/go_tests/testdata/well_known_types/input/well_known_types.proto @@ -1,7 +1,9 @@ syntax = "proto3"; import "google/protobuf/wrappers.proto"; +import "google/protobuf/empty.proto"; message Message { google.protobuf.DoubleValue double_value_field = 1; + google.protobuf.Empty empty = 2; }