branch: elpa/typescript-mode
commit a3c91282bc516d8b8498d5ceb7657610532e1c8e
Author: Jostein Kjønigsen <[email protected]>
Commit: Jostein Kjønigsen <[email protected]>
Add test-case and indentation-reference document.
---
test-files/indentation-reference-document.ts | 92 ++++++++++++++++++++++++++++
typescript-mode-tests.el | 34 ++++++++++
2 files changed, 126 insertions(+)
diff --git a/test-files/indentation-reference-document.ts
b/test-files/indentation-reference-document.ts
new file mode 100644
index 0000000000..a6df0e6dc0
--- /dev/null
+++ b/test-files/indentation-reference-document.ts
@@ -0,0 +1,92 @@
+/// <reference types="node" />
+/// <reference path="shared.ts" />
+/// <reference path="session.ts" />
+// used in fs.writeSync
+/* tslint:disable:no-null-keyword */
+
+/*
+ * this file is a butchered copy of TypeScript's tsserver.ts file
+ * made to contain the most important syntactical elements
+ * of TypeScript to verify indentation-code.
+ *
+ * It will not build, and that's NOT a problem!
+ */
+
+// namespaces indent.
+namespace ts.server {
+
+ const net: {
+ connect(options: { port: number }, onConnect?: () => void): NodeSocket
+ } = require("net");
+
+ // functions indent.
+ function getGlobalTypingsCacheLocation() {
+ // We know switch/case is indented incorrectly.
+ // TODO: FIX!
+
+ // switch (process.platform) {
+ // case "win32": {
+ // const basePath = process.env.LOCALAPPDATA ||
+ // process.env.APPDATA;
+ // return combinePaths(normalizeSlashes(basePath),
"Microsoft/TypeScript");
+ // }
+ // case "darwin":
+ // case "linux":
+ // case "android": {
+ // const cacheLocation =
getNonWindowsCacheLocation(process.platform === "darwin");
+ // return combinePaths(cacheLocation, "typescript");
+ // }
+ // default:
+ // Debug.fail(`unsupported platform '${process.platform}'`);
+ // return;
+ // }
+ }
+
+ // interfaces and classes indent.
+ interface NodeChildProcess {
+ send(message: any, sendHandle?: any): void;
+ on(message: "message" | "exit", f: (m: any) => void): void;
+ kill(): void;
+ pid: number;
+ }
+
+ class Logger implements ts.server.Logger {
+ private firstInGroup = true;
+
+ // parameter-lists are currently not indented like tsserver wants it
to...
+ // constructor(private readonly logFilename: string,
+ // private readonly traceToConsole: boolean,
+ // private readonly level: LogLevel) {
+ // }
+
+ // function-typed class-members indent.
+ constructor(private readonly logFilename: string) {
+ console.log("yes");
+ }
+
+ static padStringRight(str: string, padding: string) {
+ return (str + padding).slice(0, padding.length);
+ }
+
+ close() {
+ if (this.fd >= 0) {
+ fs.close(this.fd);
+ }
+ }
+ }
+
+ // object initialization/parameter-lists indent.
+ const ioSession = new IOSession(
+ sys,
+ cancellationToken,
+ eventPort,
+ /*canUseEvents*/ eventPort === undefined,
+ useSingleInferredProject,
+ disableAutomaticTypingAcquisition,
+ getGlobalTypingsCacheLocation(),
+ telemetryEnabled,
+ logger);
+ process.on("uncaughtException", function (err: Error) {
+ ioSession.logError(err, "unknown");
+ });
+}
diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el
new file mode 100644
index 0000000000..fb40785094
--- /dev/null
+++ b/typescript-mode-tests.el
@@ -0,0 +1,34 @@
+
+;;; typescript-mode-tests --- This file contains automated tests for
typescript-mode.el
+
+;;; Commentary:
+;; Run tests using (ert-run-tests-interactively t).
+
+;;; Code:
+
+(require 'ert)
+(require 'typescript-mode)
+
+(defun typescript-test-get-doc ()
+ (buffer-substring-no-properties (point-min) (point-max)))
+
+(defun typescript-test-indent-all ()
+ (delete-trailing-whitespace)
+ (indent-region (point-min) (point-max) nil)
+ (untabify (point-min) (point-max)))
+
+(ert-deftest indentation-reference-document-is-reflowed-correctly ()
+ (let* ((buffer (find-file "test-files/indentation-reference-document.ts")))
+ ;; double ensure mode is active
+ (typescript-mode)
+
+ (let ((test-reference (typescript-test-get-doc)))
+ (typescript-test-indent-all)
+ (should (string-equal test-reference
+ (typescript-test-get-doc))))
+
+ (kill-buffer buffer)))
+
+(provide 'typescript-mode-tests)
+
+;;; typescript-mode-tests.el ends here