Skip to content

Commit

Permalink
. d Verify documentation links to call with Options
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottBob committed Jan 25, 2024
1 parent 3d8fb62 commit 95250bc
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,48 @@
import com.spun.util.StringUtils;
import org.approvaltests.core.Options;
import org.junit.jupiter.api.Test;
import org.lambda.functions.Function1;
import org.lambda.query.Query;
import org.lambda.query.Queryable;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Parameter;
import java.util.List;

public class DocumentHelpersTest
{
public class DocumentHelpersTest {
@Test
void listAllVerifyFunctions()
{
void listAllVerifyFunctions() {
Queryable<Method> methods = getAllVerifyFunctionsWithOptions(OptionsTest.getApprovalClasses());
Queryable<String> lines = methods.select(m -> String.format("%s. [%s ](%s) (%s)",
m.getDeclaringClass().getSimpleName(), m.getName(), getLink(m), showParameters(m)))
.orderBy(s -> s.replaceAll("#L\\d+-L\\d+", ""));
m.getDeclaringClass().getSimpleName(), m.getName(), getLink(m), showParametersExceptOptions(m)))
.orderBy(s -> s.replaceAll("#L\\d+-L\\d+", ""));
Approvals.verifyAll("", lines, l -> String.format(" * %s ", l), new Options().forFile().withExtension(".md"));
}

@Test
void testLineNumbers()
{
void testLineNumbers() {
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#L98-L101
""";
String verifyAll = getLink(Query.first(Approvals.class.getMethods(),
m -> m.getName().equals("verifyAll") && m.getParameterTypes()[0].equals(Object[].class)));
Approvals.verify(verifyAll, new Options().inline(expected));
}
public static String showParameters(Method m)

public static String showParameters(Method m) {
return showParametersExcept(m, p -> true);
}
public static String showParametersExceptOptions(Method m)
{
return StringUtils.join(Query.select(m.getParameters(), p -> String.format("%s", p.getType().getSimpleName())),
",");
return showParametersExcept(m, p -> !p.getType().getSimpleName().equals("Options"));
}

private static String showParametersExcept(Method m, Function1<Parameter, Boolean> filter) {
Queryable<Parameter> withoutOptions = Query.where(m.getParameters(), filter);
return StringUtils.join(withoutOptions.select(p -> String.format("%s", p.getType().getSimpleName())), ",");
}

public static String getLink(Method m)
{
String baseUrl = "https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/src/main/java";
Expand All @@ -55,7 +64,7 @@ private Queryable<Method> getAllVerifyFunctionsWithOptions(List<Class<?>> approv
Queryable<Method> declaredMethods = Queryable.as(c.getDeclaredMethods());
Queryable<Method> methodList = declaredMethods.where(m -> m.getName().startsWith("verify")
&& Modifier.isPublic(m.getModifiers()) && !m.isAnnotationPresent(Deprecated.class));
List<Method> methodsWithOptions = methodList.where(m -> !OptionsTest.isOptionsPresent(m));
List<Method> methodsWithOptions = methodList.where(m -> OptionsTest.isOptionsPresent(m));
methods.addAll(methodsWithOptions);
}
return methods;
Expand Down
Loading

0 comments on commit 95250bc

Please sign in to comment.