Skip to content

Commit

Permalink
Use Core Schema by default as recommended by the YAML specification
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Feb 5, 2025
1 parent d6ad5b6 commit ca983e7
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import it.krzeminski.snakeyaml.engine.kmp.emitter.Emitter
import it.krzeminski.snakeyaml.engine.kmp.exceptions.EmitterException
import it.krzeminski.snakeyaml.engine.kmp.exceptions.YamlEngineException
import it.krzeminski.snakeyaml.engine.kmp.nodes.Tag
import it.krzeminski.snakeyaml.engine.kmp.schema.JsonSchema
import it.krzeminski.snakeyaml.engine.kmp.schema.CoreSchema
import it.krzeminski.snakeyaml.engine.kmp.schema.Schema
import it.krzeminski.snakeyaml.engine.kmp.serializer.AnchorGenerator
import it.krzeminski.snakeyaml.engine.kmp.serializer.NumberAnchorGenerator
Expand Down Expand Up @@ -54,7 +54,7 @@ class DumpSettingsBuilder internal constructor() {
private var indentWithIndicator = false
private var dumpComments = false
private var isDereferenceAliases = false
private var schema: Schema = JsonSchema()
private var schema: Schema = CoreSchema()

/**
* Define flow style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import it.krzeminski.snakeyaml.engine.kmp.api.LoadSettings.SpecVersionMutator
import it.krzeminski.snakeyaml.engine.kmp.env.EnvConfig
import it.krzeminski.snakeyaml.engine.kmp.exceptions.YamlVersionException
import it.krzeminski.snakeyaml.engine.kmp.nodes.Tag
import it.krzeminski.snakeyaml.engine.kmp.schema.JsonSchema
import it.krzeminski.snakeyaml.engine.kmp.schema.CoreSchema
import it.krzeminski.snakeyaml.engine.kmp.schema.Schema

/**
Expand Down Expand Up @@ -49,7 +49,7 @@ class LoadSettingsBuilder internal constructor() {
private var useMarks: Boolean = true
private var envConfig: EnvConfig? = null // no ENV substitution by default
private var codePointLimit: Int = 3 * 1024 * 1024 // 3 MB
private var schema: Schema = JsonSchema()
private var schema: Schema = CoreSchema()

/**
* Label for the input data. Can be used to improve the error message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import it.krzeminski.snakeyaml.engine.kmp.api.DumpSettings;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import it.krzeminski.snakeyaml.engine.kmp.api.Dump;
import it.krzeminski.snakeyaml.engine.kmp.api.DumpSettings;
import it.krzeminski.snakeyaml.engine.kmp.api.Load;
import it.krzeminski.snakeyaml.engine.kmp.api.LoadSettings;
import it.krzeminski.snakeyaml.engine.kmp.schema.CoreSchema;

@org.junit.jupiter.api.Tag("fast")
public class BooleanCoreTest {

Load loader = new Load(LoadSettings.builder().setSchema(new CoreSchema()).build());
Load loader = new Load();

@Test
void parseBoolean() {
Expand All @@ -51,7 +49,7 @@ void parseString() {

@Test
void dumpBoolean() {
Dump dumper = new Dump(DumpSettings.builder().setSchema(new CoreSchema()).build());
Dump dumper = new Dump(DumpSettings.builder().build());
assertEquals("true\n", dumper.dumpToString(Boolean.TRUE));
assertEquals("false\n", dumper.dumpToString(Boolean.FALSE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import it.krzeminski.snakeyaml.engine.kmp.api.LoadSettings;
import it.krzeminski.snakeyaml.engine.kmp.schema.JsonSchema;
import org.junit.jupiter.api.Test;
import it.krzeminski.snakeyaml.engine.kmp.api.Dump;
import it.krzeminski.snakeyaml.engine.kmp.api.DumpSettings;
Expand All @@ -23,7 +25,7 @@
@org.junit.jupiter.api.Tag("fast")
public class BooleanJsonTest {

private final Load loader = new Load();
private final Load loader = new Load(LoadSettings.builder().setSchema(new JsonSchema()).build());

@Test
void parseBoolean() {
Expand All @@ -37,7 +39,7 @@ void parseBoolean() {

@Test
void dumpBoolean() {
Dump dumper = new Dump(DumpSettings.builder().build());
Dump dumper = new Dump(DumpSettings.builder().setSchema(new JsonSchema()).build());
assertEquals("true\n", dumper.dumpToString(Boolean.TRUE));
assertEquals("false\n", dumper.dumpToString(Boolean.FALSE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import it.krzeminski.snakeyaml.engine.kmp.api.DumpSettings;
import org.junit.jupiter.api.Test;
import it.krzeminski.snakeyaml.engine.kmp.api.Dump;
import it.krzeminski.snakeyaml.engine.kmp.api.DumpSettings;
import it.krzeminski.snakeyaml.engine.kmp.api.Load;
import it.krzeminski.snakeyaml.engine.kmp.api.LoadSettings;
import it.krzeminski.snakeyaml.engine.kmp.schema.CoreSchema;

@org.junit.jupiter.api.Tag("fast")
public class NullCoreTest {

Load loader = new Load(LoadSettings.builder().setSchema(new CoreSchema()).build());
Load loader = new Load();

@Test
void parseNull() {
Expand All @@ -40,7 +38,7 @@ void parseNull() {

@Test
void dumpNull() {
Dump dumper = new Dump(DumpSettings.builder().setSchema(new CoreSchema()).build());
Dump dumper = new Dump(DumpSettings.builder().build());
assertEquals("null\n", dumper.dumpToString(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import it.krzeminski.snakeyaml.engine.kmp.api.LoadSettings;
import it.krzeminski.snakeyaml.engine.kmp.schema.JsonSchema;
import org.junit.jupiter.api.Test;
import it.krzeminski.snakeyaml.engine.kmp.api.Dump;
import it.krzeminski.snakeyaml.engine.kmp.api.DumpSettings;
Expand All @@ -24,7 +26,7 @@
@org.junit.jupiter.api.Tag("fast")
public class NullJsonTest {

private final Load loader = new Load();
private final Load loader = new Load(LoadSettings.builder().setSchema(new JsonSchema()).build());

@Test
void parseNull() {
Expand All @@ -34,7 +36,7 @@ void parseNull() {

@Test
void dumpNull() {
Dump dumper = new Dump(DumpSettings.builder().build());
Dump dumper = new Dump(DumpSettings.builder().setSchema(new JsonSchema()).build());
assertEquals("null\n", dumper.dumpToString(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.math.BigInteger;

import it.krzeminski.snakeyaml.engine.kmp.api.DumpSettings;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import it.krzeminski.snakeyaml.engine.kmp.api.Dump;
import it.krzeminski.snakeyaml.engine.kmp.api.DumpSettings;
import it.krzeminski.snakeyaml.engine.kmp.api.Load;
import it.krzeminski.snakeyaml.engine.kmp.api.LoadSettings;
import it.krzeminski.snakeyaml.engine.kmp.schema.CoreSchema;

@org.junit.jupiter.api.Tag("fast")
public class NumberCoreTest {

Load loader = new Load(LoadSettings.builder().setSchema(new CoreSchema()).build());
Load loader = new Load();

@Test
@DisplayName("Test all integers which are defined in the core schema & JSON")
Expand Down Expand Up @@ -116,7 +115,7 @@ void parseDoubleSpecial() {
@Test
@DisplayName("Dump special doubles which are defined in the core schema")
void dumpDoubleSpecial() {
Dump dumper = new Dump(DumpSettings.builder().setSchema(new CoreSchema()).build());
Dump dumper = new Dump(DumpSettings.builder().build());
assertEquals(".inf\n", dumper.dumpToString(Double.POSITIVE_INFINITY));
assertEquals(".inf\n", dumper.dumpToString(Float.POSITIVE_INFINITY));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.math.BigInteger;

import it.krzeminski.snakeyaml.engine.kmp.api.LoadSettings;
import it.krzeminski.snakeyaml.engine.kmp.schema.JsonSchema;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import it.krzeminski.snakeyaml.engine.kmp.api.Dump;
Expand All @@ -25,7 +28,7 @@
@org.junit.jupiter.api.Tag("fast")
public class NumberJsonTest {

private final Load loader = new Load();
private final Load loader = new Load(LoadSettings.builder().setSchema(new JsonSchema()).build());

@Test
@DisplayName("Test all integers which are define in the core schema & JSON")
Expand Down Expand Up @@ -100,7 +103,7 @@ void parseDoubleSpecial() {
@Test
@DisplayName("Dump special doubles which are defined in the JSON schema, but not in JSON")
void dumpDoubleSpecial() {
Dump dumper = new Dump(DumpSettings.builder().build());
Dump dumper = new Dump(DumpSettings.builder().setSchema(new JsonSchema()).build());
assertEquals(".inf\n", dumper.dumpToString(Double.POSITIVE_INFINITY));
assertEquals(".inf\n", dumper.dumpToString(Float.POSITIVE_INFINITY));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

import it.krzeminski.snakeyaml.engine.kmp.api.*;
import it.krzeminski.snakeyaml.engine.kmp.api.LoadSettings;
import it.krzeminski.snakeyaml.engine.kmp.schema.CoreSchema;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import it.krzeminski.snakeyaml.engine.kmp.api.LoadSettings.SpecVersionMutator;
import it.krzeminski.snakeyaml.engine.kmp.exceptions.DuplicateKeyException;
import it.krzeminski.snakeyaml.engine.kmp.schema.JsonSchema;

@Tag("fast")
class LoadSettingsTest {
Expand Down Expand Up @@ -107,7 +107,7 @@ void bufferSize() {
@DisplayName("Use JSON schema by default")
void defaultSchema() {
LoadSettings settings = LoadSettings.builder().build();
assertEquals(JsonSchema.class, settings.schema.getClass());
assertEquals(CoreSchema.class, settings.schema.getClass());
}

public enum SomeStatus implements SettingKey {
Expand Down

0 comments on commit ca983e7

Please sign in to comment.