#!/bin/bash
. ./Common

###############################################################################

tst "characteristics: one file" -dc <<EOF
<T> = R;
<FP> = 0402<0603<0805;
{ FP=<FP> }
T=<T> {
	R: { R=#R TOL=%R };
};
!-c
FOO BAR1	T=R FP=0603 R=100R TOL=5%
FOO BAR2	T=R FP=0603 R=1k TOL=1%
EOF

expect <<EOF
FOO BAR1
    FP=0603 T=R R=100R TOL=-5/+5%
FOO BAR2
    FP=0603 T=R R=1000R TOL=-1/+1%
EOF

#------------------------------------------------------------------------------

tst "characteristics: two files" -dc <<EOF
<T> = R;
<FP> = 0402<0603<0805;
{ FP=<FP> }
T=<T> {
	R: { R=#R TOL=%R };
};
!-c1
FOO BAR1	T=R FP=0603 R=100R TOL=5%
FOO BAR2	T=R FP=0603 R=1k TOL=1%
!-c2
FOO BAR3	T=R FP=0402 R=100R TOL=2%
EOF

expect <<EOF
FOO BAR1
    FP=0603 T=R R=100R TOL=-5/+5%
FOO BAR2
    FP=0603 T=R R=1000R TOL=-1/+1%
FOO BAR3
    FP=0402 T=R R=100R TOL=-2/+2%
EOF

#------------------------------------------------------------------------------

tst_fail "characteristics: duplicate part" -dc <<EOF
<T> = R;
<FP> = 0402<0603<0805;
{ FP=<FP> }
T=<T> {
	R: { R=#R TOL=%R };
};
!-c
FOO BAR1	T=R FP=0603 R=100R TOL=5%
FOO BAR1	T=R FP=0603 R=1k TOL=1%
EOF

expect <<EOF
c:3: FOO BAR1 parameters already defined
EOF

#------------------------------------------------------------------------------

tst_fail "characteristics: invalid/unknown value" -dc <<EOF
<T> = R;
<FP> = 0402<0603<0805;
{ FP=<FP> }
T=<T> {
	R: { R=#R TOL=%R };
};
!-c
FOO BAR1	T=R FP=0603 R=100R TOL=5%
FOO BAR2	T=R FP=0603 R=1uF
EOF

expect <<EOF
c:3: invalid value for R
EOF

#------------------------------------------------------------------------------

tst "characteristics: unknown parameter" -dc <<EOF
<T> = R;
<FP> = 0402<0603<0805;
{ FP=<FP> }
T=<T> {
	R: { R=#R TOL=%R };
};
!-c
FOO BAR1	T=R FP=0603 R=100R TOL=5%
FOO BAR2	T=R FP=0603 R=1k TOL=1% BLAH=3
EOF

expect <<EOF
c:3: warning: extra parameter: BLAH
FOO BAR1
    FP=0603 T=R R=100R TOL=-5/+5%
FOO BAR2
    FP=0603 T=R R=1000R TOL=-1/+1%
EOF

###############################################################################