project renamed to wson

This commit is contained in:
2021-01-13 08:47:02 +01:00
parent f96ab24ad7
commit 6422a91568
71 changed files with 462 additions and 494 deletions

18
antlr/build.sbt Normal file
View File

@@ -0,0 +1,18 @@
organization := (organization in LocalRootProject).value
name := "worth-antlr"
version := (version in LocalRootProject).value
resourceDirectory := (resourceDirectory in(LocalRootProject, Test)).value
antlr4Version in Antlr4 := Versions.antlr
antlr4PackageName in Antlr4 := Some("net.woggioni.worth.antlr")
skip in publish := true
libraryDependencies += "org.projectlombok" % "lombok" % Versions.lombok % Provided
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % Versions.jackson % Test
libraryDependencies += "org.tukaani" % "xz" % Versions.xz % Test
libraryDependencies += "org.antlr" % "antlr4" % Versions.antlr % Test
libraryDependencies += "org.antlr" % "antlr4-runtime" % Versions.antlr % Test
libraryDependencies += "net.aichler" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test
libraryDependencies += "org.junit.jupiter" % "junit-jupiter-params" % JupiterKeys.junitJupiterVersion.value % Test
enablePlugins(JupiterPlugin)

View File

@@ -1,7 +1,7 @@
package net.woggioni.worth.antlr;
package net.woggioni.wson.antlr;
import net.woggioni.worth.serialization.ValueParser;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.serialization.ValueParser;
import net.woggioni.wson.xface.Value;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;

View File

