@@ -55,6 +55,75 @@ suite("CachedAsyncIterable", function() {
5555 } ) ;
5656 } ) ;
5757
58+ suite ( "sync iteration over cached elements" , function ( ) {
59+ let o1 , o2 ;
60+
61+ suiteSetup ( function ( ) {
62+ o1 = Object ( ) ;
63+ o2 = Object ( ) ;
64+ } ) ;
65+
66+ test ( "sync iterable with no cached elements yet" , function ( ) {
67+ function * generate ( ) {
68+ yield * [ o1 , o2 ] ;
69+ }
70+
71+ const iterable = new CachedAsyncIterable ( generate ( ) ) ;
72+ assert . deepEqual ( [ ...iterable ] , [ ] ) ;
73+ } ) ;
74+
75+ test ( "sync iterable with a few elements cached so far" , async function ( ) {
76+ function * generate ( ) {
77+ yield * [ o1 , o2 ] ;
78+ }
79+
80+ const iterable = new CachedAsyncIterable ( generate ( ) ) ;
81+ await iterable . touchNext ( ) ;
82+ assert . deepEqual ( [ ...iterable ] , [ o1 ] ) ;
83+ } ) ;
84+
85+ test ( "iterable with all cached elements" , async function ( ) {
86+ function * generate ( ) {
87+ yield * [ o1 , o2 ] ;
88+ }
89+
90+ const iterable = new CachedAsyncIterable ( generate ( ) ) ;
91+ await iterable . touchNext ( ) ;
92+ await iterable . touchNext ( ) ;
93+ assert . deepEqual ( [ ...iterable ] , [ o1 , o2 ] ) ;
94+ } ) ;
95+
96+ test ( "async iterable with no cached elements yet" , async function ( ) {
97+ async function * generate ( ) {
98+ yield * [ o1 , o2 ] ;
99+ }
100+
101+ const iterable = new CachedAsyncIterable ( generate ( ) ) ;
102+ assert . deepEqual ( [ ...iterable ] , [ ] ) ;
103+ } ) ;
104+
105+ test ( "async iterable with a few elements cached so far" , async function ( ) {
106+ async function * generate ( ) {
107+ yield * [ o1 , o2 ] ;
108+ }
109+
110+ const iterable = new CachedAsyncIterable ( generate ( ) ) ;
111+ await iterable . touchNext ( ) ;
112+ assert . deepEqual ( [ ...iterable ] , [ o1 ] ) ;
113+ } ) ;
114+
115+ test ( "async iterable with all cached elements" , async function ( ) {
116+ async function * generate ( ) {
117+ yield * [ o1 , o2 ] ;
118+ }
119+
120+ const iterable = new CachedAsyncIterable ( generate ( ) ) ;
121+ await iterable . touchNext ( ) ;
122+ await iterable . touchNext ( ) ;
123+ assert . deepEqual ( [ ...iterable ] , [ o1 , o2 ] ) ;
124+ } ) ;
125+ } ) ;
126+
58127 suite ( "async iteration" , function ( ) {
59128 let o1 , o2 ;
60129
0 commit comments