Skip to content

Commit

Permalink
Makes incremental mode work
Browse files Browse the repository at this point in the history
  • Loading branch information
gampleman committed May 17, 2024
1 parent a1c660c commit 02b1916
Show file tree
Hide file tree
Showing 10 changed files with 1,189 additions and 105 deletions.
2 changes: 1 addition & 1 deletion docs.json

Large diffs are not rendered by default.

106 changes: 85 additions & 21 deletions e2e/E2E.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,119 @@ module E2E exposing (suite)

-- Please edit this only in the e2e directory. The point of this is that the code is generated.

import Standard exposing (..)
import Csv.Decode
import Expect
import Fuzz exposing (Fuzzer)
import Json.Decode exposing (Decoder)
import Json.Encode exposing (Value)
import Fuzz exposing (Fuzzer)
import Serialize exposing (Codec)
import Standard exposing (..)
import Test exposing (Test)
import Expect


decoder : Decoder (A Int)
decoder =
Debug.todo ""

encode : A Int -> Value

encode : A Int -> Value
encode =
Debug.todo ""


serialize : Codec e (A Int)
serialize =
Debug.todo ""


fuzz : Fuzzer (A Int)
fuzz =
Debug.todo ""

type Foo
= X | Y | Z

all : List Foo
type Foo
= X
| Y
| Z


all : List Foo
all =
Debug.todo ""

toString : Foo -> String

toString : Foo -> String
toString =
Debug.todo ""

fromString : String -> Maybe Foo

fromString : String -> Maybe Foo
fromString =
Debug.todo ""


type alias FlatData =
{ a : Int
, b : String
, c : Bool
, d : Maybe Float
, f : Foo
}


csvDecoder : Csv.Decode.Decoder FlatData
csvDecoder =
Debug.todo ""


random : Random.Generator FlatData
random =
Debug.todo ""


