我正在尝试编写一个简单hunit-test
的方法来验证 aText.XML.Light.Element
是如何从函数创建的。
功能是:
createElement :: String -> String -> XML.Element
createElement tg txt =
blank_element{ elName = qualName tg
, elContent = [ Text blank_cdata { cdData = txt } ]
}
我的测试很简单:
import Test.Framework (defaultMain)
import Test.Framework.Providers.HUnit (testCase)
import Test.HUnit (Assertion, assertEqual)
import Text.XML.Light as XML
import MyModule.MyCode (createElement)
testCreateElement :: Assertion
testCreateElement = do
let tg = "item"
let txt = "example of text"
let expectedElement = XML.Element {
elName = XML.QName{ qName = tg, qURI = Nothing, qPrefix = Nothing }
, elAttribs = [] :: [ Attr ]
, elContent = [ fromString txt ] :: [ Content ]
, elLine = Nothing
}
assertEqual "create an element" expectedElement (createElement tg txt)
-- utils
fromString :: String -> Content
fromString txt = Text blank_cdata { cdData = txt }
我得到的是这个错误:
No instance for (Eq Element) arising from a use of ‘assertEqual’
In a stmt of a 'do' block:
assertEqual "create an element" expectedElement (xmlElement tg txt)
In the expression:....
我检查了源代码,Text.XML.Light
看起来没有Eq
为Element
. 我怎样才能使测试工作?