# Basic test for support of protobuf "editions" feature
# that replaces the proto2/proto3 syntax specifiers.

Import("env")

import re
version = None
if 'PROTOC_VERSION' in env:
    match = re.search('([0-9]+).([0-9]+)', env['PROTOC_VERSION'])
    version = (int(match.group(1)), int(match.group(2)))

# Edition 2024 is supported by protoc >= 32.x
if env.GetOption('clean') or (version and version[0] >= 32):
    env.NanopbProto("edition_2024.proto")
    enc = env.Program(["encode_2024.c", "edition_2024.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"])
    dec = env.Program(["decode_2024.c", "edition_2024.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"])

    env.RunTest(enc)
    env.RunTest([dec, "encode_2024.output"])
    env.Decode(["encode_2024.output", "edition_2024.proto"], MESSAGE = "EditionMessage")
    env.Compare(["decode_2024.output", "encode_2024.decoded"])
