From a7e4c7aadc68323161ef80ee12e4a225c7d6c093 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 20 Aug 2017 21:36:09 +0200 Subject: [PATCH] Added unit tests for expressions (required for strmxor) --- src/unit_tests/gsiExpression.cc | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/unit_tests/gsiExpression.cc b/src/unit_tests/gsiExpression.cc index 3f2c393a0..1a54709a9 100644 --- a/src/unit_tests/gsiExpression.cc +++ b/src/unit_tests/gsiExpression.cc @@ -532,3 +532,37 @@ TEST(8) v = e.parse ("var l = Layout.new(); l.create_cell('TOP'); var c = l.top_cell; l._destroy; c._destroyed").execute (); EXPECT_EQ (v.to_string (), std::string ("true")); } + +namespace +{ + +class CollectFunction + : public tl::EvalFunction +{ +public: + virtual void execute (const tl::ExpressionParserContext & /*context*/, tl::Variant &out, const std::vector &args) const + { + out = tl::Variant (); + if (args.size () > 0) { + values.push_back (args.front ().to_double ()); + } + } + + mutable std::vector values; +}; + +} + +TEST(9) +{ + tl::Eval e; + CollectFunction *collect_func = new CollectFunction (); + e.define_function ("put", collect_func); + + tl::Variant v; + v = e.parse ("var x=Region.new(Box.new(0,0,100,100)); put(x.area); x=x.sized(10); put(x.area); x=x.sized(10); put(x.area);").execute (); + EXPECT_EQ (collect_func->values.size (), size_t (3)); + EXPECT_EQ (collect_func->values[0], 10000); + EXPECT_EQ (collect_func->values[1], 14400); + EXPECT_EQ (collect_func->values[2], 19600); +}