-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcollection.test.ts
More file actions
64 lines (55 loc) · 1.44 KB
/
Copy pathcollection.test.ts
File metadata and controls
64 lines (55 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { test, expect, expectTypeOf } from 'vitest'
import { Collection, type UniqueWithLocations } from './collection'
let loc = { line: 1, column: 1, offset: 1, length: 1 }
test('basic collection - size()', () => {
let collection = new Collection()
collection.p('a', loc)
collection.p('a', loc)
expect(collection.size()).toEqual(2)
})
test('count with useLocations=undefined', () => {
let collection = new Collection()
collection.p('a', loc)
collection.p('a', loc)
let count = collection.c()
expect(count).toEqual({
total: 2,
totalUnique: 1,
unique: {
a: 2,
},
uniquenessRatio: 0.5,
})
expectTypeOf(count['uniqueWithLocations']).toBeUndefined()
})
test('count with useLocations=false', () => {
let collection = new Collection(false)
collection.p('a', loc)
collection.p('a', loc)
let count = collection.c()
expect(count).toEqual({
total: 2,
totalUnique: 1,
unique: {
a: 2,
},
uniquenessRatio: 0.5,
})
expectTypeOf(count['uniqueWithLocations']).toBeUndefined()
})
test('count with useLocations=true', () => {
let collection = new Collection(true)
collection.p('a', loc)
collection.p('a', loc)
let count = collection.c()
expect(count).toEqual({
total: 2,
totalUnique: 1,
unique: { a: 2 },
uniquenessRatio: 0.5,
})
expectTypeOf(count['uniqueWithLocations']).toBeUndefined()
let locs = collection.locs()
let pos = { offset: 1, length: 1, line: 1, column: 1 }
expect(locs).toEqual({ a: [pos, pos] })
})