bool EvaluationContext::evaluateIn(const Optional<TokenLocation> &loc, const EvaluationValue &self, const EvaluationValue &value)
{
+ try {
+ switch (self.kind()) {
+ case EvaluationValue::Kind::STRING: {
+ auto val = detail::ConvertTo<std::string>::convert(*this, value);
+ return self.asString().find(val) != std::string::npos;
+ }
+ case EvaluationValue::Kind::SET: {
+ return self.asSet().find(value) != self.asSet().end();
+ }
+ case EvaluationValue::Kind::DICT: {
+ return self.asDict().find(value) != self.asDict().end();
+ }
+ case EvaluationValue::Kind::VECTOR:
+ for (auto &v : self.asVector())
+ if (v == value) return true;
+ return true;
+ case EvaluationValue::Kind::FUNCTION:
+ case EvaluationValue::Kind::INTEGER:
+ case EvaluationValue::Kind::DOUBLE:
+ case EvaluationValue::Kind::UIELEMENT:
+ case EvaluationValue::Kind::BOOLEAN:
+ case EvaluationValue::Kind::POINT:
+ case EvaluationValue::Kind::EMPTY:
+ break;
+ }
+ } catch (EvaluationFailure &e) {
+ if (loc) e.setLocationIfMissing(*loc);
+ throw;
+ }
throw EvaluationFailure{loc} << "value of type " << EvaluationValue::toString(self.kind()) << " is not a collection";
}
, 18);
}
+TEST_F(ScriptTest, set)
+{
+ execute(
+ "v = {1, 2, 3, '1', '2', '3'}\n"
+ "assert(1 in v)\n"
+ "assert(2 in v)\n"
+ "assert(3 in v)\n"
+ "assert('1' in v)\n"
+ "assert('2' in v)\n"
+ "assert('3' in v)\n"
+ "assert('4' not in v)\n"
+ "assert(not ('4' in v))\n"
+ , 8);
+}
+
+TEST_F(ScriptTest, map)
+{
+ execute(
+ "v = {1: 1, 2: 2, '1': 3}\n"
+ "assert(1 in v)\n"
+ "assert(2 in v)\n"
+ "assert(3 not in v)\n"
+ "assert('1' in v)\n"
+ "assert('2' not in v)\n"
+ "assert(v[1] == 1)\n"
+ "assert(v['1'] == 3)\n"
+ , 7);
+}
+
+
int main(int argc, char *argv[])
{
try {