[
    {
        "description": "root pointer ref",
        "schema": {
            "properties": {
                "foo": {"$ref": "#"}
            },
            "additionalProperties": false
        },
        "tests": [
            {
                "description": "match",
                "data": {"foo": false},
                "valid": true
            },
            {
                "description": "recursive match",
                "data": {"foo": {"foo": false}},
                "valid": true
            },
            {
                "description": "mismatch",
                "data": {"bar": false},
                "valid": false
            },
            {
                "description": "recursive mismatch",
                "data": {"foo": {"bar": false}},
                "valid": false
            }
        ]
    },
    {
        "description": "relative pointer ref to object",
        "schema": {
            "properties": {
                "foo": {"type": "integer"},
                "bar": {"$ref": "#/properties/foo"}
            }
        },
        "tests": [
            {
                "description": "match",
                "data": {"bar": 3},
                "valid": true
            },
            {
                "description": "mismatch",
                "data": {"bar": true},
                "valid": false
            }
        ]
    },
    {
        "description": "relative pointer ref to array",
        "schema": {
            "items": [
                {"type": "integer"},
                {"$ref": "#/items/0"}
            ]
        },
        "tests": [
            {
                "description": "match array",
                "data": [1, 2],
                "valid": true
            },
            {
                "description": "mismatch array",
                "data": [1, "foo"],
                "valid": false
            }
        ]
    },
    {
        "description": "escaped pointer ref",
        "schema": {
            "$defs": {
                "tilda~field": {"type": "integer"},
                "slash/field": {"type": "integer"},
                "percent%field": {"type": "integer"}
            },
            "properties": {
                "tilda": {"$ref": "#/$defs/tilda~0field"},
                "slash": {"$ref": "#/$defs/slash~1field"},
                "percent": {"$ref": "#/$defs/percent%25field"}
            }
        },
        "tests": [
            {
                "description": "slash invalid",
                "data": {"slash": "aoeu"},
                "valid": false
            },
            {
                "description": "tilda invalid",
                "data": {"tilda": "aoeu"},
                "valid": false
            },
            {
                "description": "percent invalid",
                "data": {"percent": "aoeu"},
                "valid": false
            },
            {
                "description": "slash valid",
                "data": {"slash": 123},
                "valid": true
            },
            {
                "description": "tilda valid",
                "data": {"tilda": 123},
                "valid": true
            },
            {
                "description": "percent valid",
                "data": {"percent": 123},
                "valid": true
            }
        ]
    },
    {
        "description": "nested refs",
        "schema": {
            "$defs": {
                "a": {"type": "integer"},
                "b": {"$ref": "#/$defs/a"},
                "c": {"$ref": "#/$defs/b"}
            },
            "$ref": "#/$defs/c"
        },
        "tests": [
            {
                "description": "nested ref valid",
                "data": 5,
                "valid": true
            },
            {
                "description": "nested ref invalid",
                "data": "a",
                "valid": false
            }
        ]
    },
    {
        "description": "ref applies alongside sibling keywords",
        "schema": {
            "$defs": {
                "reffed": {
                    "type": "array"
                }
            },
            "properties": {
                "foo": {
                    "$ref": "#/$defs/reffed",
                    "maxItems": 2
                }
            }
        },
        "tests": [
            {
                "description": "ref valid, maxItems valid",
                "data": { "foo": [] },
                "valid": true
            },
            {
                "description": "ref valid, maxItems invalid",
                "data": { "foo": [1, 2, 3] },
                "valid": false
            },
            {
                "description": "ref invalid",
                "data": { "foo": "string" },
                "valid": false
            }
        ]
    },
    {
        "description": "remote ref, containing refs itself",
        "schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"},
        "tests": [
            {
                "description": "remote ref valid",
                "data": {"minLength": 1},
                "valid": true
            },
            {
                "description": "remote ref invalid",
                "data": {"minLength": -1},
                "valid": false
            }
        ]
    },
    {
        "description": "property named $ref that is not a reference",
        "schema": {
            "properties": {
                "$ref": {"type": "string"}
            }
        },
        "tests": [
            {
                "description": "property named $ref valid",
                "data": {"$ref": "a"},
                "valid": true
            },
            {
                "description": "property named $ref invalid",
                "data": {"$ref": 2},
                "valid": false
            }
        ]
    },
    {
        "description": "$ref to boolean schema true",
        "schema": {
            "$ref": "#/$defs/bool",
            "$defs": {
                "bool": true
            }
        },
        "tests": [
            {
                "description": "any value is valid",
                "data": "foo",
                "valid": true
            }
        ]
    },
    {
        "description": "$ref to boolean schema false",
        "schema": {
            "$ref": "#/$defs/bool",
            "$defs": {
                "bool": false
            }
        },
        "tests": [
            {
                "description": "any value is invalid",
                "data": "foo",
                "valid": false
            }
        ]
    },
    {
        "description": "Recursive references between schemas",
        "schema": {
            "$id": "http://localhost:1234/tree",
            "description": "tree of nodes",
            "type": "object",
            "properties": {
                "meta": {"type": "string"},
                "nodes": {
                    "type": "array",
                    "items": {"$ref": "node"}
                }
            },
            "required": ["meta", "nodes"],
            "$defs": {
                "node": {
                    "$id": "http://localhost:1234/node",
                    "description": "node",
                    "type": "object",
                    "properties": {
                        "value": {"type": "number"},
                        "subtree": {"$ref": "tree"}
                    },
                    "required": ["value"]
                }
            }
        },
        "tests": [
            {
                "description": "valid tree",
                "data": { 
                    "meta": "root",
                    "nodes": [
                        {
                            "value": 1,
                            "subtree": {
                                "meta": "child",
                                "nodes": [
                                    {"value": 1.1},
                                    {"value": 1.2}
                                ]
                            }
                        },
                        {
                            "value": 2,
                            "subtree": {
                                "meta": "child",
                                "nodes": [
                                    {"value": 2.1},
                                    {"value": 2.2}
                                ]
                            }
                        }
                    ]
                },
                "valid": true
            },
            {
                "description": "invalid tree",
                "data": { 
                    "meta": "root",
                    "nodes": [
                        {
                            "value": 1,
                            "subtree": {
                                "meta": "child",
                                "nodes": [
                                    {"value": "string is invalid"},
                                    {"value": 1.2}
                                ]
                            }
                        },
                        {
                            "value": 2,
                            "subtree": {
                                "meta": "child",
                                "nodes": [
                                    {"value": 2.1},
                                    {"value": 2.2}
                                ]
                            }
                        }
                    ]
                },
                "valid": false
            }
        ]
    },
    {
        "description": "refs with quote",
        "schema": {
            "properties": {
                "foo\"bar": {"$ref": "#/$defs/foo%22bar"}
            },
            "$defs": {
                "foo\"bar": {"type": "number"}
            }
        },
        "tests": [
            {
                "description": "object with numbers is valid",
                "data": {
                    "foo\"bar": 1
                },
                "valid": true
            },
            {
                "description": "object with strings is invalid",
                "data": {
                    "foo\"bar": "1"
                },
                "valid": false
            }
        ]
    },
    {
        "description": "ref creates new scope when adjacent to keywords",
        "schema": {
            "$defs": {
                "A": {
                    "unevaluatedProperties": false
                }
            },
            "properties": {
                "prop1": {
                    "type": "string"
                }
            },
            "$ref": "#/$defs/A"
        },
        "tests": [
            {
                "description": "referenced subschema doesn't see annoations from properties",
                "data": {
                    "prop1": "match"
                },
                "valid": false
            }
        ]
    }
]