{"action":"created","comment":{"url":"https://api.github.com/repos/heremaps/flatdata/pulls/comments/167434068","pull_request_review_id":95651932,"id":167434068,"diff_hunk":"@@ -0,0 +1,1059 @@\n+'''\n+ Copyright (c) 2017 HERE Europe B.V.\n+ See the LICENSE file in the root of this project for license details.\n+'''\n+\n+from generator.generators.GoGenerator import GoGenerator\n+\n+from .assertions import *\n+\n+\n+def test_base_generation():\n+    generate_and_assert_in(\"\"\"namespace xyz{\n+        \n+}\n+    \"\"\", GoGenerator, \"\"\"/////////////////////////////////////////////////////////////////////////\n+//    ATTENTION!\n+//    This code is automatically generated by flatdata generator.\n+//    Any modifications to this file will be lost upon next regeneration.\n+/////////////////////////////////////////////////////////////////////////\n+package xyz\n+\n+import (\n+\t\"bytes\"\n+\t\"encoding/binary\"\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"log\"\n+\t\"strconv\"\n+\n+\t\"github.com/heremaps/flatdata/flatdata-go/flatdata\"\n+)\n+\n+const (\n+    flatdataOffsetSizeInBits uint = 64\n+    flatdataPaddingSizeInBits uint = 64\n+)\"\"\")\n+\n+\n+def test_constants_are_declared_correctly():\n+    generate_and_assert_in(\"\"\"\n+        namespace n{\n+        const i8 foo = 17;\n+        const u16 bar = 0x42;\n+        }\n+    \"\"\", GoGenerator, \"\"\"\n+    Bar uint16 = 0x42\n+    Foo int8 = 17\n+    \"\"\")\n+\n+\n+def test_structures_are_declared_correctly():\n+    expected_lines = [\n+        \"\"\"sSizeInBytes = 3\"\"\",\n+        \"\"\"type S struct {\n+    internal flatdata.ResourceHandle\n+\tposition int\n+\tmultivector bool\n+}\"\"\",\n+        \"\"\"func (v *S) GetF0() uint8 {\n+    elementSize := uint(3)\n+    elementOffset := uint(0)\n+    var b int\n+    if v.multivector {\n+        b = flatdata.Read(v.internal, (uint(v.position)*8)+elementOffset, elementSize, false)\n+    } else {\n+        b = flatdata.Read(v.internal, flatdataOffsetSizeInBits+(sSizeInBytes*8*uint(v.position))+elementOffset, elementSize, false)\n+    }\n+    return uint8(b)\n+}\"\"\",\n+        \"\"\"func (v *S) GetF1() uint16 {\n+    elementSize := uint(15)\n+    elementOffset := uint(3)\n+    var b int\n+    if v.multivector {\n+        b = flatdata.Read(v.internal, (uint(v.position)*8)+elementOffset, elementSize, false)\n+    } else {\n+        b = flatdata.Read(v.internal, flatdataOffsetSizeInBits+(sSizeInBytes*8*uint(v.position))+elementOffset, elementSize, false)\n+    }\n+    return uint16(b)\n+}\"\"\",\n+        \"\"\"func (v *S) ToString() string {\"\"\"\n+    ]\n+\n+    generate_and_assert_in(\"\"\"\n+        namespace n{\n+        struct S {\n+            f0 : u8 : 3;\n+            f1 : u16 : 15;\n+        }\n+        }\n+    \"\"\", GoGenerator, *expected_lines)\n+\n+\n+def test_archives_are_declared_correctly():\n+    expected_lines = [\n+        \"\"\"sSizeInBytes = 1\"\"\",\n+        \"\"\"type S struct {\n+    internal flatdata.ResourceHandle\n+\tposition int\n+    multivector bool\n+}\n+\n+func (v *S) GetF0() uint8 {\n+    elementSize := uint(3)\n+    elementOffset := uint(0)\n+    var b int\n+    if v.multivector {\n+        b = flatdata.Read(v.internal, (uint(v.position)*8)+elementOffset, elementSize, false)\n+    } else {\n+        b = flatdata.Read(v.internal, flatdataOffsetSizeInBits+(sSizeInBytes*8*uint(v.position))+elementOffset, elementSize, false)\n+    }\n+    return uint8(b)\n+}\"\"\",\n+        \"\"\"func (v *S) ToString() string {\"\"\",\n+        \"\"\"type AR0Instance struct {\n+    internal flatdata.ResourceHandle\n+    IsOptional bool\n+    IsOpen bool\n+}\n+\n+func (v *AR0Instance) Get() *S {\n+\treturn &S{\n+\t    internal: v.internal,\n+\t}\n+}\n+\n+func (v *AR0Instance) GetSize() int {\n+\treturn 1\n+}\n+\n+func (v *AR0Instance) Close() {\n+    v.internal.Close()\n+    v.IsOpen = false\n+}\n+\n+func (v *AR0Instance) GetSizeInBytes() int {\n+    return v.internal.Len()\n+}\"\"\",\n+        \"\"\"type AArchive struct {\n+    IsOptional bool\n+    IsOpen bool\n+    R0Instance *AR0Instance\n+}\n+\n+func (v *AArchive) Close() {\n+    if v.R0Instance.IsOpen {\n+        v.R0Instance.Close()\n+    }\n+}\n+\n+func (v *AArchive) GetSizeInBytes() int {\n+    var size int\n+    if v.R0Instance.IsOpen {\n+        size += v.R0Instance.GetSizeInBytes()\n+    }\n+    return size\n+}\"\"\",\n+        \"\"\"func OpenAArchive(resource flatdata.ResourceProvider) (*AArchive, error) {\n+    v := &AArchive{}\n+    // Initialize resources\n+\tr0IsOpen := true\n+\tr0Handle, schema, err := resource.GetHandle(\"r0\")\n+\tif err != nil {\n+        log.Println(err)\n+\t    if err.Error() == flatdata.ErrorCantAccessResource {\n+\t        r0IsOpen = false\n+\t    } else {\n+\t\t    return v, err\n+\t\t}\n+\t}\"\"\",\n+        \"\"\"// Add resources to archive\n+    v.R0Instance = &AR0Instance {\n+        internal: r0Handle,\n+        IsOptional: false,\n+        IsOpen: r0IsOpen,\n+    }\n+\treturn v, nil\n+}\"\"\"\n+    ]\n+\n+    generate_and_assert_in(\"\"\"\n+    namespace n{\n+    struct S {\n+        f0 : u8 : 3;\n+    }\n+    archive A {\n+        r0 : S;\n+    }\n+    }\"\"\", GoGenerator, *expected_lines)\n+\n+\n+def test_vector_resource_is_declared_correctly():\n+    expected_lines = [\n+        \"\"\"tSizeInBytes = 1\"\"\",\n+        \"\"\"type T struct {\n+    internal flatdata.ResourceHandle\n+\tposition int\n+    multivector bool\n+}\n+\n+func (v *T) GetF0() uint8 {\n+    elementSize := uint(3)\n+    elementOffset := uint(0)\n+    var b int\n+    if v.multivector {\n+        b = flatdata.Read(v.internal, (uint(v.position)*8)+elementOffset, elementSize, false)\n+    } else {\n+        b = flatdata.Read(v.internal, flatdataOffsetSizeInBits+(tSizeInBytes*8*uint(v.position))+elementOffset, elementSize, false)\n+    }\n+    return uint8(b)\n+}\"\"\",\n+        \"\"\"func (v *T) ToString() string {\"\"\",\n+        \"\"\"type AVectorResourceVector struct {\n+    internal flatdata.ResourceHandle\n+    IsOptional bool\n+    IsOpen bool\n+}\n+\n+func (v *AVectorResourceVector) Get(i int) *T {\n+\treturn &T{\n+\t\tinternal: v.internal,\n+\t\tposition: i,\n+\t}\n+}\n+\n+func (v *AVectorResourceVector) GetSize() int {\n+\tsize := make([]byte, 8)\n+\t_, err := v.internal.ReadAt(size, 0)\n+\tif err != nil {\n+\t\treturn 0\n+\t}\n+\tintSize := binary.LittleEndian.Uint64(size)\n+\treturn int(intSize) / tSizeInBytes\n+}\n+\n+func (v *AVectorResourceVector) GetSlice(start, end, step int) []*T {\n+\tvar result []*T\t\n+\tfor start <= end {\n+\t\tresult = append(result, &T{\n+\t\t\tinternal: v.internal,\n+\t\t\tposition: start,\n+\t\t})\n+\t\tstart += step\n+\t}\n+\treturn result\n+}\n+\n+func (v *AVectorResourceVector) Close() {\n+    v.internal.Close()\n+    v.IsOpen = false\n+}\n+\n+func (v *AVectorResourceVector) GetSizeInBytes() int {\n+    return v.internal.Len()\n+}\"\"\",\n+        \"\"\"type AArchive struct {\n+    IsOptional bool\n+    IsOpen bool\n+    VectorResourceVector *AVectorResourceVector\n+}\n+\n+func (v *AArchive) Close() {\n+    if v.VectorResourceVector.IsOpen {\n+        v.VectorResourceVector.Close()\n+    }\n+}\n+\n+func (v *AArchive) GetSizeInBytes() int {\n+    var size int\n+    if v.VectorResourceVector.IsOpen {\n+        size += v.VectorResourceVector.GetSizeInBytes()\n+    }\n+    return size\n+}\"\"\",\n+        \"\"\"func OpenAArchive(resource flatdata.ResourceProvider) (*AArchive, error) {\n+    v := &AArchive{}\n+    // Initialize resources\n+\tvectorResourceIsOpen := true\n+\tvectorResourceHandle, schema, err := resource.GetHandle(\"vector_resource\")\n+\tif err != nil {\n+        log.Println(err)\n+\t    if err.Error() == flatdata.ErrorCantAccessResource {\n+\t        vectorResourceIsOpen = false\n+\t    } else {\n+\t\t    return v, err\n+\t\t}\n+\t}\"\"\",\n+        \"\"\"// Add resources to archive\n+    v.VectorResourceVector = &AVectorResourceVector{\n+        internal: vectorResourceHandle,\n+        IsOptional: false,\n+        IsOpen: vectorResourceIsOpen,\n+    }\n+\treturn v, nil\n+}\"\"\"\n+    ]\n+\n+    generate_and_assert_in(\"\"\"\n+    namespace n{\n+    struct T {\n+        f0 : u8 : 3;\n+    }\n+    archive A {\n+        vector_resource : vector< T >;\n+    }\n+    }\"\"\", GoGenerator, *expected_lines)\n+\n+\n+def test_multi_vector_resource_is_declared_correctly():\n+    expected_lines = [\n+        \"\"\"indexType33SizeInBytes = 5\n+    uSizeInBytes = 1\n+    tSizeInBytes = 1\"\"\",\n+        \"\"\"type IndexType33 struct {\n+    internal flatdata.ResourceHandle\n+\tposition int\n+    multivector bool\n+}\n+\n+func (v *IndexType33) GetValue() uint64 {\n+    elementSize := uint(33)\n+    elementOffset := uint(0)\n+    var b int\n+    if v.multivector {\n+        b = flatdata.Read(v.internal, (uint(v.position)*8)+elementOffset, elementSize, false)\n+    } else {\n+        b = flatdata.Read(v.internal, flatdataOffsetSizeInBits+(indexType33SizeInBytes*8*uint(v.position))+elementOffset, elementSize, false)\n+    }\n+    return uint64(b)\n+}\"\"\",\n+        \"\"\"type U struct {\n+    internal flatdata.ResourceHandle\n+\tposition int\n+    multivector bool\n+}\n+\n+func (v *U) GetF0() uint8 {\n+    elementSize := uint(3)\n+    elementOffset := uint(0)\n+    var b int\n+    if v.multivector {\n+        b = flatdata.Read(v.internal, (uint(v.position)*8)+elementOffset, elementSize, false)\n+    } else {\n+        b = flatdata.Read(v.internal, flatdataOffsetSizeInBits+(uSizeInBytes*8*uint(v.position))+elementOffset, elementSize, false)\n+    }\n+    return uint8(b)\n+}\"\"\",\n+        \"\"\"type T struct {\n+    internal flatdata.ResourceHandle\n+\tposition int\n+    multivector bool\n+}\n+\n+func (v *T) GetF0() uint8 {\n+    elementSize := uint(3)\n+    elementOffset := uint(0)\n+    var b int\n+    if v.multivector {\n+        b = flatdata.Read(v.internal, (uint(v.position)*8)+elementOffset, elementSize, false)\n+    } else {\n+        b = flatdata.Read(v.internal, flatdataOffsetSizeInBits+(tSizeInBytes*8*uint(v.position))+elementOffset, elementSize, false)\n+    }\n+    return uint8(b)\n+}\"\"\",\n+        \"\"\"type AMultivectorResourceVector struct {\n+    internal flatdata.ResourceHandle\n+    IsOptional bool\n+    IsOpen bool\n+}\n+\n+func (v *AMultivectorResourceVector) Get(i int) *IndexType33 {\n+\treturn &IndexType33{\n+\t\tinternal: v.internal,\n+\t\tposition: i,\n+\t}\n+}\n+\n+func (v *AMultivectorResourceVector) GetSize() int {\n+\tsize := make([]byte, 8)\n+\t_, err := v.internal.ReadAt(size, 0)\n+\tif err != nil {\n+\t\treturn 0\n+\t}\n+\tintSize := binary.LittleEndian.Uint64(size)\n+\treturn int(intSize) / indexType33SizeInBytes\n+}\n+\n+func (v *AMultivectorResourceVector) GetSlice(start, end, step int) []*IndexType33 {\n+\tvar result []*IndexType33\t\n+\tfor start <= end {\n+\t\tresult = append(result, &IndexType33{\n+\t\t\tinternal: v.internal,\n+\t\t\tposition: start,\n+\t\t})\n+\t\tstart += step\n+\t}\n+\treturn result\n+}\n+\n+func (v *AMultivectorResourceVector) Close() {\n+    v.internal.Close()\n+    v.IsOpen = false\n+}\n+\n+func (v *AMultivectorResourceVector) GetSizeInBytes() int {\n+    return v.internal.Len()\n+}\"\"\",\n+        \"\"\"type AMultivectorResourceMultivector struct {\n+    internal flatdata.ResourceHandle\n+    index      *AMultivectorResourceVector\n+\ttypes      map[int]interface{}\n+    IsOptional bool\n+    IsOpen bool\n+}\n+\n+func (v *AMultivectorResourceMultivector) Close() {\n+    v.internal.Close()\n+    v.IsOpen = false\n+}\n+\n+func (v *AMultivectorResourceMultivector) GetSize() int {\n+\treturn v.index.GetSize()\n+}\n+\n+func (v *AMultivectorResourceMultivector) GetSizeInBytes() int {\n+    return v.internal.Len()\n+}\n+\n+func (v *AMultivectorResourceMultivector) getBucketOffset(i int) int {\n+\tif i == v.index.GetSize() {\n+\t\treturn v.internal.Len() - int(flatdataPaddingSizeInBits/8)\n+\t} \n+\treturn int(v.index.Get(i).GetValue()) + int(flatdataOffsetSizeInBits/8)\n+}\n+\n+func (v *AMultivectorResourceMultivector) Get(i int) []interface{} {\n+    offset := v.getBucketOffset(i)\n+\tnextOffset := v.getBucketOffset(i + 1)\n+\tvar result []interface{}\n+\n+\tfor offset < nextOffset {\n+\t    elementType := flatdata.Read(v.internal, uint(offset*8), 8, false)\n+\t\toffset++\n+\t\tabstractElement, ok := v.types[elementType]\n+\t\tif !ok {\n+\t\t\t//TODO: How to process case, then type of element is not found?\n+\t\t\tlog.Println(\"Can't get type of element\")\n+\t\t}\n+\t\ttemp := 0\n+\t\tswitch element := abstractElement.(type) {\n+\t\tcase *T:\n+\t\t\telement.position = offset\n+            element.multivector = true\n+\t\t\tresult = append(result, element)\n+\t\t\ttemp = tSizeInBytes\n+\t\tcase *U:\n+\t\t\telement.position = offset\n+            element.multivector = true\n+\t\t\tresult = append(result, element)\n+\t\t\ttemp = uSizeInBytes\n+\t\tdefault:\n+\t\t\t//TODO: How to react in case if it's impossible to cast?\n+\t\t\tlog.Println(\"Can't cast element. Type is unknown...\")\n+\t\t}\n+\t\toffset += temp\n+\t}\n+\t\n+\treturn result\n+}\"\"\",\n+        \"\"\"type AArchive struct {\n+    IsOptional bool\n+    IsOpen bool\n+    MultivectorResourceMultivector *AMultivectorResourceMultivector\n+}\n+\n+func (v *AArchive) Close() {\n+    if v.MultivectorResourceMultivector.IsOpen {\n+        v.MultivectorResourceMultivector.Close()\n+    }\n+}\n+\n+func (v *AArchive) GetSizeInBytes() int {\n+    var size int\n+    if v.MultivectorResourceMultivector.IsOpen {\n+        size += v.MultivectorResourceMultivector.GetSizeInBytes()\n+    }\n+    return size\n+}\"\"\",\n+        \"\"\"func OpenAArchive(resource flatdata.ResourceProvider) (*AArchive, error) {\n+    v := &AArchive{}\n+    // Initialize resources\n+\tmultivectorResourceIsOpen := true\n+\tmultivectorResourceHandle, schema, err := resource.GetHandle(\"multivector_resource\")\n+\tif err != nil {\n+        log.Println(err)\n+\t    if err.Error() == flatdata.ErrorCantAccessResource {\n+\t        multivectorResourceIsOpen = false\n+\t    } else {\n+\t\t    return v, err\n+\t\t}\n+\t}\n+\tmultivectorResourceIndexHandle, _, err := resource.GetHandle(\"multivector_resource_index\")\n+\tif err != nil {\n+\t    log.Println(err)\n+\t    if err.Error() == flatdata.ErrorCantAccessResource {\n+\t        multivectorResourceIsOpen = false\n+\t    } else {\n+\t\t    return v, err\n+\t\t}\n+\t}\"\"\",\n+        \"\"\"v.MultivectorResourceMultivector = &AMultivectorResourceMultivector{\n+        internal: multivectorResourceHandle,\n+        index: &AMultivectorResourceVector{internal: multivectorResourceIndexHandle},\n+        types: map[int]interface{}{\n+            0: &T{internal: multivectorResourceHandle},\n+            1: &U{internal: multivectorResourceHandle},\n+        },\n+        IsOptional: false,\n+        IsOpen: multivectorResourceIsOpen,\n+    }\n+\treturn v, nil\n+}\"\"\"\n+    ]\n+\n+    generate_and_assert_in(\"\"\"\n+    namespace n{\n+    struct U {\n+        f0 : u8 : 3;\n+    }\n+    struct T {\n+        f0 : u8 : 3;\n+    }\n+    archive A {\n+        multivector_resource : multivector< 33, T, U >;\n+    }\n+    }\"\"\", GoGenerator, *expected_lines)\n+\n+\n+def test_raw_data_resource_is_declared_correctly():\n+    expected_lines = [\n+        \"\"\"type ARawDataResourceRawData struct {\n+    internal flatdata.ResourceHandle\n+    IsOptional bool\n+    IsOpen bool\n+}\n+\n+func (v *ARawDataResourceRawData) GetValue() []byte {\n+\tdata := make([]byte, v.GetSize())\n+\t_, err := v.internal.ReadAt(data, 8)\n+\tif err != nil {\n+\t\treturn make([]byte, 0)\n+\t}\n+\treturn data\n+}\n+\n+func (v *ARawDataResourceRawData) GetSize() int {\n+\tsize := make([]byte, 8)\n+\t_, err := v.internal.ReadAt(size, 0)\n+\tif err != nil {\n+\t\treturn 0\n+\t}\n+\treturn int(binary.LittleEndian.Uint64(size))\n+}\n+\n+func (v *ARawDataResourceRawData) Close() {\n+    v.internal.Close()\n+    v.IsOpen = false\n+}\n+\n+func (v *ARawDataResourceRawData) GetSizeInBytes() int {\n+    return v.internal.Len()\n+}\"\"\",\n+        \"\"\"type AArchive struct {\n+    IsOptional bool\n+    IsOpen bool\n+    RawDataResourceRawData *ARawDataResourceRawData\n+}\n+\n+func (v *AArchive) Close() {\n+    if v.RawDataResourceRawData.IsOpen {\n+        v.RawDataResourceRawData.Close()\n+    }\n+}\n+\n+func (v *AArchive) GetSizeInBytes() int {\n+    var size int\n+    if v.RawDataResourceRawData.IsOpen {\n+        size += v.RawDataResourceRawData.GetSizeInBytes()\n+    }\n+    return size\n+}\"\"\",\n+        \"\"\"func OpenAArchive(resource flatdata.ResourceProvider) (*AArchive, error) {\n+    v := &AArchive{}\n+    // Initialize resources\n+\trawDataResourceIsOpen := true\n+\trawDataResourceHandle, schema, err := resource.GetHandle(\"raw_data_resource\")\n+\tif err != nil {\n+        log.Println(err)\n+\t    if err.Error() == flatdata.ErrorCantAccessResource {\n+\t        rawDataResourceIsOpen = false\n+\t    } else {\n+\t\t    return v, err\n+\t\t}\n+\t}\"\"\",\n+        \"\"\"v.RawDataResourceRawData = &ARawDataResourceRawData{\n+        internal: rawDataResourceHandle,\n+        IsOptional: false,\n+        IsOpen: rawDataResourceIsOpen,\n+    }\n+\treturn v, nil\n+}\"\"\"\n+    ]\n+\n+    generate_and_assert_in(\"\"\"\n+    namespace n{\n+    archive A {\n+        raw_data_resource : raw_data;\n+    }\n+    }\"\"\", GoGenerator, *expected_lines)\n+\n+\n+def test_structures_are_defined_correctly():\n+    expected_lines = [\n+        \"\"\"sSizeInBytes = 3\"\"\",\n+        \"\"\"type S struct {\n+    internal flatdata.ResourceHandle\n+\tposition int\n+\tmultivector bool\n+}\n+\n+func (v *S) GetF0() uint8 {\n+    elementSize := uint(7)\n+    elementOffset := uint(0)\n+    var b int\n+    if v.multivector {\n+        b = flatdata.Read(v.internal, (uint(v.position)*8)+elementOffset, elementSize, false)\n+    } else {\n+        b = flatdata.Read(v.internal, flatdataOffsetSizeInBits+(sSizeInBytes*8*uint(v.position))+elementOffset, elementSize, false)\n+    }\n+    return uint8(b)\n+}\n+\n+func (v *S) GetF1() int16 {\n+    elementSize := uint(13)\n+    elementOffset := uint(7)\n+    var b int\n+    if v.multivector {\n+        b = flatdata.Read(v.internal, (uint(v.position)*8)+elementOffset, elementSize, true)\n+    } else {\n+        b = flatdata.Read(v.internal, flatdataOffsetSizeInBits+(sSizeInBytes*8*uint(v.position))+elementOffset, elementSize, true)\n+    }\n+    return int16(b)\n+}\"\"\"\n+    ]\n+\n+    generate_and_assert_in(\"\"\"\n+    namespace n{\n+    struct S {\n+        f0 : u8 : 7;\n+        f1 : i16 : 13;\n+    }\n+    }\n+    \"\"\", GoGenerator, *expected_lines)\n+\n+\n+def test_archives_are_defined_correctly():\n+    expected_lines = [\n+        \"\"\"type ARawDataResourceRawData struct {\n+    internal flatdata.ResourceHandle\n+    IsOptional bool\n+    IsOpen bool\n+}\n+\n+func (v *ARawDataResourceRawData) GetValue() []byte {\n+\tdata := make([]byte, v.GetSize())\n+\t_, err := v.internal.ReadAt(data, 8)\n+\tif err != nil {\n+\t\treturn make([]byte, 0)\n+\t}\n+\treturn data\n+}\n+\n+func (v *ARawDataResourceRawData) GetSize() int {\n+\tsize := make([]byte, 8)\n+\t_, err := v.internal.ReadAt(size, 0)\n+\tif err != nil {\n+\t\treturn 0\n+\t}\n+\treturn int(binary.LittleEndian.Uint64(size))\n+}\n+\n+func (v *ARawDataResourceRawData) Close() {\n+    v.internal.Close()\n+    v.IsOpen = false\n+}\n+\n+func (v *ARawDataResourceRawData) GetSizeInBytes() int {\n+    return v.internal.Len()\n+}\"\"\",\n+        \"\"\"type AArchive struct {\n+    IsOptional bool\n+    IsOpen bool\n+    RawDataResourceRawData *ARawDataResourceRawData\n+}\n+\n+func (v *AArchive) Close() {\n+    if v.RawDataResourceRawData.IsOpen {\n+        v.RawDataResourceRawData.Close()\n+    }\n+}\n+\n+func (v *AArchive) GetSizeInBytes() int {\n+    var size int\n+    if v.RawDataResourceRawData.IsOpen {\n+        size += v.RawDataResourceRawData.GetSizeInBytes()\n+    }\n+    return size\n+}\"\"\",\n+        \"\"\"func OpenAArchive(resource flatdata.ResourceProvider) (*AArchive, error) {\n+    v := &AArchive{}\n+    // Initialize resources\n+\trawDataResourceIsOpen := true\n+\trawDataResourceHandle, schema, err := resource.GetHandle(\"raw_data_resource\")\n+\tif err != nil {\n+        log.Println(err)\n+\t    if err.Error() == flatdata.ErrorCantAccessResource {\n+\t        rawDataResourceIsOpen = false\n+\t    } else {\n+\t\t    return v, err\n+\t\t}\n+\t}\"\"\",\n+        \"\"\"// Add resources to archive\n+    v.RawDataResourceRawData = &ARawDataResourceRawData{\n+        internal: rawDataResourceHandle,\n+        IsOptional: false,\n+        IsOpen: rawDataResourceIsOpen,\n+    }\n+\treturn v, nil\n+}\"\"\"\n+    ]\n+\n+    generate_and_assert_in(\"\"\"\n+    namespace n{\n+    archive A {\n+        raw_data_resource : raw_data;\n+    }\n+    }\n+    \"\"\", GoGenerator, *expected_lines)\n+\n+\n+def test_optional_resource_is_declared_correctly():\n+    expected_lines = [\n+        \"\"\"type ARawDataResourceRawData struct {\n+    internal flatdata.ResourceHandle\n+    IsOptional bool\n+    IsOpen bool\n+}\n+\n+func (v *ARawDataResourceRawData) GetValue() []byte {\n+\tdata := make([]byte, v.GetSize())\n+\t_, err := v.internal.ReadAt(data, 8)\n+\tif err != nil {\n+\t\treturn make([]byte, 0)\n+\t}\n+\treturn data\n+}\n+\n+func (v *ARawDataResourceRawData) GetSize() int {\n+\tsize := make([]byte, 8)\n+\t_, err := v.internal.ReadAt(size, 0)\n+\tif err != nil {\n+\t\treturn 0\n+\t}\n+\treturn int(binary.LittleEndian.Uint64(size))\n+}\n+\n+func (v *ARawDataResourceRawData) Close() {\n+    v.internal.Close()\n+    v.IsOpen = false\n+}\n+\n+func (v *ARawDataResourceRawData) GetSizeInBytes() int {\n+    return v.internal.Len()\n+}\"\"\",\n+        \"\"\"type AArchive struct {\n+    IsOptional bool\n+    IsOpen bool\n+    RawDataResourceRawData *ARawDataResourceRawData\n+}\n+\n+func (v *AArchive) Close() {\n+    if v.RawDataResourceRawData.IsOpen {\n+        v.RawDataResourceRawData.Close()\n+    }\n+}\n+\n+func (v *AArchive) GetSizeInBytes() int {\n+    var size int\n+    if v.RawDataResourceRawData.IsOpen {\n+        size += v.RawDataResourceRawData.GetSizeInBytes()\n+    }\n+    return size\n+}\"\"\",\n+        \"\"\"func OpenAArchive(resource flatdata.ResourceProvider) (*AArchive, error) {\n+    v := &AArchive{}\n+    // Initialize resources\n+\trawDataResourceIsOpen := true\n+\trawDataResourceHandle, schema, err := resource.GetHandle(\"raw_data_resource\")\n+\tif err != nil {\n+        log.Println(err)\n+\t    if err.Error() == flatdata.ErrorCantAccessResource {\n+\t        rawDataResourceIsOpen = false\n+\t    } else {\n+\t\t    return v, err\n+\t\t}\n+\t}\"\"\",\n+        \"\"\"v.RawDataResourceRawData = &ARawDataResourceRawData{\n+        internal: rawDataResourceHandle,\n+        IsOptional: true,\n+        IsOpen: rawDataResourceIsOpen,\n+    }\n+\treturn v, nil\n+}\"\"\"\n+    ]\n+\n+    generate_and_assert_in(\"\"\"\n+    namespace n{\n+    archive A {\n+        @optional\n+        raw_data_resource : raw_data;\n+    }\n+    }\"\"\", GoGenerator, *expected_lines)\n+\n+\n+def test_optional_resource_is_declared_correctly():","path":"tests/generators/test_go_generator.py","position":835,"original_position":835,"commit_id":"38e1cd82f9a10166fb054a249c4c882f657e2d8e","original_commit_id":"38e1cd82f9a10166fb054a249c4c882f657e2d8e","user":{"login":"imagovrn","id":7044014,"avatar_url":"https://avatars3.githubusercontent.com/u/7044014?v=4","gravatar_id":"","url":"https://api.github.com/users/imagovrn","html_url":"https://github.com/imagovrn","followers_url":"https://api.github.com/users/imagovrn/followers","following_url":"https://api.github.com/users/imagovrn/following{/other_user}","gists_url":"https://api.github.com/users/imagovrn/gists{/gist_id}","starred_url":"https://api.github.com/users/imagovrn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imagovrn/subscriptions","organizations_url":"https://api.github.com/users/imagovrn/orgs","repos_url":"https://api.github.com/users/imagovrn/repos","events_url":"https://api.github.com/users/imagovrn/events{/privacy}","received_events_url":"https://api.github.com/users/imagovrn/received_events","type":"User","site_admin":false},"body":"In all tests (but here is a good example) please check only what is necessary. First tests exhaustively check the code for structures and resources. So here it's enough to only check lines responsible for \"optionality\". ","created_at":"2018-02-11T13:00:35Z","updated_at":"2018-02-11T13:13:59Z","html_url":"https://github.com/heremaps/flatdata/pull/16#discussion_r167434068","pull_request_url":"https://api.github.com/repos/heremaps/flatdata/pulls/16","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/heremaps/flatdata/pulls/comments/167434068"},"html":{"href":"https://github.com/heremaps/flatdata/pull/16#discussion_r167434068"},"pull_request":{"href":"https://api.github.com/repos/heremaps/flatdata/pulls/16"}}},"pull_request":{"url":"https://api.github.com/repos/heremaps/flatdata/pulls/16","id":166981255,"html_url":"https://github.com/heremaps/flatdata/pull/16","diff_url":"https://github.com/heremaps/flatdata/pull/16.diff","patch_url":"https://github.com/heremaps/flatdata/pull/16.patch","issue_url":"https://api.github.com/repos/heremaps/flatdata/issues/16","number":16,"state":"open","locked":false,"title":"Initial implementation of Flatdata reader in Go","user":{"login":"artemnikitin","id":2201424,"avatar_url":"https://avatars1.githubusercontent.com/u/2201424?v=4","gravatar_id":"","url":"https://api.github.com/users/artemnikitin","html_url":"https://github.com/artemnikitin","followers_url":"https://api.github.com/users/artemnikitin/followers","following_url":"https://api.github.com/users/artemnikitin/following{/other_user}","gists_url":"https://api.github.com/users/artemnikitin/gists{/gist_id}","starred_url":"https://api.github.com/users/artemnikitin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artemnikitin/subscriptions","organizations_url":"https://api.github.com/users/artemnikitin/orgs","repos_url":"https://api.github.com/users/artemnikitin/repos","events_url":"https://api.github.com/users/artemnikitin/events{/privacy}","received_events_url":"https://api.github.com/users/artemnikitin/received_events","type":"User","site_admin":false},"body":"Go implementation supports all features from C++/Python implementations.\r\nTo be able to run Go tests in Travis, Docker image should be updated from Dockerfile from this PR.","created_at":"2018-02-03T21:21:36Z","updated_at":"2018-02-11T13:13:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"88d8dcbb741bae122c9d294c7a33aa6efb692e16","assignee":null,"assignees":[],"requested_reviewers":[{"login":"VeaaC","id":14972638,"avatar_url":"https://avatars2.githubusercontent.com/u/14972638?v=4","gravatar_id":"","url":"https://api.github.com/users/VeaaC","html_url":"https://github.com/VeaaC","followers_url":"https://api.github.com/users/VeaaC/followers","following_url":"https://api.github.com/users/VeaaC/following{/other_user}","gists_url":"https://api.github.com/users/VeaaC/gists{/gist_id}","starred_url":"https://api.github.com/users/VeaaC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VeaaC/subscriptions","organizations_url":"https://api.github.com/users/VeaaC/orgs","repos_url":"https://api.github.com/users/VeaaC/repos","events_url":"https://api.github.com/users/VeaaC/events{/privacy}","received_events_url":"https://api.github.com/users/VeaaC/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":828534217,"url":"https://api.github.com/repos/heremaps/flatdata/labels/golang","name":"golang","color":"ce1873","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/heremaps/flatdata/pulls/16/commits","review_comments_url":"https://api.github.com/repos/heremaps/flatdata/pulls/16/comments","review_comment_url":"https://api.github.com/repos/heremaps/flatdata/pulls/comments{/number}","comments_url":"https://api.github.com/repos/heremaps/flatdata/issues/16/comments","statuses_url":"https://api.github.com/repos/heremaps/flatdata/statuses/38e1cd82f9a10166fb054a249c4c882f657e2d8e","head":{"label":"artemnikitin:go-reader-v1","ref":"go-reader-v1","sha":"38e1cd82f9a10166fb054a249c4c882f657e2d8e","user":{"login":"artemnikitin","id":2201424,"avatar_url":"https://avatars1.githubusercontent.com/u/2201424?v=4","gravatar_id":"","url":"https://api.github.com/users/artemnikitin","html_url":"https://github.com/artemnikitin","followers_url":"https://api.github.com/users/artemnikitin/followers","following_url":"https://api.github.com/users/artemnikitin/following{/other_user}","gists_url":"https://api.github.com/users/artemnikitin/gists{/gist_id}","starred_url":"https://api.github.com/users/artemnikitin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artemnikitin/subscriptions","organizations_url":"https://api.github.com/users/artemnikitin/orgs","repos_url":"https://api.github.com/users/artemnikitin/repos","events_url":"https://api.github.com/users/artemnikitin/events{/privacy}","received_events_url":"https://api.github.com/users/artemnikitin/received_events","type":"User","site_admin":false},"repo":{"id":119341128,"name":"flatdata","full_name":"artemnikitin/flatdata","owner":{"login":"artemnikitin","id":2201424,"avatar_url":"https://avatars1.githubusercontent.com/u/2201424?v=4","gravatar_id":"","url":"https://api.github.com/users/artemnikitin","html_url":"https://github.com/artemnikitin","followers_url":"https://api.github.com/users/artemnikitin/followers","following_url":"https://api.github.com/users/artemnikitin/following{/other_user}","gists_url":"https://api.github.com/users/artemnikitin/gists{/gist_id}","starred_url":"https://api.github.com/users/artemnikitin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artemnikitin/subscriptions","organizations_url":"https://api.github.com/users/artemnikitin/orgs","repos_url":"https://api.github.com/users/artemnikitin/repos","events_url":"https://api.github.com/users/artemnikitin/events{/privacy}","received_events_url":"https://api.github.com/users/artemnikitin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/artemnikitin/flatdata","description":"Zero-copy memory-mapped data storage ","fork":true,"url":"https://api.github.com/repos/artemnikitin/flatdata","forks_url":"https://api.github.com/repos/artemnikitin/flatdata/forks","keys_url":"https://api.github.com/repos/artemnikitin/flatdata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/artemnikitin/flatdata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/artemnikitin/flatdata/teams","hooks_url":"https://api.github.com/repos/artemnikitin/flatdata/hooks","issue_events_url":"https://api.github.com/repos/artemnikitin/flatdata/issues/events{/number}","events_url":"https://api.github.com/repos/artemnikitin/flatdata/events","assignees_url":"https://api.github.com/repos/artemnikitin/flatdata/assignees{/user}","branches_url":"https://api.github.com/repos/artemnikitin/flatdata/branches{/branch}","tags_url":"https://api.github.com/repos/artemnikitin/flatdata/tags","blobs_url":"https://api.github.com/repos/artemnikitin/flatdata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/artemnikitin/flatdata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/artemnikitin/flatdata/git/refs{/sha}","trees_url":"https://api.github.com/repos/artemnikitin/flatdata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/artemnikitin/flatdata/statuses/{sha}","languages_url":"https://api.github.com/repos/artemnikitin/flatdata/languages","stargazers_url":"https://api.github.com/repos/artemnikitin/flatdata/stargazers","contributors_url":"https://api.github.com/repos/artemnikitin/flatdata/contributors","subscribers_url":"https://api.github.com/repos/artemnikitin/flatdata/subscribers","subscription_url":"https://api.github.com/repos/artemnikitin/flatdata/subscription","commits_url":"https://api.github.com/repos/artemnikitin/flatdata/commits{/sha}","git_commits_url":"https://api.github.com/repos/artemnikitin/flatdata/git/commits{/sha}","comments_url":"https://api.github.com/repos/artemnikitin/flatdata/comments{/number}","issue_comment_url":"https://api.github.com/repos/artemnikitin/flatdata/issues/comments{/number}","contents_url":"https://api.github.com/repos/artemnikitin/flatdata/contents/{+path}","compare_url":"https://api.github.com/repos/artemnikitin/flatdata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/artemnikitin/flatdata/merges","archive_url":"https://api.github.com/repos/artemnikitin/flatdata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/artemnikitin/flatdata/downloads","issues_url":"https://api.github.com/repos/artemnikitin/flatdata/issues{/number}","pulls_url":"https://api.github.com/repos/artemnikitin/flatdata/pulls{/number}","milestones_url":"https://api.github.com/repos/artemnikitin/flatdata/milestones{/number}","notifications_url":"https://api.github.com/repos/artemnikitin/flatdata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/artemnikitin/flatdata/labels{/name}","releases_url":"https://api.github.com/repos/artemnikitin/flatdata/releases{/id}","deployments_url":"https://api.github.com/repos/artemnikitin/flatdata/deployments","created_at":"2018-01-29T06:25:40Z","updated_at":"2018-02-03T10:07:18Z","pushed_at":"2018-02-11T08:06:19Z","git_url":"git://github.com/artemnikitin/flatdata.git","ssh_url":"git@github.com:artemnikitin/flatdata.git","clone_url":"https://github.com/artemnikitin/flatdata.git","svn_url":"https://github.com/artemnikitin/flatdata","homepage":"","size":182,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"heremaps:master","ref":"master","sha":"ab0d9741e0e6c9375f61c20e654bf33651733386","user":{"login":"heremaps","id":2835506,"avatar_url":"https://avatars0.githubusercontent.com/u/2835506?v=4","gravatar_id":"","url":"https://api.github.com/users/heremaps","html_url":"https://github.com/heremaps","followers_url":"https://api.github.com/users/heremaps/followers","following_url":"https://api.github.com/users/heremaps/following{/other_user}","gists_url":"https://api.github.com/users/heremaps/gists{/gist_id}","starred_url":"https://api.github.com/users/heremaps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heremaps/subscriptions","organizations_url":"https://api.github.com/users/heremaps/orgs","repos_url":"https://api.github.com/users/heremaps/repos","events_url":"https://api.github.com/users/heremaps/events{/privacy}","received_events_url":"https://api.github.com/users/heremaps/received_events","type":"Organization","site_admin":false},"repo":{"id":118035076,"name":"flatdata","full_name":"heremaps/flatdata","owner":{"login":"heremaps","id":2835506,"avatar_url":"https://avatars0.githubusercontent.com/u/2835506?v=4","gravatar_id":"","url":"https://api.github.com/users/heremaps","html_url":"https://github.com/heremaps","followers_url":"https://api.github.com/users/heremaps/followers","following_url":"https://api.github.com/users/heremaps/following{/other_user}","gists_url":"https://api.github.com/users/heremaps/gists{/gist_id}","starred_url":"https://api.github.com/users/heremaps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heremaps/subscriptions","organizations_url":"https://api.github.com/users/heremaps/orgs","repos_url":"https://api.github.com/users/heremaps/repos","events_url":"https://api.github.com/users/heremaps/events{/privacy}","received_events_url":"https://api.github.com/users/heremaps/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/heremaps/flatdata","description":"Zero copy memory-mapped data storage ","fork":false,"url":"https://api.github.com/repos/heremaps/flatdata","forks_url":"https://api.github.com/repos/heremaps/flatdata/forks","keys_url":"https://api.github.com/repos/heremaps/flatdata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/heremaps/flatdata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/heremaps/flatdata/teams","hooks_url":"https://api.github.com/repos/heremaps/flatdata/hooks","issue_events_url":"https://api.github.com/repos/heremaps/flatdata/issues/events{/number}","events_url":"https://api.github.com/repos/heremaps/flatdata/events","assignees_url":"https://api.github.com/repos/heremaps/flatdata/assignees{/user}","branches_url":"https://api.github.com/repos/heremaps/flatdata/branches{/branch}","tags_url":"https://api.github.com/repos/heremaps/flatdata/tags","blobs_url":"https://api.github.com/repos/heremaps/flatdata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/heremaps/flatdata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/heremaps/flatdata/git/refs{/sha}","trees_url":"https://api.github.com/repos/heremaps/flatdata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/heremaps/flatdata/statuses/{sha}","languages_url":"https://api.github.com/repos/heremaps/flatdata/languages","stargazers_url":"https://api.github.com/repos/heremaps/flatdata/stargazers","contributors_url":"https://api.github.com/repos/heremaps/flatdata/contributors","subscribers_url":"https://api.github.com/repos/heremaps/flatdata/subscribers","subscription_url":"https://api.github.com/repos/heremaps/flatdata/subscription","commits_url":"https://api.github.com/repos/heremaps/flatdata/commits{/sha}","git_commits_url":"https://api.github.com/repos/heremaps/flatdata/git/commits{/sha}","comments_url":"https://api.github.com/repos/heremaps/flatdata/comments{/number}","issue_comment_url":"https://api.github.com/repos/heremaps/flatdata/issues/comments{/number}","contents_url":"https://api.github.com/repos/heremaps/flatdata/contents/{+path}","compare_url":"https://api.github.com/repos/heremaps/flatdata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/heremaps/flatdata/merges","archive_url":"https://api.github.com/repos/heremaps/flatdata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/heremaps/flatdata/downloads","issues_url":"https://api.github.com/repos/heremaps/flatdata/issues{/number}","pulls_url":"https://api.github.com/repos/heremaps/flatdata/pulls{/number}","milestones_url":"https://api.github.com/repos/heremaps/flatdata/milestones{/number}","notifications_url":"https://api.github.com/repos/heremaps/flatdata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/heremaps/flatdata/labels{/name}","releases_url":"https://api.github.com/repos/heremaps/flatdata/releases{/id}","deployments_url":"https://api.github.com/repos/heremaps/flatdata/deployments","created_at":"2018-01-18T20:34:58Z","updated_at":"2018-02-08T18:25:59Z","pushed_at":"2018-02-11T11:34:59Z","git_url":"git://github.com/heremaps/flatdata.git","ssh_url":"git@github.com:heremaps/flatdata.git","clone_url":"https://github.com/heremaps/flatdata.git","svn_url":"https://github.com/heremaps/flatdata","homepage":"","size":404,"stargazers_count":12,"watchers_count":12,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":5,"mirror_url":null,"archived":false,"open_issues_count":17,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":5,"open_issues":17,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/heremaps/flatdata/pulls/16"},"html":{"href":"https://github.com/heremaps/flatdata/pull/16"},"issue":{"href":"https://api.github.com/repos/heremaps/flatdata/issues/16"},"comments":{"href":"https://api.github.com/repos/heremaps/flatdata/issues/16/comments"},"review_comments":{"href":"https://api.github.com/repos/heremaps/flatdata/pulls/16/comments"},"review_comment":{"href":"https://api.github.com/repos/heremaps/flatdata/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/heremaps/flatdata/pulls/16/commits"},"statuses":{"href":"https://api.github.com/repos/heremaps/flatdata/statuses/38e1cd82f9a10166fb054a249c4c882f657e2d8e"}},"author_association":"NONE"}}
{"actor":{"display_login":"imagovrn"}}