public void TestJsonSchemaCommon(IYamlSchema schema) { Assert.Equal(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar(null, null, "true", ScalarStyle.DoubleQuoted, false, false))); Assert.Equal(JsonSchema.BoolShortTag, schema.GetDefaultTag(new Scalar("true"))); Assert.Equal(JsonSchema.NullShortTag, schema.GetDefaultTag(new Scalar("null"))); Assert.Equal(JsonSchema.IntShortTag, schema.GetDefaultTag(new Scalar("5"))); Assert.Equal(JsonSchema.FloatShortTag, schema.GetDefaultTag(new Scalar("5.5"))); Assert.Equal(JsonSchema.NullLongTag, schema.ExpandTag("!!null")); Assert.Equal(JsonSchema.BoolLongTag, schema.ExpandTag("!!bool")); Assert.Equal(JsonSchema.IntLongTag, schema.ExpandTag("!!int")); Assert.Equal(JsonSchema.FloatLongTag, schema.ExpandTag("!!float")); Assert.Equal("!!null", schema.ShortenTag(JsonSchema.NullLongTag)); Assert.Equal("!!bool", schema.ShortenTag(JsonSchema.BoolLongTag)); Assert.Equal("!!int", schema.ShortenTag(JsonSchema.IntLongTag)); Assert.Equal("!!float", schema.ShortenTag(JsonSchema.FloatLongTag)); TryParse(schema, "null", JsonSchema.NullShortTag, null); TryParse(schema, "true", JsonSchema.BoolShortTag, true); TryParse(schema, "false", JsonSchema.BoolShortTag, false); TryParse(schema, "5", JsonSchema.IntShortTag, 5); TryParse(schema, "5.5", JsonSchema.FloatShortTag, 5.5); TryParse(schema, ".inf", JsonSchema.FloatShortTag, double.PositiveInfinity); }
public void TestCoreSchemaCommon(IYamlSchema schema) { TestJsonSchemaCommon(schema); // Core schema is accepting plain string Assert.Equal(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar("boom"))); Assert.Equal(JsonSchema.BoolShortTag, schema.GetDefaultTag(new Scalar("True"))); Assert.Equal(JsonSchema.BoolShortTag, schema.GetDefaultTag(new Scalar("TRUE"))); Assert.Equal(JsonSchema.IntShortTag, schema.GetDefaultTag(new Scalar("0x10"))); TryParse(schema, "TRUE", JsonSchema.BoolShortTag, true); TryParse(schema, "FALSE", JsonSchema.BoolShortTag, false); TryParse(schema, "0x10", JsonSchema.IntShortTag, 16); TryParse(schema, "16", JsonSchema.IntShortTag, 16); }
public void TestCoreSchemaCommon(IYamlSchema schema) { TestJsonSchemaCommon(schema); // Core schema is accepting plain string Assert.AreEqual(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar("boom"))); Assert.AreEqual(JsonSchema.BoolShortTag, schema.GetDefaultTag(new Scalar("True"))); Assert.AreEqual(JsonSchema.BoolShortTag, schema.GetDefaultTag(new Scalar("TRUE"))); Assert.AreEqual(JsonSchema.IntShortTag, schema.GetDefaultTag(new Scalar("0x10"))); TryParse(schema, "TRUE", JsonSchema.BoolShortTag, true); TryParse(schema, "FALSE", JsonSchema.BoolShortTag, false); TryParse(schema, "0x10", JsonSchema.IntShortTag, 16); TryParse(schema, "16", JsonSchema.IntShortTag, 16); }
public void TestFailsafeSchemaCommon(IYamlSchema schema) { Assert.Equal(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar("true"))); Assert.Equal(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar("custom", "boom"))); Assert.Equal(FailsafeSchema.MapShortTag, schema.GetDefaultTag(new MappingStart())); Assert.Equal(FailsafeSchema.SeqShortTag, schema.GetDefaultTag(new SequenceStart())); Assert.Equal(FailsafeSchema.MapLongTag, schema.ExpandTag("!!map")); Assert.Equal(FailsafeSchema.SeqLongTag, schema.ExpandTag("!!seq")); Assert.Equal(SchemaBase.StrLongTag, schema.ExpandTag("!!str")); Assert.Equal("!!map", schema.ShortenTag(FailsafeSchema.MapLongTag)); Assert.Equal("!!seq", schema.ShortenTag(FailsafeSchema.SeqLongTag)); Assert.Equal("!!str", schema.ShortenTag(SchemaBase.StrLongTag)); TryParse(schema, "true", SchemaBase.StrShortTag, "true"); }
public YamlValue(object value, IYamlSchema schema = null) { var valueString = PrimitiveSerializer.ConvertValue(value); if (schema == null) { schema = CoreSchema.Instance; } Scalar = new Scalar(schema.GetDefaultTag(value.GetType()), valueString); }
public virtual string TagFromType(Type type) { if (type == null) { return("!!null"); } string tagName; // First try to resolve a tag from registered tag if (!typeToTag.TryGetValue(type, out tagName)) { // Else try to use schema tag for scalars // Else use full name of the type var typeName = UseShortTypeName ? type.GetShortAssemblyQualifiedName() : type.AssemblyQualifiedName; tagName = schema.GetDefaultTag(type) ?? Uri.EscapeUriString(string.Format("!{0}", typeName)); typeToTag.Add(type, tagName); } return(tagName); }
public void TestFailsafeSchemaCommon(IYamlSchema schema) { Assert.AreEqual(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar("true"))); Assert.AreEqual(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar("custom", "boom"))); Assert.AreEqual(FailsafeSchema.MapShortTag, schema.GetDefaultTag(new MappingStart())); Assert.AreEqual(FailsafeSchema.SeqShortTag, schema.GetDefaultTag(new SequenceStart())); Assert.AreEqual(FailsafeSchema.MapLongTag, schema.ExpandTag("!!map")); Assert.AreEqual(FailsafeSchema.SeqLongTag, schema.ExpandTag("!!seq")); Assert.AreEqual(SchemaBase.StrLongTag, schema.ExpandTag("!!str")); Assert.AreEqual("!!map", schema.ShortenTag(FailsafeSchema.MapLongTag)); Assert.AreEqual("!!seq", schema.ShortenTag(FailsafeSchema.SeqLongTag)); Assert.AreEqual("!!str", schema.ShortenTag(SchemaBase.StrLongTag)); TryParse(schema, "true", SchemaBase.StrShortTag, "true"); }
public void TestJsonSchemaCommon(IYamlSchema schema) { Assert.AreEqual(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar(null, null, "true", ScalarStyle.DoubleQuoted, false, false))); Assert.AreEqual(JsonSchema.BoolShortTag, schema.GetDefaultTag(new Scalar("true"))); Assert.AreEqual(JsonSchema.NullShortTag, schema.GetDefaultTag(new Scalar("null"))); Assert.AreEqual(JsonSchema.IntShortTag, schema.GetDefaultTag(new Scalar("5"))); Assert.AreEqual(JsonSchema.FloatShortTag, schema.GetDefaultTag(new Scalar("5.5"))); Assert.AreEqual(JsonSchema.NullLongTag, schema.ExpandTag("!!null")); Assert.AreEqual(JsonSchema.BoolLongTag, schema.ExpandTag("!!bool")); Assert.AreEqual(JsonSchema.IntLongTag, schema.ExpandTag("!!int")); Assert.AreEqual(JsonSchema.FloatLongTag, schema.ExpandTag("!!float")); Assert.AreEqual("!!null", schema.ShortenTag(JsonSchema.NullLongTag)); Assert.AreEqual("!!bool", schema.ShortenTag(JsonSchema.BoolLongTag)); Assert.AreEqual("!!int", schema.ShortenTag(JsonSchema.IntLongTag)); Assert.AreEqual("!!float", schema.ShortenTag(JsonSchema.FloatLongTag)); TryParse(schema, "null", JsonSchema.NullShortTag, null); TryParse(schema, "true", JsonSchema.BoolShortTag, true); TryParse(schema, "false", JsonSchema.BoolShortTag, false); TryParse(schema, "5", JsonSchema.IntShortTag, 5); TryParse(schema, "5.5", JsonSchema.FloatShortTag, 5.5); TryParse(schema, ".inf", JsonSchema.FloatShortTag, double.PositiveInfinity); }