StringCreationLibraryMatrixTest
The same string produced in different ways is `==`, finds the same `Dict`
entry, and matches the same string pattern in a `case`.
The string `"abc123"` is produced four ways: as a literal, as `"abc" ++
String.fromInt 123`, with `String.slice`, and with `String.reverse`. The test
logs three results:
- `eq`: all four are equal and the concatenated one has length 6;
- `dict`: a `Dict` keyed by the concatenated one returns its value for the
literal, sliced and reversed ones;
- `case`: the concatenated, sliced and reversed ones each match the
`"abc123"` pattern.
The strings are made by library functions; StringCreationMatrixTest makes the same string in
several ways with `++` alone.Results
elm-0.19.1
passran in 42 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. Creation.eq: True Creation.dict: True Creation.case: True
elm-0.19.2
passran in 44 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. Creation.eq: True Creation.dict: True Creation.case: True
elm-0.19.3
passran in 39 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. Creation.case: True Creation.eq: True Creation.dict: True
lamdera-1.5.0
passran in 38 msOutput
Creation.case: True Creation.eq: True Creation.dict: True
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/StringCreationLibraryMatrixTest] in its title.
Source
The -- CHECK: lines give the expected output.
module StringCreationLibraryMatrixTest exposing (main)
{-| The same string produced in different ways is `==`, finds the same `Dict`
entry, and matches the same string pattern in a `case`.
The string `"abc123"` is produced four ways: as a literal, as `"abc" ++
String.fromInt 123`, with `String.slice`, and with `String.reverse`. The test
logs three results:
- `eq`: all four are equal and the concatenated one has length 6;
- `dict`: a `Dict` keyed by the concatenated one returns its value for the
literal, sliced and reversed ones;
- `case`: the concatenated, sliced and reversed ones each match the
`"abc123"` pattern.
The strings are made by library functions; StringCreationMatrixTest makes the same string in
several ways with `++` alone.
-}
-- CHECK: Creation.eq: True
-- CHECK: Creation.dict: True
-- CHECK: Creation.case: True
import Dict
import Html exposing (text)
classify : String -> String
classify s =
case s of
"abc123" ->
"matched"
_ ->
"no"
main : Html.Html msg
main =
let
viaLiteral =
"abc123"
viaConcat =
"abc" ++ String.fromInt 123
viaSlice =
String.slice 2 8 "XYabc123ZW"
viaReverse =
String.reverse "321cba"
eq =
(viaLiteral == viaConcat)
&& (viaConcat == viaSlice)
&& (viaSlice == viaReverse)
&& (String.length viaConcat == 6)
d =
Dict.fromList [ ( viaConcat, 1 ), ( "other", 2 ) ]
dictOk =
(Dict.get "abc123" d == Just 1)
&& (Dict.get viaSlice d == Just 1)
&& (Dict.get viaReverse d == Just 1)
caseOk =
(classify viaConcat == "matched")
&& (classify viaSlice == "matched")
&& (classify viaReverse == "matched")
_ =
Debug.log "Creation.eq" eq
_ =
Debug.log "Creation.dict" dictOk
_ =
Debug.log "Creation.case" caseOk
in
text ""