Changeset 295

Show
Ignore:
Timestamp:
09/18/06 16:26:02 (2 years ago)
Author:
thomase
Message:

Now produces comprehensive tests that reliably handle unicode characters in all relevant fields.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • GeographicEntityLite/trunk/GeographicEntityLite/tests/data/maketest.xsl

    r284 r295  
    3838     
    3939    <xsl:template match="gaz:modernLocation"> 
    40     &gt;&gt;&gt; en.setModernLocation(u'<xsl:apply-templates />') 
    41     >>> en.getModernLocation() 
    42     '<xsl:apply-templates />' 
     40    &gt;&gt;&gt; sourcetext = u'<xsl:apply-templates/>' 
     41    &gt;&gt;&gt; sourcetext_utf8 = sourcetext.encode('utf8') 
     42    &gt;&gt;&gt; en.setModernLocation(sourcetext_utf8) 
     43    &gt;&gt;&gt; resulttext_utf8 = en.getModernLocation() 
     44    &gt;&gt;&gt; resulttext_utf8 == sourcetext_utf8 
     45    True 
     46    &gt;&gt;&gt; resulttext = unicode(resulttext_utf8, 'utf8') 
     47    &gt;&gt;&gt; resulttext == sourcetext 
     48    True 
     49    &gt;&gt;&gt; resulttext == u'<xsl:apply-templates/>' 
     50    True 
    4351    </xsl:template> 
    4452     
     
    4654        <xsl:if test="count(preceding-sibling::gaz:timePeriod) = 0"> 
    4755            <xsl:variable name="timestring"><xsl:for-each select="../gaz:timePeriod">'<xsl:value-of select="normalize-space(gaz:timePeriodName)"/>'<xsl:if test="count(following-sibling::gaz:timePeriod) &gt; 0">, </xsl:if></xsl:for-each></xsl:variable> 
    48     &gt;&gt;&gt; en.setTimePeriods([<xsl:value-of select="$timestring"/>]) 
    49     &gt;&gt;&gt; en.getTimePeriods() 
    50     (<xsl:value-of select="$timestring"/><xsl:if test="count(../gaz:timePeriod) = 1">,</xsl:if>) 
    51         </xsl:if> 
    52     </xsl:template> 
     56    &gt;&gt;&gt; sourcelist = [<xsl:value-of select="$timestring"/>] 
     57    &gt;&gt;&gt; en.setTimePeriods(sourcelist) 
     58    &gt;&gt;&gt; results = en.getTimePeriods() 
     59    <xsl:for-each select="../gaz:timePeriod"> 
     60    &gt;&gt;&gt; results[<xsl:value-of select="count(preceding-sibling::gaz:timePeriod)"/>] == '<xsl:value-of select="normalize-space(gaz:timePeriodName)"/>' 
     61    True 
     62    </xsl:for-each> 
     63            </xsl:if> 
     64    </xsl:template> 
     65     
    5366    <!-- note: handling name classification is currently disabled b/c the content type doesn't support it --> 
    5467    <xsl:template match="gaz:classificationSection"> 
     
    6881        <xsl:if test="count(preceding-sibling::tei:bibl) = 0"> 
    6982            <xsl:variable name="biblstring"><xsl:for-each select="../tei:bibl">u'<xsl:apply-templates/>'<xsl:if test="count(following-sibling::tei:bibl) &gt; 0">, </xsl:if></xsl:for-each></xsl:variable> 
    70     &gt;&gt;&gt; en.setSecondaryReferences([<xsl:value-of select="$biblstring"/>]) 
    71     &gt;&gt;&gt; en.getSecondaryReferences() 
    72     (<xsl:value-of select="$biblstring"/>) 
     83    &gt;&gt;&gt; sourcelist = [<xsl:value-of select="$biblstring"/>] 
     84    &gt;&gt;&gt; en.setSecondaryReferences(sourcelist) 
     85    &gt;&gt;&gt; resultlist = en.getSecondaryReferences() 
     86    <xsl:for-each select="../tei:bibl"> 
     87    &gt;&gt;&gt; resultlist[<xsl:value-of select="count(preceding-sibling::tei:bibl)"/>] == sourcelist[<xsl:value-of select="count(preceding-sibling::tei:bibl)"/>].encode('utf8') 
     88    True 
     89    </xsl:for-each> 
    7390        </xsl:if> 
    7491    </xsl:template> 
     
    100117     
    101118    <xsl:template match="gaz:nameString"> 
    102     &gt;&gt;&gt; en_name.setNameAttested(u'<xsl:apply-templates />') 
    103     &gt;&gt;&gt; en_name.getNameAttested() 
    104     u'<xsl:apply-templates />' 
     119    &gt;&gt;&gt; sourcetext = u'<xsl:apply-templates/>' 
     120    &gt;&gt;&gt; sourcetext_utf8 = sourcetext.encode('utf8') 
     121    &gt;&gt;&gt; en_name.setNameAttested(sourcetext_utf8) 
     122    &gt;&gt;&gt; resulttext_utf8 = en_name.getNameAttested() 
     123    &gt;&gt;&gt; resulttext_utf8 == sourcetext_utf8 
     124    True 
     125    &gt;&gt;&gt; resulttext = unicode(resulttext_utf8, 'utf8') 
     126    &gt;&gt;&gt; resulttext == sourcetext 
     127    True 
     128    &gt;&gt;&gt; resulttext == u'<xsl:apply-templates/>' 
     129    True 
     130         
    105131        <xsl:variable name="language"><xsl:call-template name="getlangstring"><xsl:with-param name="langcode"><xsl:value-of select="@xml:lang"/></xsl:with-param></xsl:call-template></xsl:variable> 
    106132    &gt;&gt;&gt; en_name.setNameLanguage('<xsl:value-of select="normalize-space($language)"/>') 
     
    108134    <xsl:choose> 
    109135    <xsl:when test="contains($language, 'unknown')">''</xsl:when> 
    110     <xsl:otherwise>'<xsl:value-of select="normalize-space($language)"/></xsl:otherwise> 
     136    <xsl:otherwise>'<xsl:value-of select="normalize-space($language)"/>'</xsl:otherwise> 
    111137    </xsl:choose> 
    112138    </xsl:template> 
     
    125151     
    126152    <xsl:template match="text()"> 
    127         <xsl:variable name="normedtext"><xsl:value-of select="."/></xsl:variable> 
     153        <xsl:variable name="normedtext"><xsl:value-of select="normalize-space(.)"/></xsl:variable> 
    128154  <xsl:for-each select="string-to-codepoints($normedtext)"> 
    129     <xsl:choose> 
    130         <xsl:when test=". = 160"> </xsl:when>  <!-- get rid of non-breaking spaces --> 
    131       <xsl:when test=". > 127">\x<xsl:call-template name="toHex"><xsl:with-param name="decimalNumber"><xsl:value-of select="."/></xsl:with-param></xsl:call-template></xsl:when> 
    132         <xsl:otherwise><xsl:value-of select="codepoints-to-string(.)"/></xsl:otherwise> 
    133     </xsl:choose> 
     155        <xsl:choose> 
     156            <xsl:when test=". &lt; 128"><xsl:value-of select="codepoints-to-string(.)"/></xsl:when> 
     157            <xsl:when test=". = 160"><xsl:text> </xsl:text></xsl:when>  <!-- get rid of non-breaking spaces --> 
     158            <xsl:otherwise> 
     159                <xsl:call-template name="genpythouniesc"> 
     160                    <xsl:with-param name="codepoint-decimal"><xsl:value-of select="."/></xsl:with-param> 
     161                </xsl:call-template> 
     162            </xsl:otherwise> 
     163        </xsl:choose> 
    134164  </xsl:for-each> 
    135165    </xsl:template> 
     
    146176    </xsl:template> 
    147177     
     178    <xsl:template name="genpythouniesc"> 
     179        <xsl:param name="codepoint-decimal"/> 
     180        <xsl:variable name="codepoint-hex"> 
     181            <xsl:call-template name="toHex"> 
     182                <xsl:with-param name="decimalNumber"><xsl:value-of select="$codepoint-decimal"/></xsl:with-param> 
     183            </xsl:call-template> 
     184        </xsl:variable> 
     185        <xsl:variable name="hexlen"><xsl:value-of select="string-length(string($codepoint-hex))"/></xsl:variable> 
     186        <xsl:text>\U</xsl:text><xsl:value-of select="concat(substring('00000000', 1, 8-$hexlen), string($codepoint-hex))"/> 
     187    </xsl:template> 
    148188    <!-- The toHex template was written by Peter Doggett.  
    149189          This copy was obtained from http://www.mhonarc.org/archive/html/xsl-list/2003-03/msg01227.html 
    150           on 14 September 2006 --> 
     190          on 14 September 2006 --> 
    151191    <xsl:variable name="hexDigits" select="'0123456789ABCDEF'" /> 
    152192        <xsl:template name="toHex"> 
    153         <xsl:param name="decimalNumber" /> 
    154         <xsl:if test="$decimalNumber >= 16"> 
    155           <xsl:call-template name="toHex"> 
    156             <xsl:with-param name="decimalNumber"  
    157         select="floor($decimalNumber div 16)" /> 
    158           </xsl:call-template> 
    159         </xsl:if> 
    160         <xsl:value-of select="substring($hexDigits,  
    161         ($decimalNumber mod 16) + 1, 1)" /> 
     193            <xsl:param name="decimalNumber" /> 
     194            <xsl:if test="$decimalNumber >= 16"> 
     195              <xsl:call-template name="toHex"> 
     196                <xsl:with-param name="decimalNumber"  
     197            select="floor($decimalNumber div 16)" /> 
     198              </xsl:call-template> 
     199            </xsl:if> 
     200            <xsl:value-of select="substring($hexDigits,  
     201            ($decimalNumber mod 16) + 1, 1)" /> 
    162202        </xsl:template> 
    163203</xsl:stylesheet>