Skip to content

Instantly share code, notes, and snippets.

@manuscrypt
Created May 28, 2016 21:12
Show Gist options
  • Save manuscrypt/48a1408c8d5ad5611682fb439cb63c50 to your computer and use it in GitHub Desktop.
Save manuscrypt/48a1408c8d5ad5611682fb439cb63c50 to your computer and use it in GitHub Desktop.
module Tests exposing (..)
import Tweet exposing (..)
import Html exposing (..)
import Json.Encode as Encode
import Random exposing (Generator)
import Shrink
import Check exposing (..)
import Check.Test
import Check.Producer exposing (..)
import ElmTest
toJson : Int -> String -> String
toJson id txt =
[ ("id", Encode.int id)
, ("id_str", Encode.string (toString id))
, ("text", Encode.string txt)
] |> Encode.object |> Encode.encode 0
myClaims : Claim
myClaims =
suite "Tweet Decoding"
[ Check.claim
"Decoding string containing proper tweet-JSON yields Tweet"
`that`
(\(id, txt) -> Tweet.decode <| toJson id txt )
`is`
(\(id, txt) -> Just (Tweet.Model id (toString id) txt))
`for`
producer
]
producer : Producer (Int,String)
producer = Producer generator Shrink.noShrink
generator : Generator (Int, String)
generator = Random.pair (Random.int 100 100000) string.generator
evidence : Evidence
evidence = quickCheck myClaims
main : Html a
main =
div [] [text <| ElmTest.consoleRunner (Check.Test.evidenceToTest evidence)]
@manuscrypt
Copy link
Author

note: this is certainly not how you run tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment