File: lsp-javascript-test.el

package info (click to toggle)
lsp-mode 9.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,472 kB
  • sloc: lisp: 27,961; makefile: 62; java: 34; cpp: 33; javascript: 31; xml: 23; python: 14; sh: 2
file content (108 lines) | stat: -rw-r--r-- 4,420 bytes parent folder | download | duplicates (2)
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
;;; lsp-clients-test.el --- unit tests for lsp-clients.el -*- lexical-binding: t -*-

;; Copyright (C) 2019 Daniel Martín <mardani29@yahoo.es>.

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Code:

(require 'ert)
(require 'lsp-javascript)
(require 'js) ;; Standard mode in Emacs for JS.

(defconst test-location (file-name-directory (or load-file-name buffer-file-name)))

;; Some of the different flavors of the @flow tag we may
;; encounter, and things we don't want to match.
(defconst lsp-flow-regular-tag "// @flow")
(defconst lsp-flow-c-style-tag "/* @flow */")
(defconst lsp-flow-simple-multiline-tag
  "/**
    * @flow
    */")
(defconst lsp-flow-multiline-with-comments-before-tag
  "/**
    * This is a wonderful Flow file.
    *
    * Author: Awesome programmer.
    *
    * @flow
    */")
(defconst lsp-flow-wrong-tag
  "/**
    * @notflow
    */")
(defconst lsp-flow-but-not-in-comment-tag "@flow")

(ert-deftest lsp-flow-regular-tag-detection ()
  (should (with-temp-buffer
            (insert lsp-flow-regular-tag)
            (lsp-clients-flow-tag-string-present-p))))

(ert-deftest lsp-flow-c-style-tag-detection ()
  (should (with-temp-buffer
            (insert lsp-flow-c-style-tag)
            (lsp-clients-flow-tag-string-present-p))))

(ert-deftest lsp-flow-simple-multiline-tag-detection ()
  (should (with-temp-buffer
            (insert lsp-flow-simple-multiline-tag)
            (lsp-clients-flow-tag-string-present-p))))

(ert-deftest lsp-flow-simple-multiline-with-comments-before-tag-detection ()
  (should (with-temp-buffer
            (insert lsp-flow-multiline-with-comments-before-tag)
            (lsp-clients-flow-tag-string-present-p))))

(ert-deftest lsp-flow-wrong-tag-detection ()
  (should-not (with-temp-buffer
                (insert lsp-flow-wrong-tag)
                (lsp-clients-flow-tag-string-present-p))))

(ert-deftest lsp-flow-but-not-in-comment-tag-detection ()
  (should-not (with-temp-buffer
                (insert lsp-flow-but-not-in-comment-tag)
                (lsp-clients-flow-tag-string-present-p))))

(ert-deftest lsp-flow-should-activate-on-flow-project ()
  ;; Set `js-mode' ON and check that a Flow project activates the Flow
  ;; LSP client.
  (let ((major-mode 'js-mode))
    (should (lsp-clients-flow-activate-p (concat test-location "fixtures/SampleFlowProject/src/sample.js") nil))))

(ert-deftest lsp-flow-should-activate-on-flow-project-without-flow-file-comment ()
  (let ((major-mode 'js-mode))
    (should (lsp-clients-flow-activate-p (concat test-location "fixtures/SampleFlowProject/src/sample-without-flow-comment.js") nil))))

(ert-deftest lsp-flow-should-not-activate-if-not-flow-project-or-no-tag ()
  (let ((major-mode 'js-mode))
    (should-not (lsp-clients-flow-activate-p (concat test-location "fixtures/SampleJsProject/src/sample.js") nil))))

(ert-deftest lsp-flow-should-not-activate-on-typescript-project ()
  ;; Set `js-mode' ON and check that a TypeScript project does not
  ;; activate the Flow LSP client.
  (let ((major-mode 'js-mode))
    (should-not (lsp-clients-flow-activate-p (concat test-location "fixtures/SampleTypeScriptProject/src/sample.ts") nil))))

(ert-deftest lsp-typescript-javascript-activates-based-on-file-extension ()
  (should (lsp-typescript-javascript-tsx-jsx-activate-p "abc.js"))
  (should (lsp-typescript-javascript-tsx-jsx-activate-p "abc.jsx"))
  (should (lsp-typescript-javascript-tsx-jsx-activate-p "abc.ts"))
  (should (lsp-typescript-javascript-tsx-jsx-activate-p "abc.tsx"))
  (should (lsp-typescript-javascript-tsx-jsx-activate-p "a1.ts"))
  (should (lsp-typescript-javascript-tsx-jsx-activate-p "a1.d.ts"))
  (should-not (lsp-typescript-javascript-tsx-jsx-activate-p "abc.tsxx"))
  (should-not (lsp-typescript-javascript-tsx-jsx-activate-p "abc.jss")))

;;; lsp-clients-test.el ends here