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

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());
});
}

Binary file not shown.

Binary file not shown.

View File

@@ -1,36 +0,0 @@
handlers=java.util.logging.ConsoleHandler
config=
sun.net.www.protocol.http.HttpURLConnection.handlers=java.util.logging.ConsoleHandler
#sun.net.www.protocol.http.HttpURLConnection.level=ALL
java.util.logging.FileHandler.level = WARNING
java.util.logging.FileHandler.filter =
java.util.logging.FileHandler.formatter =
java.util.logging.FileHandler.encoding =
java.util.logging.FileHandler.limit =
java.util.logging.FileHandler.count =
java.util.logging.FileHandler.append = false
java.util.logging.FileHandler.pattern = log.%u.%g.txt
#java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.filter =
java.util.logging.ConsoleHandler.formatter =
java.util.logging.ConsoleHandler.encoding =
java.util.logging.StreamHandler.level = WARNING
java.util.logging.StreamHandler.filter =
java.util.logging.StreamHandler.formatter =
java.util.logging.StreamHandler.encoding =
java.util.logging.SocketHandler.level = WARNING
java.util.logging.SocketHandler.filter =
java.util.logging.SocketHandler.formatter =
java.util.logging.SocketHandler.encoding =
java.util.logging.SocketHandler.host =
java.util.logging.SocketHandler.port =
java.util.logging.MemoryHandler.level = WARNING
java.util.logging.MemoryHandler.filter =
java.util.logging.MemoryHandler.size =
java.util.logging.MemoryHandler.push =
java.util.logging.MemoryHandler.target =

View File

@@ -1,31 +0,0 @@
{
"widget": {
"debug": "on",
"window": {
"parent" : null,
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 501
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center",
"tags" : ["Ireland", "Amazon", "development"],
"monochromatic" : false
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}
}

File diff suppressed because one or more lines are too long