Extract functions to a helper module

This commit is contained in:
Jeroen Engels 2021-10-17 09:37:13 +02:00
parent 28a3973272
commit 819b373522
6 changed files with 78 additions and 191 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,14 +1,12 @@
module Review.Test.Dependencies.ElmCore exposing (dependency)
import Elm.Constraint
import Elm.Docs
import Elm.License
import Elm.Module
import Elm.Package
import Elm.Project
import Elm.Type exposing (Type(..))
import Elm.Version
import Review.Project.Dependency as Dependency exposing (Dependency)
import Review.Test.Dependencies.Unsafe as Unsafe
dependency : Dependency
@ -21,17 +19,17 @@ dependency =
elmJson : Elm.Project.Project
elmJson =
Elm.Project.Package
{ elm = unsafeConstraint "0.19.0 <= v < 0.20.0"
{ elm = Unsafe.constraint "0.19.0 <= v < 0.20.0"
, exposed =
Elm.Project.ExposedDict
[ ( "Primitives", [ unsafeModuleName "Basics", unsafeModuleName "String", unsafeModuleName "Char", unsafeModuleName "Bitwise", unsafeModuleName "Tuple" ] )
, ( "Collections", [ unsafeModuleName "List", unsafeModuleName "Dict", unsafeModuleName "Set", unsafeModuleName "Array" ] )
, ( "Error Handling", [ unsafeModuleName "Maybe", unsafeModuleName "Result" ] )
, ( "Debug", [ unsafeModuleName "Debug" ] )
, ( "Effects", [ unsafeModuleName "Platform.Cmd", unsafeModuleName "Platform.Sub", unsafeModuleName "Platform", unsafeModuleName "Process", unsafeModuleName "Task" ] )
[ ( "Primitives", [ Unsafe.moduleName "Basics", Unsafe.moduleName "String", Unsafe.moduleName "Char", Unsafe.moduleName "Bitwise", Unsafe.moduleName "Tuple" ] )
, ( "Collections", [ Unsafe.moduleName "List", Unsafe.moduleName "Dict", Unsafe.moduleName "Set", Unsafe.moduleName "Array" ] )
, ( "Error Handling", [ Unsafe.moduleName "Maybe", Unsafe.moduleName "Result" ] )
, ( "Debug", [ Unsafe.moduleName "Debug" ] )
, ( "Effects", [ Unsafe.moduleName "Platform.Cmd", Unsafe.moduleName "Platform.Sub", Unsafe.moduleName "Platform", Unsafe.moduleName "Process", Unsafe.moduleName "Task" ] )
]
, license = Elm.License.fromString "BSD-3-Clause" |> Maybe.withDefault Elm.License.bsd3
, name = unsafePackageName "elm/core"
, name = Unsafe.packageName "elm/core"
, summary = "Elm's standard libraries"
, deps = []
, testDeps = []
@ -3521,42 +3519,3 @@ info on this. (Picking appropriate data structures is super important in Elm!)
]
}
]
unsafePackageName : String -> Elm.Package.Name
unsafePackageName packageName =
case Elm.Package.fromString packageName of
Just name ->
name
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
unsafePackageName packageName
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity
unsafeModuleName : String -> Elm.Module.Name
unsafeModuleName moduleName =
case Elm.Module.fromString moduleName of
Just name ->
name
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
unsafeModuleName moduleName
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity
unsafeConstraint : String -> Elm.Constraint.Constraint
unsafeConstraint constraint =
case Elm.Constraint.fromString constraint of
Just constr ->
constr
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
unsafeConstraint constraint
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity

View File

