text:
using Orleans.Serialization.Buffers;
using Orleans.Serialization.Cloning;
using Orleans.Serialization.GeneratedCodeHelpers;
using Orleans.Serialization.WireProtocol;
using System;
using System.Runtime.CompilerServices;

namespace Orleans.Serialization.Codecs
{
    /// <summary>
    /// Serializer for <see cref="ValueTuple"/>.
    /// </summary>
    [RegisterSerializer]
    public sealed class ValueTupleCodec : IFieldCodec<ValueTuple>
    {
        /// <inheritdoc />
        void IFieldCodec<ValueTuple>.WriteField<TBufferWriter>(ref Writer<TBufferWriter> writer, uint fieldIdDelta, Type expectedType, ValueTuple value)
        {
            ReferenceCodec.MarkValueField(writer.Session);
            writer.WriteFieldHeader(fieldIdDelta, expectedType, value.GetType(), WireType.VarInt);
            writer.WriteVarUInt32(0);
        }

        /// <inheritdoc />
        ValueTuple IFieldCodec<ValueTuple>.ReadValue<TInput>(ref Reader<TInput> reader, Field field)
        {
            if (field.WireType != WireType.VarInt)
            {
                ThrowUnsupportedWireTypeException();
            }

            ReferenceCodec.MarkValueField(reader.Session);
            _ = reader.ReadVarUInt64();

            return default;
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void ThrowUnsupportedWireTypeException() => throw new UnsupportedWireTypeException(
            $"Only a {nameof(WireType)} value of {WireType.TagDelimited} is supported for tuple fields.");
    }

    /// <summary>
    /// Copier for <see cref="ValueTuple"/>.
    /// </summary>
    [RegisterCopier]
    public class ValueTupleCopier : IDeepCopier<ValueTuple>
    {
        public ValueTuple DeepCopy(ValueTuple input, CopyContext _) => input;
    }

    /// <summary>
    /// Serializer for <see cref="ValueTuple{T1}"/>.
    /// </summary>
    /// <typeparam name="T">The element type.</typeparam>
    [RegisterSerializer]
    public sealed class ValueTupleCodec<T> : IFieldCodec<ValueTuple<T>>
    {
        private static readonly Type ElementType1 = typeof(T);

        private readonly IFieldCodec<T> _valueCodec;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCodec{T}"/> class.
        /// </summary>
        /// <param name="valueCodec">The value codec.</param>
        public ValueTupleCodec(IFieldCodec<T> valueCodec)
        {
            _valueCodec = OrleansGeneratedCodeHelper.UnwrapService(this, valueCodec);
        }

        /// <inheritdoc />
        void IFieldCodec<ValueTuple<T>>.WriteField<TBufferWriter>(
            ref Writer<TBufferWriter> writer,
            uint fieldIdDelta,
            Type expectedType,
            ValueTuple<T> value)
        {
            ReferenceCodec.MarkValueField(writer.Session);
            writer.WriteFieldHeader(fieldIdDelta, expectedType, value.GetType(), WireType.TagDelimited);

            _valueCodec.WriteField(ref writer, 1, ElementType1, value.Item1);

            writer.WriteEndObject();
        }

        /// <inheritdoc />
        ValueTuple<T> IFieldCodec<ValueTuple<T>>.ReadValue<TInput>(ref Reader<TInput> reader, Field field)
        {
            if (field.WireType != WireType.TagDelimited)
            {
                ThrowUnsupportedWireTypeException();
            }

            ReferenceCodec.MarkValueField(reader.Session);
            var item1 = default(T);
            uint fieldId = 0;
            while (true)
            {
                var header = reader.ReadFieldHeader();
                if (header.IsEndBaseOrEndObject)
                {
                    break;
                }

                fieldId += header.FieldIdDelta;
                switch (fieldId)
                {
                    case 1:
                        item1 = _valueCodec.ReadValue(ref reader, header);
                        break;
                    default:
                        reader.ConsumeUnknownField(header);
                        break;
                }
            }

            return new ValueTuple<T>(item1);
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void ThrowUnsupportedWireTypeException() => throw new UnsupportedWireTypeException(
            $"Only a {nameof(WireType)} value of {WireType.TagDelimited} is supported for tuple fields.");
    }

    /// <summary>
    /// Copier for <see cref="ValueTuple{T}"/>.
    /// </summary>
    /// <typeparam name="T">The element type.</typeparam>
    [RegisterCopier]
    public class ValueTupleCopier<T> : IDeepCopier<ValueTuple<T>>
    {
        private readonly IDeepCopier<T> _copier;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCopier{T}"/> class.
        /// </summary>
        /// <param name="copier">The copier.</param>
        public ValueTupleCopier(IDeepCopier<T> copier)
        {
            _copier = copier;
        }

        /// <inheritdoc />
        public ValueTuple<T> DeepCopy(ValueTuple<T> input, CopyContext context) => new(_copier.DeepCopy(input.Item1, context));
    }

    /// <summary>
    /// Serializer for <see cref="ValueTuple{T1, T2}"/>
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    [RegisterSerializer]
    public sealed class ValueTupleCodec<T1, T2> : IFieldCodec<ValueTuple<T1, T2>>
    {
        private static readonly Type ElementType1 = typeof(T1);
        private static readonly Type ElementType2 = typeof(T2);

        private readonly IFieldCodec<T1> _item1Codec;
        private readonly IFieldCodec<T2> _item2Codec;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCodec{T1, T2}"/> class.
        /// </summary>
        /// <param name="item1Codec">The <typeparamref name="T1"/> codec.</param>
        /// <param name="item2Codec">The <typeparamref name="T2"/> codec.</param>
        public ValueTupleCodec(IFieldCodec<T1> item1Codec, IFieldCodec<T2> item2Codec)
        {
            _item1Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item1Codec);
            _item2Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item2Codec);
        }

        /// <inheritdoc />
        void IFieldCodec<ValueTuple<T1, T2>>.WriteField<TBufferWriter>(
            ref Writer<TBufferWriter> writer,
            uint fieldIdDelta,
            Type expectedType,
            (T1, T2) value)
        {
            ReferenceCodec.MarkValueField(writer.Session);
            writer.WriteFieldHeader(fieldIdDelta, expectedType, value.GetType(), WireType.TagDelimited);

            _item1Codec.WriteField(ref writer, 1, ElementType1, value.Item1);
            _item2Codec.WriteField(ref writer, 1, ElementType2, value.Item2);

            writer.WriteEndObject();
        }

        /// <inheritdoc />
        (T1, T2) IFieldCodec<ValueTuple<T1, T2>>.ReadValue<TInput>(ref Reader<TInput> reader, Field field)
        {
            if (field.WireType != WireType.TagDelimited)
            {
                ThrowUnsupportedWireTypeException();
            }

            ReferenceCodec.MarkValueField(reader.Session);
            var item1 = default(T1);
            var item2 = default(T2);
            uint fieldId = 0;
            while (true)
            {
                var header = reader.ReadFieldHeader();
                if (header.IsEndBaseOrEndObject)
                {
                    break;
                }

                fieldId += header.FieldIdDelta;
                switch (fieldId)
                {
                    case 1:
                        item1 = _item1Codec.ReadValue(ref reader, header);
                        break;
                    case 2:
                        item2 = _item2Codec.ReadValue(ref reader, header);
                        break;
                    default:
                        reader.ConsumeUnknownField(header);
                        break;
                }
            }

            return new ValueTuple<T1, T2>(item1, item2);
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void ThrowUnsupportedWireTypeException() => throw new UnsupportedWireTypeException(
            $"Only a {nameof(WireType)} value of {WireType.TagDelimited} is supported for tuple fields.");
    }

    /// <summary>
    /// Copier for <see cref="ValueTuple{T1, T2}"/>
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    [RegisterCopier]
    public class ValueTupleCopier<T1, T2> : IDeepCopier<ValueTuple<T1, T2>>
    {
        private readonly IDeepCopier<T1> _copier1;
        private readonly IDeepCopier<T2> _copier2;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCopier{T1, T2}"/> class.
        /// </summary>
        /// <param name="copier1">The copier for <typeparamref name="T1"/>.</param>
        /// <param name="copier2">The copier for <typeparamref name="T2"/>.</param>
        public ValueTupleCopier(IDeepCopier<T1> copier1, IDeepCopier<T2> copier2)
        {
            _copier1 = copier1;
            _copier2 = copier2;
        }

        /// <inheritdoc />
        public ValueTuple<T1, T2> DeepCopy(ValueTuple<T1, T2> input, CopyContext context) => ValueTuple.Create(
                _copier1.DeepCopy(input.Item1, context),
                _copier2.DeepCopy(input.Item2, context));
    }

    /// <summary>
    /// Serializer for <see cref="ValueTuple{T1, T2, T3}"/>.
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
    [RegisterSerializer]
    public sealed class ValueTupleCodec<T1, T2, T3> : IFieldCodec<ValueTuple<T1, T2, T3>>
    {
        private static readonly Type ElementType1 = typeof(T1);
        private static readonly Type ElementType2 = typeof(T2);
        private static readonly Type ElementType3 = typeof(T3);

        private readonly IFieldCodec<T1> _item1Codec;
        private readonly IFieldCodec<T2> _item2Codec;
        private readonly IFieldCodec<T3> _item3Codec;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCodec{T1, T2, T3}"/> class.
        /// </summary>
        /// <param name="item1Codec">The <typeparamref name="T1"/> codec.</param>
        /// <param name="item2Codec">The <typeparamref name="T2"/> codec.</param>
        /// <param name="item3Codec">The <typeparamref name="T3"/> codec.</param>
        public ValueTupleCodec(
            IFieldCodec<T1> item1Codec,
            IFieldCodec<T2> item2Codec,
            IFieldCodec<T3> item3Codec)
        {
            _item1Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item1Codec);
            _item2Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item2Codec);
            _item3Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item3Codec);
        }

        /// <inheritdoc />
        void IFieldCodec<ValueTuple<T1, T2, T3>>.WriteField<TBufferWriter>(
            ref Writer<TBufferWriter> writer,
            uint fieldIdDelta,
            Type expectedType,
            (T1, T2, T3) value)
        {
            ReferenceCodec.MarkValueField(writer.Session);
            writer.WriteFieldHeader(fieldIdDelta, expectedType, value.GetType(), WireType.TagDelimited);

            _item1Codec.WriteField(ref writer, 1, ElementType1, value.Item1);
            _item2Codec.WriteField(ref writer, 1, ElementType2, value.Item2);
            _item3Codec.WriteField(ref writer, 1, ElementType3, value.Item3);

            writer.WriteEndObject();
        }

        /// <inheritdoc />
        (T1, T2, T3) IFieldCodec<ValueTuple<T1, T2, T3>>.ReadValue<TInput>(ref Reader<TInput> reader, Field field)
        {
            if (field.WireType != WireType.TagDelimited)
            {
                ThrowUnsupportedWireTypeException();
            }

            ReferenceCodec.MarkValueField(reader.Session);
            var item1 = default(T1);
            var item2 = default(T2);
            var item3 = default(T3);
            uint fieldId = 0;
            while (true)
            {
                var header = reader.ReadFieldHeader();
                if (header.IsEndBaseOrEndObject)
                {
                    break;
                }

                fieldId += header.FieldIdDelta;
                switch (fieldId)
                {
                    case 1:
                        item1 = _item1Codec.ReadValue(ref reader, header);
                        break;
                    case 2:
                        item2 = _item2Codec.ReadValue(ref reader, header);
                        break;
                    case 3:
                        item3 = _item3Codec.ReadValue(ref reader, header);
                        break;
                    default:
                        reader.ConsumeUnknownField(header);
                        break;
                }
            }

            return new ValueTuple<T1, T2, T3>(item1, item2, item3);
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void ThrowUnsupportedWireTypeException() => throw new UnsupportedWireTypeException(
            $"Only a {nameof(WireType)} value of {WireType.TagDelimited} is supported for tuple fields.");
    }

    /// <summary>
    /// Copier for <see cref="ValueTuple{T1, T2, T3}"/>.
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
    [RegisterCopier]
    public class ValueTupleCopier<T1, T2, T3> : IDeepCopier<ValueTuple<T1, T2, T3>>
    {
        private readonly IDeepCopier<T1> _copier1;
        private readonly IDeepCopier<T2> _copier2;
        private readonly IDeepCopier<T3> _copier3;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCopier{T1, T2, T3}"/> class.
        /// </summary>
        /// <param name="copier1">The <typeparamref name="T1"/> copier.</param>
        /// <param name="copier2">The <typeparamref name="T2"/> copier.</param>
        /// <param name="copier3">The <typeparamref name="T3"/> copier.</param>
        public ValueTupleCopier(
            IDeepCopier<T1> copier1,
            IDeepCopier<T2> copier2,
            IDeepCopier<T3> copier3)
        {
            _copier1 = copier1;
            _copier2 = copier2;
            _copier3 = copier3;
        }

        /// <inheritdoc />
        public ValueTuple<T1, T2, T3> DeepCopy(ValueTuple<T1, T2, T3> input, CopyContext context) => ValueTuple.Create(
                _copier1.DeepCopy(input.Item1, context),
                _copier2.DeepCopy(input.Item2, context),
                _copier3.DeepCopy(input.Item3, context));
    }

    /// <summary>
    /// Serializer for <see cref="ValueTuple{T1, T2, T3, T4}"/>.
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
    /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
    [RegisterSerializer]
    public sealed class ValueTupleCodec<T1, T2, T3, T4> : IFieldCodec<ValueTuple<T1, T2, T3, T4>>
    {
        private static readonly Type ElementType1 = typeof(T1);
        private static readonly Type ElementType2 = typeof(T2);
        private static readonly Type ElementType3 = typeof(T3);
        private static readonly Type ElementType4 = typeof(T4);

        private readonly IFieldCodec<T1> _item1Codec;
        private readonly IFieldCodec<T2> _item2Codec;
        private readonly IFieldCodec<T3> _item3Codec;
        private readonly IFieldCodec<T4> _item4Codec;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCodec{T1, T2, T3, T4}"/> class.
        /// </summary>
        /// <param name="item1Codec">The <typeparamref name="T1"/> codec.</param>
        /// <param name="item2Codec">The <typeparamref name="T2"/> codec.</param>
        /// <param name="item3Codec">The <typeparamref name="T3"/> codec.</param>
        /// <param name="item4Codec">The <typeparamref name="T4"/> codec.</param>
        public ValueTupleCodec(
            IFieldCodec<T1> item1Codec,
            IFieldCodec<T2> item2Codec,
            IFieldCodec<T3> item3Codec,
            IFieldCodec<T4> item4Codec)
        {
            _item1Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item1Codec);
            _item2Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item2Codec);
            _item3Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item3Codec);
            _item4Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item4Codec);
        }

        /// <inheritdoc />
        void IFieldCodec<ValueTuple<T1, T2, T3, T4>>.WriteField<TBufferWriter>(
            ref Writer<TBufferWriter> writer,
            uint fieldIdDelta,
            Type expectedType,
            (T1, T2, T3, T4) value)
        {
            ReferenceCodec.MarkValueField(writer.Session);
            writer.WriteFieldHeader(fieldIdDelta, expectedType, value.GetType(), WireType.TagDelimited);

            _item1Codec.WriteField(ref writer, 1, ElementType1, value.Item1);
            _item2Codec.WriteField(ref writer, 1, ElementType2, value.Item2);
            _item3Codec.WriteField(ref writer, 1, ElementType3, value.Item3);
            _item4Codec.WriteField(ref writer, 1, ElementType4, value.Item4);

            writer.WriteEndObject();
        }

        /// <inheritdoc />
        (T1, T2, T3, T4) IFieldCodec<ValueTuple<T1, T2, T3, T4>>.ReadValue<TInput>(ref Reader<TInput> reader, Field field)
        {
            if (field.WireType != WireType.TagDelimited)
            {
                ThrowUnsupportedWireTypeException();
            }

            ReferenceCodec.MarkValueField(reader.Session);
            var item1 = default(T1);
            var item2 = default(T2);
            var item3 = default(T3);
            var item4 = default(T4);
            uint fieldId = 0;
            while (true)
            {
                var header = reader.ReadFieldHeader();
                if (header.IsEndBaseOrEndObject)
                {
                    break;
                }

                fieldId += header.FieldIdDelta;
                switch (fieldId)
                {
                    case 1:
                        item1 = _item1Codec.ReadValue(ref reader, header);
                        break;
                    case 2:
                        item2 = _item2Codec.ReadValue(ref reader, header);
                        break;
                    case 3:
                        item3 = _item3Codec.ReadValue(ref reader, header);
                        break;
                    case 4:
                        item4 = _item4Codec.ReadValue(ref reader, header);
                        break;
                    default:
                        reader.ConsumeUnknownField(header);
                        break;
                }
            }

            return new ValueTuple<T1, T2, T3, T4>(item1, item2, item3, item4);
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void ThrowUnsupportedWireTypeException() => throw new UnsupportedWireTypeException(
            $"Only a {nameof(WireType)} value of {WireType.TagDelimited} is supported for tuple fields.");
    }

    /// <summary>
    /// Copier for <see cref="ValueTuple{T1, T2, T3, T4}"/>.
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
    /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
    [RegisterCopier]
    public class ValueTupleCopier<T1, T2, T3, T4> : IDeepCopier<ValueTuple<T1, T2, T3, T4>>
    {
        private readonly IDeepCopier<T1> _copier1;
        private readonly IDeepCopier<T2> _copier2;
        private readonly IDeepCopier<T3> _copier3;
        private readonly IDeepCopier<T4> _copier4;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCopier{T1, T2, T3, T4}"/> class.
        /// </summary>
        /// <param name="copier1">The <typeparamref name="T1"/> copier.</param>
        /// <param name="copier2">The <typeparamref name="T2"/> copier.</param>
        /// <param name="copier3">The <typeparamref name="T3"/> copier.</param>
        /// <param name="copier4">The <typeparamref name="T4"/> copier.</param>
        public ValueTupleCopier(
            IDeepCopier<T1> copier1,
            IDeepCopier<T2> copier2,
            IDeepCopier<T3> copier3,
            IDeepCopier<T4> copier4)
        {
            _copier1 = copier1;
            _copier2 = copier2;
            _copier3 = copier3;
            _copier4 = copier4;
        }

        /// <inheritdoc />
        public ValueTuple<T1, T2, T3, T4> DeepCopy(ValueTuple<T1, T2, T3, T4> input, CopyContext context) => ValueTuple.Create(
                _copier1.DeepCopy(input.Item1, context),
                _copier2.DeepCopy(input.Item2, context),
                _copier3.DeepCopy(input.Item3, context),
                _copier4.DeepCopy(input.Item4, context));
    }

    /// <summary>
    /// Serializer for <see cref="ValueTuple{T1, T2, T3, T4, T5}"/>.
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
    /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
    /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
    [RegisterSerializer]
    public sealed class ValueTupleCodec<T1, T2, T3, T4, T5> : IFieldCodec<ValueTuple<T1, T2, T3, T4, T5>>
    {
        private static readonly Type ElementType1 = typeof(T1);
        private static readonly Type ElementType2 = typeof(T2);
        private static readonly Type ElementType3 = typeof(T3);
        private static readonly Type ElementType4 = typeof(T4);
        private static readonly Type ElementType5 = typeof(T5);

        private readonly IFieldCodec<T1> _item1Codec;
        private readonly IFieldCodec<T2> _item2Codec;
        private readonly IFieldCodec<T3> _item3Codec;
        private readonly IFieldCodec<T4> _item4Codec;
        private readonly IFieldCodec<T5> _item5Codec;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCodec{T1, T2, T3, T4, T5}"/> class.
        /// </summary>
        /// <param name="item1Codec">The <typeparamref name="T1"/> codec.</param>
        /// <param name="item2Codec">The <typeparamref name="T2"/> codec.</param>
        /// <param name="item3Codec">The <typeparamref name="T3"/> codec.</param>
        /// <param name="item4Codec">The <typeparamref name="T4"/> codec.</param>
        /// <param name="item5Codec">The <typeparamref name="T5"/> codec.</param>
        public ValueTupleCodec(
            IFieldCodec<T1> item1Codec,
            IFieldCodec<T2> item2Codec,
            IFieldCodec<T3> item3Codec,
            IFieldCodec<T4> item4Codec,
            IFieldCodec<T5> item5Codec)
        {
            _item1Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item1Codec);
            _item2Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item2Codec);
            _item3Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item3Codec);
            _item4Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item4Codec);
            _item5Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item5Codec);
        }

        /// <inheritdoc />
        void IFieldCodec<ValueTuple<T1, T2, T3, T4, T5>>.WriteField<TBufferWriter>(ref Writer<TBufferWriter> writer,
            uint fieldIdDelta,
            Type expectedType,
            (T1, T2, T3, T4, T5) value)
        {
            ReferenceCodec.MarkValueField(writer.Session);
            writer.WriteFieldHeader(fieldIdDelta, expectedType, value.GetType(), WireType.TagDelimited);

            _item1Codec.WriteField(ref writer, 1, ElementType1, value.Item1);
            _item2Codec.WriteField(ref writer, 1, ElementType2, value.Item2);
            _item3Codec.WriteField(ref writer, 1, ElementType3, value.Item3);
            _item4Codec.WriteField(ref writer, 1, ElementType4, value.Item4);
            _item5Codec.WriteField(ref writer, 1, ElementType5, value.Item5);

            writer.WriteEndObject();
        }

        /// <inheritdoc />
        (T1, T2, T3, T4, T5) IFieldCodec<ValueTuple<T1, T2, T3, T4, T5>>.ReadValue<TInput>(ref Reader<TInput> reader, Field field)
        {
            if (field.WireType != WireType.TagDelimited)
            {
                ThrowUnsupportedWireTypeException();
            }

            ReferenceCodec.MarkValueField(reader.Session);
            var item1 = default(T1);
            var item2 = default(T2);
            var item3 = default(T3);
            var item4 = default(T4);
            var item5 = default(T5);
            uint fieldId = 0;
            while (true)
            {
                var header = reader.ReadFieldHeader();
                if (header.IsEndBaseOrEndObject)
                {
                    break;
                }

                fieldId += header.FieldIdDelta;
                switch (fieldId)
                {
                    case 1:
                        item1 = _item1Codec.ReadValue(ref reader, header);
                        break;
                    case 2:
                        item2 = _item2Codec.ReadValue(ref reader, header);
                        break;
                    case 3:
                        item3 = _item3Codec.ReadValue(ref reader, header);
                        break;
                    case 4:
                        item4 = _item4Codec.ReadValue(ref reader, header);
                        break;
                    case 5:
                        item5 = _item5Codec.ReadValue(ref reader, header);
                        break;
                    default:
                        reader.ConsumeUnknownField(header);
                        break;
                }
            }

            return new ValueTuple<T1, T2, T3, T4, T5>(item1, item2, item3, item4, item5);
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void ThrowUnsupportedWireTypeException() => throw new UnsupportedWireTypeException(
            $"Only a {nameof(WireType)} value of {WireType.TagDelimited} is supported for tuple fields.");
    }

    /// <summary>
    /// Copier for <see cref="ValueTuple{T1, T2, T3, T4, T5}"/>.
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
    /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
    /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
    [RegisterCopier]
    public class ValueTupleCopier<T1, T2, T3, T4, T5> : IDeepCopier<ValueTuple<T1, T2, T3, T4, T5>>
    {
        private readonly IDeepCopier<T1> _copier1;
        private readonly IDeepCopier<T2> _copier2;
        private readonly IDeepCopier<T3> _copier3;
        private readonly IDeepCopier<T4> _copier4;
        private readonly IDeepCopier<T5> _copier5;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCopier{T1, T2, T3, T4, T5}"/> class.
        /// </summary>
        /// <param name="copier1">The <typeparamref name="T1"/> copier.</param>
        /// <param name="copier2">The <typeparamref name="T2"/> copier.</param>
        /// <param name="copier3">The <typeparamref name="T3"/> copier.</param>
        /// <param name="copier4">The <typeparamref name="T4"/> copier.</param>
        /// <param name="copier5">The <typeparamref name="T5"/> copier.</param>
        public ValueTupleCopier(
            IDeepCopier<T1> copier1,
            IDeepCopier<T2> copier2,
            IDeepCopier<T3> copier3,
            IDeepCopier<T4> copier4,
            IDeepCopier<T5> copier5)
        {
            _copier1 = copier1;
            _copier2 = copier2;
            _copier3 = copier3;
            _copier4 = copier4;
            _copier5 = copier5;
        }

        /// <inheritdoc />
        public ValueTuple<T1, T2, T3, T4, T5> DeepCopy(ValueTuple<T1, T2, T3, T4, T5> input, CopyContext context) => ValueTuple.Create(
                _copier1.DeepCopy(input.Item1, context),
                _copier2.DeepCopy(input.Item2, context),
                _copier3.DeepCopy(input.Item3, context),
                _copier4.DeepCopy(input.Item4, context),
                _copier5.DeepCopy(input.Item5, context));
    }

    /// <summary>
    /// Serializer for <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/>.
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
    /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
    /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
    /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
    [RegisterSerializer]
    public sealed class ValueTupleCodec<T1, T2, T3, T4, T5, T6> : IFieldCodec<ValueTuple<T1, T2, T3, T4, T5, T6>>
    {
        private static readonly Type ElementType1 = typeof(T1);
        private static readonly Type ElementType2 = typeof(T2);
        private static readonly Type ElementType3 = typeof(T3);
        private static readonly Type ElementType4 = typeof(T4);
        private static readonly Type ElementType5 = typeof(T5);
        private static readonly Type ElementType6 = typeof(T6);

        private readonly IFieldCodec<T1> _item1Codec;
        private readonly IFieldCodec<T2> _item2Codec;
        private readonly IFieldCodec<T3> _item3Codec;
        private readonly IFieldCodec<T4> _item4Codec;
        private readonly IFieldCodec<T5> _item5Codec;
        private readonly IFieldCodec<T6> _item6Codec;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCodec{T1, T2, T3, T4, T5, T6}"/> class.
        /// </summary>
        /// <param name="item1Codec">The <typeparamref name="T1"/> codec.</param>
        /// <param name="item2Codec">The <typeparamref name="T2"/> codec.</param>
        /// <param name="item3Codec">The <typeparamref name="T3"/> codec.</param>
        /// <param name="item4Codec">The <typeparamref name="T4"/> codec.</param>
        /// <param name="item5Codec">The <typeparamref name="T5"/> codec.</param>
        /// <param name="item6Codec">The <typeparamref name="T6"/> codec.</param>
        public ValueTupleCodec(
            IFieldCodec<T1> item1Codec,
            IFieldCodec<T2> item2Codec,
            IFieldCodec<T3> item3Codec,
            IFieldCodec<T4> item4Codec,
            IFieldCodec<T5> item5Codec,
            IFieldCodec<T6> item6Codec)
        {
            _item1Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item1Codec);
            _item2Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item2Codec);
            _item3Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item3Codec);
            _item4Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item4Codec);
            _item5Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item5Codec);
            _item6Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item6Codec);
        }

        /// <inheritdoc />
        void IFieldCodec<ValueTuple<T1, T2, T3, T4, T5, T6>>.WriteField<TBufferWriter>(ref Writer<TBufferWriter> writer,
            uint fieldIdDelta,
            Type expectedType,
            (T1, T2, T3, T4, T5, T6) value)
        {
            ReferenceCodec.MarkValueField(writer.Session);
            writer.WriteFieldHeader(fieldIdDelta, expectedType, value.GetType(), WireType.TagDelimited);

            _item1Codec.WriteField(ref writer, 1, ElementType1, value.Item1);
            _item2Codec.WriteField(ref writer, 1, ElementType2, value.Item2);
            _item3Codec.WriteField(ref writer, 1, ElementType3, value.Item3);
            _item4Codec.WriteField(ref writer, 1, ElementType4, value.Item4);
            _item5Codec.WriteField(ref writer, 1, ElementType5, value.Item5);
            _item6Codec.WriteField(ref writer, 1, ElementType6, value.Item6);

            writer.WriteEndObject();
        }

        /// <inheritdoc />
        (T1, T2, T3, T4, T5, T6) IFieldCodec<ValueTuple<T1, T2, T3, T4, T5, T6>>.ReadValue<TInput>(ref Reader<TInput> reader, Field field)
        {
            if (field.WireType != WireType.TagDelimited)
            {
                ThrowUnsupportedWireTypeException();
            }

            ReferenceCodec.MarkValueField(reader.Session);
            var item1 = default(T1);
            var item2 = default(T2);
            var item3 = default(T3);
            var item4 = default(T4);
            var item5 = default(T5);
            var item6 = default(T6);
            uint fieldId = 0;
            while (true)
            {
                var header = reader.ReadFieldHeader();
                if (header.IsEndBaseOrEndObject)
                {
                    break;
                }

                fieldId += header.FieldIdDelta;
                switch (fieldId)
                {
                    case 1:
                        item1 = _item1Codec.ReadValue(ref reader, header);
                        break;
                    case 2:
                        item2 = _item2Codec.ReadValue(ref reader, header);
                        break;
                    case 3:
                        item3 = _item3Codec.ReadValue(ref reader, header);
                        break;
                    case 4:
                        item4 = _item4Codec.ReadValue(ref reader, header);
                        break;
                    case 5:
                        item5 = _item5Codec.ReadValue(ref reader, header);
                        break;
                    case 6:
                        item6 = _item6Codec.ReadValue(ref reader, header);
                        break;
                    default:
                        reader.ConsumeUnknownField(header);
                        break;
                }
            }

            return new ValueTuple<T1, T2, T3, T4, T5, T6>(item1, item2, item3, item4, item5, item6);
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void ThrowUnsupportedWireTypeException() => throw new UnsupportedWireTypeException(
            $"Only a {nameof(WireType)} value of {WireType.TagDelimited} is supported for tuple fields.");
    }

    /// <summary>
    /// Copier for <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/>.
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
    /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
    /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
    /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
    [RegisterCopier]
    public class ValueTupleCopier<T1, T2, T3, T4, T5, T6> : IDeepCopier<ValueTuple<T1, T2, T3, T4, T5, T6>>
    {
        private readonly IDeepCopier<T1> _copier1;
        private readonly IDeepCopier<T2> _copier2;
        private readonly IDeepCopier<T3> _copier3;
        private readonly IDeepCopier<T4> _copier4;
        private readonly IDeepCopier<T5> _copier5;
        private readonly IDeepCopier<T6> _copier6;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCopier{T1, T2, T3, T4, T5, T6}"/> class.
        /// </summary>
        /// <param name="copier1">The <typeparamref name="T1"/> copier.</param>
        /// <param name="copier2">The <typeparamref name="T2"/> copier.</param>
        /// <param name="copier3">The <typeparamref name="T3"/> copier.</param>
        /// <param name="copier4">The <typeparamref name="T4"/> copier.</param>
        /// <param name="copier5">The <typeparamref name="T5"/> copier.</param>
        /// <param name="copier6">The <typeparamref name="T6"/> copier.</param>
        public ValueTupleCopier(
            IDeepCopier<T1> copier1,
            IDeepCopier<T2> copier2,
            IDeepCopier<T3> copier3,
            IDeepCopier<T4> copier4,
            IDeepCopier<T5> copier5,
            IDeepCopier<T6> copier6)
        {
            _copier1 = copier1;
            _copier2 = copier2;
            _copier3 = copier3;
            _copier4 = copier4;
            _copier5 = copier5;
            _copier6 = copier6;
        }

        /// <inheritdoc />
        public ValueTuple<T1, T2, T3, T4, T5, T6> DeepCopy(ValueTuple<T1, T2, T3, T4, T5, T6> input, CopyContext context) => ValueTuple.Create(
                _copier1.DeepCopy(input.Item1, context),
                _copier2.DeepCopy(input.Item2, context),
                _copier3.DeepCopy(input.Item3, context),
                _copier4.DeepCopy(input.Item4, context),
                _copier5.DeepCopy(input.Item5, context),
                _copier6.DeepCopy(input.Item6, context));
    }

    /// <summary>
    /// Serializer for <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/>.
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
    /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
    /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
    /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
    /// <typeparam name="T7">The type of the tuple's seventh component.</typeparam>
    [RegisterSerializer]
    public sealed class ValueTupleCodec<T1, T2, T3, T4, T5, T6, T7> : IFieldCodec<ValueTuple<T1, T2, T3, T4, T5, T6, T7>>
    {
        private static readonly Type ElementType1 = typeof(T1);
        private static readonly Type ElementType2 = typeof(T2);
        private static readonly Type ElementType3 = typeof(T3);
        private static readonly Type ElementType4 = typeof(T4);
        private static readonly Type ElementType5 = typeof(T5);
        private static readonly Type ElementType6 = typeof(T6);
        private static readonly Type ElementType7 = typeof(T7);

        private readonly IFieldCodec<T1> _item1Codec;
        private readonly IFieldCodec<T2> _item2Codec;
        private readonly IFieldCodec<T3> _item3Codec;
        private readonly IFieldCodec<T4> _item4Codec;
        private readonly IFieldCodec<T5> _item5Codec;
        private readonly IFieldCodec<T6> _item6Codec;
        private readonly IFieldCodec<T7> _item7Codec;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCodec{T1, T2, T3, T4, T5, T6, T7}"/> class.
        /// </summary>
        /// <param name="item1Codec">The <typeparamref name="T1"/> codec.</param>
        /// <param name="item2Codec">The <typeparamref name="T2"/> codec.</param>
        /// <param name="item3Codec">The <typeparamref name="T3"/> codec.</param>
        /// <param name="item4Codec">The <typeparamref name="T4"/> codec.</param>
        /// <param name="item5Codec">The <typeparamref name="T5"/> codec.</param>
        /// <param name="item6Codec">The <typeparamref name="T6"/> codec.</param>
        /// <param name="item7Codec">The <typeparamref name="T7"/> codec.</param>
        public ValueTupleCodec(
            IFieldCodec<T1> item1Codec,
            IFieldCodec<T2> item2Codec,
            IFieldCodec<T3> item3Codec,
            IFieldCodec<T4> item4Codec,
            IFieldCodec<T5> item5Codec,
            IFieldCodec<T6> item6Codec,
            IFieldCodec<T7> item7Codec)
        {
            _item1Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item1Codec);
            _item2Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item2Codec);
            _item3Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item3Codec);
            _item4Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item4Codec);
            _item5Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item5Codec);
            _item6Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item6Codec);
            _item7Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item7Codec);
        }

        /// <inheritdoc />
        void IFieldCodec<ValueTuple<T1, T2, T3, T4, T5, T6, T7>>.WriteField<TBufferWriter>(ref Writer<TBufferWriter> writer,
            uint fieldIdDelta,
            Type expectedType,
            (T1, T2, T3, T4, T5, T6, T7) value)
        {
            ReferenceCodec.MarkValueField(writer.Session);
            writer.WriteFieldHeader(fieldIdDelta, expectedType, value.GetType(), WireType.TagDelimited);

            _item1Codec.WriteField(ref writer, 1, ElementType1, value.Item1);
            _item2Codec.WriteField(ref writer, 1, ElementType2, value.Item2);
            _item3Codec.WriteField(ref writer, 1, ElementType3, value.Item3);
            _item4Codec.WriteField(ref writer, 1, ElementType4, value.Item4);
            _item5Codec.WriteField(ref writer, 1, ElementType5, value.Item5);
            _item6Codec.WriteField(ref writer, 1, ElementType6, value.Item6);
            _item7Codec.WriteField(ref writer, 1, ElementType7, value.Item7);

            writer.WriteEndObject();
        }

        /// <inheritdoc />
        (T1, T2, T3, T4, T5, T6, T7) IFieldCodec<ValueTuple<T1, T2, T3, T4, T5, T6, T7>>.ReadValue<TInput>(
            ref Reader<TInput> reader,
            Field field)
        {
            if (field.WireType != WireType.TagDelimited)
            {
                ThrowUnsupportedWireTypeException();
            }

            ReferenceCodec.MarkValueField(reader.Session);
            var item1 = default(T1);
            var item2 = default(T2);
            var item3 = default(T3);
            var item4 = default(T4);
            var item5 = default(T5);
            var item6 = default(T6);
            var item7 = default(T7);
            uint fieldId = 0;
            while (true)
            {
                var header = reader.ReadFieldHeader();
                if (header.IsEndBaseOrEndObject)
                {
                    break;
                }

                fieldId += header.FieldIdDelta;
                switch (fieldId)
                {
                    case 1:
                        item1 = _item1Codec.ReadValue(ref reader, header);
                        break;
                    case 2:
                        item2 = _item2Codec.ReadValue(ref reader, header);
                        break;
                    case 3:
                        item3 = _item3Codec.ReadValue(ref reader, header);
                        break;
                    case 4:
                        item4 = _item4Codec.ReadValue(ref reader, header);
                        break;
                    case 5:
                        item5 = _item5Codec.ReadValue(ref reader, header);
                        break;
                    case 6:
                        item6 = _item6Codec.ReadValue(ref reader, header);
                        break;
                    case 7:
                        item7 = _item7Codec.ReadValue(ref reader, header);
                        break;
                    default:
                        reader.ConsumeUnknownField(header);
                        break;
                }
            }

            return new ValueTuple<T1, T2, T3, T4, T5, T6, T7>(item1, item2, item3, item4, item5, item6, item7);
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void ThrowUnsupportedWireTypeException() => throw new UnsupportedWireTypeException(
            $"Only a {nameof(WireType)} value of {WireType.TagDelimited} is supported for tuple fields.");
    }

    /// <summary>
    /// Copier for <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/>.
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
    /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
    /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
    /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
    /// <typeparam name="T7">The type of the tuple's seventh component.</typeparam>
    [RegisterCopier]
    public class ValueTupleCopier<T1, T2, T3, T4, T5, T6, T7> : IDeepCopier<ValueTuple<T1, T2, T3, T4, T5, T6, T7>>
    {
        private readonly IDeepCopier<T1> _copier1;
        private readonly IDeepCopier<T2> _copier2;
        private readonly IDeepCopier<T3> _copier3;
        private readonly IDeepCopier<T4> _copier4;
        private readonly IDeepCopier<T5> _copier5;
        private readonly IDeepCopier<T6> _copier6;
        private readonly IDeepCopier<T7> _copier7;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCopier{T1, T2, T3, T4, T5, T6, T7}"/> class.
        /// </summary>
        /// <param name="copier1">The <typeparamref name="T1"/> copier.</param>
        /// <param name="copier2">The <typeparamref name="T2"/> copier.</param>
        /// <param name="copier3">The <typeparamref name="T3"/> copier.</param>
        /// <param name="copier4">The <typeparamref name="T4"/> copier.</param>
        /// <param name="copier5">The <typeparamref name="T5"/> copier.</param>
        /// <param name="copier6">The <typeparamref name="T6"/> copier.</param>
        /// <param name="copier7">The <typeparamref name="T7"/> copier.</param>
        public ValueTupleCopier(
            IDeepCopier<T1> copier1,
            IDeepCopier<T2> copier2,
            IDeepCopier<T3> copier3,
            IDeepCopier<T4> copier4,
            IDeepCopier<T5> copier5,
            IDeepCopier<T6> copier6,
            IDeepCopier<T7> copier7)
        {
            _copier1 = copier1;
            _copier2 = copier2;
            _copier3 = copier3;
            _copier4 = copier4;
            _copier5 = copier5;
            _copier6 = copier6;
            _copier7 = copier7;
        }

        /// <inheritdoc />
        public ValueTuple<T1, T2, T3, T4, T5, T6, T7> DeepCopy(ValueTuple<T1, T2, T3, T4, T5, T6, T7> input, CopyContext context) => ValueTuple.Create(
                _copier1.DeepCopy(input.Item1, context),
                _copier2.DeepCopy(input.Item2, context),
                _copier3.DeepCopy(input.Item3, context),
                _copier4.DeepCopy(input.Item4, context),
                _copier5.DeepCopy(input.Item5, context),
                _copier6.DeepCopy(input.Item6, context),
                _copier7.DeepCopy(input.Item7, context));
    }

    /// <summary>
    /// Serializer for <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, T8}"/>.
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
    /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
    /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
    /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
    /// <typeparam name="T7">The type of the tuple's seventh component.</typeparam>
    /// <typeparam name="T8">The type of the tuple's eighth component.</typeparam>
    [RegisterSerializer]
    public sealed class ValueTupleCodec<T1, T2, T3, T4, T5, T6, T7, T8> : IFieldCodec<ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8>> where T8 : struct
    {
        private static readonly Type ElementType1 = typeof(T1);
        private static readonly Type ElementType2 = typeof(T2);
        private static readonly Type ElementType3 = typeof(T3);
        private static readonly Type ElementType4 = typeof(T4);
        private static readonly Type ElementType5 = typeof(T5);
        private static readonly Type ElementType6 = typeof(T6);
        private static readonly Type ElementType7 = typeof(T7);
        private static readonly Type ElementType8 = typeof(T8);

        private readonly IFieldCodec<T1> _item1Codec;
        private readonly IFieldCodec<T2> _item2Codec;
        private readonly IFieldCodec<T3> _item3Codec;
        private readonly IFieldCodec<T4> _item4Codec;
        private readonly IFieldCodec<T5> _item5Codec;
        private readonly IFieldCodec<T6> _item6Codec;
        private readonly IFieldCodec<T7> _item7Codec;
        private readonly IFieldCodec<T8> _item8Codec;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCodec{T1, T2, T3, T4, T5, T6, T7, T8}"/> class.
        /// </summary>
        /// <param name="item1Codec">The <typeparamref name="T1"/> codec.</param>
        /// <param name="item2Codec">The <typeparamref name="T2"/> codec.</param>
        /// <param name="item3Codec">The <typeparamref name="T3"/> codec.</param>
        /// <param name="item4Codec">The <typeparamref name="T4"/> codec.</param>
        /// <param name="item5Codec">The <typeparamref name="T5"/> codec.</param>
        /// <param name="item6Codec">The <typeparamref name="T6"/> codec.</param>
        /// <param name="item7Codec">The <typeparamref name="T7"/> codec.</param>
        /// <param name="item8Codec">The <typeparamref name="T8"/> codec.</param>
        public ValueTupleCodec(
            IFieldCodec<T1> item1Codec,
            IFieldCodec<T2> item2Codec,
            IFieldCodec<T3> item3Codec,
            IFieldCodec<T4> item4Codec,
            IFieldCodec<T5> item5Codec,
            IFieldCodec<T6> item6Codec,
            IFieldCodec<T7> item7Codec,
            IFieldCodec<T8> item8Codec)
        {
            _item1Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item1Codec);
            _item2Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item2Codec);
            _item3Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item3Codec);
            _item4Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item4Codec);
            _item5Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item5Codec);
            _item6Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item6Codec);
            _item7Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item7Codec);
            _item8Codec = OrleansGeneratedCodeHelper.UnwrapService(this, item8Codec);
        }

        /// <inheritdoc />
        void IFieldCodec<ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8>>.WriteField<TBufferWriter>(
            ref Writer<TBufferWriter> writer,
            uint fieldIdDelta,
            Type expectedType,
            ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8> value)
        {
            ReferenceCodec.MarkValueField(writer.Session);
            writer.WriteFieldHeader(fieldIdDelta, expectedType, value.GetType(), WireType.TagDelimited);

            _item1Codec.WriteField(ref writer, 1, ElementType1, value.Item1);
            _item2Codec.WriteField(ref writer, 1, ElementType2, value.Item2);
            _item3Codec.WriteField(ref writer, 1, ElementType3, value.Item3);
            _item4Codec.WriteField(ref writer, 1, ElementType4, value.Item4);
            _item5Codec.WriteField(ref writer, 1, ElementType5, value.Item5);
            _item6Codec.WriteField(ref writer, 1, ElementType6, value.Item6);
            _item7Codec.WriteField(ref writer, 1, ElementType7, value.Item7);
            _item8Codec.WriteField(ref writer, 1, ElementType8, value.Rest);

            writer.WriteEndObject();
        }

        /// <inheritdoc />
        ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8> IFieldCodec<ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8>>.ReadValue<TInput>(ref Reader<TInput> reader,
            Field field)
        {
            if (field.WireType != WireType.TagDelimited)
            {
                ThrowUnsupportedWireTypeException();
            }

            ReferenceCodec.MarkValueField(reader.Session);
            var item1 = default(T1);
            var item2 = default(T2);
            var item3 = default(T3);
            var item4 = default(T4);
            var item5 = default(T5);
            var item6 = default(T6);
            var item7 = default(T7);
            var item8 = default(T8);
            uint fieldId = 0;
            while (true)
            {
                var header = reader.ReadFieldHeader();
                if (header.IsEndBaseOrEndObject)
                {
                    break;
                }

                fieldId += header.FieldIdDelta;
                switch (fieldId)
                {
                    case 1:
                        item1 = _item1Codec.ReadValue(ref reader, header);
                        break;
                    case 2:
                        item2 = _item2Codec.ReadValue(ref reader, header);
                        break;
                    case 3:
                        item3 = _item3Codec.ReadValue(ref reader, header);
                        break;
                    case 4:
                        item4 = _item4Codec.ReadValue(ref reader, header);
                        break;
                    case 5:
                        item5 = _item5Codec.ReadValue(ref reader, header);
                        break;
                    case 6:
                        item6 = _item6Codec.ReadValue(ref reader, header);
                        break;
                    case 7:
                        item7 = _item7Codec.ReadValue(ref reader, header);
                        break;
                    case 8:
                        item8 = _item8Codec.ReadValue(ref reader, header);
                        break;
                    default:
                        reader.ConsumeUnknownField(header);
                        break;
                }
            }

            return new ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8>(item1, item2, item3, item4, item5, item6, item7, item8);
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void ThrowUnsupportedWireTypeException() => throw new UnsupportedWireTypeException(
            $"Only a {nameof(WireType)} value of {WireType.TagDelimited} is supported for tuple fields.");
    }

    /// <summary>
    /// Copier for <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, T8}"/>.
    /// </summary>
    /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
    /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
    /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
    /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
    /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
    /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
    /// <typeparam name="T7">The type of the tuple's seventh component.</typeparam>
    /// <typeparam name="T8">The type of the tuple's eighth component.</typeparam>
    [RegisterCopier]
    public class ValueTupleCopier<T1, T2, T3, T4, T5, T6, T7, T8> : IDeepCopier<ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8>> where T8 : struct
    {
        private readonly IDeepCopier<T1> _copier1;
        private readonly IDeepCopier<T2> _copier2;
        private readonly IDeepCopier<T3> _copier3;
        private readonly IDeepCopier<T4> _copier4;
        private readonly IDeepCopier<T5> _copier5;
        private readonly IDeepCopier<T6> _copier6;
        private readonly IDeepCopier<T7> _copier7;
        private readonly IDeepCopier<T8> _copier8;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueTupleCopier{T1, T2, T3, T4, T5, T6, T7, T8}"/> class.
        /// </summary>
        /// <param name="copier1">The <typeparamref name="T1"/> copier.</param>
        /// <param name="copier2">The <typeparamref name="T2"/> copier.</param>
        /// <param name="copier3">The <typeparamref name="T3"/> copier.</param>
        /// <param name="copier4">The <typeparamref name="T4"/> copier.</param>
        /// <param name="copier5">The <typeparamref name="T5"/> copier.</param>
        /// <param name="copier6">The <typeparamref name="T6"/> copier.</param>
        /// <param name="copier7">The <typeparamref name="T7"/> copier.</param>
        /// <param name="copier8">The <typeparamref name="T8"/> copier.</param>
        public ValueTupleCopier(
            IDeepCopier<T1> copier1,
            IDeepCopier<T2> copier2,
            IDeepCopier<T3> copier3,
            IDeepCopier<T4> copier4,
            IDeepCopier<T5> copier5,
            IDeepCopier<T6> copier6,
            IDeepCopier<T7> copier7,
            IDeepCopier<T8> copier8)
        {
            _copier1 = copier1;
            _copier2 = copier2;
            _copier3 = copier3;
            _copier4 = copier4;
            _copier5 = copier5;
            _copier6 = copier6;
            _copier7 = copier7;
            _copier8 = copier8;
        }

        /// <inheritdoc />
        public ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8> DeepCopy(ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8> input, CopyContext context) => new(
                _copier1.DeepCopy(input.Item1, context),
                _copier2.DeepCopy(input.Item2, context),
                _copier3.DeepCopy(input.Item3, context),
                _copier4.DeepCopy(input.Item4, context),
                _copier5.DeepCopy(input.Item5, context),
                _copier6.DeepCopy(input.Item6, context),
                _copier7.DeepCopy(input.Item7, context),
                _copier8.DeepCopy(input.Rest, context));
    }
}


text:
<?php

declare(strict_types=1);

/**
 * This file is part of Narrowspark Framework.
 *
 * (c) Daniel Bannert <d.bannert@anolilab.de>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

//
// use Psr\Container\ContainerInterface;
// use Swift_Mailer;
// use Viserio\Contract\Container\ServiceProvider as ServiceProviderContract;
// use Viserio\Contract\Profiler\Profiler as ProfilerContract;
// use Viserio\Component\Profiler\DataCollector\Bridge\SwiftMailDataCollector;
//
// class ProfilerSwiftMailerBridgeServiceProvider implements ServiceProviderContract
// {
//    /**
//     * {@inheritdoc}
//     */
//    public function getFactories(): array
//    {
//        return [];
//    }
//
//    /**
//     * {@inheritdoc}
//     */
//    public function getExtensions(): array
//    {
//        return [
//            ProfilerContract::class => [self::class, 'extendProfiler'],
//        ];
//    }
//
//    /**
//     * Extend viserio profiler with data collector.
//     *
//     * @param \Psr\Container\ContainerInterface                  $container
//     * @param null|\Viserio\Contract\Profiler\Profiler $profiler
//     *
//     * @return null|\Viserio\Contract\Profiler\Profiler
//     */
//    public static function extendProfiler(
//        ContainerInterface $container,
//        ?ProfilerContract $profiler = null
//    ): ?ProfilerContract {
//        if ($profiler !== null) {
//            $profiler->addCollector(new SwiftMailDataCollector(
//                $container->get(Swift_Mailer::class)
//            ));
//        }
//
//        return $profiler;
//    }
// }

redpajama_set_name: RedPajamaGithub


text:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">
        <item
            android:id="@+id/course_table"
            android:title="@string/course_table" />
        <item
            android:id="@+id/grade"
            android:title="@string/grade" />
        <item
            android:id="@+id/plan"
            android:title="@string/plan" />
        <item
            android:id="@+id/course_class"
            android:title="@string/course_class" />
        <item
            android:id="@+id/setting"
            android:title="@string/setting" />
        <item
            android:id="@+id/logout"
            android:title="@string/logout" />
    </group>
</menu>


text:
package s29752.command.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import s29752.command.Sleep;

public abstract class GuiUtil {
  private static Clipboard systemClipboard;

  public static synchronized void copyToClipboard(String s) {
    if (systemClipboard == null)
      systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    systemClipboard.setContents(new StringSelection(s), new ClipboardOwner() {
      public void lostOwnership(Clipboard clipboard, Transferable contents) {}
    });
  }

  public static void exchangeColor(Component c) {
    final Color tmp = c.getBackground();
    c.setBackground(c.getForeground());
    c.setForeground(tmp);
  }

  public static void showAndWait(JFrame f) {
    for (f.setVisible(true); f.isVisible(); Sleep.second(1))
      ;
  }

  public static JFrame newJFrame(Component c, String title, int w, int h) {
    JFrame f = new JFrame(title);
    f.getContentPane().add(c, BorderLayout.CENTER);
    f.setSize(w, h);
    f.pack();
    // f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    return f;
  }

