MCPcopy Create free account
hub / github.com/BowenFu/hspp / main

Function main

sample/parse_expr.cpp:105–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103TEParser<int> const expr = toTEParser || (term <chainl1> addOp);
104
105int main()
106{
107 {
108 auto const rawResult = apply || many | digit || " 1 2 34";
109 auto const& result = std::get<0>(rawResult.at(0));
110 auto const expected = std::vector{1, 2, 3, 4};
111 expectTrue(std::equal(result.begin(), result.end(), expected.begin()));
112 }
113
114 {
115 auto const result = apply || addOp || " + * /-";
116 expectEq(std::get<0>(result.at(0))| 1 | 2, 3);
117
118 auto const result2 = apply || mulOp || " * /-";
119 expectEq(std::get<0>(result2.at(0))| 1 | 2, 2);
120 }
121
122 {
123 auto const p = digit <chainl1> addOp;
124 auto const result = runParser | p | "1 + 2";
125 auto const expected = 3;
126 expectEq(std::get<0>(result.at(0)), expected);
127 }
128
129 {
130 auto const result = apply | expr | "1 - 2 * 3 + 4";
131 auto const expected = -1;
132 expectEq(std::get<0>(result.at(0)), expected);
133 }
134 return 0;
135}

Callers

nothing calls this directly

Calls 4

expectTrueFunction · 0.85
expectEqFunction · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected