Esempio n. 1
0
        public void DoubleEmbedded()
        {
            ;
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("field1", new Signed(null, 16), null, null));
            object1.Fields.Add(("field2", new Unsigned(null, 32), null, null));

            var superembedded = new BiPaGe.AST.FieldTypes.InlineObject(null, new List <BiPaGe.AST.Field> {
                new Field(null, "nestnest1", new Utf8String(null), new BiPaGe.AST.Literals.Integer(null, "64"), null),
                new Field(null, "nestnest2", new Identifier(null, "SomeOtherObject"), null, null),
                new Field(null, "nestnest3", new Unsigned(null, 12), null, null),
            });

            var embedded = new BiPaGe.AST.FieldTypes.InlineObject(null, new List <BiPaGe.AST.Field> {
                new Field(null, "embedded1", new Float(null, 32), null, null),
                new Field(null, "embedded2", new BiPaGe.AST.FieldTypes.Boolean(null), new BiPaGe.AST.Literals.Integer(null, "3"), null),
                new Field(null, "embedded_embedded", superembedded, null, null)
            });

            object1.Fields.Add(("embedded_object", embedded, null, null));
            expected.Validate(SimpleBuilder.Build("Object1{field1:int16;field2:u32;embedded_object:{embedded1:f32;embedded2:bool[3];embedded_embedded:{nestnest1:utf8_string[64];nestnest2:SomeOtherObject;nestnest3:u12;}};}"));
        }
Esempio n. 2
0
        public void SingleEmbedded()
        {
            var input    = @"
Object1
{
    field1 : int16;
    field2 : u32;
    embedded_object : { embedded1 : f32 ; embedded2 : bool[3] ; embedded3 : ascii_string[8]; };
}";
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("field1", new Signed(null, 16), null, null));
            object1.Fields.Add(("field2", new Unsigned(null, 32), null, null));

            var embedded = new BiPaGe.AST.FieldTypes.InlineObject(null, new List <BiPaGe.AST.Field> {
                new Field(null, "embedded1", new Float(null, 32), null, null),
                new Field(null, "embedded2", new BiPaGe.AST.FieldTypes.Boolean(null), new BiPaGe.AST.Literals.Integer(null, "3"), null),
                new Field(null, "embedded3", new AsciiString(null), new BiPaGe.AST.Literals.Integer(null, "8"), null),
            });

            object1.Fields.Add(("embedded_object", embedded, null, null));
            expected.Validate(SimpleBuilder.Build(input));
        }
Esempio n. 3
0
        public void SingleLevelMultipleValue()
        {
            var input    = @"
Object1
{
    field1 : i32;
    field2 : SomeOtherObject(field1 = 5, field2 = 1.23, field3 = ""Some string"", field4 = {1,2,3,4,5}, field5 = false);
}";
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("field1", new Signed(null, 32), null, null));
            object1.Fields.Add(("field2", new Identifier(null, "SomeOtherObject"), null,
                                new BiPaGe.AST.Constants.ObjectConstant(null,
                                                                        new List <ObjectField> {
                new ObjectField("field1", new BiPaGe.AST.Literals.Integer(null, "5")),
                new ObjectField("field2", new BiPaGe.AST.Literals.Float(null, "1.23")),
                new ObjectField("field3", new BiPaGe.AST.Literals.StringLiteral(null, "Some string")),
                new ObjectField("field4", new LiteralCollection(null, new List <BiPaGe.AST.Literals.Literal> {
                    new BiPaGe.AST.Literals.Integer(null, "1"),
                    new BiPaGe.AST.Literals.Integer(null, "2"),
                    new BiPaGe.AST.Literals.Integer(null, "3"),
                    new BiPaGe.AST.Literals.Integer(null, "4"),
                    new BiPaGe.AST.Literals.Integer(null, "5")
                })),
                new ObjectField("field5", new BiPaGe.AST.Literals.Boolean(null, "false"))
            })));
            expected.Validate(SimpleBuilder.Build(input));
        }
Esempio n. 4
0
        public void Basic()
        {
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("field1", new Signed(null, 16), null, null));
            object1.Fields.Add(("field2", new Unsigned(null, 32), null, null));
            object1.Fields.Add(("field3", new Float(null, 32), null, null));
            object1.Fields.Add(("field4", new Float(null, 64), null, null));
            object1.Fields.Add(("field5", new BiPaGe.AST.FieldTypes.Boolean(null), null, null));
            expected.Validate(SimpleBuilder.Build("Object1{field1:int16;field2:u32;field3:float32;field4:f64;field5:bool;}"));
        }
Esempio n. 5
0
        public void SignedPositive()
        {
            var input    = @"
Object1
{
    field1 : int16 = 5;
}";
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("field1", new Signed(null, 16), null, new BiPaGe.AST.Literals.Integer(null, "5")));
            expected.Validate(SimpleBuilder.Build(input));
        }
Esempio n. 6
0
        public void FloatNegative()
        {
            var input    = @"
Object1
{
    field1 : float64 = -3.14;
}";
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("field1", new Float(null, 64), null, new BiPaGe.AST.Literals.Float(null, "-3.14")));
            expected.Validate(SimpleBuilder.Build(input));
        }
