%%
%% This is file `protecteddef-test2.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% protecteddef.dtx  (with options: `test2')
%% 
%% This is a generated file.
%% 
%% Project: protecteddef
%% Version: 2011/01/31 v1.0
%% 
%% Copyright (C) 2011 by
%%    Heiko Oberdiek <heiko.oberdiek at googlemail.com>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. This version of this license is in
%%    http://www.latex-project.org/lppl/lppl-1-3c.txt
%% and the latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% This Current Maintainer of this work is Heiko Oberdiek.
%% 
%% The Base Interpreter refers to any `TeX-Format',
%% because some files are installed in TDS:tex/generic//.
%% 
%% This work consists of the main source file protecteddef.dtx
%% and the derived files
%%    protecteddef.sty, protecteddef.pdf, protecteddef.ins, protecteddef.drv,
%%    protecteddef-test1.tex, protecteddef-test2.tex.
%% 
\errorcontextlines=10000 %
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname RequirePackage\endcsname\relax
  \input protecteddef.sty\relax
  \catcode`\{=1 %
  \catcode`\}=2 %
  \catcode`\#=6 %
\else
  \RequirePackage{protecteddef}[2011/01/31]%
\fi
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname protected\endcsname\relax
  \let\pdef\def
\else
  \def\pdef{\protected\def}%
\fi
\def\msg#{\immediate\write16}
\countdef\errcount=2 %
\long\def\BeginCheck#1\ProtectedDef#2\EndCheck{%
  \begingroup
    \toks0={\ProtectedDef#2}%
    \msg{<<\the\toks0>>}%
  \endgroup
  \setbox0=\hbox{%
    #1%
    \ProtectedDef#2%
    \check\foo
  }%
  \ifdim\wd0=0pt\relax
  \else
    \errmessage{[Definition] Unwanted spaces?!}%
  \fi
  \setbox0=\hbox{%
    \def\fooinitial{XYZ}%
    \let\foo\fooinitial
    \errcount=0 %
    \expandafter\def\csname @PackageError\endcsname##1##2##3{%
      \advance\errcount by 1 %
    }%
    \expandafter\def\csname @notdefinable\endcsname{%
      \advance\errcount by 1 %
    }%
    \ProtectedDef#2%
    \ifnum\errcount=1 %
    \else
      \errmessage{1 error expected, but found: \the\errcount}%
    \fi
    \ifx\foo\fooinitial
    \else
      \def\space{ }%
      \errmessage{\string\foo\space is overwritten}%
    \fi
  }%
  \ifdim\wd0=0pt\relax
  \else
    \errmessage{[Error] Unwanted spaces?!}%
  \fi
}
\chardef\DeclareVersion=0 %
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname protected\endcsname\relax
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname DeclareRobustCommand\endcsname\relax
  \else
    \chardef\DeclareVersion=1 %
  \fi
\fi
\ifnum\DeclareVersion=0 %
  \def\check#1{%
    \ifx\cmp#1%
      \msg{* Test passed.}%
    \else
      \msg{}%
      \msg{[\meaning#1]}%
      \msg{[\meaning\cmp]}%
      \errmessage{Test failed!}%
    \fi
  }%
\else
  \def\check#1{%
    \begingroup
      \escapechar=-1 %
    \edef\x{\endgroup
      \def\noexpand\cs/{\string#1}%
    }\x
    \edef\CMP{%
      \noexpand\protect
      \expandafter\noexpand\csname\cs/ \endcsname
    }%
    \ifx\CMP#1%
      \expandafter\ifx\csname\cs/ \endcsname\cmp
        \msg{Test passed.}%
      \else
        \msg{}%
        \msg{[\expandafter\meaning\csname\cs/ \endcsname]}%
        \msg{[\meaning\cmp]}%
        \errmessage{Test failed!}%
      \fi
    \else
      \msg{}%
      \msg{[\meaning#1]}%
      \msg{[\meaning\CMP]}%
      \errmessage{Test failed!}%
    \fi
  }%
\fi

\tracingmacros=1

\BeginCheck
  \pdef\cmp{}%
  \ProtectedDef*\foo{}%
\EndCheck

\BeginCheck
  \pdef\cmp{}%
  \ProtectedDef*\foo[0]{}%
\EndCheck

\BeginCheck
  \pdef\cmp#1{<#1>}%
  \ProtectedDef*\foo[1]{<#1>}%
\EndCheck

\BeginCheck
  \pdef\cmp(#1){<#1>}%
  \ProtectedDef*\foo(#1){<#1>}%
\EndCheck

\BeginCheck
  \long\pdef\cmp{}%
  \ProtectedDef\foo{}%
\EndCheck

\BeginCheck
  \long\pdef\cmp{}%
  \ProtectedDef\foo[0]{}%
\EndCheck

\BeginCheck
  \long\pdef\cmp#1{<#1>}%
  \ProtectedDef\foo[1]{<#1>}%
\EndCheck

\BeginCheck
  \long\pdef\cmp(#1){<#1>}%
  \ProtectedDef\foo(#1){<#1>}%
\EndCheck

\csname @@end\endcsname\end
\endinput
%%
%% End of file `protecteddef-test2.tex'.
