Skip to content

Commit

Permalink
- F allow people to pass their own xml pretty printer
Browse files Browse the repository at this point in the history
Co-authored-by: Jay Bazuzi <[email protected]>
Co-authored-by: Llewellyn Falco <[email protected]>
  • Loading branch information
3 people committed Oct 7, 2024
1 parent 84cb835 commit aa8d2c3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void testLineNumbers()
{
ParsingFilesTest.addApprovalTestPath();
var expected = """
https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L98-L101
https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L103-L106
""";
String verifyAll = getLink(Queryable.as(Approvals.class.getMethods()).orderBy(m -> m.getParameterCount())
.first(m -> m.getName().equals("verifyAll") && m.getParameterTypes()[0].equals(Object[].class)));
Expand Down Expand Up @@ -72,4 +72,4 @@ private Queryable<Method> getAllVerifyFunctionsWithOptions(List<Class<?>> approv
}
return methods;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L214-L230) (ApprovalApprover, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L189-L192) (ApprovalWriter, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L181-L184) (ApprovalWriter, ApprovalNamer, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L235-L238) (ExecutableCommand, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L165-L168) (File, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L243-L246) (Map, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L56-L60) (Object, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L251-L254) (ResultSet, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L259-L262) (SqlLoader, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L48-L51) (String, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L65-L69) (Verifiable, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L106-L109) (Iterable, Function1, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L110-L114) (Object[], Function1, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L140-L143) (String, Iterable, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L127-L131) (String, Iterable, Function1, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L85-L88) (String, Object[], $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L119-L122) (String, Object[], Function1, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L148-L152) (String, String, Iterable, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L93-L97) (String, String, Object[], $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyEachFileInDirectory ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L271-L274) (File, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyEachFileInDirectory ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L279-L282) (File, FileFilter, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyEachFileInDirectory ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L287-L290) (File, FilenameFilter, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyException ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L392-L398) (Action0, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyHtml ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L157-L160) (String, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyXml ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L197-L201) (String, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L227-L243) (ApprovalApprover, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L194-L197) (ApprovalWriter, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L186-L189) (ApprovalWriter, ApprovalNamer, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L248-L251) (ExecutableCommand, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L170-L173) (File, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L256-L259) (Map, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L61-L65) (Object, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L264-L267) (ResultSet, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L272-L275) (SqlLoader, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L53-L56) (String, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L70-L74) (Verifiable, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L111-L114) (Iterable, Function1, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L115-L119) (Object[], Function1, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L145-L148) (String, Iterable, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L132-L136) (String, Iterable, Function1, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L90-L93) (String, Object[], $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L124-L127) (String, Object[], Function1, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L153-L157) (String, String, Iterable, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyAll ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L98-L102) (String, String, Object[], $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyEachFileInDirectory ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L284-L287) (File, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyEachFileInDirectory ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L292-L295) (File, FileFilter, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyEachFileInDirectory ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L300-L303) (File, FilenameFilter, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyException ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L405-L411) (Action0, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyHtml ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L162-L165) (String, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyXml ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L202-L205) (String, $\color{#AAA}{\textsf{Options}}$)
* Approvals. [verifyXml ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/Approvals.java#L210-L214) (String, Function1, $\color{#AAA}{\textsf{Options}}$)
* AwtApprovals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/awt/AwtApprovals.java#L44-L47) (BufferedImage, $\color{#AAA}{\textsf{Options}}$)
* AwtApprovals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/awt/AwtApprovals.java#L52-L55) (Component, $\color{#AAA}{\textsf{Options}}$)
* AwtApprovals. [verify ](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java/org/approvaltests/awt/AwtApprovals.java#L36-L39) (Image, $\color{#AAA}{\textsf{Options}}$)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ public static void org.approvaltests.Approvals.verifyJson(java.lang.String)
public static void org.approvaltests.Approvals.verifyJson(java.lang.String,org.approvaltests.core.Options)
public static void org.approvaltests.Approvals.verifyXml(java.lang.String)
public static void org.approvaltests.Approvals.verifyXml(java.lang.String,org.approvaltests.core.Options)
public static void org.approvaltests.Approvals.verifyXml(java.lang.String,org.lambda.functions.Function1)
public static void org.approvaltests.Approvals.verifyXml(java.lang.String,org.lambda.functions.Function1,org.approvaltests.core.Options)
17 changes: 15 additions & 2 deletions approvaltests/src/main/java/org/approvaltests/Approvals.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
import com.spun.util.persistence.SqlLoader;
import org.approvaltests.approvers.ApprovalApprover;
import org.approvaltests.approvers.FileApprover;
import org.approvaltests.core.*;
import org.approvaltests.core.ApprovalFailureReporter;
import org.approvaltests.core.ApprovalWriter;
import org.approvaltests.core.Options;
import org.approvaltests.core.Verifiable;
import org.approvaltests.core.VerifyParameters;
import org.approvaltests.core.VerifyResult;
import org.approvaltests.namer.ApprovalNamer;
import org.approvaltests.namer.MasterDirectoryNamer;
import org.approvaltests.namer.NamerFactoryForOptions;
Expand Down Expand Up @@ -196,7 +201,15 @@ public static void verifyXml(String xml)
}
public static void verifyXml(String xml, Options options)
{
final String formattedXml = ApprovalXmlWriter.prettyPrint(xml, 2);
verifyXml(xml, x -> ApprovalXmlWriter.prettyPrint(x, 2), options);
}
public static void verifyXml(String xml, Function1<String, String> prettyPrinter)
{
verifyXml(xml, prettyPrinter, new Options());
}
public static void verifyXml(String xml, Function1<String, String> prettyPrinter, Options options)
{
String formattedXml = prettyPrinter.call(xml);
verify(formattedXml, options.forFile().withExtension(".xml"));
}
public static void verify(ApprovalApprover approver)
Expand Down

0 comments on commit aa8d2c3

Please sign in to comment.