gimsieke/xspec

a way to specify expected attributes for templates which "yields attributes"

Opened this issue · 1 comments

Is there a way to test templates which yield attributes? i.e.,

<xsl:template select="src-element" mode="attr-group-1">
  <xsl:attribute name="a">...</xsl:attribute>
  <xsl:attribute name="b">...</xsl:attribute>
</xsl:template>

<xsl:template select="src-element" mode="attr-group-2">
  <xsl:attribute name="c">...</xsl:attribute>
  <xsl:attribute name="d">...</xsl:attribute>
</xsl:template>

<scenario>
  <context mode="attr-group-1">
    <src-element ... />
  </context>
  <expect>
    <!-- ??? specify expected attributes -->
   </expect>
</scenario>


Here's some backgrounds:

I have many templates yield common set of attributes for different elements 
(from different source elements), i.e.,

<template match="S1" mode="T1">
  <element name="T1">
    <attribute name="common-a"><value-of select="@s1-a"></attribute>
    <attribute name="common-b"><value-of select="@s1-b"></attribute>
    <attribute name="t1">...</attribute>
  </element>
</template>

<template match="S1" mode="T2">
  <element name="T2">
    <attribute name="common-a"><value-of select="@s1-a"></attribute>
    <attribute name="common-b"><value-of select="@s1-b"></attribute>
    <attribute name="t2">...</attribute>
  </element>
</template>

<template match="S2" mode="T1">
  <element name="T1">
    <attribute name="common-a"><value-of select="@s2-a"></attribute>
    <attribute name="common-b"><value-of select="@s2-b"></attribute>
    <attribute name="t1">...</attribute>
  </element>
</template>

<template match="S1" mode="T2">
  <element name="T2">
    <attribute name="common-a"><value-of select="@s1-a"></attribute>
    <attribute name="common-b"><value-of select="@s1-b"></attribute>
    <attribute name="t2">...</attribute>
  </element>
</template>

<template match="S2" mode="T2">
  <element name="T2">
    <attribute name="common-a"><value-of select="@s2-a"></attribute>
    <attribute name="common-b"><value-of select="@s2-b"></attribute>
    <attribute name="t2">...</attribute>
  </element>
</template>

There are so many duplications, so I want to refactor these templates as like 
following:

<!-- common attributes -->
<template match="S1" mode="common-attrs">
  <attribute name="common-a"><value-of select="@s1-a"></attribute>
  <attribute name="common-b"><value-of select="@s1-b"></attribute>
</template>

<template match="S2" mode="common-attrs">
  <attribute name="common-a"><value-of select="@s2-a"></attribute>
  <attribute name="common-b"><value-of select="@s2-b"></attribute>
</template>

<!-- each transforms of {S1,S2} x {T1, T2} -->
<template match="S1" mode="T1">
  <element name="T1">
    <apply-templates select="." mode="common-attrs" />
    <attribute name="t1">...</attribute>
  </element>
</template>

<template match="S1" mode="T2">
  <element name="T2">
    <apply-templates select="." mode="common-attrs" />
    <attribute name="t2">...</attribute>
  </element>
</template>

<template match="S2" mode="T1">
  <element name="T1">
    <apply-templates select="." mode="common-attrs" />
    <attribute name="t1">...</attribute>
  </element>
</template>

<template match="S2" mode="T2">
  <element name="T2">
    <apply-templates select="." mode="common-attrs" />
    <attribute name="t2">...</attribute>
  </element>
</template>

So it would be great there is some ways to test the "common-attrs" templates.

Original issue reported on code.google.com by met...@sarangbang.or.kr on 15 Sep 2012 at 8:11

Oops, the template S1->T2 (the one before the refactoring) is duplicated. Sorry 
for the mess.

Original comment by met...@sarangbang.or.kr on 15 Sep 2012 at 8:14