# TODO(fmt): wild attempt to align fields of builtin struct arguments: cuelang.org/issue/1546

# generated from the original tests.
# Henceforth it may be nicer to group tests into separate files.
-- in.cue --
import "encoding/yaml"

t1: yaml.Validate("a: 2\n---\na: 4", {a:        <3})
t2: yaml.Validate("a: 2\n---\na: 4", {a:        <5})
t3: yaml.Validate("a: 2\n", {a:                 <5, b: int})
t4: yaml.ValidatePartial("a: 2\n---\na: 4", {a: <3})
t5: yaml.ValidatePartial("a: 2\n---\na: 4", {a: <5})
t6: yaml.ValidatePartial("a: 2\n", {a:          <5, b:  int})
t7: yaml.MarshalStream([{a:                     1}, {b: 2}])
t8: yaml.Marshal({b:                            int | *2})
t9: yaml.MarshalStream([{a:                     1}, {b: int | *2}])

unmarshalStream: {
	t1:    yaml.UnmarshalStream("a: 1\n---\nb: 2")
	t1:    yaml.UnmarshalStream('a: 1\n---\nb: 2')
	empty: yaml.UnmarshalStream('')
	empty: yaml.UnmarshalStream("")
	nums:  yaml.UnmarshalStream('1\n---\n2')
	nums:  yaml.UnmarshalStream("1\n---\n2")
	null1: yaml.UnmarshalStream('1\n---\n---\n2')
	null1: yaml.UnmarshalStream("1\n---\n---\n2")
	null2: yaml.UnmarshalStream('1\n---\n---\n2')
	null2: yaml.UnmarshalStream("1\n---\n---\n2")
}

unmarshalTrailingInput: {
	valid:   yaml.Unmarshal("1\n---\n2")
	invalid: yaml.Unmarshal("1\n---\n}invalid yaml")
}
-- out/yaml --
Errors:
t1: error in call to encoding/yaml.Validate: invalid value 4 (out of bound <3):
    ./in.cue:3:5
    ./in.cue:3:49
    yaml.Validate:3:4
t3: error in call to encoding/yaml.Validate: incomplete value int:
    ./in.cue:5:5
    ./in.cue:5:56
t4: error in call to encoding/yaml.ValidatePartial: invalid value 4 (out of bound <3):
    ./in.cue:6:5
    ./in.cue:6:49
    yaml.ValidatePartial:3:4
unmarshalTrailingInput.valid: error in call to encoding/yaml.Unmarshal: 3:1: expected a single YAML document:
    ./in.cue:27:11
unmarshalTrailingInput.invalid: error in call to encoding/yaml.Unmarshal: expected a single YAML document: :2: did not find expected node content:
    ./in.cue:28:11

Result:
t1: _|_ // t1: error in call to encoding/yaml.Validate: t1.a: invalid value 4 (out of bound <3)
t2: true
t3: _|_ // t3: error in call to encoding/yaml.Validate: t3.b: incomplete value int
t4: _|_ // t4: error in call to encoding/yaml.ValidatePartial: t4.a: invalid value 4 (out of bound <3)
t5: true
t6: true
t7: """
	a: 1
	---
	b: 2

	"""
t8: """
	b: 2

	"""
t9: """
	a: 1
	---
	b: 2

	"""
unmarshalStream: {
	t1: [{
		a: 1
	}, {
		b: 2
	}]
	empty: [*null | _]
	nums: [1, 2]
	null1: [1, null, 2]
	null2: [1, null, 2]
}
unmarshalTrailingInput: {
	valid:   _|_ // unmarshalTrailingInput.valid: error in call to encoding/yaml.Unmarshal: 3:1: expected a single YAML document
	invalid: _|_ // unmarshalTrailingInput.invalid: error in call to encoding/yaml.Unmarshal: expected a single YAML document: :2: did not find expected node content
}
