text:
@media screen and (max-width: 1084px) {
	.container-panel h1 {
		font-size: 10px !important;
	}
	.container-panel {
		width: 90px !important;
	}
	.container-panel a {
		width: 90px !important;
	}
	.settings {
		margin-left: 120px !important;
	}
}

@media screen and (max-width: 768px) {
	.container-panel h1 {
		font-size: 10px !important;
	}
	.container-panel {
		width: 75px !important;
	}
	.container-panel a {
		width: 75px !important;
	}
	.settings {
		margin-left: 105px !important;
	}
}

@media screen and (max-width: 480px) {
	.container-panel h1 {
		display: none;
	}
	.container-panel {
		width: 25px !important;
	}
	.container-panel a {
		width: 25px !important;
		font-size: 7px !important;
	}
	.settings {
		margin-left: 55px !important;
	}
}


text:
package org.openstack.atlas.common.ip.exception;

public class IPBigIntegerConversionException extends IPException {

    public IPBigIntegerConversionException() {
        super();
    }

    public IPBigIntegerConversionException(String msg) {
        super(msg);
    }

    public IPBigIntegerConversionException(String msg,Throwable th) {
        super(msg,th);
    }

    public IPBigIntegerConversionException(Throwable th) {
        super(th);
    }
}

redpajama_set_name: RedPajamaGithub


text:
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text;

namespace System.Numerics
{
    /// <summary>
    /// A structure encapsulating four single precision floating point values and provides hardware accelerated methods.
    /// </summary>
    public partial struct Vector4 : IEquatable<Vector4>, IFormattable
    {
        #region Public Static Properties
        /// <summary>
        /// Returns the vector (0,0,0,0).
        /// </summary>
        public static Vector4 Zero { get { return new Vector4(); } }
        /// <summary>
        /// Returns the vector (1,1,1,1).
        /// </summary>
        public static Vector4 One { get { return new Vector4(1.0f, 1.0f, 1.0f, 1.0f); } }
        /// <summary>
        /// Returns the vector (1,0,0,0).
        /// </summary>
        public static Vector4 UnitX { get { return new Vector4(1.0f, 0.0f, 0.0f, 0.0f); } }
        /// <summary>
        /// Returns the vector (0,1,0,0).
        /// </summary>
        public static Vector4 UnitY { get { return new Vector4(0.0f, 1.0f, 0.0f, 0.0f); } }
        /// <summary>
        /// Returns the vector (0,0,1,0).
        /// </summary>
        public static Vector4 UnitZ { get { return new Vector4(0.0f, 0.0f, 1.0f, 0.0f); } }
        /// <summary>
        /// Returns the vector (0,0,0,1).
        /// </summary>
        public static Vector4 UnitW { get { return new Vector4(0.0f, 0.0f, 0.0f, 1.0f); } }
        #endregion Public Static Properties

        #region Public instance methods
        /// <summary>
        /// Returns the hash code for this instance.
        /// </summary>
        /// <returns>The hash code.</returns>
        public override int GetHashCode()
        {
            int hash = this.X.GetHashCode();
            hash = HashCodeHelper.CombineHashCodes(hash, this.Y.GetHashCode());
            hash = HashCodeHelper.CombineHashCodes(hash, this.Z.GetHashCode());
            hash = HashCodeHelper.CombineHashCodes(hash, this.W.GetHashCode());
            return hash;
        }

        /// <summary>
        /// Returns a boolean indicating whether the given Object is equal to this Vector4 instance.
        /// </summary>
        /// <param name="obj">The Object to compare against.</param>
        /// <returns>True if the Object is equal to this Vector4; False otherwise.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override bool Equals(object obj)
        {
            if (!(obj is Vector4))
                return false;
            return Equals((Vector4)obj);
        }

        /// <summary>
        /// Returns a String representing this Vector4 instance.
        /// </summary>
        /// <returns>The string representation.</returns>
        public override string ToString()
        {
            return ToString("G", CultureInfo.CurrentCulture);
        }

        /// <summary>
        /// Returns a String representing this Vector4 instance, using the specified format to format individual elements.
        /// </summary>
        /// <param name="format">The format of individual elements.</param>
        /// <returns>The string representation.</returns>
        public string ToString(string format)
        {
            return ToString(format, CultureInfo.CurrentCulture);
        }

        /// <summary>
        /// Returns a String representing this Vector4 instance, using the specified format to format individual elements
        /// and the given IFormatProvider.
        /// </summary>
        /// <param name="format">The format of individual elements.</param>
        /// <param name="formatProvider">The format provider to use when formatting elements.</param>
        /// <returns>The string representation.</returns>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            StringBuilder sb = new StringBuilder();
            string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator + " ";
            sb.Append("<");
            sb.Append(this.X.ToString(format, formatProvider));
            sb.Append(separator);
            sb.Append(this.Y.ToString(format, formatProvider));
            sb.Append(separator);
            sb.Append(this.Z.ToString(format, formatProvider));
            sb.Append(separator);
            sb.Append(this.W.ToString(format, formatProvider));
            sb.Append(">");
            return sb.ToString();
        }

        /// <summary>
        /// Returns the length of the vector. This operation is cheaper than Length().
        /// </summary>
        /// <returns>The vector's length.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public float Length()
        {
            if (Vector.IsHardwareAccelerated)
            {
                float ls = Vector4.Dot(this, this);
                return (float)System.Math.Sqrt(ls);
            }
            else
            {
                float ls = X * X + Y * Y + Z * Z + W * W;

                return (float)Math.Sqrt((double)ls);
            }
        }

        /// <summary>
        /// Returns the length of the vector squared.
        /// </summary>
        /// <returns>The vector's length squared.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public float LengthSquared()
        {
            if (Vector.IsHardwareAccelerated)
            {
                return Vector4.Dot(this, this);
            }
            else
            {
                return X * X + Y * Y + Z * Z + W * W;
            }
        }
        #endregion Public Instance Methods

        #region Public Static Methods
        /// <summary>
        /// Returns the Euclidean distance between the two given points.
        /// </summary>
        /// <param name="value1">The first point.</param>
        /// <param name="value2">The second point.</param>
        /// <returns>The distance.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static float Distance(Vector4 value1, Vector4 value2)
        {
            if (Vector.IsHardwareAccelerated)
            {
                Vector4 difference = value1 - value2;
                float ls = Vector4.Dot(difference, difference);
                return (float)System.Math.Sqrt(ls);
            }
            else
            {
                float dx = value1.X - value2.X;
                float dy = value1.Y - value2.Y;
                float dz = value1.Z - value2.Z;
                float dw = value1.W - value2.W;

                float ls = dx * dx + dy * dy + dz * dz + dw * dw;

                return (float)Math.Sqrt((double)ls);
            }
        }

        /// <summary>
        /// Returns the Euclidean distance squared between the two given points.
        /// </summary>
        /// <param name="value1">The first point.</param>
        /// <param name="value2">The second point.</param>
        /// <returns>The distance squared.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static float DistanceSquared(Vector4 value1, Vector4 value2)
        {
            if (Vector.IsHardwareAccelerated)
            {
                Vector4 difference = value1 - value2;
                return Vector4.Dot(difference, difference);
            }
            else
            {
                float dx = value1.X - value2.X;
                float dy = value1.Y - value2.Y;
                float dz = value1.Z - value2.Z;
                float dw = value1.W - value2.W;

                return dx * dx + dy * dy + dz * dz + dw * dw;
            }
        }

        /// <summary>
        /// Returns a vector with the same direction as the given vector, but with a length of 1.
        /// </summary>
        /// <param name="vector">The vector to normalize.</param>
        /// <returns>The normalized vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Normalize(Vector4 vector)
        {
            if (Vector.IsHardwareAccelerated)
            {
                float length = vector.Length();
                return vector / length;
            }
            else
            {
                float ls = vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z + vector.W * vector.W;
                float invNorm = 1.0f / (float)Math.Sqrt((double)ls);

                return new Vector4(
                    vector.X * invNorm,
                    vector.Y * invNorm,
                    vector.Z * invNorm,
                    vector.W * invNorm);
            }
        }

        /// <summary>
        /// Restricts a vector between a min and max value.
        /// </summary>
        /// <param name="value1">The source vector.</param>
        /// <param name="min">The minimum value.</param>
        /// <param name="max">The maximum value.</param>
        /// <returns>The restricted vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Clamp(Vector4 value1, Vector4 min, Vector4 max)
        {
            // This compare order is very important!!!
            // We must follow HLSL behavior in the case user specified min value is bigger than max value.

            float x = value1.X;
            x = (x > max.X) ? max.X : x;
            x = (x < min.X) ? min.X : x;

            float y = value1.Y;
            y = (y > max.Y) ? max.Y : y;
            y = (y < min.Y) ? min.Y : y;

            float z = value1.Z;
            z = (z > max.Z) ? max.Z : z;
            z = (z < min.Z) ? min.Z : z;

            float w = value1.W;
            w = (w > max.W) ? max.W : w;
            w = (w < min.W) ? min.W : w;

            return new Vector4(x, y, z, w);
        }

        /// <summary>
        /// Linearly interpolates between two vectors based on the given weighting.
        /// </summary>
        /// <param name="value1">The first source vector.</param>
        /// <param name="value2">The second source vector.</param>
        /// <param name="amount">Value between 0 and 1 indicating the weight of the second source vector.</param>
        /// <returns>The interpolated vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Lerp(Vector4 value1, Vector4 value2, float amount)
        {
            return new Vector4(
                value1.X + (value2.X - value1.X) * amount,
                value1.Y + (value2.Y - value1.Y) * amount,
                value1.Z + (value2.Z - value1.Z) * amount,
                value1.W + (value2.W - value1.W) * amount);
        }

