public void TestInt16() { var structure = SchemaTestUtil.Parse(@" using schema; namespace foo.bar { [BinarySchema] public class Int16Wrapper { public short field; } }"); Assert.IsEmpty(structure.Diagnostics); Assert.AreEqual("bar", structure.TypeSymbol.ContainingNamespace.Name); Assert.AreEqual("Int16Wrapper", structure.TypeSymbol.Name); Assert.AreEqual(1, structure.Members.Count); var field = structure.Members[0]; Assert.AreEqual("field", field.Name); var memberType = field.MemberType; Assert.AreEqual(SpecialType.System_Int16, memberType.TypeSymbol.SpecialType); var primitiveType = (memberType as IPrimitiveMemberType) !; Assert.AreEqual(SchemaPrimitiveType.INT16, primitiveType.PrimitiveType); Assert.AreEqual(false, primitiveType.IsReadonly); Assert.AreEqual(false, primitiveType.UseAltFormat); Assert.AreEqual(SchemaNumberType.UNDEFINED, primitiveType.AltFormat); }
public void TestConstCharArray() { var structure = SchemaTestUtil.Parse(@" namespace foo.bar { [BinarySchema] public class CharWrapper { public readonly char[] field; } }"); Assert.IsEmpty(structure.Diagnostics); var field = structure.Members[0]; Assert.AreEqual("field", field.Name); var memberType = field.MemberType; Assert.AreEqual(TypeKind.Array, memberType.TypeSymbol.TypeKind); var arrayType = (memberType as ISequenceMemberType) !; Assert.AreEqual(SequenceType.ARRAY, arrayType.SequenceType); Assert.AreEqual(SequenceLengthSourceType.CONST, arrayType.LengthSourceType); var primitiveType = (arrayType.ElementType as IPrimitiveMemberType) !; Assert.AreEqual(SchemaPrimitiveType.CHAR, primitiveType.PrimitiveType); Assert.AreEqual(false, primitiveType.IsReadonly); Assert.AreEqual(false, primitiveType.UseAltFormat); Assert.AreEqual(SchemaNumberType.UNDEFINED, primitiveType.AltFormat); }
public void TestMutableArrayWithoutLength() { var structure = SchemaTestUtil.Parse(@" namespace foo.bar { [BinarySchema] public partial class ArrayWrapper { public int[] field; } }"); SchemaTestUtil.AssertDiagnostics(structure.Diagnostics, Rules.MutableArrayNeedsLengthSource); }
public void TestBooleanWithoutAltFormat() { var structure = SchemaTestUtil.Parse(@" namespace foo.bar { [BinarySchema] public partial class BooleanWrapper { public bool field; } }"); SchemaTestUtil.AssertDiagnostics(structure.Diagnostics, Rules.BooleanNeedsIntegerFormat); }
public static void AssertGenerated(string src, string expectedReader, string expectedWriter) { var structure = SchemaTestUtil.Parse(src); Assert.IsEmpty(structure.Diagnostics); var actualReader = new SchemaReaderGenerator().Generate(structure); var actualWriter = new SchemaWriterGenerator().Generate(structure); Assert.AreEqual(expectedReader, actualReader.ReplaceLineEndings()); Assert.AreEqual(expectedWriter, actualWriter.ReplaceLineEndings()); }
public void TestEnumWithoutFormat() { var structure = SchemaTestUtil.Parse(@" namespace foo.bar { public enum ValueType { A, B, C } [BinarySchema] public partial class EnumWrapper { public ValueType field; } }"); SchemaTestUtil.AssertDiagnostics(structure.Diagnostics, Rules.EnumNeedsIntegerFormat); }
public void TestEnum() { var structure = SchemaTestUtil.Parse(@" using schema; namespace foo.bar { public enum ValueType { A, B, C } [BinarySchema] public class EnumWrapper { [IntegerFormat(SchemaIntegerType.UINT16)] public ValueType field; } }"); Assert.IsEmpty(structure.Diagnostics); Assert.AreEqual("bar", structure.TypeSymbol.ContainingNamespace.Name); Assert.AreEqual("EnumWrapper", structure.TypeSymbol.Name); Assert.AreEqual(1, structure.Members.Count); var field = structure.Members[0]; Assert.AreEqual("field", field.Name); var memberType = field.MemberType; Assert.AreEqual(TypeKind.Enum, memberType.TypeSymbol.TypeKind); var primitiveType = (memberType as IPrimitiveMemberType) !; Assert.AreEqual(SchemaPrimitiveType.ENUM, primitiveType.PrimitiveType); Assert.AreEqual(false, primitiveType.IsReadonly); Assert.AreEqual(true, primitiveType.UseAltFormat); Assert.AreEqual(SchemaNumberType.UINT16, primitiveType.AltFormat); }