Skip to content

Commit

Permalink
improve and fix spectest to document formats
Browse files Browse the repository at this point in the history
  • Loading branch information
jshook committed Jun 28, 2022
1 parent 334fb54 commit 3d20611
Show file tree
Hide file tree
Showing 30 changed files with 643 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.nosqlbench.nb.spectest.types;
package io.nosqlbench.nb.spectest.api;

import io.nosqlbench.nb.spectest.core.STNodeAssembly;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
* limitations under the License.
*/

package io.nosqlbench.nb.spectest.types;
package io.nosqlbench.nb.spectest.api;

import com.vladsch.flexmark.util.ast.Node;
import io.nosqlbench.nb.spectest.core.SpecTest;
import io.nosqlbench.nb.spectest.core.STBuilder;
import io.nosqlbench.nb.spectest.loaders.STNodePredicate;
import io.nosqlbench.nb.spectest.loaders.STNodePredicates;
import io.nosqlbench.nb.spectest.traversal.STNodePredicate;
import io.nosqlbench.nb.spectest.traversal.STNodePredicates;

import java.nio.file.Path;

public interface STBuilderFacets {

interface All extends WantsPaths, WantsPathsOrScannersOrValidators, WantsScannersOrValidators {}
interface All extends WantsPaths, WantsPathsOrScannersOrValidators, WantsScannersOrValidators, WantsDebuggingOptions {}

interface WantsPaths {
/**
Expand Down Expand Up @@ -94,18 +94,24 @@ interface WantsScannersOrValidators extends WantsValidatorsOrDone {
* is resumed on the next element not included in the result.</P>
*
* <P>The predicates can be one of the types supported by {@link STNodePredicate}
* and {@link STNodePredicates}.</P>
* and {@link STNodePredicates}. These can be wrapped in structural predicate form
* by using the helpers from {@link io.nosqlbench.nb.spectest.traversal.STPredicateVerbs},
* particularly with an import like
* <pre>{@code import static io.nosqlbench.nb.spectest.traversal.STPredicateVerbs.*;}</pre></P>
*
* @param predicates The pattern to match
* @return this SpecTestBuilder for builder method chaining
*/
WantsValidatorsOrDone matchNodes(Object... predicates);
}

interface WantsValidatorsOrDone extends Done{
Done validators(STAssemblyValidator... validators);
interface WantsValidatorsOrDone extends WantsDebuggingOptions {
WantsDebuggingOptions validators(STAssemblyValidator... validators);
}

interface WantsDebuggingOptions extends Done {
Done debug();
}
interface Done {
SpecTest build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.nosqlbench.nb.spectest.types;
package io.nosqlbench.nb.spectest.api;

import com.vladsch.flexmark.util.ast.Node;
import io.nosqlbench.nb.spectest.core.STNodeAssembly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package io.nosqlbench.nb.spectest.types;
package io.nosqlbench.nb.spectest.api;

import io.nosqlbench.nb.spectest.core.STNodeAssembly;
import io.nosqlbench.nb.spectest.loaders.STNodePredicates;
import io.nosqlbench.nb.spectest.traversal.STNodePredicates;

import java.nio.file.Path;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.nosqlbench.nb.spectest.types;
package io.nosqlbench.nb.spectest.api;

import io.nosqlbench.nb.spectest.core.STNodeAssembly;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package io.nosqlbench.nb.spectest.core;

import io.nosqlbench.nb.spectest.loaders.STDefaultLoader;
import io.nosqlbench.nb.spectest.loaders.STNodePredicate;
import io.nosqlbench.nb.spectest.types.STAssemblyValidator;
import io.nosqlbench.nb.spectest.types.STBuilderFacets;
import io.nosqlbench.nb.spectest.types.STPathLoader;
import io.nosqlbench.nb.spectest.traversal.STNodePredicate;
import io.nosqlbench.nb.spectest.api.STAssemblyValidator;
import io.nosqlbench.nb.spectest.api.STBuilderFacets;
import io.nosqlbench.nb.spectest.api.STPathLoader;

import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -32,6 +32,7 @@ public abstract class STBuilder implements STBuilderFacets.All {
protected List<Path> paths = new ArrayList<>();
protected List<STPathLoader> scanners = new ArrayList<>();
protected List<STAssemblyValidator> validators = new ArrayList<>();
protected boolean debug;

@Override
public STBuilderFacets.WantsPathsOrScannersOrValidators paths(Path... paths) {
Expand All @@ -56,9 +57,14 @@ public STBuilderFacets.WantsValidatorsOrDone matchNodes(Object... predicates) {
}

@Override
public STBuilderFacets.Done validators(STAssemblyValidator... validators) {
public STBuilderFacets.WantsDebuggingOptions validators(STAssemblyValidator... validators) {
this.validators.addAll(Arrays.asList(validators));
return this;
}

@Override
public STBuilderFacets.Done debug() {
this.debug=true;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2022 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.nosqlbench.nb.spectest.core;

public interface STDebug {
void applyDebugging(boolean enabled);
static void applyDebugging(boolean enabled, Object maybeDebuggable) {
if (maybeDebuggable instanceof STDebug d) {
d.applyDebugging(enabled);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,24 @@

package io.nosqlbench.nb.spectest.core;

import io.nosqlbench.nb.spectest.testtypes.STNodeReference;
import io.nosqlbench.nb.spectest.testmodels.STNodeReference;

import java.nio.file.Path;

public class STNameAndCodeTuple implements STNodeReference {

private final STNode nameNode;
private final STNode dataNode;
public STNameAndCodeTuple(STNode nameNode, STNode dataNode) {
this.nameNode = nameNode;
this.dataNode = dataNode;
}
public record STNameAndCodeTuple(
STNode nameNode,
STNode dataNode
) implements STNodeReference {

public String getDesc() {
return nameNode.getDesc();
}

public String getName() {
return nameNode.text.toString();
return nameNode.getText();
}

public String getData() {
return dataNode.text.toString();
return dataNode.getText();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ public final class STNode {
private final Path path;
private final int line;
private final Node refnode;
public CharSequence info;
public CharSequence text;
private final CharSequence text;

public STNode(Supplier<CharSequence> desc, Node dataNode, Path path) {
this.description = desc.get().toString();
this.text = dataNode.getFirstChild().getChars();
this.line = dataNode.getFirstChild().getLineNumber();
if (dataNode.getFirstChild()!=null) {
this.text = dataNode.getFirstChild().getChars();
this.line = dataNode.getFirstChild().getLineNumber();
} else {
this.text = "";
this.line = dataNode.getLineNumber();
}
this.path = path;
this.refnode = dataNode;
}
Expand Down Expand Up @@ -96,7 +100,6 @@ public boolean equals(Object o) {
if (!Objects.equals(description, that.description)) return false;
if (!Objects.equals(path, that.path)) return false;
if (!Objects.equals(refnode, that.refnode)) return false;
if (!Objects.equals(info, that.info)) return false;
return Objects.equals(text, that.text);
}

Expand All @@ -106,8 +109,11 @@ public int hashCode() {
result = 31 * result + (path != null ? path.hashCode() : 0);
result = 31 * result + line;
result = 31 * result + (refnode != null ? refnode.hashCode() : 0);
result = 31 * result + (info != null ? info.hashCode() : 0);
result = 31 * result + (text != null ? text.hashCode() : 0);
return result;
}

public String getText() {
return text.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.nosqlbench.nb.spectest.core;

import com.vladsch.flexmark.util.ast.Node;
import io.nosqlbench.nb.spectest.testtypes.STNamedCodeTuples;
import io.nosqlbench.nb.spectest.testmodels.STNamedCodeTuples;

import java.nio.file.Path;
import java.security.InvalidParameterException;
Expand Down Expand Up @@ -75,7 +75,7 @@ public String getDescription() {

public String getAsText(int index) {
assertRange(index);
return get(index).text.toString();
return get(index).getText();
}

public Path getPath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.vladsch.flexmark.ext.yaml.front.matter.YamlFrontMatterExtension;
import com.vladsch.flexmark.parser.Parser;
import io.nosqlbench.nb.spectest.loaders.STFileScanner;
import io.nosqlbench.nb.spectest.types.STAssemblyValidator;
import io.nosqlbench.nb.spectest.types.STBuilderFacets;
import io.nosqlbench.nb.spectest.types.STPathLoader;
import io.nosqlbench.nb.spectest.api.STAssemblyValidator;
import io.nosqlbench.nb.spectest.api.STBuilderFacets;
import io.nosqlbench.nb.spectest.api.STPathLoader;

import java.nio.file.Path;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -73,11 +73,17 @@ public class SpecTest implements Runnable {
private final List<Path> paths;
private final List<STPathLoader> pathLoaders;
private final List<STAssemblyValidator> validators;
private final boolean debug;

private SpecTest(List<Path> paths, List<STPathLoader> pathLoaders, List<STAssemblyValidator> validators) {
private SpecTest(List<Path> paths, List<STPathLoader> pathLoaders, List<STAssemblyValidator> validators, boolean debug) {
this.paths = paths;
this.pathLoaders = pathLoaders;
this.validators = validators;
this.debug = debug;
if (debug) {
pathLoaders.forEach(p -> STDebug.applyDebugging(debug,p));
validators.forEach(p -> STDebug.applyDebugging(debug,p));
}
}

@Override
Expand All @@ -99,7 +105,6 @@ public void run() {
testables.add(assembly);
}
}

}
}

Expand All @@ -117,7 +122,7 @@ public static STBuilderFacets.WantsPaths builder() {
private static class Builder extends STBuilder {
@Override
public SpecTest build() {
return new SpecTest(paths,scanners,validators);
return new SpecTest(paths,scanners,validators,debug);
}
}
}
Loading

0 comments on commit 3d20611

Please sign in to comment.