<project name="scriptselector" default="def" basedir=".">

  <property name="src.file" location="${ant.file}" />
  
  <macrodef name="testselected">
    <element name="selector" implicit="yes" optional="true"/>
    <attribute name="message"/>
    <sequential>
      <fail message="@{message} failed: file was not selected">
        <condition>
          <not>
            <isfileselected file="{src.file}">
              <selector/>
            </isfileselected>
          </not>
        </condition>
      </fail>
    </sequential>
  </macrodef>  
  
  <macrodef name="testnoselected">
    <element name="selector" implicit="yes" optional="true"/>
    <attribute name="message"/>
    <sequential>
      <fail message="@{message} failed: file was selected">
        <condition>
          <isfileselected file="{src.file}">
            <selector/>
          </isfileselected>
        </condition>
      </fail>
    </sequential>
  </macrodef>    

  <!-- this is here to test the macro is well coded -->
  <target name="testNoSelector">
    <testselected message="testNoSelector" >
    </testselected>
  </target>

  <target name="testNolanguage">
    <testselected message="testNolanguage" >
      <selector>
        <scriptselector >
          self.setSelected(true);
        </scriptselector>
      </selector>
    </testselected>
  </target>

  <target name="testSelectionSetByDefault">
    <testselected message="testSelectionSetByDefault" >
      <selector>
        <scriptselector language="javascript">
        </scriptselector>
      </selector>
    </testselected>
  </target>


  <target name="testSelectionSetWorks">
    <testselected message="testSelectionSetWorks" >
      <selector>
        <scriptselector language="javascript">
          self.setSelected(false);
          self.setSelected(true);
        </scriptselector>
      </selector>
    </testselected>
  </target>

  <target name="testSelectionClearWorks">
    <testnoselected message="testSelectionClearWorks">
      <selector>
        <scriptselector language="javascript">
          self.setSelected(false);
        </scriptselector>
      </selector>
    </testnoselected>
  </target>
  
  <target name="testFileAttribute">
    <testselected message="testFileAttribute" >
      <selector>
        <scriptselector language="javascript">
          self.setSelected(file.equals(self.getFile()));
        </scriptselector>
      </selector>
    </testselected>
  </target>  

  <target name="testFilenameAttribute">
    <testselected message="testFilenameAttribute" >
      <selector>
        <scriptselector language="javascript">
          self.setSelected(filename.equals(self.getFilename()));
        </scriptselector>
      </selector>
    </testselected>
  </target>    
  
  <target name="testBasedirAttribute">
    <testselected message="testBasedirAttribute" >
      <selector>
        <scriptselector language="javascript">
          self.setSelected(basedir.equals(self.getBasedir()));
        </scriptselector>
      </selector>
    </testselected>
  </target>
  
  <target name="notestFilenameLength">
    <testselected message="notestFilenameLength" >
      <selector>
        <scriptselector language="javascript">
          self.setSelected((filename.length%2)==0);
        </scriptselector>
      </selector>
    </testselected>
  </target>    
</project>
