MCPcopy Create free account
hub / github.com/coder/guts / TestImportDeclaration

Function TestImportDeclaration

bindings/imports_test.go:16–114  ·  view source on GitHub ↗

TestImportDeclaration exercises the goja factory wrappers for ImportSpecifier and ImportDeclaration end-to-end: build the bindings node, convert through ToTypescriptNode, then ask the embedded printer for its TypeScript representation.

(t *testing.T)

Source from the content-addressed store, hash-verified

14// convert through ToTypescriptNode, then ask the embedded printer for its
15// TypeScript representation.
16func TestImportDeclaration(t *testing.T) {
17 t.Parallel()
18
19 cases := []struct {
20 name string
21 decl *bindings.ImportDeclaration
22 want string
23 notWant string
24 }{
25 {
26 name: "single",
27 decl: &bindings.ImportDeclaration{
28 Module: "zod",
29 Named: []*bindings.ImportSpecifier{
30 {Name: "z"},
31 },
32 },
33 want: `import { z } from "zod";`,
34 },
35 {
36 name: "multiple",
37 decl: &bindings.ImportDeclaration{
38 Module: "./schemas",
39 Named: []*bindings.ImportSpecifier{
40 {Name: "Foo"},
41 {Name: "Bar"},
42 },
43 },
44 want: `import { Foo, Bar } from "./schemas";`,
45 },
46 {
47 name: "aliased",
48 decl: &bindings.ImportDeclaration{
49 Module: "./schemas",
50 Named: []*bindings.ImportSpecifier{
51 {Name: "Foo", Alias: "Bar"},
52 },
53 },
54 want: `import { Foo as Bar } from "./schemas";`,
55 },
56 {
57 name: "type only",
58 decl: &bindings.ImportDeclaration{
59 Module: "./types",
60 IsTypeOnly: true,
61 Named: []*bindings.ImportSpecifier{
62 {Name: "Baz"},
63 },
64 },
65 want: `import type { Baz } from "./types";`,
66 },
67 {
68 name: "mixed",
69 decl: &bindings.ImportDeclaration{
70 Module: "./schemas",
71 Named: []*bindings.ImportSpecifier{
72 {Name: "Foo"},
73 {Name: "Bar", Alias: "Baz"},

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
ToTypescriptNodeMethod · 0.80
SerializeToTypescriptMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…