34 BOOST_AUTO_TEST_SUITE( Libeval_Compiler )
46 {
"10mm + 20 mm",
false,
VAL( 30e6 ) },
47 {
"3*(7+8)",
false,
VAL( 3 * ( 7 + 8 ) ) },
48 {
"3*7+8",
false,
VAL( 3 * 7 + 8 ) },
49 {
"(3*7)+8",
false,
VAL( 3 * 7 + 8 ) },
50 {
"10mm + 20)",
true,
VAL( 0 ) },
52 {
"1",
false,
VAL(1) },
53 {
"1.5",
false,
VAL(1.5) },
54 {
"1,5",
false,
VAL(1.5) },
55 {
"1mm",
false,
VAL(1e6) },
57 {
" 1 + 2 ",
false,
VAL(3) },
59 {
"1.5 + 0.2 + 0.1",
false,
VAL(1.8) },
61 {
"3 - 10",
false,
VAL(-7) },
63 {
"1 + 2 + 10 + 1000.05",
false,
VAL(1013.05) },
65 {
"1 + 2 - 4 * 20 / 2",
false,
VAL(-37) },
67 {
"(1)",
false,
VAL(1) },
69 {
"-(1 + (2 - 4)) * 20.8 / 2",
false,
VAL(10.4) },
71 {
"+2 - 1",
false,
VAL(1) }
76 {
"A.type == 'Pad' && B.type == 'Pad' && (A.existsOnLayer('F.Cu'))",
false,
VAL( 0.0 ) },
77 {
"A.Width > B.Width",
false,
VAL( 0.0 ) },
78 {
"A.Width + B.Width",
false,
VAL( Mils2iu(10) + Mils2iu(20) ) },
79 {
"A.Netclass",
false,
VAL(
"HV" ) },
80 {
"(A.Netclass == 'HV') && (B.netclass == 'otherClass') && (B.netclass != 'F.Cu')",
false,
VAL( 1.0 ) },
81 {
"A.Netclass + 1.0",
false,
VAL( 1.0 ) },
82 {
"A.type == 'Track' && B.type == 'Track' && A.layer == 'F.Cu'",
false,
VAL( 1.0 ) },
83 {
"(A.type == 'Track') && (B.type == 'Track') && (A.layer == 'F.Cu')",
false,
VAL( 1.0 ) },
84 {
"A.type == 'Via' && A.isMicroVia()",
false,
VAL(0.0) }
89 bool expectError =
false,
BOARD_ITEM* itemA =
nullptr,
100 BOOST_TEST_MESSAGE(
"Expr: '" << expr.c_str() <<
"'" );
102 bool error = !compiler.
Compile( expr, &ucode, &preflightContext );
104 BOOST_CHECK_EQUAL( error, expectError );
106 if( error != expectError )
108 BOOST_TEST_MESSAGE(
"Result: FAIL: " << compiler.
GetError().
message.c_str() <<
121 result = *ucode.
Run( &context );
122 ok = ( result.
EqualTo( &expectedResult ) );
143 testEvalExpr( expr.expression, expr.expectedResult, expr.expectError );
156 NETCLASSPTR netclass1(
new NETCLASS(
"HV" ) );
157 NETCLASSPTR netclass2(
new NETCLASS(
"otherClass" ) );
162 net1info->SetNetClass( netclass1 );
163 net2info->SetNetClass( netclass2 );
165 TRACK trackA( &brd );
166 TRACK trackB( &brd );
168 trackA.
SetNet( net1info );
169 trackB.
SetNet( net2info );
178 testEvalExpr( expr.expression, expr.expectedResult, expr.expectError, &trackA, &trackB );
182 BOOST_AUTO_TEST_SUITE_END()
void Rebuild()
Rebuild the list of all registered properties.
void SetItems(BOARD_ITEM *a, BOARD_ITEM *b=nullptr)
static PROPERTY_MANAGER & Instance()
LIBEVAL::VALUE expectedResult
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
const NETINFO_LIST & GetNetInfo() const
static bool testEvalExpr(const wxString &expr, LIBEVAL::VALUE expectedResult, bool expectError=false, BOARD_ITEM *itemA=nullptr, BOARD_ITEM *itemB=nullptr)
bool Compile(const wxString &aString, UCODE *aCode, CONTEXT *aPreflightContext)
BOOST_AUTO_TEST_CASE(SimpleExpressions)
void SetWidth(int aWidth)
static const std::vector< EXPR_TO_TEST > introspectionExpressions
VAR_TYPE_T GetType() const
virtual bool EqualTo(const VALUE *b) const
Container for NETINFO_ITEM elements, which are the nets.
A collection of nets and the parameters used to route or test these nets.
const ERROR_STATUS & GetError() const
Handle the data for a net.
void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
Board layer functions and definitions.
virtual double AsDouble() const
Information pertinent to a Pcbnew printed circuit board.
virtual const wxString & AsString() const
static const std::vector< EXPR_TO_TEST > simpleExpressions
Provide class metadata.Helper macro to map type hashes to names.
VALUE * Run(CONTEXT *ctx)