Skip to content

Instantly share code, notes, and snippets.

@dvdsgl
Created October 15, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvdsgl/14a2b63284afecae4f17 to your computer and use it in GitHub Desktop.
Save dvdsgl/14a2b63284afecae4f17 to your computer and use it in GitHub Desktop.
Unit tests for a stack trace parser
module Test.Parsers (tests) where
import Prelude
import Data.Default
import Test.Prelude
import Test.Data
import Test.Unit (runTest, test, assert)
import SharpStacktrace.Types
import SharpStacktrace.Constructors
import qualified SharpStacktrace.Parsers as P
testTypeParsing = test "type parsing\n" do
let try desc raw result =
assert ("cannot parse type (" <> desc <> "): " <> raw) (P.parseType raw `hasRight` result)
try "simple, without namespace"
"object" $
def # withName "object"
try "simple, with namespace"
"System.String" $
systemString
try "simple array"
"System.String[]" $
arrayOf systemString
try "generic"
"System.Collections.Generic.List`1[System.String]" $
genericListOfString
try "generic with angle brackets"
"System.Collections.Generic.List`1<System.String>" $
genericListOfString
try "generic arity 2"
"System.Collections.Generic.Dictionary`2[System.String,System.String]" $
genericDictionaryOfStringString
try "nested"
"System.String+T1" $
systemString # withChild t1
try "nested generics"
"System.Collections.Generic.List`1+T1`1[System.String,T2]" $
genericListOfString # withChild (t1 # withGeneric t2)
testInvocationParsing = test "invocation parsing\n" do
let try desc raw result =
assert ("cannot parse invocation: (" <> desc <> "): " <> raw) (P.parseInvocation raw `hasRight` result)
try "simple"
"System.Object.ToString ()" $
systemObject .. toString
try "generic"
"System.Object.ToString[T1] ()" $
systemObject .. (toString # withGeneric t1)
try "generic type"
"System.Collections.Generic.List`1[System.String].ToString ()" $
genericListOfString .. toString
try "generic type and method"
"System.Collections.Generic.List`1[System.String].ToString[System.Object] ()" $
genericListOfString .. (toString # withGeneric systemObject)
tests = do
testTypeParsing
testInvocationParsing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment