diff --git a/tests/15library.tests b/tests/15library.tests index 15146f939..8a99f2549 100644 --- a/tests/15library.tests +++ b/tests/15library.tests @@ -452,6 +452,10 @@ END TEST "verb token based double dispatch helper" VerbFunctionDispatch_test < 'Woof-Woof!' +out-lit: consuming honk -> 'Honk-Honk!' +out-lit: consuming moo -> 'Moo-Moo!' +out-lit: consuming meh -> 'Meh!' return: 0 END diff --git a/tests/library/verb-function-dispatch-test.cpp b/tests/library/verb-function-dispatch-test.cpp index b93970d4d..0f4bfb9e7 100644 --- a/tests/library/verb-function-dispatch-test.cpp +++ b/tests/library/verb-function-dispatch-test.cpp @@ -22,22 +22,18 @@ #include "lib/test/run.hpp" -//#include "lib/util.hpp" #include "lib/format-string.hpp" #include "lib/meta/function.hpp" +#include "lib/symbol.hpp" -//#include -#include #include #include -//#include +#include -//using boost::lexical_cast; -//using util::contains; using std::string; using util::_Fmt; +using std::vector; using std::cout; -//using std::endl; namespace lib { @@ -51,6 +47,7 @@ namespace test{ typedef Ret (REC::*Handler) (void); Handler handler_; + Literal token_; public: Ret @@ -61,11 +58,12 @@ namespace test{ operator string() { - UNIMPLEMENTED("string representation of verb tokens"); + return string(token_); } - VerbToken(Handler handlerFunction) + VerbToken(Handler handlerFunction, Literal token) : handler_(handlerFunction) + , token_(token) { } protected: }; @@ -86,12 +84,13 @@ namespace test{ const string BEGINNING("silence"); using Verb = VerbToken; - using VerbSeq = std::initializer_list; + using VerbSeq = vector; - Verb WOOF(&Receiver::woof); - Verb HONK(&Receiver::honk); - Verb MOO(&Receiver::moo); - Verb MEH(&Receiver::meh); + + Verb WOOF(&Receiver::woof, "woof"); + Verb HONK(&Receiver::honk, "honk"); + Verb MOO(&Receiver::moo, "moo"); + Verb MEH(&Receiver::meh, "meh"); } @@ -148,10 +147,11 @@ namespace test{ /***********************************************************************//** * @test Demonstration/Concept: dispatch a specific function * based on the given verbs of an embedded custom language. - * - weakness of + * Actually what we want to achieve here is a specific form + * of double dispatch; thus the implementation relies on a + * variation of the visitor pattern. * - * @see HashIndexed_test - * @see + * @see session-structure-mapping-test.cpp */ class VerbFunctionDispatch_test : public Test {