suite : Test
suite =
Test.describe "E2E test" [
Test.fuzz fuzz "JSON encoding roundtrips on fuzzed value" <|
Test.describe "E2E test"
[ Test.fuzz fuzz "JSON encoding roundtrips on fuzzed value" <|
\val ->
encode val
encode val
|> Json.Decode.decodeValue decoder
|> Expect.equal (Ok val)

, List.map (\foo ->
Test.test (toString foo ++ " roundtrips from string") <|
\() ->
toString foo
|> fromString
|> Expect.equal (Just foo)
) all
, List.map
(\foo ->
Test.test (toString foo ++ " roundtrips from string") <|
\() ->
toString foo
|> fromString
|> Expect.equal (Just foo)
)
all
|> Test.describe "toString/fromString"
]
, Test.fuzz fuzz "serialize roundtrips on fuzzed value" <|
\val ->
Serialize.encodeToBytes serialize val
|> Serialize.decodeFromBytes serialize
|> Expect.equal (Ok val)
, Test.test "CSV decoding works" <|
\() ->
"""a,b,c_tag,d,f_tag
1,foo,True,1.0,X
2,bar,False,,Y
3,baz,True,3.0,Z"""
|> Csv.Decode.decodeCsv Csv.Decode.FieldNamesFromFirstRow csvDecoder
|> Result.mapError Csv.Decode.errorToString
|> Expect.equal
(Ok
[ { a = 1, b = "foo", c = True, d = Just 1.0, f = X }
, { a = 2, b = "bar", c = False, d = Nothing, f = Y }
, { a = 3, b = "baz", c = True, d = Just 3.0, f = Z }
]
)
, Test.test "Random generates a random-ish value" <|
\() ->
Random.initialSeed 42
|> Random.step random
|> Tuple.first
|> Expect.equal
{ a = -848567307, b = "TODO: Define string options", c = False, d = Nothing, f = X }
]
59 changes: 32 additions & 27 deletions elm.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
{
"type": "package",
"name": "gampleman/elm-review-derive",
"summary": "Generate code for json encoders/decoders, codecs, fuzzers, generators, and more",
"license": "MIT",
"version": "1.0.0",
"exposed-modules": [
"NoDebug.TodoItForMe",
"CodeGenerator",
"CodeGenerator.Test",
"TypePattern",
"ResolvedType"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm/core": "1.0.2 <= v < 2.0.0",
"elm/json": "1.1.3 <= v < 2.0.0",
"elm/project-metadata-utils": "1.0.1 <= v < 2.0.0",
"elm-explorations/test": "2.0.0 <= v < 3.0.0",
"elmcraft/core-extra": "2.0.0 <= v < 3.0.0",
"erlandsona/assoc-set": "1.1.0 <= v < 2.0.0",
"jfmengels/elm-review": "2.4.0 <= v < 3.0.0",
"pzp1997/assoc-list": "1.0.0 <= v < 2.0.0",
"stil4m/elm-syntax": "7.2.1 <= v < 8.0.0",
"the-sett/elm-pretty-printer": "3.0.0 <= v < 4.0.0",
"the-sett/elm-syntax-dsl": "6.0.1 <= v < 7.0.0"
},
"test-dependencies": {}
"type": "package",
"name": "gampleman/elm-review-derive",
"summary": "Generate code for json encoders/decoders, codecs, fuzzers, generators, and more",
"license": "MIT",
"version": "1.0.0",
"exposed-modules": [
"NoDebug.TodoItForMe",
"CodeGenerator",
"CodeGenerator.Test",
"TypePattern",
"ResolvedType"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm/core": "1.0.2 <= v < 2.0.0",
"elm/json": "1.1.3 <= v < 2.0.0",
"elm/project-metadata-utils": "1.0.1 <= v < 2.0.0",
"elm-explorations/test": "2.0.0 <= v < 3.0.0",
"elmcraft/core-extra": "2.0.0 <= v < 3.0.0",
"erlandsona/assoc-set": "1.1.0 <= v < 2.0.0",
"jfmengels/elm-review": "2.4.0 <= v < 3.0.0",
"pzp1997/assoc-list": "1.0.0 <= v < 2.0.0",
"stil4m/elm-syntax": "7.2.1 <= v < 8.0.0",
"the-sett/elm-pretty-printer": "3.0.0 <= v < 4.0.0",
"the-sett/elm-syntax-dsl": "6.0.1 <= v < 7.0.0"
},
"test-dependencies": {
"BrianHicks/elm-csv": "4.0.0 <= v < 5.0.0",
"MartinSStewart/elm-serialize": "1.3.1 <= v < 2.0.0",
"elm/random": "1.0.0 <= v < 2.0.0",
"elm-community/random-extra": "3.2.0 <= v < 4.0.0"
}
}
52 changes: 26 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"dependencies": {
"elm": "0.19.1-5",
"elm-doc-preview": "^5.0.5",
"elm-format": "^0.8.7",
"elm-review": "^2.10.2",
"elm-test": "0.19.1-revision12",
"elm-verify-examples": "^5.2.0",
"npm-run-all": "^4.1.5"
},
"scripts": {
"test": "npm-run-all --print-name --sequential test:make test:format test:e2e test:run test:review",
"test:make": "elm make --docs=docs.json",
"test:format": "elm-format src/ tests/*.elm review preview --validate",
"test:examples": "elm-verify-examples",
"test:e2e": "./e2e/test.sh",
"test:run": "elm-test",
"test:review": "elm-review",
"fix": "npm-run-all --print-name --sequential fix:format fix:review",
"fix:format": "elm-format src/ tests/*.elm review preview --yes",
"fix:review": "elm-review --fix",
"start": "npm-run-all -p -l start:docs",
"start:docs": "elm-doc-preview",
"elm-bump": "npm-run-all --print-name --sequential test bump-version 'test:review -- --fix-all-without-prompt'",
"bump-version": "(yes | elm bump)"
}
}
"dependencies": {
"elm": "0.19.1-5",
"elm-doc-preview": "^5.0.5",
"elm-format": "^0.8.7",
"elm-review": "^2.10.2",
"elm-test": "0.19.1-revision12",
"elm-verify-examples": "^5.2.0",
"npm-run-all": "^4.1.5"
},
"scripts": {
"test": "npm-run-all --print-name --sequential test:make test:format test:e2e test:run test:review",
"test:make": "elm make --docs=docs.json",
"test:format": "elm-format src/ tests/*.elm review preview --validate",
"test:examples": "elm-verify-examples",
"test:e2e": "./e2e/test.sh",
"test:run": "elm-test",
"test:review": "elm-review",
"fix": "npm-run-all --print-name --sequential fix:format fix:review",
"fix:format": "elm-format src/ tests/*.elm review preview e2e/E2E.elm --yes",
"fix:review": "elm-review --fix",
"start": "npm-run-all -p -l start:docs",
"start:docs": "elm-doc-preview",
"elm-bump": "npm-run-all --print-name --sequential test bump-version 'test:review -- --fix-all-without-prompt'",
"bump-version": "(yes | elm bump)"
}
}
2 changes: 0 additions & 2 deletions review/src/ReviewConfig.elm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import NoSimpleLetBody
import NoUnoptimizedRecursion
import NoUnused.CustomTypeConstructorArgs
import NoUnused.CustomTypeConstructors
import NoUnused.Dependencies
import NoUnused.Exports
import NoUnused.Parameters
import NoUnused.Patterns
Expand Down Expand Up @@ -60,7 +59,6 @@ config =
-- , NoPrematureLetComputation.rule
, NoUnused.CustomTypeConstructors.rule []
, NoUnused.CustomTypeConstructorArgs.rule
, NoUnused.Dependencies.rule
, NoUnused.Exports.rule
, NoUnused.Parameters.rule
, NoUnused.Patterns.rule
Expand Down
7 changes: 2 additions & 5 deletions src/CodeGenerator/Test.elm
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
module CodeGenerator.Test exposing
( codeGenTest, codeGenTestFailsWith, fakeDependency, FakeDependency
, codeGenIncrementalTest
)
module CodeGenerator.Test exposing (codeGenTest, codeGenTestFailsWith, codeGenIncrementalTest, fakeDependency, FakeDependency)