  public static JCheckBox newJCheckBox(String n, char m) {
    return newJCheckBox(n, m, false);
  }

  public static JCheckBox newJCheckBox(String n, char m, boolean isS) {
    JCheckBox cb = new JCheckBox(n);
    cb.setMnemonic(m);
    cb.setSelected(isS);
    return cb;
  }

  public static JButton newJButton(String name, String tooltip, ActionListener al) {
    JButton b = new JButton(name);
    b.setToolTipText(tooltip);
    b.addActionListener(al);
    return b;
  }

  public static JLabel newJLabel(String n, char m, Component c) {
    JLabel l = new JLabel(n);
    l.setDisplayedMnemonic(m);
    l.setLabelFor(c);
    return l;
  }

  public static JPanel newJPanel(Component... c) {
    JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
    for (int i = 0; i < c.length; i++)
      p.add(c[i]);
    return p;
  }

  public static JScrollPane newJScrollPane(String title, Component c) {
    JScrollPane sp = new JScrollPane(c);
    sp.setBorder(BorderFactory.createTitledBorder(title));
    return sp;
  }
}


text:
package actionerror

import "fmt"

// ApplicationInstanceCrashedError is returned when an instance crashes.
type ApplicationInstanceCrashedError struct {
	Name string
}

func (e ApplicationInstanceCrashedError) Error() string {
	return fmt.Sprintf("Application '%s' crashed", e.Name)
}


text:
class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :name
      t.string :ldap_id

      t.timestamps
    end
  end
end


text:
package org.apache.manifoldcf.agents.output.searchblox;

import org.apache.manifoldcf.agents.interfaces.RepositoryDocument;
import org.apache.manifoldcf.agents.output.searchblox.SearchBloxDocument.DocumentAction;
import org.apache.manifoldcf.agents.output.searchblox.SearchBloxDocument.IndexingFormat;
import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.*;