        /// <summary>
        /// Transforms a vector by the given matrix.
        /// </summary>
        /// <param name="position">The source vector.</param>
        /// <param name="matrix">The transformation matrix.</param>
        /// <returns>The transformed vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Transform(Vector2 position, Matrix4x4 matrix)
        {
            return new Vector4(
                position.X * matrix.M11 + position.Y * matrix.M21 + matrix.M41,
                position.X * matrix.M12 + position.Y * matrix.M22 + matrix.M42,
                position.X * matrix.M13 + position.Y * matrix.M23 + matrix.M43,
                position.X * matrix.M14 + position.Y * matrix.M24 + matrix.M44);
        }

        /// <summary>
        /// Transforms a vector by the given matrix.
        /// </summary>
        /// <param name="position">The source vector.</param>
        /// <param name="matrix">The transformation matrix.</param>
        /// <returns>The transformed vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Transform(Vector3 position, Matrix4x4 matrix)
        {
            return new Vector4(
                position.X * matrix.M11 + position.Y * matrix.M21 + position.Z * matrix.M31 + matrix.M41,
                position.X * matrix.M12 + position.Y * matrix.M22 + position.Z * matrix.M32 + matrix.M42,
                position.X * matrix.M13 + position.Y * matrix.M23 + position.Z * matrix.M33 + matrix.M43,
                position.X * matrix.M14 + position.Y * matrix.M24 + position.Z * matrix.M34 + matrix.M44);
        }

        /// <summary>
        /// Transforms a vector by the given matrix.
        /// </summary>
        /// <param name="vector">The source vector.</param>
        /// <param name="matrix">The transformation matrix.</param>
        /// <returns>The transformed vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Transform(Vector4 vector, Matrix4x4 matrix)
        {
            return new Vector4(
                vector.X * matrix.M11 + vector.Y * matrix.M21 + vector.Z * matrix.M31 + vector.W * matrix.M41,
                vector.X * matrix.M12 + vector.Y * matrix.M22 + vector.Z * matrix.M32 + vector.W * matrix.M42,
                vector.X * matrix.M13 + vector.Y * matrix.M23 + vector.Z * matrix.M33 + vector.W * matrix.M43,
                vector.X * matrix.M14 + vector.Y * matrix.M24 + vector.Z * matrix.M34 + vector.W * matrix.M44);
        }

        /// <summary>
        /// Transforms a vector by the given Quaternion rotation value.
        /// </summary>
        /// <param name="value">The source vector to be rotated.</param>
        /// <param name="rotation">The rotation to apply.</param>
        /// <returns>The transformed vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Transform(Vector2 value, Quaternion rotation)
        {
            float x2 = rotation.X + rotation.X;
            float y2 = rotation.Y + rotation.Y;
            float z2 = rotation.Z + rotation.Z;

            float wx2 = rotation.W * x2;
            float wy2 = rotation.W * y2;
            float wz2 = rotation.W * z2;
            float xx2 = rotation.X * x2;
            float xy2 = rotation.X * y2;
            float xz2 = rotation.X * z2;
            float yy2 = rotation.Y * y2;
            float yz2 = rotation.Y * z2;
            float zz2 = rotation.Z * z2;

            return new Vector4(
                value.X * (1.0f - yy2 - zz2) + value.Y * (xy2 - wz2),
                value.X * (xy2 + wz2) + value.Y * (1.0f - xx2 - zz2),
                value.X * (xz2 - wy2) + value.Y * (yz2 + wx2),
                1.0f);
        }

        /// <summary>
        /// Transforms a vector by the given Quaternion rotation value.
        /// </summary>
        /// <param name="value">The source vector to be rotated.</param>
        /// <param name="rotation">The rotation to apply.</param>
        /// <returns>The transformed vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Transform(Vector3 value, Quaternion rotation)
        {
            float x2 = rotation.X + rotation.X;
            float y2 = rotation.Y + rotation.Y;
            float z2 = rotation.Z + rotation.Z;

            float wx2 = rotation.W * x2;
            float wy2 = rotation.W * y2;
            float wz2 = rotation.W * z2;
            float xx2 = rotation.X * x2;
            float xy2 = rotation.X * y2;
            float xz2 = rotation.X * z2;
            float yy2 = rotation.Y * y2;
            float yz2 = rotation.Y * z2;
            float zz2 = rotation.Z * z2;

            return new Vector4(
                value.X * (1.0f - yy2 - zz2) + value.Y * (xy2 - wz2) + value.Z * (xz2 + wy2),
                value.X * (xy2 + wz2) + value.Y * (1.0f - xx2 - zz2) + value.Z * (yz2 - wx2),
                value.X * (xz2 - wy2) + value.Y * (yz2 + wx2) + value.Z * (1.0f - xx2 - yy2),
                1.0f);
        }

        /// <summary>
        /// Transforms a vector by the given Quaternion rotation value.
        /// </summary>
        /// <param name="value">The source vector to be rotated.</param>
        /// <param name="rotation">The rotation to apply.</param>
        /// <returns>The transformed vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Transform(Vector4 value, Quaternion rotation)
        {
            float x2 = rotation.X + rotation.X;
            float y2 = rotation.Y + rotation.Y;
            float z2 = rotation.Z + rotation.Z;

            float wx2 = rotation.W * x2;
            float wy2 = rotation.W * y2;
            float wz2 = rotation.W * z2;
            float xx2 = rotation.X * x2;
            float xy2 = rotation.X * y2;
            float xz2 = rotation.X * z2;
            float yy2 = rotation.Y * y2;
            float yz2 = rotation.Y * z2;
            float zz2 = rotation.Z * z2;

            return new Vector4(
                value.X * (1.0f - yy2 - zz2) + value.Y * (xy2 - wz2) + value.Z * (xz2 + wy2),
                value.X * (xy2 + wz2) + value.Y * (1.0f - xx2 - zz2) + value.Z * (yz2 - wx2),
                value.X * (xz2 - wy2) + value.Y * (yz2 + wx2) + value.Z * (1.0f - xx2 - yy2),
                value.W);
        }
        #endregion Public Static Methods

        #region Public operator methods
        // All these methods should be inlines as they are implemented
        // over JIT intrinsics

        /// <summary>
        /// Adds two vectors together.
        /// </summary>
        /// <param name="left">The first source vector.</param>
        /// <param name="right">The second source vector.</param>
        /// <returns>The summed vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Add(Vector4 left, Vector4 right)
        {
            return left + right;
        }

        /// <summary>
        /// Subtracts the second vector from the first.
        /// </summary>
        /// <param name="left">The first source vector.</param>
        /// <param name="right">The second source vector.</param>
        /// <returns>The difference vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Subtract(Vector4 left, Vector4 right)
        {
            return left - right;
        }

        /// <summary>
        /// Multiplies two vectors together.
        /// </summary>
        /// <param name="left">The first source vector.</param>
        /// <param name="right">The second source vector.</param>
        /// <returns>The product vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Multiply(Vector4 left, Vector4 right)
        {
            return left * right;
        }

        /// <summary>
        /// Multiplies a vector by the given scalar.
        /// </summary>
        /// <param name="left">The source vector.</param>
        /// <param name="right">The scalar value.</param>
        /// <returns>The scaled vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Multiply(Vector4 left, Single right)
        {
            return left * new Vector4(right, right, right, right);
        }

        /// <summary>
        /// Multiplies a vector by the given scalar.
        /// </summary>
        /// <param name="left">The scalar value.</param>
        /// <param name="right">The source vector.</param>
        /// <returns>The scaled vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Multiply(Single left, Vector4 right)
        {
            return new Vector4(left, left, left, left) * right;
        }

        /// <summary>
        /// Divides the first vector by the second.
        /// </summary>
        /// <param name="left">The first source vector.</param>
        /// <param name="right">The second source vector.</param>
        /// <returns>The vector resulting from the division.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Divide(Vector4 left, Vector4 right)
        {
            return left / right;
        }

        /// <summary>
        /// Divides the vector by the given scalar.
        /// </summary>
        /// <param name="left">The source vector.</param>
        /// <param name="divisor">The scalar value.</param>
        /// <returns>The result of the division.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Divide(Vector4 left, Single divisor)
        {
            return left / divisor;
        }

        /// <summary>
        /// Negates a given vector.
        /// </summary>
        /// <param name="value">The source vector.</param>
        /// <returns>The negated vector.</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Vector4 Negate(Vector4 value)
        {
            return -value;
        }
        #endregion Public operator methods
    }
}


text:
{% extends "symposion/proposals/proposal_submit_kind.html" %}

{% load crispy_forms_tags %}

{% block title %}Editing {{ proposal.title }} | {% endblock %}

{% block body %}

Edit: {{ proposal.title }}

Manage speakers

    <form method="POST" action="" enctype="multipart/form-data">
        {% csrf_token %}
        <fieldset>
            <legend>An asterisk (*) indicates a required field.</legend>
            {{ form|crispy }}
        </fieldset>

            <input class="btn btn-base-color" type="submit" value="Save" />
            Cancel

    </form>

{% endblock %}


text:
<!DOCTYPE html>

Apps

dhis-web-settings

dhis-web-pivot

dhis-web-visualizer

dhis-web-mapping

dhis-web-event-reports

dhis-web-event-visualizer

dhis-web-event-capture

dhis-web-tracker-capture

dhis-web-cache-cleaner

log out


text:
"""
Provides modules containing classes to support Web Services (SOAP) bindings.
"""


text:
import os
import sys

up = os.path.dirname(os.path.dirname(__file__))
sys.path.append(up)

