This repository was archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgo.test.ts
More file actions
65 lines (53 loc) · 1.92 KB
/
go.test.ts
File metadata and controls
65 lines (53 loc) · 1.92 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
65
import * as assert from 'assert'
import { goSpec } from './go'
import { nilFilterContext, nilResult } from './spec.test'
const fileContent = `
package main
import "github.com/foo/foo/s"
import bar "github.com/foo/bar"
import (
"github.com/foo/baz/s"
quux "github.com/foo/honk/s/s"
)
func main() {
// testing
}
`
describe('goSpec', () => {
it('filters definitions', () => {
const results = [
{ ...nilResult, repo: 'github.com/foo/foo', file: 's/a.go' },
{ ...nilResult, repo: 'github.com/foo/bar', file: 'b.go' },
{ ...nilResult, repo: 'github.com/foo/baz', file: 's/c.go' },
{ ...nilResult, repo: 'github.com/foo/honk', file: 's/s/d.go' },
// same package
{ ...nilResult, repo: 'github.com/foo/test', file: 'x/y/w.go' },
// incorrect repo
{ ...nilResult, repo: 'github.com/foo/quux', file: 'a.go' },
// incorrect packages
{ ...nilResult, repo: 'github.com/foo/foo', file: 'a.go' },
{ ...nilResult, repo: 'github.com/foo/foo', file: 'r/a.go' },
]
const filtered = goSpec.filterDefinitions?.(results, {
...nilFilterContext,
repo: 'github.com/foo/test',
filePath: 'x/y/z.go',
fileContent,
})
assert.deepStrictEqual(filtered, [results[0], results[1], results[2], results[3], results[4]])
})
it('filters definitions from root package', () => {
const results = [
{ ...nilResult, repo: 'github.com/foo/test', file: 'util.go' },
// incorrect repo
{ ...nilResult, repo: 'github.com/ext/bar', file: 'a.go' },
]
const filtered = goSpec.filterDefinitions?.(results, {
...nilFilterContext,
repo: 'github.com/foo/test',
filePath: 'main.go',
fileContent,
})
assert.deepStrictEqual(filtered, [results[0]])
})
})