Merge pull request #314 from KLayout/vars-for-queries

Vars for queries
This commit is contained in:
Matthias Köfferlein
2019-08-18 17:31:11 +02:00
committed by GitHub
9 changed files with 106 additions and 52 deletions
+5
View File
@@ -24,6 +24,11 @@ class TLTest(unittest.TestCase):
def test_1(self):
ctx = pya.ExpressionContext()
self.assertEqual(ctx.eval("1+2"), 3)
ctx.var("a", 21)
self.assertEqual(ctx.eval("2*a"), 42)
expr = pya.Expression()
res = expr.eval()
self.assertEqual(str(type(res)).replace("class", "type"), "<type 'NoneType'>")
+31
View File
@@ -68,6 +68,37 @@ class DBLayoutQuery_TestClass < TestBase
end
# variables
def test_4
ly = RBA::Layout::new
ly.read(ENV["TESTSRC"] + "/testdata/gds/t11.gds")
ctx = RBA::ExpressionContext::new
ctx.var("suffix", "!")
ctx.var("all", [])
ctx.var("nonmod", "")
q = RBA::LayoutQuery::new("select cell.name + suffix from *")
res = []
q.each(ly, ctx) do |iter|
res << iter.data.inspect
end
assert_equal(res.size, 2)
assert_equal(res[0], "[\"TOPTOP!\"]")
assert_equal(res[1], "[\"TOP!\"]")
q = RBA::LayoutQuery::new("with * do var nonmod = cell.name; all.push(nonmod)")
q.execute(ly, ctx)
assert_equal(ctx.eval("all").join(","), "TOPTOP,TOP")
# not modified, because we used "var nonmod" in the query which
# creates a local variable:
assert_equal(ctx.eval("nonmod"), "")
end
end
load("test_epilogue.rb")
+5
View File
@@ -29,6 +29,11 @@ class Tl_TestClass < TestBase
# Expression basics
def test_1_Expression
ctx = RBA::ExpressionContext::new
assert_equal(ctx.eval("1+2"), 3)
ctx.var("a", 21)
assert_equal(ctx.eval("2*a"), 42)
expr = RBA::Expression::new
res = expr.eval
assert_equal(res.class.to_s, "NilClass")