import ncolony as module

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.viewcode',
]
master_doc = 'index'
project = module.__name__
copyright = ', '.join((module.metadata['copyright'], module.metadata['author']))
author = module.metadata['author']
version = module.__version__
release = module.__version__


text:
first application temp

This is demo


text:
/* $OpenBSD: digest-openssl.c,v 1.2 2014/02/02 03:44:31 djm Exp $ */
/*
 * Copyright (c) 2013 Damien Miller <djm@mindrot.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "includes.h"

#include <sys/types.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>

#include <openssl/evp.h>

#include "openbsd-compat/openssl-compat.h"

#include "buffer.h"
#include "digest.h"

struct ssh_digest_ctx {
	int alg;
	EVP_MD_CTX mdctx;
};

struct ssh_digest {
	int id;
	const char *name;
	size_t digest_len;
	const EVP_MD *(*mdfunc)(void);
};

/* NB. Indexed directly by algorithm number */
const struct ssh_digest digests[] = {
	{ SSH_DIGEST_MD5,	"MD5",	 	16,	EVP_md5 },
	{ SSH_DIGEST_RIPEMD160,	"RIPEMD160",	20,	EVP_ripemd160 },
	{ SSH_DIGEST_SHA1,	"SHA1",	 	20,	EVP_sha1 },
#ifdef HAVE_EVP_SHA256 /* XXX replace with local if missing */
	{ SSH_DIGEST_SHA256,	"SHA256", 	32,	EVP_sha256 },
	{ SSH_DIGEST_SHA384,	"SHA384",	48,	EVP_sha384 },
	{ SSH_DIGEST_SHA512,	"SHA512", 	64,	EVP_sha512 },
#endif
	{ -1,			NULL,		0,	NULL },
};

static const struct ssh_digest *
ssh_digest_by_alg(int alg)
{
	if (alg < 0 || alg >= SSH_DIGEST_MAX)
		return NULL;
	if (digests[alg].id != alg) /* sanity */
		return NULL;
	return &(digests[alg]);
}

size_t
ssh_digest_bytes(int alg)
{
	const struct ssh_digest *digest = ssh_digest_by_alg(alg);

	return digest == NULL ? 0 : digest->digest_len;
}

size_t
ssh_digest_blocksize(struct ssh_digest_ctx *ctx)
{
	return EVP_MD_CTX_block_size(&ctx->mdctx);
}

struct ssh_digest_ctx *
ssh_digest_start(int alg)
{
	const struct ssh_digest *digest = ssh_digest_by_alg(alg);
	struct ssh_digest_ctx *ret;

	if (digest == NULL || ((ret = calloc(1, sizeof(*ret))) == NULL))
		return NULL;
	ret->alg = alg;
	EVP_MD_CTX_init(&ret->mdctx);
	if (EVP_DigestInit_ex(&ret->mdctx, digest->mdfunc(), NULL) != 1) {
		free(ret);
		return NULL;
	}
	return ret;
}

int
ssh_digest_copy_state(struct ssh_digest_ctx *from, struct ssh_digest_ctx *to)
{
	/* we have bcopy-style order while openssl has memcpy-style */
	if (!EVP_MD_CTX_copy_ex(&to->mdctx, &from->mdctx))
		return -1;
	return 0;
}

int
ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen)
{
	if (EVP_DigestUpdate(&ctx->mdctx, m, mlen) != 1)
		return -1;
	return 0;
}

int
ssh_digest_update_buffer(struct ssh_digest_ctx *ctx, const Buffer *b)
{
	return ssh_digest_update(ctx, buffer_ptr(b), buffer_len(b));
}

int
ssh_digest_final(struct ssh_digest_ctx *ctx, u_char *d, size_t dlen)
{
	const struct ssh_digest *digest = ssh_digest_by_alg(ctx->alg);
	u_int l = dlen;

	if (dlen > UINT_MAX)
		return -1;
	if (dlen < digest->digest_len) /* No truncation allowed */
		return -1;
	if (EVP_DigestFinal_ex(&ctx->mdctx, d, &l) != 1)
		return -1;
	if (l != digest->digest_len) /* sanity */
		return -1;
	return 0;
}

void
ssh_digest_free(struct ssh_digest_ctx *ctx)
{
	if (ctx != NULL) {
		EVP_MD_CTX_cleanup(&ctx->mdctx);
		explicit_bzero(ctx, sizeof(*ctx));
		free(ctx);
	}
}

int
ssh_digest_memory(int alg, const void *m, size_t mlen, u_char *d, size_t dlen)
{
	struct ssh_digest_ctx *ctx = ssh_digest_start(alg);

	if (ctx == NULL)
		return -1;
	if (ssh_digest_update(ctx, m, mlen) != 0 ||
	    ssh_digest_final(ctx, d, dlen) != 0)
		return -1;
	ssh_digest_free(ctx);
	return 0;
}

int
ssh_digest_buffer(int alg, const Buffer *b, u_char *d, size_t dlen)
{
	return ssh_digest_memory(alg, buffer_ptr(b), buffer_len(b), d, dlen);
}


text:
package com.diarioextractor.domain;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Vereador {

	private long id;
	private String name;
	private boolean active;
	// FIXME Extract partido
}


text:
/* dom.h - document object model interface
modifications:
june.15.2005 - Sam Skuce (ATI Industrial Automation) and Gabriel Baud-Bovy -
changed DOM_Exception to an extern to avoid redefinition problems
 */

#ifndef DOM_H
#define DOM_H

#include <stdlib.h>
#include <string.h>
#include <time.h>

/* DOM_String
 */

typedef char DOM_String;

#define DOM_String_dup ATI_strdup	// changed from strdup to ATI_strdup by DBL
char *ATI_strdup(const char *s);	// line added by DBL

#define DOM_String_len strlen
#define DOM_String_cmp strcmp

/* DOM_TimeStamp - Introduced in DOM Level 2
 */

typedef time_t DOM_TimeStamp;

/* DOM_Exception
 */

extern unsigned short DOM_Exception; // GBB: added extern (declaration moved in dom.c)

#define DOM_NO_ERR                      0
#define DOM_INDEX_SIZE_ERR              1
#define DOM_DOMSTRING_SIZE_ERR          2
#define DOM_HIERARCHY_REQUEST_ERR       3
#define DOM_WRONG_DOCUMENT_ERR          4
#define DOM_INVALID_CHARACTER_ERR       5
#define DOM_NO_DATA_ALLOWED_ERR         6
#define DOM_NO_MODIFICATION_ALLOWED_ERR 7
#define DOM_NOT_FOUND_ERR               8
#define DOM_NOT_SUPPORTED_ERR           9
#define DOM_INUSE_ATTRIBUTE_ERR         10
#define DOM_NO_MEMORY_ERR               11
#define DOM_NULL_POINTER_ERR            12
#define DOM_SYSTEM_ERR                  13
#define DOM_XML_PARSER_ERR              14

DOM_String *DOM_Exception_message(unsigned short);

/* DOM_EventException - Introduced in DOM Level 2
 */

extern unsigned short DOM_EventException;

#define DOM_UNSPECIFIED_EVENT_TYPE_ERR  0

/* DOM_Node
 */

typedef struct DOM_Node DOM_Node;
typedef struct DOM_NodeList DOM_NodeList;
typedef struct DOM_NodeList DOM_NamedNodeMap;
typedef struct NodeEntry NodeEntry;

typedef DOM_Node DOM_Attr;
typedef DOM_Node DOM_Element;
typedef DOM_Node DOM_CharacterData;
typedef DOM_CharacterData DOM_Text;
typedef DOM_CharacterData DOM_Comment;
typedef DOM_Text DOM_CDATASection;
typedef DOM_Node DOM_DocumentType;
typedef DOM_Node DOM_Notation;
typedef DOM_Node DOM_Entity;
typedef DOM_Node DOM_EntityReference;
typedef DOM_Node DOM_ProcessingInstruction;
typedef DOM_Node DOM_DocumentFragment;
typedef DOM_Node DOM_Document;
typedef DOM_Document DOM_DocumentLS;
/* Introduced in DOM Level 2: */
typedef DOM_Node DOM_EventTarget;
typedef struct ListenerEntry ListenerEntry;
typedef DOM_Document DOM_DocumentEvent;
typedef DOM_Document DOM_AbstractView;
typedef DOM_Document DOM_DocumentView;

#define DOM_ELEMENT_NODE                1
#define DOM_ATTRIBUTE_NODE              2
#define DOM_TEXT_NODE                   3
#define DOM_CDATA_SECTION_NODE          4
#define DOM_ENTITY_REFERENCE_NODE       5
#define DOM_ENTITY_NODE                 6
#define DOM_PROCESSING_INSTRUCTION_NODE 7
#define DOM_COMMENT_NODE                8
#define DOM_DOCUMENT_NODE               9
#define DOM_DOCUMENT_TYPE_NODE          10
#define DOM_DOCUMENT_FRAGMENT_NODE      11
#define DOM_NOTATION_NODE               12

/* events forward references - Introduced in DOM Level 2
 */

typedef struct DOM_Event DOM_Event;
typedef struct DOM_Event DOM_UIEvent;
typedef DOM_UIEvent DOM_KeyEvent;
typedef struct DOM_Event DOM_MutationEvent;

typedef void (*DOM_EventListener)(DOM_Event *evt);

struct ListenerEntry {
	DOM_String *type;
	DOM_EventListener listener_fn;
	int useCapture;
};