import static org.apache.manifoldcf.agents.output.searchblox.SearchBloxConfig.*;
import static org.apache.manifoldcf.agents.output.searchblox.SearchBloxDocument.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class SearchBloxDocumentTest {
    private SearchBloxDocument toTest;
    @Before
   public void setUp() throws ManifoldCFException {
       Map<String, List<String>> args=initArgs();
       String apikey="apikey";
        RepositoryDocument rd=initRepoDocument();
       String docURI = "URI";
       toTest=new SearchBloxDocument(apikey, docURI,rd,args);
   }

    @Test
    public void updateXmlString() throws SearchBloxException, ParserConfigurationException, SAXException, IOException {
        String xmlGenerated = toTest.toString(IndexingFormat.XML, DocumentAction.ADD_UPDATE);

        InputSource is = new InputSource(new ByteArrayInputStream(xmlGenerated.getBytes(StandardCharsets.UTF_8)));

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(is);
        doc.getDocumentElement().normalize();

        Element root = doc.getDocumentElement();
        assertEquals("searchblox", root.getNodeName());
        assertEquals("apikey", root.getAttribute(APIKEY_ATTRIBUTE));

        assertEquals(1, root.getElementsByTagName("document").getLength());
        assertEquals(Node.ELEMENT_NODE, root.getElementsByTagName("document").item(0).getNodeType());

        Element document = (Element) root.getElementsByTagName("document").item(0);
        assertEquals("collection1", document.getAttribute(COLNAME_ATTRIBUTE));

        NodeList nList = document.getChildNodes();
        assertEquals(18, nList.getLength());

        nList = document.getElementsByTagName(UID_ATTRIBUTE);
        assertEquals(1, nList.getLength());
        assertEquals(Node.ELEMENT_NODE, nList.item(0).getNodeType());
        assertEquals("URI", nList.item(0).getTextContent());

        nList = document.getElementsByTagName("title");
        assertEquals(1, nList.getLength());
        assertEquals(Node.ELEMENT_NODE, nList.item(0).getNodeType());
        assertEquals("I am a nice title", nList.item(0).getTextContent());
        assertEquals("1", ((Element) nList.item(0)).getAttribute(BOOST_ATTRIBUTE));

        nList = document.getElementsByTagName("content");
        assertEquals(1, nList.getLength());
        assertEquals(Node.ELEMENT_NODE, nList.item(0).getNodeType());
        assertEquals("I am a nice content in english!", nList.item(0).getTextContent());
        assertEquals("2", ((Element) nList.item(0)).getAttribute(BOOST_ATTRIBUTE));

        nList = document.getElementsByTagName("description");
        assertEquals(1, nList.getLength());
        assertEquals(Node.ELEMENT_NODE, nList.item(0).getNodeType());
        assertEquals("I am a little tiny description", nList.item(0).getTextContent());
        assertEquals("4", ((Element) nList.item(0)).getAttribute(BOOST_ATTRIBUTE));

        nList = document.getElementsByTagName("size");
        assertEquals(1, nList.getLength());
        assertEquals(Node.ELEMENT_NODE, nList.item(0).getNodeType());
        assertEquals("100", nList.item(0).getTextContent());

        nList = document.getElementsByTagName("contenttype");
        assertEquals(1, nList.getLength());
        assertEquals(Node.ELEMENT_NODE, nList.item(0).getNodeType());
        assertEquals("html", nList.item(0).getTextContent());

        nList = document.getElementsByTagName("meta");
        assertEquals(12, nList.getLength());

        assertTrue(find(nList, "meta2", "I am META2!"));
        assertTrue(find(nList, "meta1", "I am META1!"));

        assertTrue(find(nList, "share_allow", "user1"));
        assertTrue(find(nList, "share_allow", "user2"));
        assertTrue(find(nList, "share_allow", "user3"));

        assertTrue(find(nList, "document_deny", "user42"));
        assertTrue(find(nList, "document_deny", "user52"));

        assertTrue(find(nList, "share_deny", "user5"));
        assertTrue(find(nList, "share_deny", "user4"));

        assertTrue(find(nList, "document_allow", "user22"));
        assertTrue(find(nList, "document_allow", "user33"));
        assertTrue(find(nList, "document_allow", "user12"));

    }

    private boolean find(NodeList nList, String name, String textContent) {
        for (int i = 0; i < nList.getLength(); i++) {
            Node node = nList.item(i);

            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element element = (Element) node;

                if (name.equals(element.getAttribute(NAME_ATTRIBUTE)) && textContent.equals(element.getTextContent()))
                    return true;
            }
        }
        return false;
    }

    @Test
    public void updateJsonString() throws Exception {

        String jsonGenerated = toTest.toString(IndexingFormat.JSON, DocumentAction.ADD_UPDATE);

        final JSONParser parser = new JSONParser();
        JSONObject json = (JSONObject)parser.parse(new java.io.StringReader(jsonGenerated));

        assertTrue(json.get(APIKEY_ATTRIBUTE) != null);
        assertTrue(json.get("document") != null);

        Object apiObject = json.get(APIKEY_ATTRIBUTE);
        assertTrue(apiObject instanceof String);
        assertEquals("apikey", apiObject);

        Object documentObject = json.get("document");
        assertTrue(documentObject instanceof JSONObject);
        JSONObject document = (JSONObject) documentObject;

        assertTrue(document.get(UID_ATTRIBUTE) != null);
        assertTrue(document.get(UID_ATTRIBUTE) instanceof String);
        assertEquals("URI", document.get(UID_ATTRIBUTE));

        assertTrue(document.get(COLNAME_ATTRIBUTE)  != null);
        assertTrue(document.get(COLNAME_ATTRIBUTE) instanceof String);
        assertEquals("collection1", document.get(COLNAME_ATTRIBUTE));

        assertTrue(document.get("size") != null);
        assertTrue(document.get("size") instanceof String);
        assertEquals("100", document.get("size"));

        assertTrue(document.get("meta") != null);
        Object metaObject = document.get("meta");
        assertTrue(metaObject instanceof JSONObject);
        JSONObject meta = (JSONObject) metaObject;
        assertEquals(6, meta.size());

        assertTrue(find(meta, "meta2", "I am META2!", 1));
        assertTrue(find(meta, "meta1", "I am META1!", 1));

        assertTrue(find(meta, "share_allow", "user1", 3));
        assertTrue(find(meta, "share_allow", "user2", 3));
        assertTrue(find(meta, "share_allow", "user3", 3));

        assertTrue(find(meta, "document_deny", "user42", 2));
        assertTrue(find(meta, "document_deny", "user52", 2));

        assertTrue(find(meta, "share_deny", "user5", 2));
        assertTrue(find(meta, "share_deny", "user4", 2));

        assertTrue(find(meta, "document_allow", "user22", 3));
        assertTrue(find(meta, "document_allow", "user33", 3));
        assertTrue(find(meta, "document_allow", "user12", 3));

        assertTrue(document.get("description") != null);
        assertTrue(document.get("description") instanceof String);
        assertEquals("I am a little tiny description", document.get("description"));

        assertTrue(document.get("title") != null);
        assertTrue(document.get("title") instanceof String);
        assertEquals("I am a nice title", document.get("title"));

        assertTrue(document.get("content") != null);
        assertTrue(document.get("content") instanceof String);
        assertEquals("I am a nice content in english!", document.get("content"));

        assertTrue(document.get("contenttype") != null);
        assertTrue(document.get("contenttype") instanceof String);
        assertEquals("html", document.get("contenttype"));
    }

    private boolean find(JSONObject meta, String name, String textContent, int size) {

        assertTrue(meta.get(name) != null);
        assertTrue(meta.get(name) instanceof JSONArray);

        assertEquals(size, ((JSONArray) meta.get(name)).size());

        for (int i = 0; i < size; i++) {
            if (textContent.equals(((JSONArray) meta.get(name)).get(i).toString()))
                return true;
        }
        return false;
    }

    @Test
    public void deleteJsonString() throws Exception {
        String jsonGenerated=toTest.toString(IndexingFormat.JSON, DocumentAction.DELETE);

        final JSONParser parser = new JSONParser();
        JSONObject json = (JSONObject)parser.parse(new java.io.StringReader(jsonGenerated));

        assertTrue(json.get(APIKEY_ATTRIBUTE) != null);
        assertTrue(json.get("document") != null);

        Object apiObject = json.get(APIKEY_ATTRIBUTE);
        assertTrue(apiObject instanceof String);
        assertEquals("apikey", apiObject);

        Object documentObject = json.get("document");
        assertTrue(documentObject instanceof JSONObject);
        JSONObject document = (JSONObject) documentObject;

        assertTrue(document.get(UID_ATTRIBUTE) != null);
        assertTrue(document.get(COLNAME_ATTRIBUTE) != null);

        Object uidObject = document.get(UID_ATTRIBUTE);
        assertTrue(uidObject instanceof String);
        assertEquals("URI", uidObject);

        Object colObject = document.get(COLNAME_ATTRIBUTE);
        assertTrue(colObject instanceof String);
        assertEquals("collection1", colObject);
    }

    @Test
    public void deleteXmlString() throws SearchBloxException, ParserConfigurationException, SAXException, IOException {
        String xmlGenerated=toTest.toString(IndexingFormat.XML, DocumentAction.DELETE);

        InputSource is = new InputSource(new ByteArrayInputStream(xmlGenerated.getBytes(StandardCharsets.UTF_8)));

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(is);
        doc.getDocumentElement().normalize();

        Element root = doc.getDocumentElement();
        assertEquals("searchblox", root.getNodeName());
        assertEquals("apikey", root.getAttribute(APIKEY_ATTRIBUTE));

        assertEquals(1, root.getElementsByTagName("document").getLength());
        assertEquals(Node.ELEMENT_NODE, root.getElementsByTagName("document").item(0).getNodeType());

        Element document = (Element) root.getElementsByTagName("document").item(0);
        assertEquals("collection1", document.getAttribute(COLNAME_ATTRIBUTE));
        assertEquals("URI", document.getAttribute(UID_ATTRIBUTE));
    }

    private Map<String, List<String>> initArgs() {
        Map<String, List<String>> argMap=new HashMap<>();
        argMap.put(ATTRIBUTE_COLLECTION_NAME, Collections.singletonList("collection1"));
        argMap.put(ATTRIBUTE_TITLEBOOST, Collections.singletonList("1"));
        argMap.put(ATTRIBUTE_CONTENTBOOST, Collections.singletonList("2"));
        argMap.put(ATTRIBUTE_KEYWORDSBOOST, Collections.singletonList("3"));
        argMap.put(ATTRIBUTE_DESCRIPTIONBOOST, Collections.singletonList("4"));
        return argMap;

    }

    private RepositoryDocument initRepoDocument() throws ManifoldCFException {
        RepositoryDocument realRepoDoc=new RepositoryDocument();
        String binaryContent="I am the binary content of an Amazing Document";
        InputStream stream = new ByteArrayInputStream(binaryContent.getBytes(StandardCharsets.UTF_8));

        realRepoDoc.addField("title","I am a nice title");
        realRepoDoc.addField("content","I am a nice content in english!");
        realRepoDoc.addField("description","I am a little tiny description");
        realRepoDoc.addField("meta1","I am META1!");
        realRepoDoc.addField("meta2","I am META2!");
        realRepoDoc.setMimeType("html");
        realRepoDoc.setBinary(stream,100);
        realRepoDoc.setCreatedDate(new Date(System.currentTimeMillis()));
        realRepoDoc.setSecurityACL(RepositoryDocument.SECURITY_TYPE_SHARE,new String[]{"user1","user2","user3"});
        realRepoDoc.setSecurityACL(RepositoryDocument.SECURITY_TYPE_DOCUMENT,new String[]{"user12","user22","user33"});
        realRepoDoc.setSecurityDenyACL(RepositoryDocument.SECURITY_TYPE_SHARE, new String[]{"user4", "user5"});
        realRepoDoc.setSecurityDenyACL(RepositoryDocument.SECURITY_TYPE_DOCUMENT, new String[]{"user42", "user52"});
        //allowAttributeName + aclType
        return realRepoDoc;
    }

}


text:
#ifndef QUNDOGROUP_H
#define QUNDOGROUP_H

#include <QtCore/qobject.h>
#include <QtCore/qstring.h>

QT_BEGIN_NAMESPACE

class QUndoGroupPrivate;
class QUndoStack;
class QAction;