@@ -1,25 +1,25 @@
package net.woggioni.worth.antlr;
package net.woggioni.wson.antlr;
import lombok.SneakyThrows;
import net.woggioni.worth.serialization.JsonBombTest;
import net.woggioni.worth.serialization.json.JSONDumper;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.serialization.json.JSONDumper;
import net.woggioni.wson.xface.Value;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CodePointCharStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.InputStreamReader;
import static net.woggioni.worth.serialization.JsonBombTest.infiniteJson;
import static net.woggioni.wson.test.JsonBomb.infiniteJson;
public class ParseTest {
@Test
@SneakyThrows
public void test(){
public void test() {
CodePointCharStream inputStream = CharStreams.fromReader(new InputStreamReader(getClass().getResourceAsStream("/test.json")));
JSONLexer lexer = new JSONLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
@@ -31,13 +31,14 @@ public class ParseTest {
new JSONDumper().dump(result, System.out);
}
@Test(expected = OutOfMemoryError.class)
@Test
@Disabled
@SneakyThrows
public void antlr() {
CharStream inputStream = CharStreams.fromReader(new InputStreamReader(infiniteJson()));
JSONLexer lexer = new JSONLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
net.woggioni.worth.antlr.JSONParser parser = new net.woggioni.worth.antlr.JSONParser(commonTokenStream);
net.woggioni.wson.antlr.JSONParser parser = new net.woggioni.wson.antlr.JSONParser(commonTokenStream);
JSONListenerImpl listener = new JSONListenerImpl();
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(listener, parser.json());

View File

@@ -1,23 +1,23 @@
package net.woggioni.worth.serialization.json;
package net.woggioni.wson.serialization.json;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import net.woggioni.jwo.Chronometer;
import net.woggioni.worth.antlr.JSONLexer;
import net.woggioni.worth.antlr.JSONListenerImpl;
import net.woggioni.worth.serialization.binary.JBONDumper;
import net.woggioni.worth.serialization.binary.JBONParser;
import net.woggioni.worth.value.ObjectValue;
import net.woggioni.worth.xface.Dumper;
import net.woggioni.worth.xface.Parser;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.antlr.JSONLexer;
import net.woggioni.wson.antlr.JSONListenerImpl;
import net.woggioni.wson.serialization.binary.JBONDumper;
import net.woggioni.wson.serialization.binary.JBONParser;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.xface.Dumper;
import net.woggioni.wson.xface.Parser;
import net.woggioni.wson.xface.Value;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.tukaani.xz.XZInputStream;
import java.io.BufferedInputStream;
@@ -44,7 +44,7 @@ public class PerformanceTest {
}
@Test
@Ignore
@Disabled
@SneakyThrows
public void profilerTest() {
while (true) {
@@ -86,7 +86,7 @@ public class PerformanceTest {
CharStream inputStream = CharStreams.fromReader(new InputStreamReader(smallTestData()));
JSONLexer lexer = new JSONLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
net.woggioni.worth.antlr.JSONParser parser = new net.woggioni.worth.antlr.JSONParser(commonTokenStream);
net.woggioni.wson.antlr.JSONParser parser = new net.woggioni.wson.antlr.JSONParser(commonTokenStream);
JSONListenerImpl listener = new JSONListenerImpl();
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(listener, parser.json());
@@ -98,7 +98,7 @@ public class PerformanceTest {
}
@Test
@Ignore
@Disabled
@SneakyThrows
public void hugeJSONTest() {
double jacksonTime, worthTime, antlrTime;
@@ -132,7 +132,7 @@ public class PerformanceTest {
CharStream inputStream = CharStreams.fromReader(new InputStreamReader(is));
JSONLexer lexer = new JSONLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
net.woggioni.worth.antlr.JSONParser parser = new net.woggioni.worth.antlr.JSONParser(commonTokenStream);
net.woggioni.wson.antlr.JSONParser parser = new net.woggioni.wson.antlr.JSONParser(commonTokenStream);
JSONListenerImpl listener = new JSONListenerImpl();
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(listener, parser.json());
@@ -142,9 +142,9 @@ public class PerformanceTest {
}
@Test
@Ignore
@Disabled
@SneakyThrows
public void tess() {
public void test() {
Value value;
try(InputStream is = extractTestData()) {
Parser parser = JSONParser.newInstance();

13
benchmark/build.sbt Normal file
View File

@@ -0,0 +1,13 @@
organization := (organization in LocalRootProject).value
name := "worth-benchmark"
version := (version in LocalRootProject).value
resourceDirectory in Compile := (resourceDirectory in(LocalRootProject, Test)).value
skip in publish := true
maintainer := "oggioni.walter@gmail.com"
mainClass := Some("net.woggioni.worth.benchmark.Main")
javaOptions in Universal += "-J-Xmx4G"
fork := true
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % Versions.jackson
libraryDependencies += "org.tukaani" % "xz" % Versions.xz
libraryDependencies += "com.beust" % "jcommander" % Versions.jcommander
libraryDependencies += "org.projectlombok" % "lombok" % Versions.lombok % Provided

View File

@@ -1,15 +1,15 @@
package net.woggioni.worth.benchmark;
package net.woggioni.wson.benchmark;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import net.woggioni.worth.antlr.JSONLexer;
import net.woggioni.worth.antlr.JSONListenerImpl;
import net.woggioni.worth.serialization.binary.JBONParser;
import net.woggioni.worth.serialization.json.JSONParser;
import net.woggioni.wson.antlr.JSONLexer;
import net.woggioni.wson.antlr.JSONListenerImpl;
import net.woggioni.wson.serialization.binary.JBONParser;
import net.woggioni.wson.serialization.json.JSONParser;
import net.woggioni.jwo.Chronometer;
import net.woggioni.worth.value.ObjectValue;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.xface.Value;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
@@ -77,7 +77,7 @@ public class Main {
CharStream inputStream = CharStreams.fromReader(new InputStreamReader(smallTestData()));
JSONLexer lexer = new JSONLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
net.woggioni.worth.antlr.JSONParser parser = new net.woggioni.worth.antlr.JSONParser(commonTokenStream);
net.woggioni.wson.antlr.JSONParser parser = new net.woggioni.wson.antlr.JSONParser(commonTokenStream);
JSONListenerImpl listener = new JSONListenerImpl();
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(listener, parser.json());
@@ -136,7 +136,7 @@ public class Main {
CharStream inputStream = CharStreams.fromReader(new InputStreamReader(is));
JSONLexer lexer = new JSONLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
net.woggioni.worth.antlr.JSONParser parser = new net.woggioni.worth.antlr.JSONParser(commonTokenStream);
net.woggioni.wson.antlr.JSONParser parser = new net.woggioni.wson.antlr.JSONParser(commonTokenStream);
JSONListenerImpl listener = new JSONListenerImpl();
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(listener, parser.json());

View File

@@ -1,4 +1,6 @@
name := "worth"
import sbt.Keys.libraryDependencies
name := "wson"
organization := "net.woggioni"
@@ -22,67 +24,43 @@ scalacOptions ++= Seq(
git.useGitDescribe := true
//javaOptions in Test += "-Xmx14G"
javacOptions in (Compile, compile) ++= Seq("-target", "8", "-source", "8")
javacOptions in (Compile, compile) ++= Seq("--release", "8")
//scalafmtOnCompile := true
libraryDependencies += "org.projectlombok" % "lombok" % "1.18.8" % Provided
libraryDependencies += "org.projectlombok" % "lombok" % Versions.lombok % Provided
libraryDependencies += "net.woggioni" % "jwo" % "1.0" % Compile
Compile / packageBin / packageOptions +=
Package.ManifestAttributes("Automatic-Module-Name" -> "net.woggioni.worth")
Package.ManifestAttributes("Automatic-Module-Name" -> "net.woggioni.wson")
libraryDependencies += "net.aichler" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test
libraryDependencies += "org.junit.jupiter" % "junit-jupiter-params" % JupiterKeys.junitJupiterVersion.value % Test
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % Versions.jackson % Test
libraryDependencies += "org.tukaani" % "xz" % Versions.xz % Test
val testDependencies = Seq("com.novocode" % "junit-interface" % "0.11" % Test,
"com.fasterxml.jackson.core" % "jackson-databind" % "2.9.6" % Test,
"org.tukaani" % "xz" % "1.8" % Test)
libraryDependencies ++= testDependencies
testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-a")
enablePlugins(Delombok)
enablePlugins(DelombokJavadoc)
enablePlugins(JupiterPlugin)
val antlrVersion = "4.7.2"
lazy val worthAntlr = (project in file("antlr")).settings(
organization := (organization in LocalRootProject).value,
name := "worth-antlr",
version := (version in LocalRootProject).value,
resourceDirectory := (resourceDirectory in(LocalRootProject, Test)).value,
antlr4Version in Antlr4 := antlrVersion,
antlr4PackageName in Antlr4 := Some("net.woggioni.worth.antlr"),
skip in publish := true,
unmanagedClasspath in Test += (classDirectory in (LocalRootProject, Test)).value,
unmanagedClasspath in Runtime += (resourceDirectory in (LocalRootProject, Test)).value,
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % "2.9.6" % Test,
libraryDependencies += "org.tukaani" % "xz" % "1.8" % Test,
libraryDependencies += "org.antlr" % "antlr4" % antlrVersion % Test,
libraryDependencies += "org.antlr" % "antlr4-runtime" % antlrVersion % Test,
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test,
libraryDependencies += "org.projectlombok" % "lombok" % "1.18.8" % Provided,
).dependsOn(LocalRootProject).enablePlugins(Antlr4Plugin)
testOptions += Tests.Argument(jupiterTestFramework, "-q", "-a")
lazy val cli = (project in file("cli")).settings(
organization := (organization in LocalRootProject).value,
name := "worth-cli",
version := (version in LocalRootProject).value,
resourceDirectory := (resourceDirectory in(LocalRootProject, Test)).value,
skip in publish := true,
mainClass := Some("net.woggioni.worth.cli.Main"),
maintainer := "oggioni.walter@gmail.com",
unmanagedClasspath in Test += (classDirectory in (LocalRootProject, Test)).value,
libraryDependencies += "com.beust" % "jcommander" % "1.72"
).dependsOn(LocalRootProject).enablePlugins(JavaAppPackaging).enablePlugins(UniversalPlugin)
lazy val testUtils = (project in file("test-utils"))
lazy val benchmark = (project in file("benchmark")).settings(
organization := (organization in LocalRootProject).value,
name := "worth-benchmark",
version := (version in LocalRootProject).value,
resourceDirectory in Compile := (resourceDirectory in(LocalRootProject, Test)).value,
skip in publish := true,
maintainer := "oggioni.walter@gmail.com",
mainClass := Some("net.woggioni.worth.benchmark.Main"),
javaOptions in Universal += "-J-Xmx4G",
fork := true,
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % "2.9.6",
libraryDependencies += "org.tukaani" % "xz" % "1.8",
libraryDependencies += "com.beust" % "jcommander" % "1.72",
libraryDependencies += "org.projectlombok" % "lombok" % "1.18.8" % Provided
).dependsOn(LocalRootProject)
.dependsOn(worthAntlr)
.enablePlugins(JavaAppPackaging)
.enablePlugins(UniversalPlugin)
dependsOn(testUtils % "test")
lazy val worthAntlr = (project in file("antlr"))
.dependsOn(LocalRootProject)
.dependsOn(testUtils % "test")
.enablePlugins(Antlr4Plugin)
lazy val cli = (project in file("cli"))
.dependsOn(LocalRootProject)
.enablePlugins(JavaAppPackaging)
.enablePlugins(UniversalPlugin)
.enablePlugins(JlinkPlugin)
lazy val benchmark = (project in file("benchmark"))
.dependsOn(LocalRootProject)
.dependsOn(worthAntlr)
.dependsOn(testUtils)
.enablePlugins(JavaAppPackaging)
.enablePlugins(UniversalPlugin)

8
cli/build.sbt Normal file
View File

@@ -0,0 +1,8 @@
organization := (organization in LocalRootProject).value
name := "worth-cli"
version := (version in LocalRootProject).value
resourceDirectory := (resourceDirectory in(LocalRootProject, Test)).value
skip in publish := true
mainClass := Some("net.woggioni.worth.cli.Main")
maintainer := "oggioni.walter@gmail.com"
libraryDependencies += "com.beust" % "jcommander" % Versions.jcommander

View File

@@ -1,11 +1,11 @@
package net.woggioni.worth.cli
package net.woggioni.wson.cli
import java.io._
import com.beust.jcommander.{IStringConverter, JCommander, Parameter, ParameterException}
import net.woggioni.worth.serialization.binary.{JBONDumper, JBONParser}
import net.woggioni.worth.serialization.json.{JSONDumper, JSONParser}
import net.woggioni.worth.xface.Value
import net.woggioni.wson.serialization.binary.{JBONDumper, JBONParser}
import net.woggioni.wson.serialization.json.{JSONDumper, JSONParser}
import net.woggioni.wson.xface.Value
sealed abstract class SerializationFormat(val name : String) {
override def toString = name

View File

@@ -1 +1 @@
sbt.version=1.3.9
sbt.version=1.4.1

11
project/build.scala Normal file
View File

@@ -0,0 +1,11 @@
object Versions {
val slf4j = "1.7.30"
val log4j = "2.13.2"
val lombok = "1.18.16"
val junitJupiter = "5.6.2"
val junitPlatform = "1.6.2"
val jackson = "2.11.3"
val jcommander = "1.78"
val antlr = "4.7.2"
val xz = "1.8"
}

View File

@@ -6,5 +6,7 @@ addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "4.1.0")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.6")
addSbtPlugin("com.simplytyped" % "sbt-antlr4" % "0.8.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.6")
addSbtPlugin("com.simplytyped" % "sbt-antlr4" % "0.8.1")
addSbtPlugin("net.aichler" % "sbt-jupiter-interface" % "0.8.4-SNAPSHOT")
addSbtPlugin("com.thoughtworks.sbt" % "delombokjavadoc" % "1.0.0+66-8fbcf18c")

View File

@@ -1,38 +0,0 @@
package net.woggioni.worth.buffer;
import lombok.SneakyThrows;
import java.io.Reader;
public class CircularBuffer {
private int[] buffer;
private Reader reader;
private int delta = 0, cursor = 0;
public CircularBuffer(Reader reader, int size) {
this.reader = reader;
buffer = new int[size];
}
@SneakyThrows
public int next() {
if (delta < 0)
return buffer[Math.floorMod(cursor + delta++, buffer.length)];
else {
int result = reader.read();
if (result < 0) return result;
buffer[cursor] = result;
cursor = (cursor + 1) % buffer.length;
return result;
}
}
public int prev() {
return buffer[cursor + --delta >= 0 ? cursor + delta : cursor + delta + buffer.length];
}
public int size() {
return buffer.length;
}
}

View File

@@ -1,7 +0,0 @@
package net.woggioni.worth.exception;
public class IOException extends WorthException {
public IOException(String msg) {
super(msg);
}
}

View File

@@ -1,7 +0,0 @@
package net.woggioni.worth.exception;
public class MaxDepthExceededException extends WorthException {
public MaxDepthExceededException(String msg) {
super(msg);
}
}

View File

@@ -1,7 +0,0 @@
package net.woggioni.worth.exception;
public class NotImplementedException extends WorthException {
public NotImplementedException(String msg) {
super(msg);
}
}

View File

@@ -1,7 +0,0 @@
package net.woggioni.worth.exception;
public class ParseException extends WorthException {
public ParseException(String msg) {
super(msg);
}
}

View File

@@ -1,7 +0,0 @@
package net.woggioni.worth.exception;
public class TypeException extends WorthException {
public TypeException(String msg) {
super(msg);
}
}

View File

@@ -1,7 +0,0 @@
package net.woggioni.worth.exception;
public class WorthException extends RuntimeException {
public WorthException(String msg) {
super(msg);
}
}

View File

@@ -1,49 +0,0 @@
package net.woggioni.worth.utils;
import lombok.SneakyThrows;
import net.woggioni.worth.xface.Value;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
public class WorthUtils {
public static Optional<Value> nested(Value root, String... keys) {
Value result = root;
for (String key : keys) {
result = result.get(key);
if (result == null) {
break;
}
}
return Optional.ofNullable(result);
}
public static Value getOrNull(Value root, String... keys) {
Value result = root;
for (String key : keys) {
result = result.get(key);
if (result == null) {
result = Value.Null;
break;
}
}
return result;
}
public static <T> T getOrNull(Value root, Function<Value, T> callback, String... keys) {
Value result = getOrNull(root, keys);
return result.type() == Value.Type.NULL ? null : callback.apply(result);
}
@SneakyThrows
public static <T> T getOrThrow(Value root, Function<Value, T> success, Supplier<Throwable> error, String... keys) {
Value result = getOrNull(root, keys);
if (result.type() == Value.Type.NULL) {
throw error.get();
} else {
return success.apply(result);
}
}
}

View File

@@ -1,4 +1,4 @@
package net.woggioni.worth.buffer;
package net.woggioni.wson.buffer;
import lombok.SneakyThrows;

View File

@@ -1,4 +1,4 @@
package net.woggioni.worth.buffer;
package net.woggioni.wson.buffer;
import lombok.SneakyThrows;

View File

@@ -0,0 +1,7 @@
package net.woggioni.wson.exception;
public class IOException extends WsonException {
public IOException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,7 @@
package net.woggioni.wson.exception;
public class MaxDepthExceededException extends WsonException {
public MaxDepthExceededException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,7 @@
package net.woggioni.wson.exception;
public class NotImplementedException extends WsonException {
public NotImplementedException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,7 @@
package net.woggioni.wson.exception;
public class ParseException extends WsonException {
public ParseException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,7 @@
package net.woggioni.wson.exception;
public class TypeException extends WsonException {
public TypeException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,7 @@
package net.woggioni.wson.exception;
public class WsonException extends RuntimeException {
public WsonException(String msg) {
super(msg);
}
}

View File

@@ -1,13 +1,13 @@
package net.woggioni.worth.serialization;
package net.woggioni.wson.serialization;
import lombok.RequiredArgsConstructor;
import net.woggioni.worth.exception.NotImplementedException;
import net.woggioni.worth.traversal.TraversalContext;
import net.woggioni.worth.traversal.ValueIdentity;
import net.woggioni.worth.traversal.ValueVisitor;
import net.woggioni.worth.traversal.ValueWalker;
import net.woggioni.worth.xface.Dumper;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.exception.NotImplementedException;
import net.woggioni.wson.traversal.TraversalContext;
import net.woggioni.wson.traversal.ValueIdentity;
import net.woggioni.wson.traversal.ValueVisitor;
import net.woggioni.wson.traversal.ValueWalker;
import net.woggioni.wson.xface.Dumper;
import net.woggioni.wson.xface.Value;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

View File

@@ -1,17 +1,17 @@
package net.woggioni.worth.serialization;
package net.woggioni.wson.serialization;
import lombok.RequiredArgsConstructor;
import net.woggioni.worth.exception.MaxDepthExceededException;
import net.woggioni.worth.exception.NotImplementedException;
import net.woggioni.worth.exception.ParseException;
import net.woggioni.worth.value.ArrayValue;
import net.woggioni.worth.value.BooleanValue;
import net.woggioni.worth.value.FloatValue;
import net.woggioni.worth.value.IntegerValue;
import net.woggioni.worth.value.ObjectValue;
import net.woggioni.worth.value.StringValue;
import net.woggioni.worth.xface.Parser;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.exception.MaxDepthExceededException;
import net.woggioni.wson.exception.NotImplementedException;
import net.woggioni.wson.exception.ParseException;
import net.woggioni.wson.value.ArrayValue;
import net.woggioni.wson.value.BooleanValue;
import net.woggioni.wson.value.FloatValue;
import net.woggioni.wson.value.IntegerValue;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.value.StringValue;
import net.woggioni.wson.xface.Parser;
import net.woggioni.wson.xface.Value;
import java.io.InputStream;
import java.io.InputStreamReader;

View File

@@ -1,4 +1,4 @@
package net.woggioni.worth.serialization.binary;
package net.woggioni.wson.serialization.binary;
public enum BinaryMarker {
Float(0x0),

View File

@@ -1,14 +1,14 @@
package net.woggioni.worth.serialization.binary;
package net.woggioni.wson.serialization.binary;
import lombok.SneakyThrows;
import net.woggioni.jwo.Leb128;
import net.woggioni.worth.exception.NotImplementedException;
import net.woggioni.worth.serialization.ValueDumper;
import net.woggioni.worth.traversal.ValueIdentity;
import net.woggioni.worth.value.ArrayValue;
import net.woggioni.worth.value.ObjectValue;
import net.woggioni.worth.xface.Dumper;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.exception.NotImplementedException;
import net.woggioni.wson.serialization.ValueDumper;
import net.woggioni.wson.traversal.ValueIdentity;
import net.woggioni.wson.value.ArrayValue;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.xface.Dumper;
import net.woggioni.wson.xface.Value;
import java.io.OutputStream;
import java.io.Writer;

View File

@@ -1,12 +1,12 @@
package net.woggioni.worth.serialization.binary;
package net.woggioni.wson.serialization.binary;
import lombok.SneakyThrows;
import net.woggioni.jwo.Leb128;
import net.woggioni.worth.buffer.LookAheadInputStream;
import net.woggioni.worth.exception.ParseException;
import net.woggioni.worth.serialization.ValueParser;
import net.woggioni.worth.xface.Parser;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.buffer.LookAheadInputStream;
import net.woggioni.wson.exception.ParseException;
import net.woggioni.wson.serialization.ValueParser;
import net.woggioni.wson.xface.Parser;
import net.woggioni.wson.xface.Value;
import java.io.InputStream;
import java.util.function.Function;

View File

@@ -1,12 +1,10 @@
package net.woggioni.worth.serialization.json;
package net.woggioni.wson.serialization.json;
import lombok.SneakyThrows;
import net.woggioni.worth.serialization.ValueDumper;
import net.woggioni.worth.traversal.ValueIdentity;
import net.woggioni.worth.utils.WorthUtils;
import net.woggioni.worth.value.*;
import net.woggioni.worth.xface.Dumper;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.serialization.ValueDumper;
import net.woggioni.wson.traversal.ValueIdentity;
import net.woggioni.wson.xface.Dumper;
import net.woggioni.wson.xface.Value;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
@@ -15,8 +13,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
public class JSONDumper extends ValueDumper {

View File

@@ -1,14 +1,13 @@
package net.woggioni.worth.serialization.json;
package net.woggioni.wson.serialization.json;
import lombok.SneakyThrows;
import net.woggioni.worth.buffer.LookAheadTextInputStream;
import net.woggioni.worth.exception.IOException;
import net.woggioni.worth.exception.NotImplementedException;
import net.woggioni.worth.exception.ParseException;
import net.woggioni.worth.serialization.ValueParser;
import net.woggioni.worth.utils.WorthUtils;
import net.woggioni.worth.xface.Parser;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.buffer.LookAheadTextInputStream;
import net.woggioni.wson.exception.IOException;
import net.woggioni.wson.exception.NotImplementedException;
import net.woggioni.wson.exception.ParseException;
import net.woggioni.wson.serialization.ValueParser;
import net.woggioni.wson.xface.Parser;
import net.woggioni.wson.xface.Value;
import java.io.InputStream;
import java.io.InputStreamReader;

View File

@@ -1,9 +1,9 @@
package net.woggioni.worth.traversal;
package net.woggioni.wson.traversal;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.xface.Value;
@RequiredArgsConstructor
abstract class AbstractStackElement<T> implements StackElement<T> {

View File

@@ -1,8 +1,8 @@
package net.woggioni.worth.traversal;
package net.woggioni.wson.traversal;
import net.woggioni.worth.exception.NotImplementedException;
import net.woggioni.worth.value.ArrayValue;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.exception.NotImplementedException;
import net.woggioni.wson.value.ArrayValue;
import net.woggioni.wson.xface.Value;
import java.util.Iterator;

View File

@@ -1,7 +1,7 @@
package net.woggioni.worth.traversal;
package net.woggioni.wson.traversal;
import net.woggioni.worth.exception.NotImplementedException;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.exception.NotImplementedException;
import net.woggioni.wson.xface.Value;
import static net.woggioni.jwo.JWO.newThrowable;

View File

@@ -1,7 +1,7 @@
package net.woggioni.worth.traversal;
package net.woggioni.wson.traversal;
import net.woggioni.worth.value.ObjectValue;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.xface.Value;
import java.util.Iterator;
import java.util.Map;

View File

@@ -1,6 +1,6 @@
package net.woggioni.worth.traversal;
package net.woggioni.wson.traversal;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.xface.Value;
public interface StackElement<T> {
T getContext();

View File

@@ -1,4 +1,4 @@
package net.woggioni.worth.traversal;
package net.woggioni.wson.traversal;
import java.util.List;

View File

@@ -1,7 +1,7 @@
package net.woggioni.worth.traversal;
package net.woggioni.wson.traversal;
import lombok.RequiredArgsConstructor;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.xface.Value;
import java.util.Objects;

View File

@@ -1,4 +1,4 @@
package net.woggioni.worth.traversal;
package net.woggioni.wson.traversal;
public interface ValueVisitor<T> {
default boolean visitPre(TraversalContext<T> ctx) { return true; }

View File

@@ -1,8 +1,8 @@
package net.woggioni.worth.traversal;
package net.woggioni.wson.traversal;
import net.woggioni.worth.value.ArrayValue;
import net.woggioni.worth.value.ObjectValue;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.value.ArrayValue;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.xface.Value;
import java.util.ArrayList;
import java.util.Collections;

View File

@@ -0,0 +1,32 @@
package net.woggioni.wson.utils;
import lombok.SneakyThrows;
import net.woggioni.wson.xface.Value;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
public class WsonUtils {
public static Value getOrNull(Value root, String... keys) {
Value result = root;
for (String key : keys) {
if(result.type() != Value.Type.OBJECT) {
result = null;
break;
}
result = result.get(key);
}
return result;
}
public static Optional<Value> optGet(Value root, String... keys) {
return Optional.ofNullable(getOrNull(root, keys));
}
@SneakyThrows
public static <T> T getOrThrow(Value root, Function<Value, T> success, Supplier<Throwable> error, String... keys) {
return optGet(root, keys).map(success).orElseThrow(error);
}
}

View File

@@ -1,12 +1,10 @@
package net.woggioni.worth.value;
package net.woggioni.wson.value;
import lombok.EqualsAndHashCode;
import net.woggioni.worth.xface.Value;
import lombok.NonNull;
import net.woggioni.wson.xface.Value;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.*;
@EqualsAndHashCode
public class ArrayValue implements Value, Iterable<Value> {
@@ -14,10 +12,10 @@ public class ArrayValue implements Value, Iterable<Value> {
private final List<Value> value;
public ArrayValue() {
this.value = new ArrayList();
this.value = new ArrayList<>();
}
public ArrayValue(List<Value> value) {
public ArrayValue(@NonNull List<Value> value) {
this.value = value;
}

View File

@@ -1,7 +1,7 @@
package net.woggioni.worth.value;
package net.woggioni.wson.value;
import lombok.EqualsAndHashCode;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.xface.Value;
@EqualsAndHashCode
public class BooleanValue implements Value {

View File

@@ -1,7 +1,7 @@
package net.woggioni.worth.value;
package net.woggioni.wson.value;
import lombok.EqualsAndHashCode;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.xface.Value;
@EqualsAndHashCode
public class FloatValue implements Value {

View File

@@ -1,7 +1,7 @@
package net.woggioni.worth.value;
package net.woggioni.wson.value;
import lombok.EqualsAndHashCode;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.xface.Value;
@EqualsAndHashCode
public class IntegerValue implements Value {

View File

@@ -1,7 +1,7 @@
package net.woggioni.worth.value;
package net.woggioni.wson.value;
import lombok.EqualsAndHashCode;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.xface.Value;
@EqualsAndHashCode
public class NullValue implements Value {

View File

@@ -1,9 +1,9 @@
package net.woggioni.worth.value;
package net.woggioni.wson.value;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import static net.woggioni.jwo.JWO.newThrowable;
import net.woggioni.worth.xface.Value;
import net.woggioni.wson.xface.Value;
import java.util.*;
@@ -91,7 +91,7 @@ abstract class MapObjectValue implements ObjectValue {
@Override
public Value get(String key) {
return value.getOrDefault(key, Value.Null);
return value.get(key);
}
@Override
@@ -177,7 +177,7 @@ class ListObjectValue implements ObjectValue {
for (Map.Entry<String, Value> entry : value) {
if(Objects.equals(entry.getKey(), key)) return entry.getValue();
}
return Value.Null;
return null;
}
@Override

View File

@@ -1,15 +1,17 @@
package net.woggioni.worth.value;
package net.woggioni.wson.value;
import lombok.EqualsAndHashCode;
import net.woggioni.worth.xface.Value;
import lombok.NonNull;
import net.woggioni.wson.xface.Value;
import java.util.Objects;
@EqualsAndHashCode
public class StringValue implements Value {
private final String value;
public StringValue(String value)
{
public StringValue(@NonNull String value) {
this.value = value;
}

View File

@@ -1,4 +1,4 @@
package net.woggioni.worth.xface;
package net.woggioni.wson.xface;
import java.io.OutputStream;
import java.io.Writer;

View File

@@ -1,4 +1,4 @@
package net.woggioni.worth.xface;
package net.woggioni.wson.xface;
import java.io.InputStream;
import java.io.Reader;

View File

@@ -1,11 +1,10 @@
package net.woggioni.worth.xface;
package net.woggioni.wson.xface;
import lombok.Builder;
import net.woggioni.worth.exception.TypeException;
import net.woggioni.worth.value.NullValue;
import net.woggioni.worth.value.ObjectValue;
import net.woggioni.wson.exception.TypeException;
import net.woggioni.wson.value.NullValue;
import net.woggioni.wson.value.ObjectValue;
import java.util.List;
import java.util.Map;
public interface Value {

View File

@@ -1,36 +0,0 @@
package net.woggioni.worth.buffer;
import lombok.SneakyThrows;
import org.junit.Assert;
import org.junit.Test;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.util.Random;
public class CircularBufferTest {
@Test
@SneakyThrows
public void test() {
MessageDigest streamDigest = MessageDigest.getInstance("MD5"), outputDigest = MessageDigest.getInstance("MD5");
InputStream is = new DigestInputStream(getClass().getResourceAsStream("/logging.properties"), streamDigest);
CircularBuffer cb = new CircularBuffer(new InputStreamReader(is), 32);
Random rand = new Random();
while (true) {
int b = cb.next();
if (b < 0) break;
if (rand.nextInt() % 2 == 0) {
cb.prev();
} else {
char c = (char) b;
outputDigest.update((byte) b);
System.out.print(c);
}
}
System.out.println();
Assert.assertArrayEquals(streamDigest.digest(), outputDigest.digest());
}
}

View File

@@ -1,40 +0,0 @@
package net.woggioni.worth.serialization;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import net.woggioni.worth.exception.MaxDepthExceededException;
import net.woggioni.worth.serialization.json.JSONParser;
import net.woggioni.worth.xface.Parser;
import net.woggioni.worth.xface.Value;
import org.junit.Test;
import java.io.InputStream;
public class JsonBombTest {
public static InputStream infiniteJson() {
return new InputStream() {
int index = 0;
final String monomer = "{\"key\":[";
@Override
public int read() {
return (int) monomer.charAt(index++ % monomer.length());
}
};
}
@Test(expected = StackOverflowError.class)
@SneakyThrows
public void jackson() {
ObjectMapper om = new ObjectMapper();
om.readTree(infiniteJson());
}
@Test(expected = MaxDepthExceededException.class)
@SneakyThrows
public void worth() {
Value.Configuration cfg = Value.Configuration.builder().maxDepth(1024).build();
Parser parser = JSONParser.newInstance(cfg);
parser.parse(infiniteJson());
}
}

View File

@@ -0,0 +1,29 @@
package net.woggioni.wson;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class Foo {
@TempDir
Path tempDir;
@BeforeEach
void beforeEach() {
Assertions.assertTrue(Files.isDirectory(this.tempDir));
}
@Test
void throwsErrorWhenTargetFileExists() throws IOException {
Path output = Files.createFile(
tempDir.resolve("output.txt")
);
}
}

View File

@@ -0,0 +1,32 @@
package net.woggioni.wson.serialization;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import net.woggioni.wson.exception.MaxDepthExceededException;
import net.woggioni.wson.serialization.json.JSONParser;
import net.woggioni.wson.test.JsonBomb;
import net.woggioni.wson.xface.Parser;
import net.woggioni.wson.xface.Value;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class JsonBombTest {
@Test
@SneakyThrows
public void jackson() {
ObjectMapper om = new ObjectMapper();
Assertions.assertThrows(StackOverflowError.class, () -> {
om.readTree(JsonBomb.infiniteJson());
});
}
@Test
@SneakyThrows
public void worth() {
Value.Configuration cfg = Value.Configuration.builder().maxDepth(1024).build();
Parser parser = JSONParser.newInstance(cfg);
Assertions.assertThrows(MaxDepthExceededException.class, () -> {
parser.parse(JsonBomb.infiniteJson());
});
}
}

View File

@@ -1,27 +1,30 @@
package net.woggioni.worth.serialization;
package net.woggioni.wson.serialization;
import lombok.SneakyThrows;
import net.woggioni.jwo.JWO;
import net.woggioni.worth.serialization.binary.JBONDumper;
import net.woggioni.worth.serialization.binary.JBONParser;
import net.woggioni.worth.serialization.json.JSONDumper;
import net.woggioni.worth.serialization.json.JSONParser;
import net.woggioni.worth.utils.WorthUtils;
import net.woggioni.worth.value.IntegerValue;
import net.woggioni.worth.value.ObjectValue;
import net.woggioni.worth.xface.Dumper;
import net.woggioni.worth.xface.Parser;
import net.woggioni.worth.xface.Value;
import org.junit.Assert;
import org.junit.Test;
import net.woggioni.wson.serialization.binary.JBONDumper;
import net.woggioni.wson.serialization.binary.JBONParser;
import net.woggioni.wson.serialization.json.JSONDumper;
import net.woggioni.wson.serialization.json.JSONParser;
import net.woggioni.wson.value.IntegerValue;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.xface.Dumper;
import net.woggioni.wson.xface.Parser;
import net.woggioni.wson.xface.Value;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.function.Function;
public class ReferenceTest {
@TempDir
Path testDir;
@SneakyThrows
private void common(Function<Value.Configuration, Dumper> dumperConstructor,
Function<Value.Configuration, Parser> parserConstructor) {
@@ -39,14 +42,14 @@ public class ReferenceTest {
dumper.dump(value, baos);
bytes = baos.toByteArray();
}
JWO.writeBytes2File(Paths.get("/tmp/ciao.jbon"), bytes);
JWO.writeBytes2File(testDir.resolve("ciao.jbon"), bytes);
Value reparsedValue;
try(ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) {
Parser parser = parserConstructor.apply(cfg);
reparsedValue = parser.parse(bais);
}
Assert.assertEquals(reparsedValue, reparsedValue.get("child"));
Assert.assertEquals(value.get("id"), reparsedValue.get("id"));
Assertions.assertEquals(reparsedValue, reparsedValue.get("child"));
Assertions.assertEquals(value.get("id"), reparsedValue.get("id"));
}
@Test

View File

@@ -1,34 +1,29 @@
package net.woggioni.worth.serialization.binary;
package net.woggioni.wson.serialization.binary;
import lombok.SneakyThrows;
import net.woggioni.worth.buffer.LookAheadTextInputStream;
import net.woggioni.worth.serialization.json.JSONParser;
import net.woggioni.worth.value.ObjectValue;
import net.woggioni.worth.xface.Parser;
import net.woggioni.worth.xface.Value;
import org.junit.Assert;
import org.junit.Test;
import net.woggioni.wson.serialization.json.JSONParser;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.xface.Parser;
import net.woggioni.wson.xface.Value;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class JBONTest {
private String[] testFiles = new String[]{"/test.json", "/wordpress.json"};
private static String[] testFiles = new String[]{"/test.json", "/wordpress.json"};
private InputStream getTestSource(String filename) {
return getClass().getResourceAsStream(filename);
private static InputStream getTestSource(String filename) {
return JBONTest.class.getResourceAsStream(filename);
}
@TempDir
Path testDir;
@Test
@SneakyThrows
public void consistencyTest() {
@@ -50,13 +45,13 @@ public class JBONTest {
Parser parser = new JBONParser(cfg);
reParsedValue = parser.parse(is);
}
Assert.assertEquals(parsedValue, reParsedValue);
Assertions.assertEquals(parsedValue, reParsedValue);
byte[] reDumpedJBON;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
JBONDumper.newInstance().dump(reParsedValue, baos);
reDumpedJBON = baos.toByteArray();
}
Assert.assertArrayEquals(dumpedJBON, reDumpedJBON);
Assertions.assertArrayEquals(dumpedJBON, reDumpedJBON);
}
}
@@ -66,7 +61,7 @@ public class JBONTest {
for (String testFile : testFiles) {
Value originalValue = new JSONParser().parse(getTestSource(testFile));
Path outputFile = Files.createTempFile(Paths.get("/tmp"), "worth", null);
Path outputFile = Files.createTempFile(testDir, "worth", null);
try (OutputStream os = new FileOutputStream(outputFile.toFile())) {
JBONDumper jbonDumper = new JBONDumper();
jbonDumper.dump(originalValue, os);
@@ -76,7 +71,7 @@ public class JBONTest {
JBONParser jbonParser = new JBONParser();
binarySerializedValue = jbonParser.parse(is);
}
Assert.assertEquals(originalValue, binarySerializedValue);
Assertions.assertEquals(originalValue, binarySerializedValue);
}
}
}

View File

@@ -1,28 +1,23 @@
package net.woggioni.worth.serialization.json;
package net.woggioni.wson.serialization.json;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import lombok.SneakyThrows;
import net.woggioni.worth.buffer.LookAheadTextInputStream;
import net.woggioni.worth.exception.NotImplementedException;
import net.woggioni.worth.utils.WorthUtils;
import net.woggioni.worth.value.ArrayValue;
import net.woggioni.worth.value.IntegerValue;
import net.woggioni.worth.value.ObjectValue;
import net.woggioni.worth.xface.Dumper;
import net.woggioni.worth.xface.Parser;
import net.woggioni.worth.xface.Value;
import org.junit.Assert;
import org.junit.Test;
import net.woggioni.wson.buffer.LookAheadTextInputStream;
import net.woggioni.wson.exception.NotImplementedException;
import net.woggioni.wson.value.ArrayValue;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.xface.Parser;
import net.woggioni.wson.xface.Value;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Objects;
public class JSONTest {
@@ -202,11 +197,11 @@ public class JSONTest {
ByteArrayInputStream bais = new ByteArrayInputStream(barray);
parser = new JSONParser(cfg);
Value reParsedValue = parser.parse(bais);
Assert.assertEquals(parsedValue, reParsedValue);
Assertions.assertEquals(parsedValue, reParsedValue);
baos = new ByteArrayOutputStream();
JSONDumper.newInstance().dump(reParsedValue, baos);
String reDumpedJSON = new String(baos.toByteArray());
Assert.assertEquals(dumpedJSON, reDumpedJSON);
Assertions.assertEquals(dumpedJSON, reDumpedJSON);
}
}
@@ -217,8 +212,8 @@ public class JSONTest {
for (String testFile : testFiles) {
JsonNode jsonNode = om.readTree(getTestSource(testFile));
Value value = new JSONParser().parse(getTestSource(testFile));
Assert.assertTrue(compareValueAndJsonNode(value, jsonNode, (v, j) -> {
Assert.fail("Difference found");
Assertions.assertTrue(compareValueAndJsonNode(value, jsonNode, (v, j) -> {
Assertions.fail("Difference found");
}));
}
}
@@ -232,6 +227,6 @@ public class JSONTest {
LookAheadTextInputStream ltis = new LookAheadTextInputStream(new InputStreamReader(bais));
ltis.read();
int result = JSONParser.parseHex(ltis);
Assert.assertEquals(Integer.parseInt(hex, 16), result);
Assertions.assertEquals(Integer.parseInt(hex, 16), result);
}
}

View File

@@ -1,16 +1,16 @@
package net.woggioni.worth.traversal;
package net.woggioni.wson.traversal;
import lombok.SneakyThrows;
import net.woggioni.jwo.JWO;
import net.woggioni.worth.serialization.json.JSONParser;
import net.woggioni.worth.serialization.json.JSONTest;
import net.woggioni.wson.serialization.json.JSONParser;
import net.woggioni.wson.serialization.json.JSONTest;
import net.woggioni.jwo.tuple.Tuple2;
import net.woggioni.worth.value.ArrayValue;
import net.woggioni.worth.value.ObjectValue;
import net.woggioni.worth.xface.Parser;
import net.woggioni.worth.xface.Value;
import org.junit.Assert;
import org.junit.Test;
import net.woggioni.wson.value.ArrayValue;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.xface.Parser;
import net.woggioni.wson.xface.Value;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.BufferedInputStream;
import java.io.InputStream;
@@ -31,8 +31,8 @@ public class ValueWalkerTest {
}
ValueWalker valueWalker = new ValueWalker(value);
Optional<String> text = valueWalker.get("widget").get("image").get("tags").get(1).map(Value::asString);
Assert.assertTrue(text.isPresent());
Assert.assertEquals("Amazon", text.get());
Assertions.assertTrue(text.isPresent());
Assertions.assertEquals("Amazon", text.get());
}
private static class TestVisitor implements ValueVisitor<Void> {
@@ -84,8 +84,8 @@ public class ValueWalkerTest {
Value v = JSONParser.newInstance().parse(JSONTest.getTestSource("/test.json"));
TestVisitor visitor = new TestVisitor();
ValueWalker.walk(v, visitor);
Assert.assertFalse(visitor.preValues.isEmpty());
Assert.assertFalse(visitor.postValues.isEmpty());
Assert.assertEquals(recursiveWalk(v), new Tuple2<>(visitor.preValues, visitor.postValues));
Assertions.assertFalse(visitor.preValues.isEmpty());
Assertions.assertFalse(visitor.postValues.isEmpty());
Assertions.assertEquals(recursiveWalk(v), new Tuple2<>(visitor.preValues, visitor.postValues));
}
}

View File

@@ -1,9 +1,9 @@
package net.woggioni.worth.value;
package net.woggioni.wson.value;
import net.woggioni.jwo.tuple.Tuple2;
import net.woggioni.worth.xface.Value;
import org.junit.Assert;
import org.junit.Test;
import net.woggioni.wson.xface.Value;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
@@ -28,13 +28,13 @@ public class ObjectValueImplementationTest {
Class<? extends ObjectValue> expectedClass =
mapping.stream().filter(t -> t._1 == expectedImplementation).findFirst().get()._2;
ObjectValue obj = ObjectValue.newInstance();
Assert.assertEquals(expectedClass, obj.getClass());
Assertions.assertEquals(expectedClass, obj.getClass());
mapping.forEach(tuple -> {
Value.Configuration cfg = Value.Configuration.builder()
.objectValueImplementation(tuple._1)
.build();
ObjectValue obj2 = ObjectValue.newInstance(cfg);
Assert.assertEquals(tuple._2, obj2.getClass());
Assertions.assertEquals(tuple._2, obj2.getClass());
});
}

4
test-utils/build.sbt Normal file
View File

@@ -0,0 +1,4 @@
organization := (organization in LocalRootProject).value
name := "test-utils"
version := (version in LocalRootProject).value
skip in publish := true

View File

@@ -0,0 +1,16 @@
package net.woggioni.wson.test;
import java.io.InputStream;
public class JsonBomb {
public static InputStream infiniteJson() {
return new InputStream() {
int index = 0;
final String monomer = "{\"key\":[";
@Override
public int read() {
return monomer.charAt(index++ % monomer.length());
}
};
}
}