Mam wiele funkcji, takich jak: method1
, method2
, method3
. Dla wszystkich z nich istnieją funkcje testowe typu HUnit
, takie jak: testMethod1
, testMethod2
, testMethod3
.pobierz nazwę funkcji wewnątrz niego
testMethod1 = TestCase $
assertEqual "testmethod1" ...
testMethod2 = TestCase $
assertEqual "testmethod2" ...
testMethod3 = TestCase $
assertEqual "testmethod3" ...
Chciałbym uniknąć nadmiarowe kopiowanie nazwa funkcji jako prefiksu błąd wiadomości i nazywają to coś takiego:
testMethod1 = TestCase $
assertEqual_ ...
Jak to może być osiągnięte (dowolny „magia” Sztuką jest doceniana)?
Tak naprawdę pytanie brzmi, w jaki sposób nazwa funkcji może zostać użyta w jego definicji?
Aktualizacja.
To nie jest faktycznie wynika z pierwotnego pytania, które chcę obsłużyć tego typu sytuacji zbyt:
tProcess = TestCase $ do
assertEqual "tProcess" testResult $ someTest
assertEqual "tProcess" anotherTestResult $ anotherTest
assertEqual "tProcess" resultAgain $ testAgain
Wreszcie chcę napisać coś takiego:
tProcess = TestCase $ do
assertEqual_ testResult $ someTest
assertEqual_ anotherTestResult $ anotherTest
assertEqual_ resultAgain $ testAgain
Szablon haskell – pat
Moje stare pytanie może być przydatne: http://stackoverflow.com/questions/7896928/how-to-get-variable-name- in- haskell –