@@ -49,8 +49,18 @@ public class CanonicalDomFragmentTest extends AbstractCanonicalTest {
4949 @ ParameterizedTest
5050 @ MethodSource ("testFiles" )
5151 public void runTest (final File dataFile ) throws Exception {
52- final String domDataLines = getResult (dataFile );
52+ final String dataLines = getResult (dataFile , false );
53+ test (dataFile , dataLines );
54+ }
55+
56+ @ ParameterizedTest
57+ @ MethodSource ("testFiles" )
58+ public void runTestWithCachedElementsProvider (final File dataFile ) throws Exception {
59+ final String dataLines = getResult (dataFile , true );
60+ test (dataFile , dataLines );
61+ }
5362
63+ private static void test (final File dataFile , final String dataLines ) throws Exception {
5464 try {
5565 // prepare for future changes where canonical files are next to test file
5666 File canonicalFile = new File (dataFile .getParentFile (), dataFile .getName () + ".canonical-frg" );
@@ -75,23 +85,23 @@ public void runTest(final File dataFile) throws Exception {
7585 }
7686
7787 if (!canonicalFile .exists ()) {
78- fail ("Canonical file not found for input: " + dataFile .getAbsolutePath () + ": " + domDataLines );
88+ fail ("Canonical file not found for input: " + dataFile .getAbsolutePath () + ": " + dataLines );
7989 }
8090
8191 final File nyiFile = new File (canonicalFile .getParentFile (), canonicalFile .getName () + ".nyi" );
8292 if (nyiFile .exists ()) {
8393 try {
84- assertEquals (getCanonical (canonicalFile ), domDataLines , dataFile .toString ());
94+ assertEquals (getCanonical (canonicalFile ), dataLines , dataFile .toString ());
8595 fail ("test " + dataFile .getName () + "is marked as not yet implemented but already works" );
8696 }
8797 catch (final AssertionFailedError e ) {
8898 // expected
8999 }
90100
91- assertEquals (getCanonical (nyiFile ), domDataLines , "NYI: " + dataFile );
101+ assertEquals (getCanonical (nyiFile ), dataLines , "NYI: " + dataFile );
92102 }
93103 else {
94- assertEquals (getCanonical (canonicalFile ), domDataLines , dataFile .toString ());
104+ assertEquals (getCanonical (canonicalFile ), dataLines , dataFile .toString ());
95105 }
96106 }
97107 catch (final AssertionFailedError e ) {
@@ -100,15 +110,22 @@ public void runTest(final File dataFile) throws Exception {
100110 final File output = new File (OUTOUT_DIR , path + ".canonical-frg" );
101111 Files .createDirectories (Paths .get (output .getParentFile ().getPath ()));
102112 try (PrintWriter pw = new PrintWriter (Files .newOutputStream (output .toPath ()))) {
103- pw .print (domDataLines );
113+ pw .print (dataLines );
104114 }
105115 throw e ;
106116 }
107117 }
108118
109- private static String getResult (final File infile ) throws Exception {
119+ private static String getResult (final File infile , final boolean cached ) throws Exception {
110120 try (StringWriter out = new StringWriter ()) {
111- final DOMFragmentParser parser = new DOMFragmentParser ();
121+ final DOMFragmentParser parser ;
122+ if (cached ) {
123+ parser = new DOMFragmentParser (new HTMLElements .HTMLElementsWithCache (new HTMLElements ()));
124+ }
125+ else {
126+ parser = new DOMFragmentParser ();
127+ }
128+
112129
113130 final CoreDocumentImpl document = new CoreDocumentImpl ();
114131 final DocumentFragmentImpl fragment = (DocumentFragmentImpl ) document .createDocumentFragment ();
0 commit comments