Skip to content

Commit

Permalink
Further unwrapping, fix all Wire tests
Browse files Browse the repository at this point in the history
  • Loading branch information
supermario committed Nov 10, 2023
1 parent f50ba1d commit bcf01ba
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 115 deletions.
4 changes: 2 additions & 2 deletions extra/Lamdera.hs
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,9 @@ requireEnv name = do
val <- lookupEnv name
case val of
Nothing ->
error $ Prelude.concat ["🌏👀 ENV var ", name, " is required but was not found"]
error $ Prelude.concat ["🌏👀 ENV var `", name, "` is required but was not found"]
Just "" ->
error $ Prelude.concat ["🌏👀 ENV var ", name, " is required but was empty"]
error $ Prelude.concat ["🌏👀 ENV var `", name, "` is required but was empty"]
Just v -> pure v


Expand Down
16 changes: 8 additions & 8 deletions extra/Lamdera/Wire3/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ runTests isTest_ debugName pkg modul decls generatedName generated canonicalValu

else do
-- debugHaskellPass ("🏁 Actual value input for " <> (T.pack $ Data.Name.toChars generatedName)) (canonicalValue) (pure ())
let formatted = Ext.ElmFormat.format $ ToSource.convert generated
case formatted of
Right t ->
debugPassText ("💚 actual implementation pretty-printed " <> show_ (Src.getName modul)) (t) (pure ())
Left err ->
debugPassText ("❌❌❌ actual implementation pretty-printed something went wrong with formatting " <> show_ (Src.getName modul)) (err) (pure ())
-- let formatted = Ext.ElmFormat.format $ ToSource.convert generated
-- case formatted of
-- Right t ->
-- debugPassText ("💚 actual implementation pretty-printed " <> show_ (Src.getName modul)) (t) (pure ())
-- Left err ->
-- debugPassText ("❌❌❌ actual implementation pretty-printed something went wrong with formatting " <> show_ (Src.getName modul)) (err) (pure ())

-- debugPassText ("🧡 expected implementation pretty-printed " <> show_ (Src.getName modul)) (Source2.generateCodecs Map.empty wiregen) (pure ())
-- debugHaskellPass ("🧡 expected implementation AST.Canonical " <> show_ (Src.getName modul)) (testDefinition) (pure ())

-- diff <- icdiff (hindentFormatValue testDefinition) (hindentFormatValue generated)
diff <- icdiff (hindentFormatValue testDefinition) (hindentFormatValue generated)
diff2 <- icdiff (ToSource.convert (testDefinition `withName` generatedName)) (ToSource.convert generated)
-- diff2 <- do
-- l <- Ext.ElmFormat.format $ ToSource.convert testDefinition
Expand All @@ -93,7 +93,7 @@ runTests isTest_ debugName pkg modul decls generatedName generated canonicalValu
-- Left err -> show_ err
-- Right t -> t
-- icdiff (withDefault l) (withDefault r)
-- atomicPutStrLn $ "❌❌❌ failed, attempting pretty-print diff1:\n" ++ diff
atomicPutStrLn $ "❌❌❌ failed, attempting pretty-print diff1:\n" ++ diff
atomicPutStrLn $ "❌❌❌ ASTs do not match, attempting pretty-print diff2:\n" ++ diff2
-- error "exiting!"
-- atomicPutStrLn $ "❌❌❌ " ++ Data.Name.toChars (Src.getName modul) ++ "." ++ Data.Name.toChars generatedName ++ " gen does not match test definition."
Expand Down
48 changes: 18 additions & 30 deletions extra/Lamdera/Wire3/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ encodeUnsignedInt8 value =
Map.empty
(TLambda
(TType (Module.Canonical (Name "elm" "core") "Basics") "Int" [])
tLamdera_Wire_Encoder))))
tElm_Bytes_Encoder))))
[value]))


Expand All @@ -453,7 +453,7 @@ encodeUnsignedInt16 value =
((TType (Module.Canonical (Name "elm" "bytes") "Bytes") "Endianness" []))
(TLambda
(TType (Module.Canonical (Name "elm" "core") "Basics") "Int" [])
tLamdera_Wire_Encoder)))))
tElm_Bytes_Encoder)))))
[endianness, value]))


