...

Text file src/github.com/google/flatbuffers/tests/flatc/flatc_schema_tests.py

Documentation: github.com/google/flatbuffers/tests/flatc

     1# Copyright 2022 Google Inc. All rights reserved.
     2#
     3# Licensed under the Apache License, Version 2.0 (the "License");
     4# you may not use this file except in compliance with the License.
     5# You may obtain a copy of the License at
     6#
     7#     http://www.apache.org/licenses/LICENSE-2.0
     8#
     9# Unless required by applicable law or agreed to in writing, software
    10# distributed under the License is distributed on an "AS IS" BASIS,
    11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12# See the License for the specific language governing permissions and
    13# limitations under the License.
    14
    15from flatc_test import *
    16import json
    17
    18
    19class SchemaTests:
    20    def EnumValAttributes(self):
    21        # Generate .bfbs schema first
    22        flatc(["--schema", "--binary", "--bfbs-builtins", "enum_val_attributes.fbs"])
    23        assert_file_exists("enum_val_attributes.bfbs")
    24
    25        # Then turn it into JSON
    26        flatc(["--json", "--strict-json", str(reflection_fbs_path()), "--", "enum_val_attributes.bfbs"])
    27
    28        # The attributes should be present in JSON
    29        schema_json = json.loads(get_file_contents("enum_val_attributes.json"))
    30
    31        assert schema_json["enums"][0]["name"] == "ValAttributes"
    32        assert schema_json["enums"][0]["values"][0]["name"] == "Val1"
    33        assert schema_json["enums"][0]["values"][0]["attributes"][0]["key"] == "display_name"
    34        assert schema_json["enums"][0]["values"][0]["attributes"][0]["value"] == "Value 1"
    35
    36        assert schema_json["enums"][0]["values"][1]["name"] == "Val2"
    37        assert schema_json["enums"][0]["values"][1]["attributes"][0]["key"] == "display_name"
    38        assert schema_json["enums"][0]["values"][1]["attributes"][0]["value"] == "Value 2"
    39
    40        assert schema_json["enums"][0]["values"][2]["name"] == "Val3"
    41        assert schema_json["enums"][0]["values"][2]["attributes"][0]["key"] == "deprecated"
    42        assert schema_json["enums"][0]["values"][2]["attributes"][1]["key"] == "display_name"
    43        assert schema_json["enums"][0]["values"][2]["attributes"][1]["value"] == "Value 3 (deprecated)"

View as plain text