Added tests for tech component, syntax highlighter fixed.

This commit is contained in:
Matthias Koefferlein 2020-04-17 16:24:56 +02:00
parent b2216ec372
commit ca2b0cd96a
5 changed files with 104 additions and 8 deletions

View File

@ -134,10 +134,11 @@ D25TechnologyComponent::D25TechnologyComponent ()
"# 'zstart' and 'zstop'.\n"
"#\n"
"# Examples:\n"
"# 1: 0.5 1.5 # extrude layer 1/0 from 0.5 to 1.5 vertically\n"
"# 1: zstop=1.5, zstart=0.5 # same as above\n"
"# 1: height=1.0, zstop=1.5 # same as above\n"
"# 1: 1.0 zstop=1.5 # same as above\n"
"# 1: 0.5 1.5 # extrude layer 1/0 from 0.5 to 1.5 vertically\n"
"# 1/0: 0.5 1.5 # same with explicit datatype\n"
"# 1: zstop=1.5, zstart=0.5 # same with named parameters\n"
"# 1: height=1.0, zstop=1.5 # same with z stop minus height\n"
"# 1: 1.0 zstop=1.5 # same with height as unnamed parameter\n"
;
}
@ -186,6 +187,10 @@ D25TechnologyComponent::compile_from_source (const std::string &src)
while (! ex.at_end ()) {
if (ex.test ("#")) {
break;
}
double pv = 0.0;
std::string pn;
@ -227,6 +232,9 @@ D25TechnologyComponent::compile_from_source (const std::string &src)
if (! h.is_nil ()) {
info.set_zstop (info.zstart () + h.to_double ());
}
} else {
info.set_zstart (z0.to_double ());
info.set_zstop (z1.to_double ());
}
} else if (args.size () == 1) {
info.set_zstop ((! z0.is_nil () ? z0.to_double () : info.zstart ()) + args[0]);
@ -250,6 +258,21 @@ D25TechnologyComponent::compile_from_source (const std::string &src)
m_src = src;
}
std::string
D25TechnologyComponent::to_string () const
{
std::string res;
for (const_iterator i = begin (); i != end (); ++i) {
if (! res.empty ()) {
res += "\n";
}
res += i->layer ().to_string () + ": zstart=" + tl::to_string (i->zstart ()) + ", zstop=" + tl::to_string (i->zstop ());
}
return res;
}
// -----------------------------------------------------------------------------------
// D25TechnologyComponent technology component registration

View File

@ -137,6 +137,8 @@ public:
m_src = s;
}
std::string to_string () const;
db::TechnologyComponent *clone () const
{
return new D25TechnologyComponent (*this);

View File

@ -0,0 +1,70 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2020 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "dbD25TechnologyComponent.h"
#include "tlUnitTest.h"
TEST(1)
{
db::D25TechnologyComponent comp;
comp.compile_from_source ("1/0: 1.0 1.5 # a comment");
EXPECT_EQ (comp.to_string (), "1/0: zstart=1, zstop=1.5");
comp.compile_from_source ("1/0: zstart=1.0 zstop=1.5");
EXPECT_EQ (comp.to_string (), "1/0: zstart=1, zstop=1.5");
comp.compile_from_source ("1/0: zstart=1.0 height=0.5");
EXPECT_EQ (comp.to_string (), "1/0: zstart=1, zstop=1.5");
comp.compile_from_source ("1/0: zstop=1.5 height=0.5");
EXPECT_EQ (comp.to_string (), "1/0: zstart=1, zstop=1.5");
comp.compile_from_source ("1/0: zstart=1.0 zstop=1.5\nname: height=3");
EXPECT_EQ (comp.to_string (), "1/0: zstart=1, zstop=1.5\nname: zstart=1.5, zstop=4.5");
comp.compile_from_source ("1/0: zstart=1.0 zstop=1.5\nname: zstart=4.0 height=3\n\n# a comment line");
EXPECT_EQ (comp.to_string (), "1/0: zstart=1, zstop=1.5\nname: zstart=4, zstop=7");
try {
comp.compile_from_source ("blabla");
EXPECT_EQ (false, true);
} catch (...) { }
try {
comp.compile_from_source ("1/0: 1 2 3");
EXPECT_EQ (false, true);
} catch (...) { }
try {
comp.compile_from_source ("1/0: foo=1 bar=2");
EXPECT_EQ (false, true);
} catch (...) { }
try {
comp.compile_from_source ("1/0: 1;2");
EXPECT_EQ (false, true);
} catch (...) { }
}

View File

@ -73,7 +73,8 @@ SOURCES = \
dbLayoutQueryTests.cc \
dbPolygonToolsTests.cc \
dbTechnologyTests.cc \
dbStreamLayerTests.cc
dbStreamLayerTests.cc \
dbD25TechnologyComponentTests.cc
INCLUDEPATH += $$TL_INC $$DB_INC $$GSI_INC
DEPENDPATH += $$TL_INC $$DB_INC $$GSI_INC

View File

@ -15,7 +15,7 @@
<RegExpr attribute="Normal" String=":" context="After LD"/>
<RegExpr attribute="Dec" String="\-?[1-9][0-9]*" context="#stay"/>
<RegExpr attribute="Dec" String="\-?[0-9]+" context="#stay"/>
<DetectChar attribute="Normal" char="*" context="#stay"/>
<DetectChar attribute="Normal" char="(" context="#stay"/>
<DetectChar attribute="Normal" char=")" context="#stay"/>
@ -46,13 +46,13 @@
<context name="Quoted String" attribute="String" lineEndContext="Error">
<StringDetect attribute="String" String="\\" context="#stay"/>
<RegExpr attribute="String" String="\\\&quot;" context="#stay"/>
<DetectChar char="&quot;" attribute="String" context="After Key"/>
<DetectChar char="&quot;" attribute="String" context="Normal"/>
</context>
<context name="Apostrophed String" attribute="Raw String" lineEndContext="Error">
<StringDetect attribute="String" String="\\" context="#stay"/>
<RegExpr attribute="String" String="\\\'" context="#stay"/>
<DetectChar char="'" attribute="Raw String" context="After Key"/>
<DetectChar char="'" attribute="Raw String" context="Normal"/>
</context>
</contexts>