struct DOM_Node {
    DOM_String *nodeName;
    DOM_String *nodeValue;
    unsigned short nodeType;
    DOM_Node *parentNode;
    DOM_NodeList *childNodes;
    DOM_Node *firstChild;
    DOM_Node *lastChild;
    DOM_Node *previousSibling;
    DOM_Node *nextSibling;
    DOM_NamedNodeMap *attributes;
    DOM_Document *ownerDocument;
	/* Custom Fields */
	void *userPtr;
	unsigned int listeners_len;
	ListenerEntry **listeners;
    union {
        struct {
            DOM_String *name;
            int specified;
            DOM_String *value;
        } Attr;
        struct {
            DOM_String *tagName;
        } Element;
        struct {
            DOM_String *name;
            DOM_NamedNodeMap *entities;
            DOM_NamedNodeMap *notations;
        } DocumentType;
        struct {
            DOM_String *data;
            unsigned long length;
        } CharacterData;
        struct {
            DOM_String *publicId;
            DOM_String *systemId;
        } Notation;
        struct {
            DOM_String *publicId;
            DOM_String *systemId;
            DOM_String *notationName;
        } Entity;
        struct {
            DOM_String *target;
            DOM_String *data;
        } ProcessingInstruction;
        struct {
            DOM_DocumentType *doctype;
            DOM_Element *documentElement;
			/* DOM_Document implements both DOM_DocumentView and DOM_AbstractView? */
			DOM_DocumentView *document;
			DOM_AbstractView *defaultView;
        } Document;
    } u;
};

DOM_Node *DOM_Node_insertBefore(DOM_Node *node, DOM_Node *newChild, DOM_Node *refChild);
DOM_Node *DOM_Node_replaceChild(DOM_Node *node, DOM_Node *newChild, DOM_Node *oldChild);
DOM_Node *DOM_Node_removeChild(DOM_Node *node, DOM_Node *oldChild);
DOM_Node *DOM_Node_appendChild(DOM_Node *node, DOM_Node *newChild);
int DOM_Node_hasChildNodes(const DOM_Node *node);
DOM_Node *DOM_Node_cloneNode(DOM_Node *node, int deep);

/* DOM_NodeList, DOM_NamedNodeMap
 */

struct NodeEntry {
	NodeEntry *prev;
	NodeEntry *next;
	DOM_Node *node;
};
struct DOM_NodeList {
	unsigned long length;
	NodeEntry *first;
	NodeEntry *last;
};

DOM_Node *DOM_NodeList_item(const DOM_NodeList *nl, unsigned long index);

DOM_Node *DOM_NamedNodeMap_getNamedItem(const DOM_NamedNodeMap *map, const DOM_String *name);
DOM_Node *DOM_NamedNodeMap_setNamedItem(DOM_NamedNodeMap *map, DOM_Node *arg);
DOM_Node *DOM_NamedNodeMap_removeNamedItem(DOM_NamedNodeMap *map, const DOM_String *name);
DOM_Node *DOM_NamedNodeMap_item(const DOM_NamedNodeMap *map, unsigned long index);

/* DOM_Implementation
 */

int DOM_Implementation_hasFeature(DOM_String *feature, DOM_String *version);
DOM_DocumentType *DOM_Implementation_createDocumentType(DOM_String *qualifiedName,
										DOM_String *publicId, DOM_String systemId);
DOM_Document *DOM_Implementation_createDocument(DOM_String *namespaceURI,
										DOM_String *qualifiedName, DOM_DocumentType *doctype);

/* DOM_Element
 */

DOM_String *DOM_Element_getAttribute(const DOM_Element *element, const DOM_String *name);
void DOM_Element_setAttribute(DOM_Element *element, const DOM_String *name,
										const DOM_String *value);
void DOM_Element_removeAttribute(DOM_Element *element, const DOM_String *name);
DOM_Attr *DOM_Element_getAttributeNode(const DOM_Element *element, const DOM_String *name);
DOM_Attr *DOM_Element_setAttributeNode(DOM_Element *element, DOM_Attr *newAttr);
DOM_Attr *DOM_Element_removeAttributeNode(DOM_Element *element, DOM_Attr *oldAttr);
DOM_NodeList *DOM_Element_getElementsByTagName(DOM_Element *element, const DOM_String *name);
void DOM_Element_normalize(DOM_Element *element);

/* DOM_CharacterData
 */

DOM_String *DOM_CharacterData_substringData(DOM_CharacterData *data,
										unsigned long offset, unsigned long count);
void DOM_CharacterData_appendData(DOM_CharacterData *data, const DOM_String *arg);
void DOM_CharacterData_insertData(DOM_CharacterData *data, unsigned long offset,
										const DOM_String *arg);
void DOM_CharacterData_deleteData(DOM_CharacterData *data, unsigned long offset,
										unsigned long count);
void DOM_CharacterData_replaceData(DOM_CharacterData *data, unsigned long offset,
										unsigned long count, const DOM_String *arg);

/* DOM_Text
 */

DOM_Text *DOM_Text_splitText(DOM_Text *text, unsigned long offset);

/* DOM_Document
 */

DOM_Element *DOM_Document_createElement(DOM_Document *doc, const DOM_String *tagName);
DOM_DocumentFragment *DOM_Document_createDocumentFragment(DOM_Document *doc);
DOM_Text *DOM_Document_createTextNode(DOM_Document *doc, const DOM_String *data);
DOM_Comment *DOM_Document_createComment(DOM_Document *doc, const DOM_String *data);
DOM_CDATASection *DOM_Document_createCDATASection(DOM_Document *doc, const DOM_String *data);
DOM_ProcessingInstruction *DOM_Document_createProcessingInstruction(DOM_Document *doc,
										const DOM_String *target, const DOM_String *data);
DOM_Attr *DOM_Document_createAttribute(DOM_Document *doc, const DOM_String *name);
DOM_EntityReference *DOM_Docuement_createEntityReference(DOM_Document *doc,
										const DOM_String *name);
DOM_NodeList *DOM_Document_getElementsByTagName(DOM_Document *doc, const DOM_String *tagname);

void DOM_Document_destroyNode(DOM_Document *doc, DOM_Node *node);
void DOM_Document_destroyNodeList(DOM_Document *doc, DOM_NodeList *nl, int free_nodes);
void DOM_Document_destroyNamedNodeMap(DOM_Document *doc, DOM_NamedNodeMap *nnm, int free_nodes);

/* DOM_DocumentLS - Based roughly on Load and Save WD
 * http://www.w3.org/TR/2001/WD-DOM-Level-3-ASLS-20010607/load-save.html
 */

int DOM_DocumentLS_load(DOM_DocumentLS *doc, const DOM_String *uri);
int DOM_DocumentLS_save(DOM_DocumentLS *doc, const DOM_String *uri, const DOM_Node *node);

/* Events - Introduced in DOM Level 2
 * http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html
 */

/* DOM_Event - Introduced in DOM Level 2
 */

#define DOM_EVENT_CAPTURING_PHASE 1
#define DOM_EVENT_AT_TARGET       2
#define DOM_EVENT_BUBBLING_PHASE  3

struct DOM_Event {
	DOM_String *type;
	DOM_EventTarget *target;
	DOM_EventTarget *currentTarget;
	unsigned short eventPhase;
	int bubbles;
	int cancelable;
	DOM_TimeStamp timeStamp;
	/* custom -- do not touch */
	int pd;
	int sp;
	/* UIEvent members */
	DOM_AbstractView *view;
	long detail;
	union {
		struct {
			DOM_String *outputString;
			unsigned long keyVal;
			unsigned long virtKeyVal;
			int inputGenerated;
			int numPad;
		} KeyEvent;
//DBL		struct {
			/* maybe later */
//DBL		} MouseEvent;
		struct {
			DOM_Node *relatedNode;
			DOM_String *prevValue;
			DOM_String *newValue;
			DOM_String *attName;
			unsigned short attrChange;
		} MutationEvent;
	} u;
};

void DOM_Event_stopPropagation(DOM_Event *evt);
void DOM_Event_preventDefault(DOM_Event *evt);
void DOM_Event_initEvent(DOM_Event *evt, const DOM_String *eventTypeArg,
										int canBubbleArg, int cancelableArg);

/* DOM_DocumentEvent - Introduced in DOM Level 2
 */

DOM_Event *DOM_DocumentEvent_createEvent(DOM_DocumentEvent *doc,
										const DOM_String *eventType);
void DOM_DocumentEvent_destroyEvent(DOM_DocumentEvent *doc, DOM_Event *evt);

/* DOM_UIEvent
 */

void DOM_UIEvent_initUIEvent(DOM_UIEvent *evt,
										DOM_String *typeArg,
										int canBubbleArg,
										int cancelableArg,
										DOM_AbstractView *viewArg,
										long detailArg);

/* DOM_EventTarget - Introduced in DOM Level 2
 */

void DOM_EventTarget_addEventListener(DOM_EventTarget *target, const DOM_String *type,
										DOM_EventListener listener, int useCapture);
void DOM_EventTarget_removeEventListener(DOM_EventTarget *target, const DOM_String *type,
										DOM_EventListener listener, int useCapture);
int DOM_EventTarget_dispatchEvent(DOM_EventTarget *target, DOM_Event *evt);

/* DOM_KeyEvent - Introduced in DOM Level 3
 * http://www.w3.org/TR/2001/WD-DOM-Level-3-Events-20010410/events.html
 */

int DOM_KeyEvent_checkModifier(unsigned long modifier);
void DOM_KeyEvent_initKeyEvent(DOM_KeyEvent *evt, const DOM_String *typeArg,
										int canBubbleArg, int cancelableArg,
										DOM_AbstractView *viewArg, unsigned short detailArg,
										DOM_String *outputStringArg,
										unsigned long keyValArg,
										unsigned long virtKeyValArg,
										int inputGeneratedArg,
										int numPadArg);