Expand All @@ -468,35 +468,22 @@ encodeInt value =


decodeUnsignedInt8 =
(a (VarForeign mLamdera_Wire "decodeUnsignedInt8"
(a (VarForeign mBytes_Decode "unsignedInt8"
(Forall
Map.empty
(TAlias
mLamdera_Wire
"Decoder"
[("a", TType (Module.Canonical (Name "elm" "core") "Basics") "Int" [])]
(Filled
(TType
(Module.Canonical (Name "elm" "bytes") "Bytes.Decode")
"Decoder"
[TType (Module.Canonical (Name "elm" "core") "Basics") "Int" []]))))))

(tElm_Bytes_Decoder tInt)
)
))

decodeUnsignedInt16 =
a (Call (a (VarForeign mBytes_Decode "unsignedInt16"
(Forall
Map.empty
(TLambda
(TType (Module.Canonical (Name "elm" "bytes") "Bytes") "Endianness" [])
(TAlias
mLamdera_Wire
"Decoder"
[("a", TType (Module.Canonical (Name "elm" "core") "Basics") "Int" [])]
(Filled
(TType
(Module.Canonical (Name "elm" "bytes") "Bytes.Decode")
"Decoder"
[TType (Module.Canonical (Name "elm" "core") "Basics") "Int" []])))))))
(tElm_Bytes_Decoder tInt)
)
)))
[endianness]
)

Expand Down Expand Up @@ -715,18 +702,19 @@ lvar n =

-- Patterns

pint i =
a (PInt i)
pint i = a (PInt i)
pvar n = a (PVar n)
pAny_ = a (PAnything)

pvar n =
a (PVar n)
call fn args = (a (Call fn args))

pAny_ =
a (PAnything)
tInt = (TType (Module.Canonical (Name "elm" "core") "Basics") "Int" [])

call fn args =
(a (Call fn args))
tElm_Bytes_Encoder =
(TType (Module.Canonical (Name "elm" "bytes") "Bytes.Encode") "Encoder" [])

tElm_Bytes_Decoder v =
(TType (Module.Canonical (Name "elm" "bytes") "Bytes.Decode") "Decoder" [v])

