Om
decode_operation.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Operation_DecodeOperation_
16 
18 
19  #ifdef Om_Macro_Test_
20 
21  #include "om/language/system.hpp"
22 
23  #ifndef Om_Macro_Precompilation_
24 
25  #include "boost/test/unit_test.hpp"
26 
27  #endif
28 
29 namespace Om {
30 
31  namespace Language {
32 
33  namespace Operation {
34 
35  BOOST_AUTO_TEST_SUITE(DecodeOperationTest)
36 
37  BOOST_AUTO_TEST_CASE(DefinitionTest) {
38  BOOST_CHECK_EQUAL(
39  "{decode}",
40  System::Get().Evaluate("drop find {decode} system")
41  );
42  }
43 
44  BOOST_AUTO_TEST_CASE(SimpleTest) {
45  BOOST_CHECK_EQUAL(
46  "{`{`}` {{}} {quote{s}} }",
47  System::Get().Evaluate("decode {```{```}``` `{`{`}`}` {quote{s}} }")
48  );
49 
50  BOOST_CHECK_EQUAL(
51  "{{} {{}} {quote{s}} }",
52  System::Get().Evaluate("decode {`{`}` {{}} {quote{s}} }")
53  );
54 
55  BOOST_CHECK_EQUAL(
56  "{ the {end: `} really: } ! }",
57  System::Get().Evaluate("decode {` the` `{end:` ```}` really:` `}` !` }")
58  );
59 
60  // Test that each remaining encoded Operand Symbol is decoded.
61  BOOST_CHECK_EQUAL(
62  "{ the {end: } really: }",
63  System::Get().Evaluate("decode { the {end: `} really: } ! }")
64  );
65 
66  BOOST_CHECK_EQUAL(
67  "{ the {end: } really: }",
68  System::Get().Evaluate("decode { the {end: } really: }")
69  );
70  }
71 
72  BOOST_AUTO_TEST_SUITE_END()
73 
74  }
75 
76  }
77 
78 }
79 
80  #endif
81 
82 #else
83 
84  #include "om/language/literal.hpp"
85 
86 // MARK: - Om::Language::Operation::DecodeOperation
87 
88  #define Type_ \
89  Om::Language::Operation::DecodeOperation
90 
91 // MARK: public (static)
92 
93 inline char const * Type_::GetName() {
95 }
96 
97 template <typename TheDecodeOperation>
98 inline void Type_::GiveElements(
99  TheDecodeOperation &,
100  Consumer & theConsumer
101 ) {
102  theConsumer.TakeElement(
103  GetOperator()
104  );
105 }
106 
107 // MARK: public (non-static)
108 
109 template <typename TheOperand>
110 inline bool Type_::TakeOperand(
111  Evaluation & theEvaluation,
112  TheOperand & theOperand
113 ) {
114  assert(
115  !theOperand.IsEmpty()
116  );
117  return this->TakeQuotedProducer(
118  theEvaluation,
119  *theOperand.GetProgram()
120  );
121 }
122 
123 template <typename TheProducer>
124 inline bool Type_::TakeQuotedProducer(
125  Evaluation & theEvaluation,
126  TheProducer & theProducer
127 ) {
128  Literal theLiteral;
129  {
130  Operator theOperator;
131  theOperator.TakeElements(theProducer);
132  theOperator.Decode(theLiteral);
133  }
134  theEvaluation.TakeQuotedProducer(theLiteral);
135  return true;
136 }
137 
138  #undef Type_
139 
140 #endif
static System & Get()
Om header file.
#define Om_Language_Operation_DecodeOperation_GetName_()
Om header file.
The Om library.
Definition: code_point.hpp:26
Om header file.