void DOM_KeyEvent_initModifier(unsigned long modifier, int value);

/* MutationEvent
 */

#define DOM_MUTATION_EVENT_MODIFICATION 1
#define DOM_MUTATION_EVENT_ADDITION     2
#define DOM_MUTATION_EVENT_REMOVAL      3

void DOM_MutationEvent_initMutationEvent(DOM_MutationEvent *evt,
										DOM_String *typeArg,
										int canBubbleArg,
										int cancelableArg,
										DOM_Node *relatedNodeArg,
										DOM_String *prevValueArg,
										DOM_String *newValueArg,
										DOM_String *attrNameArg,
										unsigned short attrChangeArg);

/* Temporary Functions
 */

void DOM_Node_printNode(DOM_Node *node);
char *target2str(char *buf, DOM_EventTarget *target);

#endif /* DOM_H */


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using Markout.Common.DataModel.Attribute;
using Markout.Common.DataModel.Elements;
using Markout.Common.DataModel.Enumerations;

namespace Markout.Output.Inlines {

    public class MarkoutRenderer {

        private Queue<TextRun> _textRuns;
        private readonly List<Inline> _inlines = new List<Inline>();
        private Inline _currInline = null;
        private Dictionary<string, Action<TextAttributeAnchor, string>> _anchorActions = null;

        /// <summary>
        /// Convert the specified set of text runs into a set of Inlines, suitable for use
        /// in a WPF TextBlock. If the textRuns contain any anchor attributes they will
        /// be rendered as Hyperlinks and, when clicked, will attempts to call back to
        /// the anchorActions entry associated with the ActionName in the anchor attribute.
        /// </summary>
        /// <param name="textRuns"></param>
        /// <param name="anchorActions"></param>
        /// <returns></returns>
        public IEnumerable<Inline> Render(
            IEnumerable<TextRun> textRuns,
            Dictionary<string, Action<TextAttributeAnchor, string>> anchorActions = null
            ) {
            _textRuns = new Queue<TextRun>(textRuns);
            _inlines.Clear();
            _currInline = null;
            _anchorActions = anchorActions;
            ProcessRuns();
            return _inlines.AsEnumerable();
        }

        private void ProcessRuns() {
            while (_textRuns.Any()) {
                ProcessNextRun(_textRuns.Dequeue());
            }
        }

        private void ProcessNextRun(TextRun textRun) {
            if (textRun.Attributes.Any(a => a.TextAttributeType == TextAttributeTypeEnum.Anchor)) {
                _currInline = ProcessAnchorTextRun(textRun);
                _inlines.Add(_currInline);
            } else if (!string.IsNullOrEmpty(textRun.Text)) {
                _currInline = ProcessAttributes(textRun.Attributes, new Run(textRun.Text));
                _inlines.Add(_currInline);
            }
        }

        private Inline ProcessAnchorTextRun(TextRun textRun) {
            TextAttributeAnchor taa = textRun.Attributes.FirstOrDefault(ta => ta.TextAttributeType == TextAttributeTypeEnum.Anchor) as TextAttributeAnchor;
            if (taa == null) {
                throw new ApplicationException("ProcessAnchorTextRun cannot process a runs lacking an Anchor attribute");
            }
            Hyperlink hyperlink = new Hyperlink(new Run(textRun.Text));
            hyperlink.NavigateUri = taa.Uri;
            if (!string.IsNullOrWhiteSpace(taa.ActionName) && _anchorActions != null) {
                Action<TextAttributeAnchor, string> action;
                if (_anchorActions.TryGetValue(taa.ActionName.Trim(), out action)) {
                    hyperlink.Click += (sender, args) => action(taa, textRun.Text);
                }
            }
            hyperlink.Foreground = new SolidColorBrush(Colors.Blue);
            hyperlink.TextDecorations = TextDecorations.Underline;
            if (textRun.Attributes.Count() > 1) {
                ProcessAttributes(textRun.Attributes.Except(new BaseTextAttribute[] { taa }), hyperlink);
            }
            return hyperlink;
        }

        private Inline ProcessAttributes(IEnumerable<BaseTextAttribute> attributes, Inline run) {
            attributes.ToList().ForEach(a => {
                switch (a.TextAttributeType) {
                    case TextAttributeTypeEnum.Bold:
                        run.FontWeight = FontWeights.Bold;
                        break;
                    case TextAttributeTypeEnum.Color: {
                            TextAttributeColor taColor = a as TextAttributeColor;
                            if (taColor != null) {
                                run.Foreground = new SolidColorBrush(Color.FromArgb(taColor.Color.A, taColor.Color.R, taColor.Color.G, taColor.Color.B));
                            }
                        } break;
                    case TextAttributeTypeEnum.Font: {
                            TextAttributeFont taFont = a as TextAttributeFont;
                            if (taFont != null) {
                                if (taFont.Font != null) {
                                    TextDecorationCollection textDecorations = new TextDecorationCollection(); // Freezable
                                    run.FontFamily = new FontFamily(taFont.Font.FontFamily.Name);
                                    run.FontSize = taFont.Font.Size;
                                    if (taFont.Font.Style.HasFlag(System.Drawing.FontStyle.Bold)) {
                                        run.FontWeight = FontWeights.Bold;
                                    }
                                    if (taFont.Font.Style.HasFlag(System.Drawing.FontStyle.Italic)) {
                                        run.FontStyle = FontStyles.Italic;
                                    }
                                    if (taFont.Font.Style.HasFlag(System.Drawing.FontStyle.Strikeout)) {
                                        textDecorations.Add(TextDecorations.Strikethrough);
                                    }
                                    if (taFont.Font.Style.HasFlag(System.Drawing.FontStyle.Underline)) {
                                        textDecorations.Add(TextDecorations.Underline);
                                    }
                                    run.TextDecorations = new TextDecorationCollection(textDecorations); // Freezable
                                } else {
                                    run.FontFamily = new FontFamily();
                                    run.FontSize = 12;
                                    run.FontStyle = FontStyles.Normal;
                                    run.FontWeight = FontWeights.Normal;
                                }
                            }
                        } break;
                    case TextAttributeTypeEnum.Italic:
                        run.FontStyle = FontStyles.Italic;
                        break;
                    case TextAttributeTypeEnum.Underline:
                        run.TextDecorations = TextDecorations.Underline;
                        break;
                    case TextAttributeTypeEnum.Zero:
                        break;
                    case TextAttributeTypeEnum.None:
                        break;
                }
            });
            return run;
        }
    }
}


text:
package org.keycloak.testsuite.user.profile.config;

import org.keycloak.component.ComponentModel;
import org.keycloak.userprofile.UserProfileProvider;

/**
 * @author Pedro Igor
 */
public class DeclarativeUserProfileModel extends ComponentModel {

    public DeclarativeUserProfileModel() {
        setProviderId(DeclarativeUserProfileProvider.ID);
        setProviderType(UserProfileProvider.class.getName());
    }
}


text:
// flowlint ambiguous-object-type:error

'use strict';

const {getFragment, getRequest, graphql} = require('../../query/GraphQLTag');
const RelayFeatureFlags = require('../../util/RelayFeatureFlags');
const {createNormalizationSelector} = require('../RelayModernSelector');
const RelayRecordSource = require('../RelayRecordSource');
const {mark} = require('../RelayReferenceMarker');
const {ROOT_ID} = require('../RelayStoreUtils');

