Skip to content

Commit 46dcda7

Browse files
committed
test: Test cache behavior with maxRows
1 parent d982a95 commit 46dcda7

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/files/tsv.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Deno.test('TSV loading', async (t) => {
7373
assertEquals(map.b, [])
7474
assertEquals(map.c, [])
7575

76-
// Clear memoization cache. We currently do not key on maxRows.
76+
// Do not assume that caching respects maxRows in this test
7777
loadTSV.cache.clear()
7878
file.stream = streamFromString(text)
7979
map = await loadTSV(file, 1)
@@ -132,6 +132,32 @@ Deno.test('TSV loading', async (t) => {
132132
assertNotEquals(map, repeatMap)
133133
})
134134

135+
await t.step('caching is keyed on maxRows', async () => {
136+
const file = pathToFile('/long.tsv')
137+
// Use 1500 to avoid overlap with default initial capacity
138+
const text = 'a\tb\tc\n' + '1\t2\t3\n'.repeat(1500)
139+
file.stream = streamFromString(text)
140+
141+
let map = await loadTSV(file, 2)
142+
assertEquals(map.a, ['1', '1'])
143+
assertEquals(map.b, ['2', '2'])
144+
assertEquals(map.c, ['3', '3'])
145+
146+
file.stream = streamFromString(text)
147+
let repeatMap = await loadTSV(file, 3)
148+
assertNotEquals(map, repeatMap)
149+
assertEquals(repeatMap.a, ['1', '1', '1'])
150+
assertEquals(repeatMap.b, ['2', '2', '2'])
151+
assertEquals(repeatMap.c, ['3', '3', '3'])
152+
153+
file.stream = streamFromString(text)
154+
repeatMap = await loadTSV(file, 2)
155+
assertEquals(map, repeatMap)
156+
assertEquals(repeatMap.a, ['1', '1'])
157+
assertEquals(repeatMap.b, ['2', '2'])
158+
assertEquals(repeatMap.c, ['3', '3'])
159+
})
160+
135161
// Tests will have populated the memoization cache
136162
loadTSV.cache.clear()
137163
})

0 commit comments

Comments
 (0)