tLamdera_Wire_Encoder =
(TAlias
Expand Down
3 changes: 2 additions & 1 deletion test/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ allTests =
, scope "Test.Lamdera -> " $ Test.Lamdera.suite
, scope "Test.Snapshot -> " $ Test.Snapshot.suite
, scope "Test.Wire -> " $ Test.Wire.suite
, scope "Test.Ext.ElmPages.Check -> " $ Test.Ext.ElmPages.Check.suite
-- Disable temporarily as the cache busting is crazy aggressive meaning 100mb redownload each run :|
-- , scope "Test.Ext.ElmPages.Check -> " $ Test.Ext.ElmPages.Check.suite
, scope "Test.TypeHashes -> " $ Test.TypeHashes.suite
, scope "Test.Check -> " $ Test.Check.suite
, scope "Lamdera.Evergreen.TestMigrationHarness -> " $ Lamdera.Evergreen.TestMigrationHarness.suite
Expand Down
7 changes: 4 additions & 3 deletions test/Test/Wire.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ wire = do
setEnv "ELM_HOME" "/Users/mario/elm-home-elmx-test"

let testFiles =
[
"src/Test/Wire_Union_1_Basic.elm"
[ ""
, "src/Test/Wire_Union_1_Basic.elm"
, "src/Test/Wire_Union_2_Basic.elm"
, "src/Test/External.elm"
, "src/Test/Wire_Union_3_Params.elm"
, "src/Test/Wire_Union_4_Tricky.elm"
, "src/Test/Wire_Union_5_Massive.elm"
, "src/Test/Wire_Alias_1_Basic.elm"
, "src/Test/Wire_Alias_2_Record.elm"
, "src/Test/Wire_Alias_3_SubAlias.elm"
Expand All @@ -106,7 +107,7 @@ wire = do
throw e


testFiles & mapM (\filename -> do
testFiles & filter ((/=) "") & mapM (\filename -> do
putStrLn $ "testing: " <> show filename
-- Bust Elm's caching with this one weird trick!
touch $ project </> filename
Expand Down
16 changes: 9 additions & 7 deletions test/scenario-alltypes/src/Test/External.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Test.External exposing (..)

import Bytes.Decode
import Bytes.Encode
import Lamdera.Wire3


Expand Down Expand Up @@ -41,14 +43,14 @@ expected_w3_encode_ExternalCustomBasic : ExternalCustomBasic -> Lamdera.Wire3.En
expected_w3_encode_ExternalCustomBasic w3v =
case w3v of
Custom1 ->
Lamdera.Wire3.encodeUnsignedInt8 0
Bytes.Encode.unsignedInt8 0

Custom2 ->
Lamdera.Wire3.encodeUnsignedInt8 1
Bytes.Encode.unsignedInt8 1


expected_w3_decode_ExternalCustomBasic =
Lamdera.Wire3.decodeUnsignedInt8
Bytes.Decode.unsignedInt8
|> Lamdera.Wire3.andThenDecode
(\w3v ->
case w3v of
Expand Down Expand Up @@ -85,17 +87,17 @@ expected_w3_encode_ExternalCustomThreaded : (threadedTvar -> Lamdera.Wire3.Encod
expected_w3_encode_ExternalCustomThreaded w3_x_c_threadedTvar w3_x_c_threadedTvar2 w3v =
case w3v of
AlphabeticallyFirst v0 ->
Lamdera.Wire3.encodeSequenceWithoutLength [ Lamdera.Wire3.encodeUnsignedInt8 0, w3_x_c_threadedTvar2 v0 ]
Lamdera.Wire3.encodeSequenceWithoutLength [ Bytes.Encode.unsignedInt8 0, w3_x_c_threadedTvar2 v0 ]

AlphabeticallyKMiddleThreaded v0 ->
Lamdera.Wire3.encodeSequenceWithoutLength [ Lamdera.Wire3.encodeUnsignedInt8 1, w3_x_c_threadedTvar v0 ]
Lamdera.Wire3.encodeSequenceWithoutLength [ Bytes.Encode.unsignedInt8 1, w3_x_c_threadedTvar v0 ]

AlphabeticallyLast ->
Lamdera.Wire3.encodeUnsignedInt8 2
Bytes.Encode.unsignedInt8 2


expected_w3_decode_ExternalCustomThreaded w3_x_c_threadedTvar w3_x_c_threadedTvar2 =
Lamdera.Wire3.decodeUnsignedInt8
Bytes.Decode.unsignedInt8
|> Lamdera.Wire3.andThenDecode
(\w3v ->
case w3v of
Expand Down
6 changes: 4 additions & 2 deletions test/scenario-alltypes/src/Test/Wire_Alias_3_SubAlias.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Test.Wire_Alias_3_SubAlias exposing (..)

import Array exposing (Array)
import Bytes.Decode
import Bytes.Encode
import Dict exposing (Dict)
import Lamdera.Wire3
import Set exposing (Set)
Expand Down Expand Up @@ -84,11 +86,11 @@ expected_w3_encode_SubCustom : (value -> Lamdera.Wire3.Encoder) -> SubCustom val
expected_w3_encode_SubCustom w3_x_c_value w3v =
case w3v of
SubCustomValue v0 ->
Lamdera.Wire3.encodeSequenceWithoutLength [ Lamdera.Wire3.encodeUnsignedInt8 0, w3_x_c_value v0 ]
Lamdera.Wire3.encodeSequenceWithoutLength [ Bytes.Encode.unsignedInt8 0, w3_x_c_value v0 ]


expected_w3_decode_SubCustom w3_x_c_value =
Lamdera.Wire3.decodeUnsignedInt8
Bytes.Decode.unsignedInt8
|> Lamdera.Wire3.andThenDecode
(\w3v ->
case w3v of
Expand Down
6 changes: 4 additions & 2 deletions test/scenario-alltypes/src/Test/Wire_Alias_4_TvarRename.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Test.Wire_Alias_4_TvarRename exposing (..)

import Bytes.Decode
import Bytes.Encode
import Lamdera.Wire3
import Test.Wire_Alias_4_TvarRename2

Expand Down Expand Up @@ -43,11 +45,11 @@ expected_w3_encode_Also : (msg -> Lamdera.Wire3.Encoder) -> Also msg -> Lamdera.
expected_w3_encode_Also w3_x_c_msg w3v =
case w3v of
Tag v0 ->
Lamdera.Wire3.encodeSequenceWithoutLength [ Lamdera.Wire3.encodeUnsignedInt8 0, Test.Wire_Alias_4_TvarRename2.w3_encode_OnGrid (Lamdera.Wire3.encodeMaybe w3_x_c_msg) v0 ]
Lamdera.Wire3.encodeSequenceWithoutLength [ Bytes.Encode.unsignedInt8 0, Test.Wire_Alias_4_TvarRename2.w3_encode_OnGrid (Lamdera.Wire3.encodeMaybe w3_x_c_msg) v0 ]


expected_w3_decode_Also w3_x_c_msg =
Lamdera.Wire3.decodeUnsignedInt8
Bytes.Decode.unsignedInt8
|> Lamdera.Wire3.andThenDecode
(\w3v ->
case w3v of
Expand Down
10 changes: 6 additions & 4 deletions test/scenario-alltypes/src/Test/Wire_Core_Types.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Test.Wire_Core_Types exposing (..)

import Bytes
import Bytes.Decode
import Bytes.Encode
import Lamdera.Wire3
import Time
import Url
Expand All @@ -20,17 +22,17 @@ expected_w3_encode_CoreTypes : CoreTypes -> Lamdera.Wire3.Encoder
expected_w3_encode_CoreTypes w3v =
case w3v of
ValueBytes v0 ->
Lamdera.Wire3.encodeSequenceWithoutLength [ Lamdera.Wire3.encodeUnsignedInt8 0, Lamdera.Wire3.encodeBytes v0 ]
Lamdera.Wire3.encodeSequenceWithoutLength [ Bytes.Encode.unsignedInt8 0, Lamdera.Wire3.encodeBytes v0 ]

ValueTime v0 ->
Lamdera.Wire3.encodeSequenceWithoutLength [ Lamdera.Wire3.encodeUnsignedInt8 1, (\t -> Lamdera.Wire3.encodeInt (Time.posixToMillis t)) v0 ]
Lamdera.Wire3.encodeSequenceWithoutLength [ Bytes.Encode.unsignedInt8 1, (\t -> Lamdera.Wire3.encodeInt (Time.posixToMillis t)) v0 ]

ValueUrl v0 ->
Lamdera.Wire3.encodeSequenceWithoutLength [ Lamdera.Wire3.encodeUnsignedInt8 2, Url.w3_encode_Url v0 ]
Lamdera.Wire3.encodeSequenceWithoutLength [ Bytes.Encode.unsignedInt8 2, Url.w3_encode_Url v0 ]


expected_w3_decode_CoreTypes =
Lamdera.Wire3.decodeUnsignedInt8
Bytes.Decode.unsignedInt8
|> Lamdera.Wire3.andThenDecode
(\w3v ->
case w3v of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Test.Wire_Record_Extensible2_MultiParam exposing (..)

import Bytes.Decode
import Bytes.Encode
import Lamdera.Wire3


Expand Down Expand Up @@ -88,13 +90,13 @@ expected_w3_encode_C_ w3v =
case w3v of
NodeClicked_ v0 ->
Lamdera.Wire3.encodeSequenceWithoutLength
[ Lamdera.Wire3.encodeUnsignedInt8 0
[ Bytes.Encode.unsignedInt8 0
, w3_encode_ExtensibleRecordTypeUsage_ v0
]


expected_w3_decode_C_ =
Lamdera.Wire3.decodeUnsignedInt8
Bytes.Decode.unsignedInt8
|> Lamdera.Wire3.andThenDecode
(\w3v ->
case w3v of
Expand Down
18 changes: 10 additions & 8 deletions test/scenario-alltypes/src/Test/Wire_Record_Extensible3_Tricky.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Test.Wire_Record_Extensible3_Tricky exposing (..)

import Bytes.Decode
import Bytes.Encode
import Lamdera.Wire3
import Test.Wire_Alias_2_Record
import Test.Wire_Record_Extensible1_Basic
Expand Down Expand Up @@ -48,7 +50,7 @@ expected_w3_encode_Type w3_x_c_msg w3v =
case w3v of
DateType v0 ->
Lamdera.Wire3.encodeSequenceWithoutLength
[ Lamdera.Wire3.encodeUnsignedInt8 0
[ Bytes.Encode.unsignedInt8 0
, (\w3_rec_var0 ->
Lamdera.Wire3.encodeSequenceWithoutLength
[ Lamdera.Wire3.encodeList w3_x_c_msg w3_rec_var0.attributes
Expand All @@ -60,7 +62,7 @@ expected_w3_encode_Type w3_x_c_msg w3v =


expected_w3_decode_Type w3_x_c_msg =
Lamdera.Wire3.decodeUnsignedInt8
Bytes.Decode.unsignedInt8
|> Lamdera.Wire3.andThenDecode
(\w3v ->
case w3v of
Expand Down Expand Up @@ -174,7 +176,7 @@ expected_w3_encode_DatePickerType w3v =
case w3v of
DateTimeType_ v0 ->
Lamdera.Wire3.encodeSequenceWithoutLength
[ Lamdera.Wire3.encodeUnsignedInt8 0
[ Bytes.Encode.unsignedInt8 0
, (\w3_rec_var0 ->
Lamdera.Wire3.encodeSequenceWithoutLength
[ Lamdera.Wire3.encodeBool w3_rec_var0.allowYearNavigation
Expand All @@ -187,7 +189,7 @@ expected_w3_encode_DatePickerType w3v =

DateType_ v0 ->
Lamdera.Wire3.encodeSequenceWithoutLength
[ Lamdera.Wire3.encodeUnsignedInt8 1
[ Bytes.Encode.unsignedInt8 1
, (\w3_rec_var0 ->
Lamdera.Wire3.encodeSequenceWithoutLength
[ Lamdera.Wire3.encodeBool w3_rec_var0.allowYearNavigation
Expand All @@ -199,7 +201,7 @@ expected_w3_encode_DatePickerType w3v =

TimeType_ v0 ->
Lamdera.Wire3.encodeSequenceWithoutLength
[ Lamdera.Wire3.encodeUnsignedInt8 2
[ Bytes.Encode.unsignedInt8 2
, (\w3_rec_var0 ->
Lamdera.Wire3.encodeSequenceWithoutLength
[ Lamdera.Wire3.encodeString w3_rec_var0.attributes
Expand All @@ -211,7 +213,7 @@ expected_w3_encode_DatePickerType w3v =


expected_w3_decode_DatePickerType =
Lamdera.Wire3.decodeUnsignedInt8
Bytes.Decode.unsignedInt8
|> Lamdera.Wire3.andThenDecode
(\w3v ->
case w3v of
Expand Down Expand Up @@ -336,14 +338,14 @@ expected_w3_decode_TimePickerConfig =
case w3v of
Variation v0 v1 ->
Lamdera.Wire3.encodeSequenceWithoutLength
[ Lamdera.Wire3.encodeUnsignedInt8 0
[ Bytes.Encode.unsignedInt8 0
, w3_x_c_variation v0
, Lamdera.Wire3.encodeList (w3_encode_Property w3_x_c_class Lamdera.Wire3.encodeNever) v1
]
expected_w3_decode_Property w3_x_c_class w3_x_c_variation =
Lamdera.Wire3.decodeUnsignedInt8
Bytes.Decode.unsignedInt8
|> Lamdera.Wire3.andThenDecode
(\w3v ->
case w3v of
Expand Down
Loading

0 comments on commit bcf01ba

Please sign in to comment.