Esempio n. 7
0
        public void FloatPositive()
        {
            var input    = @"
Object1
{
    field1 : float32 = 123.456;
}";
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("field1", new Float(null, 32), null, new BiPaGe.AST.Literals.Float(null, "123.456")));
            expected.Validate(SimpleBuilder.Build(input));
        }
Esempio n. 8
0
        public void Unsigned()
        {
            var input    = @"
Object1
{
    field1 : uint32 = 500;
}";
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("field1", new Unsigned(null, 32), null, new BiPaGe.AST.Literals.Integer(null, "500")));
            expected.Validate(SimpleBuilder.Build(input));
        }
Esempio n. 9
0
        public void BasicTypes()
        {
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("field1", new Unsigned(null, 32), null, new BiPaGe.AST.Literals.Integer(null, "500")));
            object1.Fields.Add(("field2", new Signed(null, 16), null, new BiPaGe.AST.Literals.Integer(null, "-5")));
            object1.Fields.Add(("field3", new Float(null, 32), null, new BiPaGe.AST.Literals.Float(null, "123.456")));
            object1.Fields.Add(("field4", new Float(null, 64), null, new BiPaGe.AST.Literals.Float(null, "-3.14")));
            object1.Fields.Add(("field5", new BiPaGe.AST.FieldTypes.Boolean(null), null, new BiPaGe.AST.Literals.Boolean(null, "true")));
            object1.Fields.Add(("field6", new BiPaGe.AST.FieldTypes.Boolean(null), null, new BiPaGe.AST.Literals.Boolean(null, "false")));
            expected.Validate(SimpleBuilder.Build("Object1{field1:uint32=500;field2:int16=-5;field3:float32=123.456;field4:float64=-3.14;field5:bool=true;field6:bool=false;}"));
        }
Esempio n. 10
0
        public void Bool()
        {
            var input    = @"
Object1
{
    field1 : bool = true;
    field2 : bool = false;
}";
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("field1", new BiPaGe.AST.FieldTypes.Boolean(null), null, new BiPaGe.AST.Literals.Boolean(null, "true")));
            object1.Fields.Add(("field2", new BiPaGe.AST.FieldTypes.Boolean(null), null, new BiPaGe.AST.Literals.Boolean(null, "false")));
            expected.Validate(SimpleBuilder.Build(input));
        }
Esempio n. 11
0
        public void SingleEmbedded()
        {
            var input    = @"
Object1
{
    field1 : i32;
    field2 : SomeOtherObject;
}
";
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("field1", new Signed(null, 32), null, null));
            object1.Fields.Add(("field2", new Identifier(null, "SomeOtherObject"), null, null));
            expected.Validate(SimpleBuilder.Build(input));
        }
Esempio n. 12
0
        public void TrippleLevelSingleValue()
        {
            var input    = @"
Object1
{
    field1 : i32;
    field2 : SomeOtherObject(parent.parent.field1 = 5);
}";
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("field1", new Signed(null, 32), null, null));
            object1.Fields.Add(("field2", new Identifier(null, "SomeOtherObject"), null,
                                new BiPaGe.AST.Constants.ObjectConstant(null,
                                                                        new List <ObjectField> {
                new ObjectField("parent.paernt.field1", new BiPaGe.AST.Literals.Integer(null, "5"))
            })));
            expected.Validate(SimpleBuilder.Build(input));
        }
Esempio n. 13
0
        public void Collection()
        {
            var expected = new Helpers.ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add((null, new Signed(null, 32), new BiPaGe.AST.Literals.Integer(null, "5"), null));
            object1.Fields.Add((null, new AsciiString(null), new BiPaGe.AST.Literals.Integer(null, "32"), null));
            object1.Fields.Add((null, new Utf8String(null), new BiPaGe.AST.Literals.Integer(null, "255"), null));
            object1.Fields.Add((null, new AsciiString(null), new BiPaGe.AST.Identifiers.FieldIdentifier(null, "size"), null));
            var field5_size = new Division(
                null,
                new Subtraction(
                    null,
                    new FieldIdentifier(null, "size"),
                    new This(null)
                    ),
                new BiPaGe.AST.Literals.Integer(null, "4"));

            object1.Fields.Add((null, new Unsigned(null, 32), field5_size, null));
            var field6_size = new Subtraction(
                null,
                new Addition(
                    null,
                    new FieldIdentifier(null, "size"),
                    new FieldIdentifier(null, "size2")
                    ),
                new Multiplication(
                    null,
                    new BiPaGe.AST.Literals.Integer(null, "10"),
                    new BiPaGe.AST.Literals.Integer(null, "5")
                    ));

            object1.Fields.Add((null, new BiPaGe.AST.FieldTypes.Boolean(null), field6_size, null));
            expected.Validate(SimpleBuilder.Build("Object1{int32[5];ascii_string[32];utf8_string[255];ascii_string[size];u32[(size - this) / 4];bool[size + size2 - 10 * 5];}"));
        }