@ -1,14 +1,12 @@
module Review.Test.Dependencies.ElmHtml exposing (dependency)
import Elm.Constraint
import Elm.Docs
import Elm.License
import Elm.Module
import Elm.Package
import Elm.Project
import Elm.Type exposing (Type(..))
import Elm.Version
import Review.Project.Dependency as Dependency exposing (Dependency)
import Review.Test.Dependencies.Unsafe as Unsafe
dependency : Dependency
@ -21,19 +19,19 @@ dependency =
elmJson : Elm.Project.Project
elmJson =
Elm.Project.Package
{ elm = unsafeConstraint "0.19.0 <= v < 0.20.0"
{ elm = Unsafe.constraint "0.19.0 <= v < 0.20.0"
, exposed =
Elm.Project.ExposedDict
[ ( "HTML", [ unsafeModuleName "Html", unsafeModuleName "Html.Attributes", unsafeModuleName "Html.Events" ] )
, ( "Optimize", [ unsafeModuleName "Html.Keyed", unsafeModuleName "Html.Lazy" ] )
[ ( "HTML", [ Unsafe.moduleName "Html", Unsafe.moduleName "Html.Attributes", Unsafe.moduleName "Html.Events" ] )
, ( "Optimize", [ Unsafe.moduleName "Html.Keyed", Unsafe.moduleName "Html.Lazy" ] )
]
, license = Elm.License.fromString "BSD-3-Clause" |> Maybe.withDefault Elm.License.bsd3
, name = unsafePackageName "elm/html"
, name = Unsafe.packageName "elm/html"
, summary = "Fast HTML, rendered with virtual DOM diffing"
, deps =
[ ( unsafePackageName "elm/core", unsafeConstraint "1.0.0 <= v < 2.0.0" )
, ( unsafePackageName "elm/json", unsafeConstraint "1.0.0 <= v < 2.0.0" )
, ( unsafePackageName "elm/virtual-dom", unsafeConstraint "1.0.0 <= v < 2.0.0" )
[ ( Unsafe.packageName "elm/core", Unsafe.constraint "1.0.0 <= v < 2.0.0" )
, ( Unsafe.packageName "elm/json", Unsafe.constraint "1.0.0 <= v < 2.0.0" )
, ( Unsafe.packageName "elm/virtual-dom", Unsafe.constraint "1.0.0 <= v < 2.0.0" )
]
, testDeps = []
, version = Elm.Version.fromString "1.0.0" |> Maybe.withDefault Elm.Version.one
@ -1590,42 +1588,3 @@ we know if the input to `view` is the same, the output must be the same!
]
}
]
unsafePackageName : String -> Elm.Package.Name
unsafePackageName packageName =
case Elm.Package.fromString packageName of
Just name ->
name
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
unsafePackageName packageName
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity
unsafeModuleName : String -> Elm.Module.Name
unsafeModuleName moduleName =
case Elm.Module.fromString moduleName of
Just name ->
name
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
unsafeModuleName moduleName
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity
unsafeConstraint : String -> Elm.Constraint.Constraint
unsafeConstraint constraint =
case Elm.Constraint.fromString constraint of
Just constr ->
constr
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
unsafeConstraint constraint
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity

View File

@ -1,14 +1,12 @@
module Review.Test.Dependencies.ElmParser exposing (dependency)
import Elm.Constraint
import Elm.Docs
import Elm.License
import Elm.Module
import Elm.Package
import Elm.Project
import Elm.Type exposing (Type(..))
import Elm.Version
import Review.Project.Dependency as Dependency exposing (Dependency)
import Review.Test.Dependencies.Unsafe as Unsafe
dependency : Dependency
@ -21,12 +19,12 @@ dependency =
elmJson : Elm.Project.Project
elmJson =
Elm.Project.Package
{ elm = unsafeConstraint "0.19.0 <= v < 0.20.0"
, exposed = Elm.Project.ExposedList [ unsafeModuleName "Parser", unsafeModuleName "Parser.Advanced" ]
{ elm = Unsafe.constraint "0.19.0 <= v < 0.20.0"
, exposed = Elm.Project.ExposedList [ Unsafe.moduleName "Parser", Unsafe.moduleName "Parser.Advanced" ]
, license = Elm.License.fromString "BSD-3-Clause" |> Maybe.withDefault Elm.License.bsd3
, name = unsafePackageName "elm/parser"
, name = Unsafe.packageName "elm/parser"
, summary = "a parsing library, focused on simplicity and great error messages"
, deps = [ ( unsafePackageName "elm/core", unsafeConstraint "1.0.0 <= v < 2.0.0" ) ]
, deps = [ ( Unsafe.packageName "elm/core", Unsafe.constraint "1.0.0 <= v < 2.0.0" ) ]
, testDeps = []
, version = Elm.Version.fromString "1.1.0" |> Maybe.withDefault Elm.Version.one
}
@ -1530,42 +1528,3 @@ problem yourself.
]
}
]
unsafePackageName : String -> Elm.Package.Name
unsafePackageName packageName =
case Elm.Package.fromString packageName of
Just name ->
name
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
unsafePackageName packageName
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity
unsafeModuleName : String -> Elm.Module.Name
unsafeModuleName moduleName =
case Elm.Module.fromString moduleName of
Just name ->
name
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
unsafeModuleName moduleName
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity
unsafeConstraint : String -> Elm.Constraint.Constraint
unsafeConstraint constraint =
case Elm.Constraint.fromString constraint of
Just constr ->
constr
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
unsafeConstraint constraint
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity

