|
| 1 | +import { test } from "jsr:@denops/test@^3.0.0"; |
| 2 | +import { assertEquals } from "jsr:@std/assert@^1.0.0"; |
| 3 | +import { describe, it } from "jsr:@std/testing@^1.0.0/bdd"; |
| 4 | +import { join } from "jsr:@std/path@^1.0.8/join"; |
| 5 | + |
| 6 | +import { |
| 7 | + getActionPickerParams, |
| 8 | + getPickerParams, |
| 9 | + getSetting, |
| 10 | + listPickerNames, |
| 11 | + loadUserCustom, |
| 12 | +} from "./custom.ts"; |
| 13 | + |
| 14 | +describe("getSetting", () => { |
| 15 | + it("should return default setting", () => { |
| 16 | + const setting = getSetting(); |
| 17 | + assertEquals(typeof setting.coordinator, "object"); |
| 18 | + assertEquals(typeof setting.theme, "object"); |
| 19 | + assertEquals(setting.theme.border.length, 8); |
| 20 | + assertEquals(setting.theme.divider.length, 6); |
| 21 | + }); |
| 22 | +}); |
| 23 | + |
| 24 | +describe("getActionPickerParams", () => { |
| 25 | + it("should return default action picker params", () => { |
| 26 | + const params = getActionPickerParams(); |
| 27 | + assertEquals(Array.isArray(params.matchers), true); |
| 28 | + assertEquals(params.matchers.length, 1); |
| 29 | + assertEquals(typeof params.coordinator, "object"); |
| 30 | + }); |
| 31 | +}); |
| 32 | + |
| 33 | +describe("getPickerParams", () => { |
| 34 | + it("should return undefined for non-existent picker", () => { |
| 35 | + const params = getPickerParams("non-existent"); |
| 36 | + assertEquals(params, undefined); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +describe("listPickerNames", () => { |
| 41 | + it("should return empty array initially", () => { |
| 42 | + const names = listPickerNames(); |
| 43 | + assertEquals(Array.isArray(names), true); |
| 44 | + }); |
| 45 | +}); |
| 46 | + |
| 47 | +// Tests that require real denops instance |
| 48 | +test({ |
| 49 | + mode: "all", |
| 50 | + name: "loadUserCustom - default custom", |
| 51 | + fn: async (denops) => { |
| 52 | + await denops.cmd("let g:fall_custom_path = '/non/existent/path.ts'"); |
| 53 | + |
| 54 | + await loadUserCustom(denops); |
| 55 | + |
| 56 | + const setting = getSetting(); |
| 57 | + assertEquals(typeof setting.coordinator, "object"); |
| 58 | + assertEquals(typeof setting.theme, "object"); |
| 59 | + }, |
| 60 | +}); |
| 61 | + |
| 62 | +test({ |
| 63 | + mode: "all", |
| 64 | + name: "loadUserCustom - user custom", |
| 65 | + fn: async (denops) => { |
| 66 | + const tempDir = await Deno.makeTempDir(); |
| 67 | + const customPath = join(tempDir, "custom.ts"); |
| 68 | + |
| 69 | + await Deno.writeTextFile( |
| 70 | + customPath, |
| 71 | + ` |
| 72 | + export async function main({ refineSetting }) { |
| 73 | + refineSetting({ |
| 74 | + theme: { |
| 75 | + border: ["1", "2", "3", "4", "5", "6", "7", "8"], |
| 76 | + divider: ["a", "b", "c", "d", "e", "f"], |
| 77 | + }, |
| 78 | + }); |
| 79 | + } |
| 80 | + `, |
| 81 | + ); |
| 82 | + |
| 83 | + await denops.cmd(`let g:fall_custom_path = '${customPath}'`); |
| 84 | + await loadUserCustom(denops, { reload: true }); |
| 85 | + |
| 86 | + const setting = getSetting(); |
| 87 | + assertEquals(setting.theme.border, [ |
| 88 | + "1", |
| 89 | + "2", |
| 90 | + "3", |
| 91 | + "4", |
| 92 | + "5", |
| 93 | + "6", |
| 94 | + "7", |
| 95 | + "8", |
| 96 | + ]); |
| 97 | + assertEquals(setting.theme.divider, ["a", "b", "c", "d", "e", "f"]); |
| 98 | + |
| 99 | + await Deno.remove(tempDir, { recursive: true }); |
| 100 | + }, |
| 101 | +}); |
| 102 | + |
| 103 | +test({ |
| 104 | + mode: "all", |
| 105 | + name: "loadUserCustom - reload option", |
| 106 | + fn: async (denops) => { |
| 107 | + const tempDir = await Deno.makeTempDir(); |
| 108 | + const customPath = join(tempDir, "custom.ts"); |
| 109 | + |
| 110 | + // First version |
| 111 | + await Deno.writeTextFile( |
| 112 | + customPath, |
| 113 | + ` |
| 114 | + export async function main({ refineSetting }) { |
| 115 | + refineSetting({ |
| 116 | + theme: { |
| 117 | + border: ["1", "2", "3", "4", "5", "6", "7", "8"], |
| 118 | + divider: ["a", "b", "c", "d", "e", "f"], |
| 119 | + }, |
| 120 | + }); |
| 121 | + } |
| 122 | + `, |
| 123 | + ); |
| 124 | + |
| 125 | + await denops.cmd(`let g:fall_custom_path = '${customPath}'`); |
| 126 | + await loadUserCustom(denops); |
| 127 | + |
| 128 | + // Second version |
| 129 | + await Deno.writeTextFile( |
| 130 | + customPath, |
| 131 | + ` |
| 132 | + export async function main({ refineSetting }) { |
| 133 | + refineSetting({ |
| 134 | + theme: { |
| 135 | + border: ["x", "x", "x", "x", "x", "x", "x", "x"], |
| 136 | + divider: ["y", "y", "y", "y", "y", "y"], |
| 137 | + }, |
| 138 | + }); |
| 139 | + } |
| 140 | + `, |
| 141 | + ); |
| 142 | + |
| 143 | + await loadUserCustom(denops, { reload: true }); |
| 144 | + |
| 145 | + const setting = getSetting(); |
| 146 | + assertEquals(setting.theme.border, [ |
| 147 | + "x", |
| 148 | + "x", |
| 149 | + "x", |
| 150 | + "x", |
| 151 | + "x", |
| 152 | + "x", |
| 153 | + "x", |
| 154 | + "x", |
| 155 | + ]); |
| 156 | + assertEquals(setting.theme.divider, ["y", "y", "y", "y", "y", "y"]); |
| 157 | + |
| 158 | + await Deno.remove(tempDir, { recursive: true }); |
| 159 | + }, |
| 160 | +}); |
| 161 | + |
| 162 | +test({ |
| 163 | + mode: "all", |
| 164 | + name: "loadUserCustom - validate picker names", |
| 165 | + fn: async (denops) => { |
| 166 | + const tempDir = await Deno.makeTempDir(); |
| 167 | + const customPath = join(tempDir, "custom.ts"); |
| 168 | + |
| 169 | + await Deno.writeTextFile( |
| 170 | + customPath, |
| 171 | + ` |
| 172 | + import { fzf } from "jsr:@vim-fall/std@^0.10.0/builtin/matcher/fzf"; |
| 173 | + |
| 174 | + export async function main({ definePickerFromSource }) { |
| 175 | + definePickerFromSource( |
| 176 | + "@invalid", |
| 177 | + { collect: async function* () {} }, |
| 178 | + { |
| 179 | + matchers: [fzf()], |
| 180 | + actions: { default: { invoke: async () => {} } }, |
| 181 | + defaultAction: "default", |
| 182 | + } |
| 183 | + ); |
| 184 | + } |
| 185 | + `, |
| 186 | + ); |
| 187 | + |
| 188 | + await denops.cmd(`let g:fall_custom_path = '${customPath}'`); |
| 189 | + |
| 190 | + // Should not throw but log warning |
| 191 | + await loadUserCustom(denops, { reload: true }); |
| 192 | + |
| 193 | + await Deno.remove(tempDir, { recursive: true }); |
| 194 | + }, |
| 195 | +}); |
| 196 | + |
| 197 | +test({ |
| 198 | + mode: "all", |
| 199 | + name: "loadUserCustom - validate action names", |
| 200 | + fn: async (denops) => { |
| 201 | + const tempDir = await Deno.makeTempDir(); |
| 202 | + const customPath = join(tempDir, "custom.ts"); |
| 203 | + |
| 204 | + await Deno.writeTextFile( |
| 205 | + customPath, |
| 206 | + ` |
| 207 | + import { fzf } from "jsr:@vim-fall/std@^0.10.0/builtin/matcher/fzf"; |
| 208 | + |
| 209 | + export async function main({ definePickerFromSource }) { |
| 210 | + definePickerFromSource( |
| 211 | + "test", |
| 212 | + { collect: async function* () {} }, |
| 213 | + { |
| 214 | + matchers: [fzf()], |
| 215 | + actions: { |
| 216 | + "@invalid": { invoke: async () => {} }, |
| 217 | + valid: { invoke: async () => {} }, |
| 218 | + }, |
| 219 | + defaultAction: "valid", |
| 220 | + } |
| 221 | + ); |
| 222 | + } |
| 223 | + `, |
| 224 | + ); |
| 225 | + |
| 226 | + await denops.cmd(`let g:fall_custom_path = '${customPath}'`); |
| 227 | + |
| 228 | + // Should not throw but log warning |
| 229 | + await loadUserCustom(denops, { reload: true }); |
| 230 | + |
| 231 | + await Deno.remove(tempDir, { recursive: true }); |
| 232 | + }, |
| 233 | +}); |
| 234 | + |
| 235 | +test({ |
| 236 | + mode: "all", |
| 237 | + name: "loadUserCustom - verbose option", |
| 238 | + fn: async (denops) => { |
| 239 | + // Test that verbose option doesn't throw errors |
| 240 | + // We can't reliably intercept cmd calls on real Denops instances |
| 241 | + await denops.cmd("let g:fall_custom_path = '/non/existent/path.ts'"); |
| 242 | + |
| 243 | + // Should not throw |
| 244 | + await loadUserCustom(denops, { verbose: true, reload: true }); |
| 245 | + |
| 246 | + // If we reach here, the verbose option worked without errors |
| 247 | + assertEquals(true, true); |
| 248 | + }, |
| 249 | +}); |
0 commit comments