describe('RelayReferenceMarker', () => {
  let source;

  beforeEach(() => {
    const data = {
      '1': {
        __id: '1',
        id: '1',
        __typename: 'User',
        firstName: 'Alice',
        'friends(first:3)': {__ref: 'client:1'},
        'profilePicture(size:32)': {__ref: 'client:4'},
      },
      '2': {
        __id: '2',
        __typename: 'User',
        id: '2',
        firstName: 'Bob',
      },
      '3': {
        __id: '3',
        __typename: 'User',
        id: '3',
        firstName: 'Claire',
      },
      'client:1': {
        __id: 'client:1',
        __typename: 'FriendsConnection',
        edges: {
          __refs: ['client:2', null, 'client:3'],
        },
      },
      'client:2': {
        __id: 'client:2',
        __typename: 'FriendsConnectionEdge',
        cursor: 'cursor:2',
        node: {__ref: '2'},
      },
      'client:3': {
        __id: 'client:3',
        __typename: 'FriendsConnectionEdge',
        cursor: 'cursor:3',
        node: {__ref: '3'},
      },
      'client:4': {
        __id: 'client:4',
        __typename: 'Photo',
        uri: 'https://...',
      },
      'client:root': {
        __id: 'client:root',
        __typename: '__Root',
        'node(id:"1")': {__ref: '1'},
      },
    };

    source = RelayRecordSource.create(data);
  });

  it('marks referenced records', () => {
    const FooQuery = getRequest(graphql`
      query RelayReferenceMarkerTest1Query($id: ID, $size: [Int]) {
        node(id: $id) {
          id
          __typename
          ... on Page {
            actors {
              name
            }
          }
          ...RelayReferenceMarkerTest1Fragment @arguments(size: $size)
        }
      }
    `);
    graphql`
      fragment RelayReferenceMarkerTest1Fragment on User
      @argumentDefinitions(size: {type: "[Int]"}) {
        ... on User {
          firstName
          friends(first: 3) {
            edges {
              cursor
              node {
                id
                firstName
              }
            }
          }
          profilePicture(size: $size) {
            uri
          }
        }
      }
    `;
    const references = new Set();
    mark(
      source,
      createNormalizationSelector(FooQuery.operation, ROOT_ID, {
        id: '1',
        size: 32,
      }),
      references,
    );
    expect(Array.from(references).sort()).toEqual([
      '1',
      '2',
      '3',
      'client:1',
      'client:2',
      'client:3',
      'client:4',
      'client:root',
    ]);
  });

  it('marks "handle" nodes for queries', () => {
    const data = {
      '1': {
        __id: '1',
        __typename: 'User',
        'friends(first:1)': {__ref: 'client:1'},
        __friends_bestFriends: {__ref: 'client:bestFriends'},
      },
      '2': {
        __id: '2',
        __typename: 'User',
        id: '2',
      },
      '3': {
        __id: '3',
        __typename: 'User',
        id: '3',
      },
      'client:1': {
        __id: 'client:1',
        __typename: 'FriendsConnection',
        edges: {
          __refs: ['client:2'],
        },
      },
      'client:2': {
        __id: 'client:2',
        __typename: 'FriendsConnectionEdge',
        cursor: 'cursor:2',
        node: {__ref: '2'},
      },
      'client:bestFriends': {
        __id: 'client:bestFriends',
        __typename: 'FriendsConnection',
        edges: {
          __refs: ['client:bestFriendsEdge'],
        },
      },
      'client:bestFriendsEdge': {
        __id: 'client:bestFriendsEdge',
        __typename: 'FriendsConnectionEdge',
        cursor: 'cursor:bestFriendsEdge',
        node: {__ref: '3'},
      },
      'client:root': {
        __id: 'client:root',
        __typename: '__Root',
        'node(id:"1")': {__ref: '1'},
      },
    };
    source = RelayRecordSource.create(data);
    const UserProfile = getRequest(graphql`
      query RelayReferenceMarkerTest2Query($id: ID!) {
        node(id: $id) {
          ... on User {
            friends(first: 1) @__clientField(handle: "bestFriends") {
              edges {
                cursor
                node {
                  id
                  name @__clientField(handle: "friendsName")
                }
              }
            }
          }
        }
      }
    `);
    const references = new Set();
    mark(
      source,
      createNormalizationSelector(UserProfile.operation, ROOT_ID, {
        id: '1',
      }),
      references,
    );
    expect(Array.from(references).sort()).toEqual([
      '1',
      '2',
      '3', // bestFriends.edges[0].node
      'client:1',
      'client:2',
      'client:bestFriends', // bestFriends
      'client:bestFriendsEdge', // bestFriends.edges[0]
      'client:root',
    ]);
  });

  it('marks "handle" nodes with key and filters for queries', () => {
    const data = {
      '1': {
        __id: '1',
        __typename: 'User',
        'friends(first:1,orderby:["first name"])': {__ref: 'client:1'},
        '__UserProfile_friends_bestFriends(orderby:["first name"])': {
          __ref: 'client:bestFriends',
        },
        '__UserProfile_friends_bestFriends(orderby:["last name"])': {
          __ref: 'client:bestFriendsByLastName',
        },
      },
      '2': {
        __id: '2',
        __typename: 'User',
        id: '2',
      },
      '3': {
        __id: '3',
        __typename: 'User',
        id: '3',
      },
      'client:1': {
        __id: 'client:1',
        __typename: 'FriendsConnection',
        edges: {
          __refs: ['client:2'],
        },
      },
      'client:2': {
        __id: 'client:2',
        __typename: 'FriendsConnectionEdge',
        cursor: 'cursor:2',
        node: {__ref: '2'},
      },
      'client:bestFriends': {
        __id: 'client:bestFriends',
        __typename: 'FriendsConnection',
        edges: {
          __refs: ['client:bestFriendsEdge'],
        },
      },
      'client:bestFriendsByLastName': {
        __id: 'client:bestFriendsByLastName',
        __typename: 'FriendsConnection',
        edges: {
          __refs: [],
        },
      },
      'client:bestFriendsEdge': {
        __id: 'client:bestFriendsEdge',
        __typename: 'FriendsConnectionEdge',
        cursor: 'cursor:bestFriendsEdge',
        node: {__ref: '3'},
      },
      'client:root': {
        __id: 'client:root',
        __typename: '__Root',
        'node(id:"1")': {__ref: '1'},
      },
    };
    source = RelayRecordSource.create(data);
    const UserProfile = getRequest(graphql`
      query RelayReferenceMarkerTest3Query($id: ID!, $orderby: [String]) {
        node(id: $id) {
          ... on User {
            friends(first: 1, orderby: $orderby)
              @__clientField(
                handle: "bestFriends"
                key: "UserProfile_friends"
                filters: ["orderby"]
              ) {
              edges {
                cursor
                node {
                  id
                  name @__clientField(handle: "friendsName")
                }
              }
            }
          }
        }
      }
    `);
    let references = new Set();
    mark(
      source,
      createNormalizationSelector(UserProfile.operation, ROOT_ID, {
        id: '1',
        orderby: ['first name'],
      }),
      references,
    );
    expect(Array.from(references).sort()).toEqual([
      '1',
      '2',
      '3', // bestFriends.edges[0].node
      'client:1',
      'client:2',
      'client:bestFriends', // bestFriends
      'client:bestFriendsEdge', // bestFriends.edges[0]
      'client:root',
    ]);

    references = new Set();
    mark(
      source,
      createNormalizationSelector(UserProfile.operation, ROOT_ID, {
        id: '1',
        orderby: ['last name'],
      }),
      references,
    );
    expect(Array.from(references).sort()).toEqual([
      '1',
      'client:bestFriendsByLastName',
      'client:root',
    ]);
  });

  it('marks referenced records for client field', () => {
    const data = {
      '1': {
        __id: '1',
        id: '1',
        __typename: 'User',
        firstName: 'Alice',
        best_friends: {__ref: 'client:1'},
        client_foo: {__ref: 'client:foo'},
      },
      '2': {
        __id: '2',
        __typename: 'User',
        id: '2',
        firstName: 'Bob',
      },
      '3': {
        __id: '3',
        __typename: 'User',
        id: '3',
        firstName: 'Claire',
      },
      'client:1': {
        __id: 'client:1',
        __typename: 'FriendsConnection',
        edges: {
          __refs: ['client:2', null, 'client:3'],
        },
      },
      'client:2': {
        __id: 'client:2',
        __typename: 'FriendsConnectionEdge',
        cursor: 'cursor:2',
        node: {__ref: '2'},
      },
      'client:3': {
        __id: 'client:3',
        __typename: 'FriendsConnectionEdge',
        cursor: 'cursor:3',
        node: {__ref: '3'},
      },
      'client:foo': {
        __id: 'client:foo',
        __typename: 'Foo',
        client_name: 'client',
      },
      'client:root': {
        __id: 'client:root',
        __typename: '__Root',
        'node(id:"1")': {__ref: '1'},
      },
    };
    source = RelayRecordSource.create(data);
    const FooQuery = getRequest(graphql`
      query RelayReferenceMarkerTest4Query($id: ID) {
        node(id: $id) {
          id
          __typename
          ...RelayReferenceMarkerTest2Fragment
        }
      }
    `);
    graphql`
      fragment RelayReferenceMarkerTest2Fragment on User {
        client_foo {
          client_name
          profile_picture(scale: 2) {
            uri
          }
        }
        ... on User {
          nickname
          best_friends {
            client_friends_connection_field
            edges {
              client_friend_edge_field
              cursor
              node {
                id
                firstName
              }
            }
          }
          firstName
        }
      }
    `;
    const references = new Set();
    mark(
      source,
      createNormalizationSelector(FooQuery.operation, ROOT_ID, {
        id: '1',
        size: 32,
      }),
      references,
    );
    expect(Array.from(references).sort()).toEqual([
      '1',
      '2',
      '3',
      'client:1',
      'client:2',
      'client:3',
      'client:foo',
      'client:root',
    ]);
  });

  describe('when using a @match field', () => {
    let BarQuery;
    let loader;

    beforeEach(() => {
      const nodes = {};
      nodes.RelayReferenceMarkerTestPlainUserNameRenderer_name =
        getFragment(graphql`
          fragment RelayReferenceMarkerTestPlainUserNameRenderer_name on PlainUserNameRenderer {
            plaintext
            data {
              text
            }
          }
        `);
      nodes.RelayReferenceMarkerTestMarkdownUserNameRenderer_name =
        getFragment(graphql`
          fragment RelayReferenceMarkerTestMarkdownUserNameRenderer_name on MarkdownUserNameRenderer {
            markdown
            data {
              markup
            }
          }
        `);
      graphql`
        fragment RelayReferenceMarkerTest3Fragment on User {
          id
          nameRenderer @match {
            ...RelayReferenceMarkerTestPlainUserNameRenderer_name
              @module(name: "PlainUserNameRenderer.react")
            ...RelayReferenceMarkerTestMarkdownUserNameRenderer_name
              @module(name: "MarkdownUserNameRenderer.react")
          }
        }
      `;
      BarQuery = getRequest(graphql`
        query RelayReferenceMarkerTest5Query($id: ID!) {
          node(id: $id) {
            ...RelayReferenceMarkerTest3Fragment
          }
        }
      `);
      loader = {
        get: jest.fn(
          moduleName => nodes[String(moduleName).replace(/\$.*/, '')],
        ),
        load: jest.fn(moduleName =>
          Promise.resolve(nodes[String(moduleName).replace(/\$.*/, '')]),
        ),
      };
    });

    it('marks references when the match field/record exist and match a supported type (plaintext)', () => {
      // When the type matches PlainUserNameRenderer
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          'nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
            {
              __ref:
                'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
            },
        },
        'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
          {
            __id: 'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
            __typename: 'PlainUserNameRenderer',
            __module_component_RelayReferenceMarkerTest3Fragment:
              'PlainUserNameRenderer.react',
            __module_operation_RelayReferenceMarkerTest3Fragment:
              'RelayReferenceMarkerTestPlainUserNameRenderer_name$normalization.graphql',
            plaintext: 'plain name',
            data: {__ref: 'data'},
          },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
        data: {
          __id: 'data',
          __typename: 'PlainUserNameData',
          text: 'text',
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        loader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
        'client:root',
        'data',
      ]);
    });

    it('marks references when the match field/record exist and match a supported type (2)', () => {
      // When the type matches MarkdownUserNameRenderer
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          'nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
            {
              __ref:
                'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
            },
        },
        'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
          {
            __id: 'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
            __typename: 'MarkdownUserNameRenderer',
            __module_component_RelayReferenceMarkerTest3Fragment:
              'MarkdownUserNameRenderer.react',
            __module_operation_RelayReferenceMarkerTest3Fragment:
              'RelayReferenceMarkerTestMarkdownUserNameRenderer_name$normalization.graphql',
            markdown: 'markdown payload',
            data: {__ref: 'data'},
          },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
        data: {
          __id: 'data',
          __typename: 'MarkdownUserNameData',
          markup: '<markup/>',
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        loader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
        'client:root',
        'data',
      ]);
    });

    it('marks references when the match field/record exist but the matched fragment has not been processed', () => {
      // The field returned the MarkdownUserNameRenderer type, but the module for that branch
      // has not been loaded. The assumption is that the data cannot have been processed in that
      // case and therefore the markdown field is missing in the store.
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          'nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
            {
              __ref:
                'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
            },
        },
        'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
          {
            __id: 'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
            __typename: 'MarkdownUserNameRenderer',
            // NOTE: markdown/data fields are missing, data not processed.
          },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        // Return null to indicate the fragment is not loaded yet
        {
          get: _ => null,
          load: _ => Promise.resolve(null),
        },
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
        'client:root',
      ]);
    });

    it('marks references when the match field/record exist but a scalar field is missing', () => {
      // the `data` field for the MarkdownUserNameRenderer is missing
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          'nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
            {
              __ref:
                'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
            },
        },
        'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
          {
            __id: 'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
            __typename: 'MarkdownUserNameRenderer',
            __module_component_RelayReferenceMarkerTest3Fragment:
              'MarkdownUserNameRenderer.react',
            __module_operation_RelayReferenceMarkerTest3Fragment:
              'RelayReferenceMarkerTestMarkdownUserNameRenderer_name$normalization.graphql',
            // NOTE: 'markdown' field missing
            data: {__ref: 'data'},
          },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
        data: {
          __id: 'data',
          __typename: 'MarkdownUserNameData',
          markup: '<markup/>',
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        loader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
        'client:root',
        'data',
      ]);
    });

    it('marks references when the match field/record exist but a linked field is missing', () => {
      // the `data` field for the MarkdownUserNameRenderer is missing
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          'nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
            {
              __ref:
                'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
            },
        },
        'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
          {
            __id: 'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
            __typename: 'MarkdownUserNameRenderer',
            markdown: 'markdown text',
            // NOTE: 'data' field missing
          },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        loader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
        'client:root',
      ]);
    });

    it('marks references when the match field/record exist but do not match a supported type', () => {
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          'nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
            {
              __ref:
                'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
            },
        },
        'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
          {
            __id: 'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
            __typename: 'CustomNameRenderer',
            customField: 'custom value',
          },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        loader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])',
        'client:root',
      ]);
    });

    it('marks references when the match field is non-existent (null)', () => {
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          'nameRenderer(supported:["PlainUserNameRenderer","MarkdownUserNameRenderer"])':
            null,
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        loader,
      );
      expect(Array.from(references).sort()).toEqual(['1', 'client:root']);
    });

    it('marks references when the match field is not fetched (undefined)', () => {
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        loader,
      );
      expect(Array.from(references).sort()).toEqual(['1', 'client:root']);
    });
  });

  describe('@module', () => {
    let BarQuery;
    let loader;

    beforeEach(() => {
      const nodes = {};
      nodes.RelayReferenceMarkerTest2PlainUserNameRenderer_name =
        getFragment(graphql`
          fragment RelayReferenceMarkerTest2PlainUserNameRenderer_name on PlainUserNameRenderer {
            plaintext
            data {
              text
            }
          }
        `);
      nodes.RelayReferenceMarkerTest2MarkdownUserNameRenderer_name =
        getFragment(graphql`
          fragment RelayReferenceMarkerTest2MarkdownUserNameRenderer_name on MarkdownUserNameRenderer {
            markdown
            data {
              markup
            }
          }
        `);
      graphql`
        fragment RelayReferenceMarkerTest4Fragment on User {
          id
          nameRenderer {
            # intentionally no @match
            ...RelayReferenceMarkerTest2PlainUserNameRenderer_name
              @module(name: "PlainUserNameRenderer.react")
            ...RelayReferenceMarkerTest2MarkdownUserNameRenderer_name
              @module(name: "MarkdownUserNameRenderer.react")
          }
        }
      `;
      BarQuery = getRequest(graphql`
        query RelayReferenceMarkerTest6Query($id: ID!) {
          node(id: $id) {
            ...RelayReferenceMarkerTest4Fragment
          }
        }
      `);
      loader = {
        get: jest.fn(
          moduleName => nodes[String(moduleName).replace(/\$.*/, '')],
        ),
        load: jest.fn(moduleName =>
          Promise.resolve(nodes[String(moduleName).replace(/\$.*/, '')]),
        ),
      };
    });

    it('marks references when the field/record exists and matches a @module selection (plaintext)', () => {
      // When the type matches PlainUserNameRenderer
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          nameRenderer: {
            __ref: 'client:1:nameRenderer',
          },
        },
        'client:1:nameRenderer': {
          __id: 'client:1:nameRenderer',
          __typename: 'PlainUserNameRenderer',
          __module_component_RelayReferenceMarkerTest4Fragment:
            'PlainUserNameRenderer.react',
          __module_operation_RelayReferenceMarkerTest4Fragment:
            'RelayReferenceMarkerTest2PlainUserNameRenderer_name$normalization.graphql',
          plaintext: 'plain name',
          data: {__ref: 'data'},
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
        data: {
          __id: 'data',
          __typename: 'PlainUserNameData',
          text: 'text',
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        loader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:nameRenderer',
        'client:root',
        'data',
      ]);
    });

    it('marks references when the field/record exists and matches a @module selection (markdown)', () => {
      // When the type matches MarkdownUserNameRenderer
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          nameRenderer: {
            __ref: 'client:1:nameRenderer',
          },
        },
        'client:1:nameRenderer': {
          __id: 'client:1:nameRenderer',
          __typename: 'MarkdownUserNameRenderer',
          __module_component_RelayReferenceMarkerTest4Fragment:
            'MarkdownUserNameRenderer.react',
          __module_operation_RelayReferenceMarkerTest4Fragment:
            'RelayReferenceMarkerTest2MarkdownUserNameRenderer_name$normalization.graphql',
          markdown: 'markdown payload',
          data: {__ref: 'data'},
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
        data: {
          __id: 'data',
          __typename: 'MarkdownUserNameData',
          markup: '<markup/>',
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        loader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:nameRenderer',
        'client:root',
        'data',
      ]);
    });

    it('marks references when the field/record exists but the @module fragment has not been processed', () => {
      // The field returned the MarkdownUserNameRenderer type, but the module for that branch
      // has not been loaded. The assumption is that the data cannot have been processed in that
      // case and therefore the markdown field is missing in the store.
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          nameRenderer: {
            __ref: 'client:1:nameRenderer',
          },
        },
        'client:1:nameRenderer': {
          __id: 'client:1:nameRenderer',
          __typename: 'MarkdownUserNameRenderer',
          // NOTE: markdown/data fields are missing, data not processed.
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        // Return null to indicate the fragment is not loaded yet
        {
          get: _ => null,
          load: _ => Promise.resolve(null),
        },
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:nameRenderer',
        'client:root',
      ]);
    });

    it('marks references when the field/record exists but a scalar field is missing', () => {
      // the `data` field for the MarkdownUserNameRenderer is missing
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          nameRenderer: {
            __ref: 'client:1:nameRenderer',
          },
        },
        'client:1:nameRenderer': {
          __id: 'client:1:nameRenderer',
          __typename: 'MarkdownUserNameRenderer',
          __module_component_RelayReferenceMarkerTest4Fragment:
            'MarkdownUserNameRenderer.react',
          __module_operation_RelayReferenceMarkerTest4Fragment:
            'RelayReferenceMarkerTest2MarkdownUserNameRenderer_name$normalization.graphql',
          // NOTE: 'markdown' field missing
          data: {__ref: 'data'},
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
        data: {
          __id: 'data',
          __typename: 'MarkdownUserNameData',
          markup: '<markup/>',
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        loader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:nameRenderer',
        'client:root',
        'data',
      ]);
    });

    it('marks references when the field/record exists but a linked field is missing', () => {
      // the `data` field for the MarkdownUserNameRenderer is missing
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          nameRenderer: {
            __ref: 'client:1:nameRenderer',
          },
        },
        'client:1:nameRenderer': {
          __id: 'client:1:nameRenderer',
          __typename: 'MarkdownUserNameRenderer',
          markdown: 'markdown text',
          // NOTE: 'data' field missing
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        loader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:nameRenderer',
        'client:root',
      ]);
    });

    it('marks references when the field/record exists but do not match any @module selection', () => {
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          nameRenderer: {
            __ref: 'client:1:nameRenderer',
          },
        },
        'client:1:nameRenderer': {
          __id: 'client:1:nameRenderer',
          __typename: 'CustomNameRenderer',
          customField: 'custom value',
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        source,
        createNormalizationSelector(BarQuery.operation, 'client:root', {
          id: '1',
        }),
        references,
        loader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:nameRenderer',
        'client:root',
      ]);
    });

    it('throws if no operation loader is provided', () => {
      const storeData = {
        '1': {
          __id: '1',
          id: '1',
          __typename: 'User',
          nameRenderer: {
            __ref: 'client:1:nameRenderer',
          },
        },
        'client:1:nameRenderer': {
          __id: 'client:1:nameRenderer',
          __typename: 'PlainUserNameRenderer',
          __module_component_RelayReferenceMarkerTest4Fragment:
            'PlainUserNameRenderer.react',
          __module_operation_RelayReferenceMarkerTest4Fragment:
            'RelayReferenceMarkerTest2PlainUserNameRenderer_name$normalization.graphql',
          plaintext: 'plain name',
          data: {__ref: 'data'},
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
        data: {
          __id: 'data',
          __typename: 'PlainUserNameData',
          text: 'text',
        },
      };
      source = RelayRecordSource.create(storeData);
      const references = new Set();
      expect(() =>
        mark(
          source,
          createNormalizationSelector(BarQuery.operation, 'client:root', {
            id: '1',
          }),
          references,
          null, // operationLoader
        ),
      ).toThrow(
        'RelayReferenceMarker: Expected an operationLoader to be configured when ' +
          'using `@module`. Could not load fragment `RelayReferenceMarkerTest2PlainUserNameRenderer_name` ' +
          'in operation `RelayReferenceMarkerTest6Query`.',
      );
    });
  });

  describe('when @defer directive is present', () => {
    let Query;

    beforeEach(() => {
      graphql`
        fragment RelayReferenceMarkerTest5Fragment on Feedback {
          id
          actors {
            name
          }
        }
      `;
      Query = getRequest(graphql`
        query RelayReferenceMarkerTest7Query($id: ID!) {
          node(id: $id) {
            ...RelayReferenceMarkerTest5Fragment @defer(label: "TestFragment")
          }
        }
      `);
    });

    it('marks references when deferred selections are fetched', () => {
      const storeData = {
        '1': {
          __id: '1',
          __typename: 'Feedback',
          id: '1',
          actors: {__refs: ['2']},
        },
        '2': {
          __id: '2',
          __typename: 'User',
          id: '2',
          name: 'Alice',
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
      };
      const recordSource = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        recordSource,
        createNormalizationSelector(Query.operation, 'client:root', {id: '1'}),
        references,
      );
      expect(Array.from(references).sort()).toEqual(['1', '2', 'client:root']);
    });

    it('marks references when deferred selections are not fetched', () => {
      const storeData = {
        '1': {
          __id: '1',
          __typename: 'Feedback',
          id: '1',
          // actors not fetched
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
      };
      const recordSource = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        recordSource,
        createNormalizationSelector(Query.operation, 'client:root', {id: '1'}),
        references,
      );
      expect(Array.from(references).sort()).toEqual(['1', 'client:root']);
    });
  });

  describe('when @stream directive is present', () => {
    let Query;

    beforeEach(() => {
      graphql`
        fragment RelayReferenceMarkerTest6Fragment on Feedback {
          id
          actors @stream(label: "TestFragmentActors", initial_count: 0) {
            name
          }
        }
      `;
      Query = getRequest(graphql`
        query RelayReferenceMarkerTest8Query($id: ID!) {
          node(id: $id) {
            ...RelayReferenceMarkerTest6Fragment
          }
        }
      `);
    });

    it('marks references when streamed selections are fetched', () => {
      const storeData = {
        '1': {
          __id: '1',
          __typename: 'Feedback',
          id: '1',
          actors: {__refs: ['2']},
        },
        '2': {
          __id: '2',
          __typename: 'User',
          id: '2',
          name: 'Alice',
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
      };
      const recordSource = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        recordSource,
        createNormalizationSelector(Query.operation, 'client:root', {id: '1'}),
        references,
      );
      expect(Array.from(references).sort()).toEqual(['1', '2', 'client:root']);
    });

    it('marks references when streamed selections are not fetched', () => {
      const storeData = {
        '1': {
          __id: '1',
          __typename: 'Feedback',
          id: '1',
          // actors not fetched
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {__ref: '1'},
        },
      };
      const recordSource = RelayRecordSource.create(storeData);
      const references = new Set();
      mark(
        recordSource,
        createNormalizationSelector(Query.operation, 'client:root', {id: '1'}),
        references,
      );
      expect(Array.from(references).sort()).toEqual(['1', 'client:root']);
    });
  });

  describe('with feature ENABLE_REACT_FLIGHT_COMPONENT_FIELD', () => {
    let FlightQuery;
    let InnerQuery;
    let operationLoader;

    const readRoot = () => {
      return {
        $$typeof: Symbol.for('react.element'),
        type: 'div',
        key: null,
        ref: null,
        props: {foo: 1},
      };
    };

    beforeEach(() => {
      RelayFeatureFlags.ENABLE_REACT_FLIGHT_COMPONENT_FIELD = true;

      FlightQuery = getRequest(graphql`
        query RelayReferenceMarkerTestFlightQuery($id: ID!, $count: Int!) {
          node(id: $id) {
            ... on Story {
              flightComponent(condition: true, count: $count, id: $id)
            }
          }
        }
      `);
      InnerQuery = getRequest(graphql`
        query RelayReferenceMarkerTestInnerQuery($id: ID!) {
          node(id: $id) {
            ... on User {
              name
            }
          }
        }
      `);
      operationLoader = {
        get: jest.fn(() => getRequest(InnerQuery)),
        load: jest.fn(() => Promise.resolve(getRequest(InnerQuery))),
      };
    });
    afterEach(() => {
      RelayFeatureFlags.ENABLE_REACT_FLIGHT_COMPONENT_FIELD = false;
    });

    it('marks references when Flight fields are fetched', () => {
      const data = {
        '1': {
          __id: '1',
          __typename: 'Story',
          'flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})':
            {
              __ref:
                'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})',
            },
          id: '1',
        },
        '2': {
          __id: '2',
          __typename: 'User',
          id: '2',
          name: 'Lauren',
        },
        'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})':
          {
            __id: 'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})',
            __typename: 'ReactFlightComponent',
            executableDefinitions: [
              {
                module: {
                  __dr: 'RelayFlightExampleQuery.graphql',
                },
                variables: {
                  id: '2',
                },
              },
            ],
            tree: {
              readRoot,
            },
          },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {
            __ref: '1',
          },
          'node(id:"2")': {
            __ref: '2',
          },
        },
      };
      const recordSource = RelayRecordSource.create(data);
      const references = new Set();
      mark(
        recordSource,
        createNormalizationSelector(FlightQuery.operation, 'client:root', {
          count: 10,
          id: '1',
        }),
        references,
        operationLoader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        '2',
        'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})',
        'client:root',
      ]);
    });

    it('marks references when the Flight field exists but has not been processed', () => {
      const data = {
        '1': {
          __id: '1',
          __typename: 'Story',
          'flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})':
            {
              __ref:
                'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})',
            },
          id: '1',
        },
        'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})':
          {
            __id: 'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})',
            __typename: 'ReactFlightComponent',
          },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {
            __ref: '1',
          },
        },
      };
      const recordSource = RelayRecordSource.create(data);
      const references = new Set();
      mark(
        recordSource,
        createNormalizationSelector(FlightQuery.operation, 'client:root', {
          count: 10,
          id: '1',
        }),
        references,
        operationLoader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})',
        'client:root',
      ]);
    });

    it('marks references when the Flight field is null', () => {
      const data = {
        '1': {
          __id: '1',
          __typename: 'Story',
          'flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})':
            {
              __ref:
                'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})',
            },
          id: '1',
        },
        'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})':
          null,
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {
            __ref: '1',
          },
        },
      };
      const recordSource = RelayRecordSource.create(data);
      const references = new Set();
      mark(
        recordSource,
        createNormalizationSelector(FlightQuery.operation, 'client:root', {
          count: 10,
          id: '1',
        }),
        references,
        operationLoader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})',
        'client:root',
      ]);
    });

    it('marks references when the Flight field is undefined', () => {
      const data = {
        '1': {
          __id: '1',
          __typename: 'Story',
          'flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})':
            {
              __ref:
                'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})',
            },
          id: '1',
        },
        'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})':
          undefined,
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {
            __ref: '1',
          },
        },
      };
      const recordSource = RelayRecordSource.create(data);
      const references = new Set();
      mark(
        recordSource,
        createNormalizationSelector(FlightQuery.operation, 'client:root', {
          count: 10,
          id: '1',
        }),
        references,
        operationLoader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})',
        'client:root',
      ]);
    });

    it('marks references when the linked ReactFlightClientResponseRecord is missing', () => {
      const data = {
        '1': {
          __id: '1',
          __typename: 'Story',
          'flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})':
            {
              __ref:
                'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})',
            },
          id: '1',
        },
        'client:root': {
          __id: 'client:root',
          __typename: '__Root',
          'node(id:"1")': {
            __ref: '1',
          },
        },
      };
      const recordSource = RelayRecordSource.create(data);
      const references = new Set();
      mark(
        recordSource,
        createNormalizationSelector(FlightQuery.operation, 'client:root', {
          count: 10,
          id: '1',
        }),
        references,
        operationLoader,
      );
      expect(Array.from(references).sort()).toEqual([
        '1',
        'client:1:flight(component:"FlightComponent.server",props:{"condition":true,"count":10,"id":"1"})',
        'client:root',
      ]);
    });
  });
});