View File

@ -1,14 +1,12 @@
module Review.Test.Dependencies.ElmUrl exposing (dependency)
import Elm.Constraint
import Elm.Docs
import Elm.License
import Elm.Module
import Elm.Package
import Elm.Project
import Elm.Type exposing (Type(..))
import Elm.Version
import Review.Project.Dependency as Dependency exposing (Dependency)
import Review.Test.Dependencies.Unsafe as Unsafe
dependency : Dependency
@ -21,12 +19,12 @@ dependency =
elmJson : Elm.Project.Project
elmJson =
Elm.Project.Package
{ elm = unsafeConstraint "0.19.0 <= v < 0.20.0"
, exposed = Elm.Project.ExposedList [ unsafeModuleName "Url", unsafeModuleName "Url.Builder", unsafeModuleName "Url.Parser", unsafeModuleName "Url.Parser.Query" ]
{ elm = Unsafe.constraint "0.19.0 <= v < 0.20.0"
, exposed = Elm.Project.ExposedList [ Unsafe.moduleName "Url", Unsafe.moduleName "Url.Builder", Unsafe.moduleName "Url.Parser", Unsafe.moduleName "Url.Parser.Query" ]
, license = Elm.License.fromString "BSD-3-Clause" |> Maybe.withDefault Elm.License.bsd3
, name = unsafePackageName "elm/url"
, name = Unsafe.packageName "elm/url"
, summary = "Create and parse URLs. Use for HTTP and \"routing\" in single-page apps (SPAs)"
, deps = [ ( unsafePackageName "elm/core", unsafeConstraint "1.0.0 <= v < 2.0.0" ) ]
, deps = [ ( Unsafe.packageName "elm/core", Unsafe.constraint "1.0.0 <= v < 2.0.0" ) ]
, testDeps = []
, version = Elm.Version.fromString "1.0.0" |> Maybe.withDefault Elm.Version.one
}
@ -882,42 +880,3 @@ parameters for some reason.
]
}
]
unsafePackageName : String -> Elm.Package.Name
unsafePackageName packageName =
case Elm.Package.fromString packageName of
Just name ->
name
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
unsafePackageName packageName
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity
unsafeModuleName : String -> Elm.Module.Name
unsafeModuleName moduleName =
case Elm.Module.fromString moduleName of
Just name ->
name
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
unsafeModuleName moduleName
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity
unsafeConstraint : String -> Elm.Constraint.Constraint
unsafeConstraint constraint =
case Elm.Constraint.fromString constraint of
Just constr ->
constr
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
unsafeConstraint constraint
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity

View File

@ -0,0 +1,51 @@
module Review.Test.Dependencies.Unsafe exposing
( constraint
, moduleName
, packageName
)
import Elm.Constraint
import Elm.Module
import Elm.Package
packageName : String -> Elm.Package.Name
packageName rawName =
-- IGNORE TCO
case Elm.Package.fromString rawName of
Just name ->
name
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
packageName rawName
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity
moduleName : String -> Elm.Module.Name
moduleName rawModuleName =
-- IGNORE TCO
case Elm.Module.fromString rawModuleName of
Just name ->
name
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
moduleName rawModuleName
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity
constraint : String -> Elm.Constraint.Constraint
constraint rawConstraint =
-- IGNORE TCO
case Elm.Constraint.fromString rawConstraint of
Just constr ->
constr
Nothing ->
-- unsafe, but if the generation went well, it should all be good.
constraint rawConstraint
-- Disables the tail-call optimization, so that the test crashes if we enter this case
|> identity