#ifndef QT_NO_UNDOGROUP

class Q_WIDGETS_EXPORT QUndoGroup : public QObject
{
    Q_OBJECT
    Q_DECLARE_PRIVATE(QUndoGroup)

public:
    explicit QUndoGroup(QObject *parent = 0);
    ~QUndoGroup();

    void addStack(QUndoStack *stack);
    void removeStack(QUndoStack *stack);
    QList<QUndoStack*> stacks() const;
    QUndoStack *activeStack() const;

#ifndef QT_NO_ACTION
    QAction *createUndoAction(QObject *parent,
                                const QString &prefix = QString()) const;
    QAction *createRedoAction(QObject *parent,
                                const QString &prefix = QString()) const;
#endif // QT_NO_ACTION
    bool canUndo() const;
    bool canRedo() const;
    QString undoText() const;
    QString redoText() const;
    bool isClean() const;

public Q_SLOTS:
    void undo();
    void redo();
    void setActiveStack(QUndoStack *stack);

Q_SIGNALS:
    void activeStackChanged(QUndoStack *stack);
    void indexChanged(int idx);
    void cleanChanged(bool clean);
    void canUndoChanged(bool canUndo);
    void canRedoChanged(bool canRedo);
    void undoTextChanged(const QString &undoText);
    void redoTextChanged(const QString &redoText);

private:
    Q_DISABLE_COPY(QUndoGroup)
};

#endif // QT_NO_UNDOGROUP

QT_END_NAMESPACE

#endif // QUNDOGROUP_H


text:
-- ../src/misc.nw:7
	------ THIS FILE IS TANGLED FROM LITERATE SOURCE FILES ------
	-- Copyright (C) 2009 Tommy Pettersson <ptp@lysator.liu.se>
	-- See terms in file COPYRIGHT, or at http://lemock.luaforge.net

-- ../src/unittestfiles.nw:11

	require 'lunit'
	module( 'unit.module', lunit.testcase, package.seeall )

	require 'lemock'

	local mc, m

	function setup ()
		mc = lemock.controller()
		m  = mc:mock()
	end

-- ../src/restrictions.nw:537
	function close_test ()
		local t
		t = m.foo ;mc:times(0,1/0):returns( 1 ) :label(1)
		t = m.foo ;mc:times(0,1/0):returns( 2 ) :label(2)
		t = m.foo ;mc:times(0,1/0):returns( 3 )
		m.bar(1) ;mc:close(1)
		m.bar(2) ;mc:close(2)
		mc:replay()
		m.bar(1)
		assert_equal( 2, m.foo )
		assert_equal( 2, m.foo )
		assert_equal( 2, m.foo )
		m.bar(2)
		assert_equal( 3, m.foo )
		mc:verify()
	end
	function close_unsatisfied_action_fails_test ()
		m.a = 1 ;mc:label(1)
		m.b = 2 ;mc:close(1)
		mc:replay()
		local ok, err = pcall( function() m.b = 2 end )
		assert_false( ok, "Undetected close of unsatisfied action" )
		assert_match( "Closes unsatisfied action", err )
	end
	function close_multiple_test ()
		m.foo(1) ;mc:label(1) :times(0,1)
		m.foo(1) ;mc:label(2) :times(0,1)
		m.foo(1)
		m.bar() ;mc:close(1,2)
		mc:replay()
		m.bar()
		m.foo(1)
		mc:verify()
	end

-- ../src/restrictions.nw:573
	function close_chaining_test ()
		m.a = 1 ;mc:label 'A'
		m.b = 1 ;mc:label 'B'
		m.c = 1 ;mc:close('A'):close('B')
	end
	function close_in_replay_mode_fails_test ()
		mc:replay()
		local ok, err = pcall( function() mc:close( 'foo' ) end )
		assert_false( ok, "accepted close in replay mode" )
		assert_match( "Can not insert close in replay mode", err )
	end
	function close_on_empty_actionlist_fails_test ()
		local ok, err = pcall( function() mc:close( 'bar' ) end )
		assert_false( ok, "accepted close with empty action list" )
		assert_match( "No action is recorded yet", err )
	end
-- ../src/unittestfiles.nw:25

-- ../src/restrictions.nw:240
	function depend_fulfilled_test ()
		m.foo = 1 ;mc:label 'A'
		m.bar = 2 ;mc:depend 'A'
		mc:replay()
		m.foo = 1
		m.bar = 2
		mc:verify()
	end
	function depend_unfulfilled_fails_test ()
		m.foo = 1 ;mc:label 'A'
		m.bar = 2 ;mc:depend 'A'
		mc:replay()
		local ok, err = pcall( function() m.bar = 2 end )
		assert_false( ok, "replayed blocked action" )
		assert_match( "Unexpected action newindex", err )
	end
	function depend_fulfilled_any_order_test ()
		local tmp
		m.a = 1 ;mc:label 'A'
		tmp = m.b ;mc:returns(2):depend 'A'
		tmp = m.b ;mc:returns(3)
		mc:replay()
		assert_equal( 3, m.b, "replayed wrong b" )
		m.a = 1
		assert_equal( 2, m.b, "replayed wrong b" )
		mc:verify()
	end
	function depend_serial_blocks_test ()
		local tmp
		tmp = m:a() ;mc:label 'a'
		tmp = m:c() ;mc:label 'c' :depend 'b'
		tmp = m:b() ;mc:label 'b' :depend 'a'
		mc:replay()
		local ok, err = pcall( function() tmp = m:b() end )
		assert_false( ok, "replayed blocked action" )
		assert_match( "Unexpected action", err )
		local ok, err = pcall( function() tmp = m:c() end )
		assert_false( ok, "replayed blocked action" )
		assert_match( "Unexpected action", err )
		m:a()
		local ok, err = pcall( function() tmp = m:c() end )
		assert_false( ok, "replayed blocked action" )
		assert_match( "Unexpected action", err )
		m:b()
		m:c()
		mc:verify()
	end
	function depend_on_many_labels_test ()
		local tmp
		tmp = m:b() ;mc:label 'b'
		tmp = m:c() ;mc:label 'c' :depend( 'a', 'b' )
		tmp = m:a() ;mc:label 'a'
		mc:replay()
		local ok, err = pcall( function() tmp = m:c() end )
		assert_false( ok, "replayed blocked action" )
		assert_match( "Unexpected action", err )
		m:a()
		local ok, err = pcall( function() tmp = m:c() end )
		assert_false( ok, "replayed blocked action" )
		assert_match( "Unexpected action", err )
		m:b()
		m:c()
		mc:verify()
	end
	function depend_on_many_labels_test2_test ()
		-- swap order, in case whole list is not checked
		local tmp
		tmp = m:b() ;mc:label 'b'
		tmp = m:c() ;mc:label 'c' :depend( 'b', 'a' )
		tmp = m:a() ;mc:label 'a'
		mc:replay()
		local ok, err = pcall( function() tmp = m:c() end )
		assert_false( ok, "replayed blocked action" )
		assert_match( "Unexpected action", err )
		m:a()
		local ok, err = pcall( function() tmp = m:c() end )
		assert_false( ok, "replayed blocked action" )
		assert_match( "Unexpected action", err )
		m:b()
		m:c()
		mc:verify()
	end
	function depend_on_many_bloskers_with_same_label_test ()
		tmp = m:c() ;mc:label 'c' :depend 'b'
		tmp = m:a() ;mc:label 'b'
		tmp = m:b() ;mc:label 'b'
		mc:replay()
		local ok, err = pcall( function() tmp = m:c() end )
		assert_false( ok, "replayed blocked action" )
		assert_match( "Unexpected action", err )
		m:a()
		local ok, err = pcall( function() tmp = m:c() end )
		assert_false( ok, "replayed blocked action" )
		assert_match( "Unexpected action", err )
		m:b()
		m:c()
		mc:verify()
	end
-- ../src/restrictions.nw:344
	function depend_ignors_unknown_label_test ()
		m.foo = 1 ;mc:label 'A'
		m.bar = 2 ;mc:depend 'B'
		mc:replay()
		m.foo = 1
		m.bar = 2
		mc:verify()
	end
-- ../src/restrictions.nw:361
	function depend_detect_cycle_test ()
		local ok, err = pcall( function()
			m.foo = 1 ;mc:label 'A' :depend 'B'
			m.bar = 2 ;mc:label 'B' :depend 'A'
			mc:replay()
			m.foo = 1
		end )
		assert_false( ok, "replayed cyclically blocked action" )
		assert_match( "dependency cycle", err )
	end

-- ../src/restrictions.nw:373
	function depend_chaining_test ()
		m.a = 1 ;mc:label 'A'
		m.b = 1 ;mc:label 'B'
		m.c = 1 ;mc:depend('A'):depend('B')
	end
	function depend_in_replay_mode_fails_test ()
		mc:replay()
		local ok, err = pcall( function() mc:depend( 'foo' ) end )
		assert_false( ok, "set dependency in replay mode" )
		assert_match( "Can not add dependency in replay mode", err )
	end
	function depend_on_empty_actionlist_fails_test ()
		local ok, err = pcall( function() mc:depend( 'bar' ) end )
		assert_false( ok, "set dependency with empty action list" )
		assert_match( "No action is recorded yet", err )
	end
	function depend_reports_expected_actions_on_faliure_test ()
		local tmp
		tmp = m.foo ;mc:depend 'B'
		tmp = m.bar ;mc:label 'B'
		mc:replay()
		local ok, err = pcall( function() tmp = m.foo end )
		assert_false( ok, "replayed blocked action" )
		assert_match( "expected:.*index bar", err )
		assert_not_match( "expected:.*index foo", err )
		tmp = m.bar
		local ok, err = pcall( function() tmp = m.bar end )
		assert_false( ok, "expected:.*replayed blocked action" )
		assert_not_match( "expected:.*index bar", err )
		assert_match( "index foo", err )
	end
-- ../src/unittestfiles.nw:26

-- ../src/restrictions.nw:130
	function label_in_replay_mode_fails_test ()
		mc:replay()
		local ok, err = pcall( function() mc:label( 'foo' ) end )
		assert_false( ok, "set label in replay mode" )
		assert_match( "Can not add labels in replay mode", err )
	end
	function label_on_empty_actionlist_fails_test ()
		local ok, err = pcall( function() mc:label( 'bar' ) end )
		assert_false( ok, "set label with empty action list" )
		assert_match( "No action is recorded yet", err )
	end

-- ../src/unittestfiles.nw:27

-- ../src/main.nw:510
	function returns_on_empty_list_fails_test ()
		local ok, err = pcall( function() mc:returns(nil) end )
		assert_false( ok, "returns called on nothing" )
		assert_match( "No action is recorded yet.", err )
	end
	function returns_make_call_fail_test ()
		local tmp = m.foo ;mc:returns(1)
		local ok, err = pcall( function() tmp(2) end )
		assert_false( ok, "called index with returnvalue" )
		assert_match( "Can not call foo. It has a returnvalue.", err )
	end
	function callable_index_replays_anytimes_test ()
		local tmp = m.foo()
		mc:replay()
		tmp = m.foo
		tmp = m.foo
		tmp = m.foo()
		mc:verify()
	end

