15 #ifndef Om_Language_Operation_DefineOperation_
21 #ifndef Om_Macro_Precompilation_
23 #include "boost/test/unit_test.hpp"
33 BOOST_AUTO_TEST_SUITE(DefineOperationTest)
35 BOOST_AUTO_TEST_CASE(DefinitionTest) {
42 BOOST_AUTO_TEST_CASE(BasicSubstitutionTest) {
49 BOOST_AUTO_TEST_CASE(IdentityDefinitionTest) {
56 BOOST_AUTO_TEST_CASE(EmptyDefinitionTest) {
63 BOOST_AUTO_TEST_CASE(EmptyLexiconTest) {
70 BOOST_AUTO_TEST_CASE(EmptyKeyFallThroughTest) {
78 BOOST_AUTO_TEST_CASE(MultipleDefinitionTest) {
81 System::Get().Evaluate(
"define { A {{B}} A {{C}} } {A}")
86 BOOST_AUTO_TEST_CASE(MultipleEmptyKeyTest) {
89 System::Get().Evaluate(
"define { {{B}} {{C}} } {A}")
94 BOOST_AUTO_TEST_CASE(ChainedLookupTest) {
100 System::Get().Evaluate(
"define {A {B}} {dequote {A} A}")
114 System::Get().Evaluate(
"define fill {a` b} {1} {do{a b}}")
118 System::Get().Evaluate(
"define {a` b{{1}}} {do{a b}}")
128 "{do{the` glaven} do{the` flaven}}"
134 BOOST_AUTO_TEST_CASE(NestedEvaluationOrderTest) {
138 "define { b {B} {{b-default}} }{"
139 "define { a {A} {{a-default}} } { b }"
146 "define { b {B} {{b-default}} }{"
147 "define { a {A} } { b }"
153 BOOST_AUTO_TEST_CASE(SimpleNestedTest) {
156 System::Get().Evaluate(
"define{a{define{b{c}}{b}}}{a}")
160 BOOST_AUTO_TEST_CASE(DeletedOperatorTest) {
163 System::Get().Evaluate(
"define {define} {define {a{A}} {a}}")
167 BOOST_AUTO_TEST_CASE(EvaluationTest) {
170 System::Get().Evaluate(
"define {a{{1}c{2}} c{{3}}} {a}")
174 BOOST_AUTO_TEST_SUITE_END()
188 #ifndef Om_Macro_Precompilation_
190 #include "boost/utility/in_place_factory.hpp"
197 Om::Language::Operation::DefineOperation
201 inline char const * Type_::GetName() {
205 template <
typename TheDefineOperation>
206 inline void Type_::GiveElements(
207 TheDefineOperation & theDefineOperation,
208 Consumer & theConsumer
210 theConsumer.TakeElement(
213 if (theDefineOperation.thisLexicon) {
214 theConsumer.TakeQuotedElements(*theDefineOperation.thisLexicon);
220 inline Type_::DefineOperation():
223 template <
typename TheOperand>
224 inline bool Type_::TakeOperand(
225 Evaluation & theEvaluation,
226 TheOperand & theOperand
229 !theOperand.IsEmpty()
231 return this->TakeQuotedProducer(
233 *theOperand.GetProgram()
237 template <
typename TheProducer>
238 inline bool Type_::TakeQuotedProducer(
239 Evaluation & theEvaluation,
240 TheProducer & theProducer
242 if (this->thisLexicon) {
243 Expression theExpression;
245 Environment theEnvironment;
250 theEvaluation.GetTranslator()
252 theEnvironment.Push(*this->thisLexicon);
257 theProducer.GiveElements(theScope);
259 theEvaluation.TakeProducer(theExpression);
262 this->thisLexicon = boost::in_place();
263 assert(this->thisLexicon);
264 this->thisLexicon->TakeElements(theProducer);
#define Om_Language_Operation_DefineOperation_GetName_()