Om
substitute_operation.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Operation_SubstituteOperation_
16 
18 
19  #ifdef Om_Macro_Test_
20 
21  #ifndef Om_Macro_Precompilation_
22 
23  #include "boost/test/unit_test.hpp"
24 
25  #endif
26 
27 namespace Om {
28 
29  namespace Language {
30 
31  namespace Operation {
32 
33  BOOST_AUTO_TEST_SUITE(SubstituteOperationTest)
34 
35  BOOST_AUTO_TEST_CASE(DefinitionTest) {
36  BOOST_CHECK_EQUAL(
37  "{substitute}",
38  System::Get().Evaluate("drop find {substitute} system")
39  );
40  }
41 
42  BOOST_AUTO_TEST_CASE(BasicSubstitutionTest) {
43  BOOST_CHECK_EQUAL(
44  "{A{B}}{B}",
45  System::Get().Evaluate("substitute {A {B}} {A}")
46  );
47  }
48 
49  BOOST_AUTO_TEST_CASE(IdentityDefinitionTest) {
50  BOOST_CHECK_EQUAL(
51  "{A{}}{}",
52  System::Get().Evaluate("substitute {A {}} {A}")
53  );
54  }
55 
56  BOOST_AUTO_TEST_CASE(EmptyDefinitionTest) {
57  BOOST_CHECK_EQUAL(
58  "{A}{A}",
59  System::Get().Evaluate("substitute {A} {A}")
60  );
61  }
62 
63  BOOST_AUTO_TEST_CASE(EmptyLexiconTest) {
64  BOOST_CHECK_EQUAL(
65  "{}{}",
66  System::Get().Evaluate("substitute {} {}")
67  );
68  }
69 
70  BOOST_AUTO_TEST_CASE(EmptyKeyFallThroughTest) {
71  BOOST_CHECK_EQUAL(
72  "{{{A}}}{{A}}",
73  System::Get().Evaluate("substitute {{{A}}} {B}")
74  );
75  }
76 
77  // Confirms that the last definition wins.
78  BOOST_AUTO_TEST_CASE(MultipleDefinitionTest) {
79  BOOST_CHECK_EQUAL(
80  "{A{{C}}}{{C}}",
81  System::Get().Evaluate("substitute { A {{B}} A {{C}} } {A}")
82  );
83  }
84 
85  // Confirms that the last definition wins.
86  BOOST_AUTO_TEST_CASE(MultipleEmptyKeyTest) {
87  BOOST_CHECK_EQUAL(
88  "{{{C}}}{{C}}",
89  System::Get().Evaluate("substitute { {{B}} {{C}} } {A}")
90  );
91  }
92 
93  // Confirms that underlying non-constant definitions are used.
94  BOOST_AUTO_TEST_CASE(ChainedLookupTest) {
95  BOOST_CHECK_EQUAL(
96  (
97  "{A{B}}{"
98  "unquote{A}\n"
99  "B"
100  "}"
101  ),
102  System::Get().Evaluate("substitute {A {B}} {unquote {A} A}")
103  );
104 
105  BOOST_CHECK_EQUAL(
106  "{blaven{42}}{do{blaven}}",
107  System::Get().Evaluate("substitute{blaven{42}}{do{blaven}}")
108  );
109  }
110 
111  BOOST_AUTO_TEST_SUITE_END()
112 
113  }
114 
115  }
116 
117 }
118 
119  #endif
120 
121 #else
122 
123 // MARK: - Om::Language::Operation::SubstituteOperation
124 
125  #define Type_ \
126  Om::Language::Operation::SubstituteOperation
127 
128 // MARK: public (static)
129 
130 inline char const * Type_::GetName() {
132 }
133 
134 // MARK: public (non-static)
135 
136 template <typename TheProducer>
137 inline void Type_::Translate(
138  Translator const &,
139  TheProducer & theProducer,
140  Expression & theExpression
141 ) const {
142  Evaluator theScope(
143  theExpression,
144  *this->thisLexicon
145  );
146  theProducer.GiveElements(theScope);
147 }
148 
149  #undef Type_
150 
151 #endif
static System & Get()
The Om library.
Definition: code_point.hpp:26
#define Om_Language_Operation_SubstituteOperation_GetName_()