-- ../src/unittestfiles.nw:28

-- ../src/main.nw:449
	function create_completely_empty_mock_test ()
		for k, v in pairs( m ) do
			fail( "Mock should be empty but contains "..tostring(k) )
		end
	end
	function create_mock_during_replay_fails_test ()
		mc:replay()
		local ok, err = pcall( function() mc:mock() end )
		assert_false( ok, "mock() succeeded" )
		assert_match( "New mock during replay.", err )
	end

-- ../src/unittestfiles.nw:29

-- ../src/main.nw:692
	function replay_in_any_order_test ()
		m.a = 1
		m.b = 2
		m.c = 3
		mc:replay()
		m.c = 3
		m.a = 1
		m.b = 2
		mc:verify()
	end
	function replaying_unexpected_action_fails_test ()
		mc:replay()
		local ok, err = pcall( function() m:somethingelse() end )
		assert_false( ok, "unexpected replay succeeded" )
		assert_match( "Unexpected action index somethingelse", err )
	end
-- ../src/main.nw:718
	function cached_recording_callable_fails_during_replay_test ()
		local tmp = m.foo ; tmp()
		mc:replay()
		local ok, err = pcall( function() tmp() end )
		assert_false( ok, "Cached callable not detected" )
		assert_match( "client uses cached callable from recording", err )
	end
-- ../src/unittestfiles.nw:30

-- ../src/main.nw:642
	function replay_twice_fails_test ()
		mc:replay()
		local ok, err = pcall( function() mc:replay() end )
		assert_false( ok, "replay succeeded twice" )
		assert_match( "Replay called twice.", err )
	end
	function multiple_controllers_test ()
		local mc2 = lemock.controller()
		local m2  = mc2:mock()

		-- m --         -- m2 --
		m.foo = 1
		mc:replay()
						m2.bar = 2
		m.foo = 1
						mc2:replay()
		mc:verify()
						m2.bar = 2
						mc2:verify()
	end

-- ../src/unittestfiles.nw:31

-- ../src/restrictions.nw:38
	function times_test ()
		local tmp = m.foo ;mc:returns( 2 ):times( 2, 3 )
		mc:replay()
		-- 1
		local tmp = m.foo
		local ok, err = pcall( function() mc:verify() end )
		assert_false( ok, "verified unsatisfied action" )
		assert_match( "Wrong replay count 1 ", err )
		-- 2
		local tmp = m.foo
		mc:verify()
		-- 3
		local tmp = m.foo
		mc:verify()
		-- 4
		local ok, err = pcall( function() local tmp = m.foo end )
		assert_false( ok, "replaied finished action" )
		assert_match( "Unexpected action index foo", err )
	end
	function times_called_twice_test ()
		m.foo = 1 ;mc:times( 0, math.huge ):times( 1 )
	end
	function times_in_replay_mode_fails_test ()
		mc:replay()
		local ok, err = pcall( function() mc:times(1) end )
		assert_false( ok, "changed times in replay mode" )
		assert_match( "Can not set times in replay mode.", err )
	end
	function unrealistic_times_fails_with_message_test ()
		m.a = 'a'
		local ok, err = pcall( function() mc:times(0) end )
		assert_false( ok, "accepted unrealistic time arguments" )
		assert_match( "Unrealistic time arguments", err )
	end

-- ../src/unittestfiles.nw:32

-- ../src/main.nw:736
	function verify_during_record_phase_fails_test ()
		local ok, err = pcall( function() mc:verify() end )
		assert_false( ok, "Verify succeeded" )
		assert_match( "Verify called during record.", err )
	end
	function verify_replayed_actionlist_test ()
		mc:replay()
		mc:verify()
	end
	function verify_unreplyed_actionlist_fails_test ()
		local tmp = m.foo
		mc:replay()
		local ok, err = pcall( function() mc:verify() end )
		assert_false( ok, "Verify succeeded" )
		assert_match( "Wrong replay count 0 ", err )
	end

-- ../src/unittestfiles.nw:33

-- ../src/action/call.nw:13
	function call_test ()
		m.foo(1,2,3)
		mc:replay()
		local tmp = m.foo(1,2,3)
		assert_nil( tmp )
		mc:verify()
	end
	function call_anyarg_test ()
		m.foo(1,mc.ANYARG,3)
		mc:replay()
		local tmp = m.foo(1,2,3)
		mc:verify()
	end
	function call_anyargs_test ()
		m.foo(mc.ANYARGS)
		mc:replay()
		local tmp = m.foo(1,2,3)
		mc:verify()
	end
	function call_anyargs_bad_fails_test ()
		local ok, err = pcall( function() m.foo(mc.ANYARGS, 1) end )
		assert_false( ok, "ANYARGS misused" )
		assert_match( "ANYARGS not at end", err )
	end
	function call_return_test ()
		m.foo(1,2,3) ;mc:returns( 0, 9 )
		mc:replay()
		local tmp1, tmp2 = m.foo(1,2,3)
		assert_equal( 0, tmp1 )
		assert_equal( 9, tmp2 )
		mc:verify()
	end
	function call_wrong_name_fails_test ()
		m.foo(1,2,3) ;mc:returns( 0 )
		mc:replay()
		local ok, err = pcall( function() m:bar(1,2,3) end )
		assert_false( ok, "replay wrong index" )
		assert_match( "Unexpected action index bar", err )
	end
	function call_wrong_arg_fails_test ()
		m.foo(1,2,3) ;mc:returns( 0 )
		mc:replay()
		local ok, err = pcall( function() m.foo(1) end )
		assert_false( ok, "replay succeeded" )
		assert_match( "Unexpected action call foo", err )
	end
	function call_throws_error_test ()
		m.boo('Ba') ;mc:error( "Call throws error" )
		mc:replay()
		local ok, err = pcall( function() m.boo('Ba') end )
		assert_false( ok, "did not throw error" )
		assert_match( "Call throws error", err )
	end
-- ../src/unittestfiles.nw:35

-- ../src/main.nw:596
	function error_during_replay_fails_test ()
		local tmp = m.foo
		mc:replay()
		local ok, err = pcall( function() mc:error(1) end )
		assert_false( ok, "error() succeeded during replay" )
		assert_match( "Error called during replay.", err )
	end
	function error_twice_fails_test ()
		local tmp = m.foo ;mc:error(1)
		local ok, err = pcall( function() mc:error(2) end )
		assert_false( ok, "duplicate error() succeeded" )
		assert_match( "Returns and/or Error called twice for same action.", err )
	end
	function error_plus_returns_fails_test ()
		local tmp = m.foo ;mc:returns(1)
		local ok, err = pcall( function() mc:error(2) end )
		assert_false( ok, "both error and returns succeeded" )
		assert_match( "Returns and/or Error called twice for same action.", err )
	end

-- ../src/unittestfiles.nw:36

-- ../src/action/index.nw:13
	function index_test ()
		local tmp = m.foo
		mc:replay()
		local tmp = m.foo
		assert_nil( tmp )
		mc:verify()
	end
	function index_returns_test ()
		local tmp = m.foo ;mc:returns( 1 )
		mc:replay()
		local tmp = m.foo
		assert_equal( 1, tmp )
		mc:verify()
	end
	function index_wrong_key_fails_test ()
		local tmp = m.foo ;mc:returns( 1 )
		mc:replay()
		local ok, err = pcall( function() local tmp = m.bar end )
		assert_false( ok, "replay succeeded" )
		assert_match( "Unexpected action index bar", err )
	end
	function index_throws_error_test ()
		local tmp = m.foo ;mc:error( "Index throws error" )
		mc:replay()
		local ok, err = pcall( function() tmp = m.foo end )
		assert_false( ok, "did not throw error" )
		assert_match( "Index throws error", err )
	end
-- ../src/unittestfiles.nw:37

-- ../src/action/newindex.nw:9
	function newindex_test ()
		m.foo = 1
		mc:replay()
		m.foo = 1
		mc:verify()
	end
	function newindex_anyarg_test ()
		m.foo = mc.ANYARG
		mc:replay()
		m.foo = 1
		mc:verify()
	end
	function newindex_wrong_key_fails_test ()
		m.foo = 1
		mc:replay()
		local ok, err = pcall( function() m.bar = 1 end )
		assert_false( ok, "replay succeeded" )
		assert_match( "Unexpected action newindex", err )
	end
	function newindex_wrong_value_fails_test ()
		m.foo = 1
		mc:replay()
		local ok, err = pcall( function() m.foo = 0 end )
		assert_false( ok, "replay succeeded" )
		assert_match( "Unexpected action newindex foo", err )
	end
	function newindex_throws_error_test ()
		m.foo = 1 ;mc:error( "newindex throws error" )
		mc:replay()
		local ok, err = pcall( function() m.foo = 1 end )
		assert_false( ok, "did not throw error" )
		assert_match( "newindex throws error", err )
	end
-- ../src/unittestfiles.nw:38

-- ../src/main.nw:550
	function returns_during_replay_fails_test ()
		local tmp = m.foo
		mc:replay()
		local ok, err = pcall( function() mc:returns(1) end )
		assert_false( ok, "returns() succeeded during replay" )
		assert_match( "Returns called during replay.", err )
	end
	function returns_on_nonreturning_action_fails_test ()
		m.foo = 1 -- assignments can't return
		local ok, err = pcall( function() mc:returns(0) end )
		assert_false( ok, "returns() succeeded on non-returning action" )
		assert_match( "Previous action can not return anything.", err )
	end
	function returns_twice_fails_test ()
		local tmp = m.foo ;mc:returns(1)
		local ok, err = pcall( function() mc:returns(2) end )
		assert_false( ok, "duplicate returns() succeeded" )
		assert_match( "Returns and/or Error called twice for same action.", err )
	end

-- ../src/unittestfiles.nw:39

-- ../src/action/selfcall.nw:12
	function selfcall_test ()
		m(11)
		mc:replay()
		local tmp = m(11)
		assert_nil( tmp )
		mc:verify()
	end
	function selfcall_returns_test ()
		m(99) ;mc:returns(1,nil,'foo')
		mc:replay()
		local a,b,c = m(99)
		assert_equal( 1, a )
		assert_equal( nil, b )
		assert_equal( 'foo', c )
		mc:verify()
	end
	function selfcall_wrong_argument_fails_test ()
		m(99) ;mc:returns('a','b','c')
		mc:replay()
		local ok, err = pcall( function() m(90) end )
		assert_false( ok, "replay succeeded" )
		assert_match( "Unexpected action selfcall", err )
	end
	function selfcall_wrong_number_of_arguments_fails_test ()
		m(1,2,3)
		mc:replay()
		local ok, err = pcall( function() m(1,2,3,4) end )
		assert_false( ok, "replay succeeded" )
		assert_match( "Unexpected action selfcall", err )
	end
	function selfcall_throws_error_test ()
		m('Ba') ;mc:error( "Selfcall throws error" )
		mc:replay()
		local ok, err = pcall( function() m('Ba') end )
		assert_false( ok, "did not throw error" )
		assert_match( "Selfcall throws error", err )
	end