GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — TypeScriptToLua/test/cli/parse.spec.ts at master · TypeScriptToLua/TypeScriptToLua Expand file tree/ Copy pathparse.spec.tsMore file actions 270 lines (208 loc) · 11.1 KB / Copy pathparse.spec.tsFile metadata and controls270 lines (208 loc) · 11.1 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 import * as ts from "typescript"; import * as tstl from "../../src"; describe("command line", () => { test("should support aliases", () => { const full = tstl.parseCommandLine(["--luaTarget", "5.1"]); const alias = tstl.parseCommandLine(["-lt", "5.1"]); expect(full).toEqual(alias); }); test("should support standard typescript options", () => { const commandLine = "main.ts --project tsconfig.json --noHeader -t es3 -lt 5.3"; const result = tstl.parseCommandLine(commandLine.split(" ")); expect(result.errors).not.toHaveDiagnostics(); expect(result.fileNames).toEqual(["main.ts"]); expect(result.options).toEqual({ project: "tsconfig.json", noHeader: true, target: ts.ScriptTarget.ES3, luaTarget: tstl.LuaTarget.Lua53, }); }); test("should error on unknown options", () => { const result = tstl.parseCommandLine(["--unknownOption"]); expect(result.errors).toHaveDiagnostics(); }); test("should parse options case-insensitively", () => { const result = tstl.parseCommandLine(["--NoHeader"]); expect(result.errors).not.toHaveDiagnostics(); expect(result.options.noHeader).toBe(true); }); describe("enum options", () => { test("should parse enums", () => { const result = tstl.parseCommandLine(["--luaTarget", "5.1"]); expect(result.errors).not.toHaveDiagnostics(); expect(result.options.luaTarget).toBe(tstl.LuaTarget.Lua51); }); test("should be case-insensitive", () => { for (const value of ["jit", "JiT", "JIT"]) { const result = tstl.parseCommandLine(["--luaTarget", value]); expect(result.errors).not.toHaveDiagnostics(); expect(result.options.luaTarget).toBe(tstl.LuaTarget.LuaJIT); } }); test("should error on invalid value", () => { const result = tstl.parseCommandLine(["--luaTarget", "invalid"]); expect(result.errors).toHaveDiagnostics(); }); }); describe("array-of-objects options", () => { test.each([["{"], ["{}"], ["0"], ["''"]])("should error on invalid value (%s)", value => { const result = tstl.parseCommandLine(["--luaPlugins", value]); expect(result.errors).toHaveDiagnostics(); }); }); describe("boolean options", () => { test.each([true, false])("should parse booleans (%p)", value => { const result = tstl.parseCommandLine(["--noHeader", value.toString()]); expect(result.errors).not.toHaveDiagnostics(); expect(result.options.noHeader).toBe(value); }); test("should be case-sensitive", () => { const result = tstl.parseCommandLine(["--noHeader", "FALSE"]); expect(result.errors).not.toHaveDiagnostics(); expect(result.options.noHeader).toBe(true); expect(result.fileNames).toEqual(["FALSE"]); }); test("should be parsed without a value", () => { const result = tstl.parseCommandLine(["--noHeader"]); expect(result.errors).not.toHaveDiagnostics(); expect(result.options.noHeader).toBe(true); }); test("shouldn't parse following arguments as values", () => { const result = tstl.parseCommandLine(["--noHeader", "--noImplicitSelf"]); expect(result.errors).not.toHaveDiagnostics(); expect(result.options.noHeader).toBe(true); expect(result.options.noImplicitSelf).toBe(true); }); test("shouldn't parse following files as values", () => { const result = tstl.parseCommandLine(["--noHeader", "file.ts"]); expect(result.errors).not.toHaveDiagnostics(); expect(result.options.noHeader).toBe(true); }); }); describe("integration", () => { test.each<[string, string, tstl.CompilerOptions]>([ ["noHeader", "false", { noHeader: false }], ["noHeader", "true", { noHeader: true }], ["sourceMapTraceback", "false", { sourceMapTraceback: false }], ["sourceMapTraceback", "true", { sourceMapTraceback: true }], ["tstlVerbose", "true", { tstlVerbose: true }], ["tstlVerbose", "false", { tstlVerbose: false }], ["buildMode", "default", { buildMode: tstl.BuildMode.Default }], ["buildMode", "library", { buildMode: tstl.BuildMode.Library }], ["luaLibImport", "none", { luaLibImport: tstl.LuaLibImportKind.None }], ["luaLibImport", "inline", { luaLibImport: tstl.LuaLibImportKind.Inline }], ["luaLibImport", "require", { luaLibImport: tstl.LuaLibImportKind.Require }], ["luaTarget", "universal", { luaTarget: tstl.LuaTarget.Universal }], ["luaTarget", "5.1", { luaTarget: tstl.LuaTarget.Lua51 }], ["luaTarget", "5.2", { luaTarget: tstl.LuaTarget.Lua52 }], ["luaTarget", "5.3", { luaTarget: tstl.LuaTarget.Lua53 }], ["luaTarget", "jit", { luaTarget: tstl.LuaTarget.LuaJIT }], ["luaBundle", "foo", { luaBundle: "foo" }], ["luaBundleEntry", "bar", { luaBundleEntry: "bar" }], ["extension", ".lua", { extension: ".lua" }], ["extension", "scar", { extension: "scar" }], ["luaPlugins", '[{ "name": "a" }]', { luaPlugins: [{ name: "a" }] }], ["luaPlugins", '[{ "name": "a" },{ "name": "b" }]', { luaPlugins: [{ name: "a" }, { name: "b" }] }], ["noResolvePaths", "path1", { noResolvePaths: ["path1"] }], ["noResolvePaths", "path1,path2", { noResolvePaths: ["path1", "path2"] }], ])("--%s %s", (optionName, value, expected) => { const result = tstl.parseCommandLine([`--${optionName}`, value]); expect(result.errors).not.toHaveDiagnostics(); expect(result.options).toEqual(expected); }); }); }); describe("tsconfig", () => { const parseConfigFileContent = (config: any) => { // Specifying `files` option disables automatic file searching, that includes all files in // the project, making these tests slow. Empty file list is considered as an error. config.files = ["src/index.ts"]; return tstl.updateParsedConfigFile(ts.parseJsonConfigFileContent(config, ts.sys, "")); }; test("should support deprecated root-level options", () => { const rootLevel = parseConfigFileContent({ noHeader: true }); const namespaced = parseConfigFileContent({ tstl: { noHeader: true } }); expect(rootLevel.errors).toEqual([expect.objectContaining({ category: ts.DiagnosticCategory.Warning })]); expect(rootLevel.options).toEqual(namespaced.options); }); test("should allow unknown root-level options", () => { const result = parseConfigFileContent({ unknownOption: true }); expect(result.errors).not.toHaveDiagnostics(); expect(result.options.unknownOption).toBeUndefined(); }); test("should error on unknown namespaced options", () => { const result = parseConfigFileContent({ tstl: { unknownOption: true } }); expect(result.errors).toHaveDiagnostics(); expect(result.options.unknownOption).toBeUndefined(); }); test("should parse options case-sensitively", () => { // eslint-disable-next-line @typescript-eslint/naming-convention const result = parseConfigFileContent({ tstl: { NoHeader: true } }); expect(result.errors).toHaveDiagnostics(); expect(result.options.NoHeader).toBeUndefined(); expect(result.options.noHeader).toBeUndefined(); }); describe("enum options", () => { test("should parse enums", () => { const result = parseConfigFileContent({ tstl: { luaTarget: "5.1" } }); expect(result.errors).not.toHaveDiagnostics(); expect(result.options.luaTarget).toBe(tstl.LuaTarget.Lua51); }); test("should be case-insensitive", () => { for (const value of ["jit", "JiT", "JIT"]) { const result = parseConfigFileContent({ tstl: { luaTarget: value } }); expect(result.errors).not.toHaveDiagnostics(); expect(result.options.luaTarget).toBe(tstl.LuaTarget.LuaJIT); } }); test("should error on invalid value", () => { const result = parseConfigFileContent({ tstl: { luaTarget: "invalid" } }); expect(result.errors).toHaveDiagnostics(); }); }); describe("boolean options", () => { test.each([true, false])("should parse booleans (%p)", value => { const result = parseConfigFileContent({ tstl: { noHeader: value } }); expect(result.errors).not.toHaveDiagnostics(); expect(result.options.noHeader).toBe(value); }); test("shouldn't parse strings", () => { const result = parseConfigFileContent({ tstl: { noHeader: "true" } }); expect(result.errors).toHaveDiagnostics(); expect(result.options.noHeader).toBeUndefined(); }); }); describe("integration", () => { test.each<[string, any, tstl.CompilerOptions]>([ ["noHeader", false, { noHeader: false }], ["noHeader", true, { noHeader: true }], ["sourceMapTraceback", false, { sourceMapTraceback: false }], ["sourceMapTraceback", true, { sourceMapTraceback: true }], ["buildMode", "default", { buildMode: tstl.BuildMode.Default }], ["buildMode", "library", { buildMode: tstl.BuildMode.Library }], ["luaLibImport", "none", { luaLibImport: tstl.LuaLibImportKind.None }], ["luaLibImport", "inline", { luaLibImport: tstl.LuaLibImportKind.Inline }], ["luaLibImport", "require", { luaLibImport: tstl.LuaLibImportKind.Require }], ["luaTarget", "universal", { luaTarget: tstl.LuaTarget.Universal }], ["luaTarget", "5.0", { luaTarget: tstl.LuaTarget.Lua50 }], ["luaTarget", "5.1", { luaTarget: tstl.LuaTarget.Lua51 }], ["luaTarget", "5.2", { luaTarget: tstl.LuaTarget.Lua52 }], ["luaTarget", "5.3", { luaTarget: tstl.LuaTarget.Lua53 }], ["luaTarget", "5.4", { luaTarget: tstl.LuaTarget.Lua54 }], ["luaTarget", "5.5", { luaTarget: tstl.LuaTarget.Lua55 }], ["luaTarget", "jit", { luaTarget: tstl.LuaTarget.LuaJIT }], ["luaTarget", "luau", { luaTarget: tstl.LuaTarget.Luau }], ["luaBundle", "foo", { luaBundle: "foo" }], ["luaBundleEntry", "bar", { luaBundleEntry: "bar" }], ["noImplicitSelf", true, { noImplicitSelf: true }], ["tstlVerbose", true, { tstlVerbose: true }], ["noResolvePaths", [], { noResolvePaths: [] }], ["noResolvePaths", ["path1", "path2"], { noResolvePaths: ["path1", "path2"] }], ])("{ %p: %p }", (optionName, value, expected) => { const result = parseConfigFileContent({ tstl: { [optionName]: value } }); expect(result.errors).not.toHaveDiagnostics(); expect(result.options).toEqual(expected); }); }); }); |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |