@@ -3,13 +3,14 @@ import { Document, parse, parseDocument } from 'yaml'
33
44test ( 'basic' , ( ) => {
55 const src = `- &a 1\n- *a\n`
6- const doc = parseDocument < YAMLSeq > ( src )
6+ const doc = parseDocument < YAMLSeq , false > ( src )
77 expect ( doc . errors ) . toHaveLength ( 0 )
88 expect ( doc . contents ?. items ) . toMatchObject ( [
99 { anchor : 'a' , value : 1 } ,
1010 { source : 'a' }
1111 ] )
1212 expect ( String ( doc ) ) . toBe ( src )
13+ expect ( doc . get ( 1 ) . resolve ( doc ) ) . toBe ( doc . get ( 0 , true ) )
1314} )
1415
1516test ( 're-defined anchor' , ( ) => {
@@ -27,7 +28,7 @@ test('re-defined anchor', () => {
2728
2829test ( 'circular reference' , ( ) => {
2930 const src = '&a [ 1, *a ]\n'
30- const doc = parseDocument ( src )
31+ const doc = parseDocument < YAMLSeq , false > ( src )
3132 expect ( doc . errors ) . toHaveLength ( 0 )
3233 expect ( doc . warnings ) . toHaveLength ( 0 )
3334 expect ( doc . contents ) . toMatchObject ( {
@@ -37,6 +38,7 @@ test('circular reference', () => {
3738 const res = doc . toJS ( )
3839 expect ( res [ 1 ] ) . toBe ( res )
3940 expect ( String ( doc ) ) . toBe ( src )
41+ expect ( doc . get ( 1 ) . resolve ( doc ) ) . toBe ( doc . contents )
4042} )
4143
4244describe ( 'anchor on tagged collection' , ( ) => {
@@ -146,6 +148,25 @@ describe('errors', () => {
146148 const doc = parseDocument ( '- &\n' )
147149 expect ( doc . errors ) . toMatchObject ( [ { code : 'BAD_ALIAS' } ] )
148150 } )
151+
152+ test ( 'resolution with maxAliasCount:0' , ( ) => {
153+ const src = `- &a 1\n- *a\n`
154+ const doc = parseDocument < YAMLSeq , false > ( src )
155+ expect ( doc . errors ) . toHaveLength ( 0 )
156+ expect ( ( ) => doc . get ( 1 ) . resolve ( doc , { maxAliasCount : 0 } ) ) . toThrow (
157+ ReferenceError
158+ )
159+ } )
160+
161+ test ( 'circular reference' , ( ) => {
162+ const src = '&A { <<: *A, B: b }\n'
163+ const doc = parseDocument ( src , { merge : true } )
164+ expect ( doc . errors ) . toHaveLength ( 0 )
165+ expect ( doc . warnings ) . toHaveLength ( 0 )
166+ expect ( ( ) => doc . toJS ( ) ) . toThrow ( 'Maximum call stack size exceeded' )
167+ expect ( ( ) => doc . toJS ( { maxAliasCount : 0 } ) ) . toThrow ( ReferenceError )
168+ expect ( String ( doc ) ) . toBe ( src )
169+ } )
149170} )
150171
151172describe ( 'warnings' , ( ) => {
455476 )
456477 } )
457478
458- test ( 'circular reference' , ( ) => {
459- const src = '&A { <<: *A, B: b }\n'
460- const doc = parseDocument ( src , { merge : true } )
461- expect ( doc . errors ) . toHaveLength ( 0 )
462- expect ( doc . warnings ) . toHaveLength ( 0 )
463- expect ( ( ) => doc . toJS ( ) ) . toThrow ( 'Maximum call stack size exceeded' )
464- expect ( String ( doc ) ) . toBe ( src )
465- } )
466-
467479 test ( 'missing whitespace' , ( ) => {
468480 expect ( ( ) => parse ( '&a{}' ) ) . toThrow (
469481 'Tags and anchors must be separated from the next token by white space'
0 commit comments