# Tests that matching a data value against a large matchIf schema (with many
# nested disjunctions and required fields) completes in bounded time. The
# schema models a Dependabot config; the original issue caused a hang.
# https://cuelang.org/issue/3514
-- in.cue --
import "list"

_schema & _data
_data: {
	"updates": [
		{
			"schedule": {
				"interval": "daily"
			}
		}
	]
}

_schema: {
	matchIf(
	null | bool | number | string | [...] | {"enable-beta-ecosystems"!: true},
	_,
	null | bool | number | string | [...] | {
		"updates"?: null | bool | number | string | [...null | bool | number | string | [...] | {...}] | {...}
		...
	},
	) & {
		"updates"!: [...#update]
	}

	#update: {
		"schedule"!: {
			"timezone"?: #timezone
			...
		}
		...
	}

	// This was originally a list of 571 explicit time zones.
	#timezone: or([for i in list.Range(0, 571, 1) {"\(i)"}])
}
-- out/compile --
--- in.cue
{
  (〈0;_schema〉 & 〈0;_data〉)
  _data: {
    updates: [
      {
        schedule: {
          interval: "daily"
        }
      },
    ]
  }
  _schema: {
    (matchIf((null|bool|number|string|[
      ...,
    ]|{
      "enable-beta-ecosystems"!: true
    }), _, (null|bool|number|string|[
      ...,
    ]|{
      updates?: (null|bool|number|string|[
        ...(null|bool|number|string|[
          ...,
        ]|{
          ...
        }),
      ]|{
        ...
      })
      ...
    })) & {
      updates!: [
        ...〈2;#update〉,
      ]
    })
    #update: {
      schedule!: {
        timezone?: 〈2;#timezone〉
        ...
      }
      ...
    }
    #timezone: or([
      for _, i in 〈import;list〉.Range(0, 571, 1) {
        "\(〈1;i〉)"
      },
    ])
  }
}