{-| Testing code generators can be tricky, but very rewarding as it makes developing CodeGenerators much easier.
@docs codeGenTest, codeGenTestFailsWith, fakeDependency, FakeDependency
@docs codeGenTest, codeGenTestFailsWith, codeGenIncrementalTest, fakeDependency, FakeDependency
-}

Expand Down
2 changes: 2 additions & 0 deletions src/Internal/Builtin/Random.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import TypePattern exposing (TypePattern(..))

random =
{ int = \min max -> CG.apply [ CG.fqFun [ "Random" ] "int", min, max ]
, float = \min max -> CG.apply [ CG.fqFun [ "Random" ] "float", min, max ]
, minInt = CG.fqVal [ "Random" ] "minInt"
, maxInt = CG.fqVal [ "Random" ] "maxInt"
, uniform = \fst rest -> CG.apply [ CG.fqFun [ "Random" ] "uniform", fst, rest ]
Expand Down Expand Up @@ -37,6 +38,7 @@ codeGen =
}
[ CodeGenerator.int (random.int random.minInt random.maxInt)
, CodeGenerator.int randomExtra.anyInt |> CodeGenerator.ifUserHasDependency "elm-community/random-extra"
, CodeGenerator.float (random.float (CG.float 0) (CG.float 1))
, CodeGenerator.string (random.uniform (CG.string "TODO: Define string options") (CG.list []))
, CodeGenerator.list random.list
, CodeGenerator.pipeline random.constant (\arg -> CG.apply [ CG.fqFun [ "Random" ] "map2", CG.parens (CG.binOp CG.piper), arg ])
Expand Down
Loading

0 comments on commit 02b1916

Please sign in to comment.