Fixed sample.

pull/3/head
yhirose 9 years ago
parent f7eca8eac5
commit f0351a9909
  1. 8
      README.md
  2. 8
      test/test.cc

@ -53,9 +53,11 @@ int main(void) {
[](const vector<any>& v) { return v[0]; } // 2nd choice
};
/* This action is not necessary.
parser["Primary"] = [](const vector<any>& v) {
return v.size() == 1 ? v[0] : v[1];
return v[0];
};
*/
parser["Number"] = [](const char* s, size_t l) {
return stoi(string(s, l), nullptr, 10);
@ -63,9 +65,9 @@ int main(void) {
// (4) Parse
int val;
parser.parse("1+2*3", val);
parser.parse("(1+2)*3", val);
assert(val == 7);
assert(val == 9);
}
```

@ -164,18 +164,14 @@ TEST_CASE("Simple calculator test", "[general]")
return v.size() == 1 ? v[0].get<int>() : v[0].get<int>() * v[1].get<int>();
};
parser["Primary"] = [](const vector<any>& v) {
return v.size() == 1 ? v[0] : v[1];
};
parser["Number"] = [](const char* s, size_t l) {
return atoi(s);
};
int val;
parser.parse("1+2*3", val);
parser.parse("(1+2)*3", val);
REQUIRE(val == 7);
REQUIRE(val == 9);
}
TEST_CASE("Calculator test", "[general]")

Loading…
Cancel
Save