| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # |
| 3 | # StreamNode test cases for go-yaml |
| 4 | # |
| 5 | # Purpose: Tests YAML stream node functionality including stream boundaries, |
| 6 | # directives, and encoding information. Validates that WithStreamNodes() option |
| 7 | # correctly returns interleaved StreamNode and DocumentNode patterns. |
| 8 | # |
| 9 | # Format: Test cases use type-as-key format: |
| 10 | # - stream-test: |
| 11 | # name: Test case name |
| 12 | # yaml: YAML input string |
| 13 | # with: # Optional: loader options |
| 14 | # no-stream-nodes: true # Disable stream nodes |
| 15 | # want: List of expected nodes with their properties |
| 16 | # |
| 17 | # Test Types: |
| 18 | # stream-test - Validates stream node patterns and metadata |
| 19 | # |
| 20 | # Common Keys: |
| 21 | # name - Test case name (string) |
| 22 | # yaml - Input YAML string to parse |
| 23 | # with - Optional loader options (map) |
| 24 | # no-stream-nodes - Disable stream nodes (default: false) |
| 25 | # want - List of expected nodes with kind and optional properties |
| 26 | # |
| 27 | # Node Format in 'want': |
| 28 | # kind: - Node kind: Stream or Document (required) |
| 29 | # stream: - Stream metadata (for Stream nodes only, nested structure): |
| 30 | # encoding: - Encoding name: UTF-8, UTF-16LE, UTF-16BE |
| 31 | # version: - Version string like "1.1" |
| 32 | # tag-directives: - List of tag directive objects |
| 33 | |
| 34 | # Empty stream returns single StreamNode |
| 35 | - stream-test: |
| 36 | name: empty stream |
| 37 | yaml: '' |
| 38 | want: |
| 39 | - kind: Stream |
| 40 | stream: |
| 41 | encoding: UTF-8 |
| 42 | |
| 43 | # Single document returns [Stream, Doc, Stream] |
| 44 | - stream-test: |
| 45 | name: single document |
| 46 | yaml: 'key: value' |
| 47 | want: |
| 48 | - kind: Stream |
| 49 | stream: |
| 50 | encoding: UTF-8 |
| 51 | - kind: Document |
| 52 | - kind: Stream |
| 53 | stream: |
| 54 | encoding: UTF-8 |
| 55 | |
| 56 | # Multiple documents return interleaved pattern |
| 57 | - stream-test: |
| 58 | name: multi document |
| 59 | yaml: | |
| 60 | --- |
| 61 | key1: value1 |
| 62 | --- |
| 63 | key2: value2 |
| 64 | want: |
| 65 | - kind: Stream |
| 66 | stream: |
| 67 | encoding: UTF-8 |
| 68 | - kind: Document |
| 69 | - kind: Stream |
| 70 | stream: |
| 71 | encoding: UTF-8 |
| 72 | - kind: Document |
| 73 | - kind: Stream |
| 74 | stream: |
| 75 | encoding: UTF-8 |
| 76 | |
| 77 | # YAML version directive captured on first StreamNode |
| 78 | - stream-test: |
| 79 | name: version directive |
| 80 | yaml: | |
| 81 | %YAML 1.1 |
| 82 | %TAG ! tag:example.com,2000:app/ |
| 83 | --- |
| 84 | key: value |
| 85 | want: |
| 86 | - kind: Stream |
| 87 | stream: |
| 88 | encoding: UTF-8 |
| 89 | version: "1.1" |
| 90 | tag-directives: |
| 91 | - handle: "!" |
| 92 | prefix: "tag:example.com,2000:app/" |
| 93 | - kind: Document |
| 94 | - kind: Stream |
| 95 | stream: |
| 96 | encoding: UTF-8 |
| 97 | |
| 98 | # Encoding is set on all StreamNodes |
| 99 | - stream-test: |
| 100 | name: encoding check |
| 101 | yaml: 'key: value' |
| 102 | want: |
| 103 | - kind: Stream |
| 104 | stream: |
| 105 | encoding: UTF-8 |
| 106 | - kind: Document |
| 107 | - kind: Stream |
| 108 | stream: |
| 109 | encoding: UTF-8 |
| 110 | |
| 111 | # Backward compatibility - without stream nodes option |
| 112 | - stream-test: |
| 113 | name: backward compat |
| 114 | yaml: | |
| 115 | --- |
| 116 | a: 1 |
| 117 | --- |
| 118 | b: 2 |
| 119 | with: |
| 120 | no-stream-nodes: true |
| 121 | want: |
| 122 | - kind: Document |
| 123 | - kind: Document |
| 124 | |
| 125 | # Explicitly disabled stream nodes |
| 126 | - stream-test: |
| 127 | name: disabled |
| 128 | yaml: 'key: value' |
| 129 | with: |
| 130 | no-stream-nodes: true |
| 131 | want: |
| 132 | - kind: Document |