mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-31 04:41:23 -08:00
* lisp/subr.el (if-let*, when-let*, if-let, when-let): Mark if-let and when-let obsolete (bug#73853 and elsewhere). Move docstring text around so that if-let* and when-let* descriptions no longer refer to if-let and when-let. * etc/NEWS: Announce the change. * admin/admin.el (reminder-for-release-blocking-bugs): * doc/misc/erc.texi (display-buffer): * lisp/ansi-color.el (ansi-color-apply) (ansi-color--face-vec-face): * lisp/ansi-osc.el (ansi-osc-apply-on-region) (ansi-osc-hyperlink): * lisp/arc-mode.el (archive-goto-file) (archive-next-file-displayer): * lisp/auth-source-pass.el (auth-source-pass-search) (auth-source-pass--parse-data) (auth-source-pass--find-match-many): * lisp/autorevert.el (auto-revert-notify-rm-watch): * lisp/buff-menu.el (Buffer-menu-unmark-all-buffers) (Buffer-menu-group-by-root): * lisp/calendar/parse-time.el (parse-iso8601-time-string): * lisp/cedet/pulse.el (pulse-tick): * lisp/comint.el (comint--fontify-input-ppss-flush-indirect) (comint--intersect-regions): * lisp/completion-preview.el (completion-preview--try-table) (completion-preview--capf-wrapper, completion-preview--update): * lisp/cus-edit.el (setopt--set) (custom-dirlocals-maybe-update-cons, custom-dirlocals-validate): * lisp/custom.el (load-theme): * lisp/descr-text.el (describe-char): * lisp/desktop.el (desktop--emacs-pid-running-p): * lisp/dired-x.el (menu): * lisp/dired.el (dired-font-lock-keywords) (dired-insert-directory, dired--insert-disk-space, dired-mode): * lisp/dnd.el (dnd-handle-multiple-urls): * lisp/dom.el (dom-remove-attribute): * lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): * lisp/emacs-lisp/bytecomp.el (bytecomp--custom-declare): * lisp/emacs-lisp/comp-common.el (comp-function-type-spec): * lisp/emacs-lisp/comp-cstr.el (comp--all-classes) (comp-cstr-set-range-for-arithm, comp--cstr-union-1-no-mem) (comp-cstr-intersection-no-mem, comp-cstr-fixnum-p) (comp-cstr-type-p): * lisp/emacs-lisp/comp-run.el (comp-subr-trampoline-install) (native--compile-async): * lisp/emacs-lisp/comp.el (comp--get-function-cstr) (comp--function-pure-p, comp--intern-func-in-ctxt) (comp--addr-to-bb-name, comp--emit-assume, comp--maybe-add-vmvar) (comp--add-call-cstr, comp--compute-dominator-tree) (comp--dom-tree-walker, comp--ssa-rename) (comp--function-call-maybe-fold, comp--fwprop-call) (comp--call-optim-func): * lisp/emacs-lisp/edebug.el (edebug-global-prefix) (edebug-remove-instrumentation): * lisp/emacs-lisp/eieio.el (initialize-instance): * lisp/emacs-lisp/ert-x.el (ert-resource-directory): * lisp/emacs-lisp/ert.el (ert--expand-should-1) (ert-test-location, ert-write-junit-test-report) (ert-test--erts-test): * lisp/emacs-lisp/icons.el (icon-complete-spec, icon-string) (icons--create): * lisp/emacs-lisp/lisp-mode.el (lisp--local-defform-body-p): * lisp/emacs-lisp/loaddefs-gen.el (loaddefs-generate--make-autoload) (loaddefs-generate--parse-file): * lisp/emacs-lisp/multisession.el (multisession-edit-mode--revert, multisession-edit-value): * lisp/emacs-lisp/package-vc.el (package-vc--read-archive-data) (package-vc--version, package-vc--clone): * lisp/emacs-lisp/package.el (package--reload-previously-loaded): * lisp/emacs-lisp/pp.el (pp--insert-lisp): * lisp/emacs-lisp/subr-x.el (add-display-text-property): * lisp/emacs-lisp/tabulated-list.el (tabulated-list-print): * lisp/emacs-lisp/timer.el (run-at-time): * lisp/emacs-lisp/vtable.el (vtable-goto-table) (vtable-goto-column, vtable-update-object, vtable--insert-line) (vtable--compute-widths, vtable--make-keymap): * lisp/emacs-lisp/warnings.el (display-warning): * lisp/epa-file.el (epa-file-insert-file-contents): * lisp/epa.el (epa-show-key): * lisp/erc/erc-backend.el (erc--split-line, erc--conceal-prompt) (PRIVMSG, erc--get-isupport-entry): * lisp/erc/erc-button.el (erc-button-add-nickname-buttons) (erc--button-next): * lisp/erc/erc-common.el (erc--find-group): * lisp/erc/erc-fill.el (erc-fill, erc-fill-static) (erc-fill--wrap-escape-hidden-speaker) (erc-fill--wrap-unmerge-on-date-stamp) (erc-fill--wrap-massage-initial-message-post-clear) (erc-fill-wrap, erc-fill--wrap-rejigger-region): * lisp/erc/erc-goodies.el (erc--scrolltobottom-all) (erc--keep-place-indicator-on-window-buffer-change) (keep-place-indicator, erc--keep-place-indicator-adjust-on-clear) (erc-keep-place-move, erc--command-indicator-display): * lisp/erc/erc-ibuffer.el (erc-members): * lisp/erc/erc-join.el (erc-join--remove-requested-channel) (erc-autojoin--join): * lisp/erc/erc-networks.el (erc-networks--id-qualifying-init-parts, erc-networks--id-reload) (erc-networks--id-ensure-comparable) (erc-networks--reclaim-orphaned-target-buffers) (erc-networks--server-select): * lisp/erc/erc-nicks.el (erc-nicks-invert) (erc-nicks--redirect-face-widget-link, erc-nicks--highlight) (erc-nicks--highlight-button) (erc-nicks--list-faces-help-button-action, erc-nicks-list-faces) (erc-nicks-refresh, erc-nicks--colors-from-faces) (erc-nicks--track-prioritize) (erc-nicks--remember-face-for-track): * lisp/erc/erc-notify.el (querypoll, erc--querypoll-get-next) (erc--querypoll-on-352, erc--querypoll-send): * lisp/erc/erc-sasl.el (erc-sasl--read-password): * lisp/erc/erc-services.el (erc-services-issue-ghost-and-retry-nick): * lisp/erc/erc-speedbar.el (erc-speedbar--ensure, nickbar) (erc-speedbar-toggle-nicknames-window-lock) (erc-speedbar--compose-nicks-face): * lisp/erc/erc-stamp.el (erc-stamp--recover-on-reconnect) (erc-stamp-prefix-log-filter, erc--conceal-prompt) (erc--insert-timestamp-left, erc-insert-timestamp-right) (erc-stamp--defer-date-insertion-on-post-modify) (erc-insert-timestamp-left-and-right) (erc-stamp--redo-right-stamp-post-clear) (erc-stamp--reset-on-clear, erc-stamp--dedupe-date-stamps): * lisp/erc/erc-status-sidebar.el (bufbar) (erc-status-sidebar-prefer-target-as-name) (erc-status-sidebar-default-allsort, erc-status-sidebar-click): * lisp/erc/erc-track.el (erc-track--shortened-names-get) (erc-track--setup, erc-track--select-mode-line-face) (erc-track-modified-channels, erc-track--collect-faces-in) (erc-track--switch-buffer, erc-track--replace-killed-buffer): * lisp/erc/erc-truncate.el (erc-truncate--setup) (erc-truncate-buffer): * lisp/erc/erc.el (erc--ensure-query-member) (erc--ensure-query-members, erc--remove-channel-users-but) (erc--cusr-change-status, erc--find-mode, erc--update-modules) (erc-log-irc-protocol, erc--refresh-prompt) (erc--restore-important-text-props) (erc--order-text-properties-from-hash, erc-send-input-line) (erc-cmd-IGNORE, erc--unignore-user, erc-cmd-QUERY) (erc-cmd-BANLIST, erc--speakerize-nick) (erc--format-speaker-input-message, erc-channel-receive-names) (erc-send-current-line, erc-format-target-and/or-network) (erc-kill-buffer-function, erc-restore-text-properties) (erc--get-eq-comparable-cmd): * lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias--which) (eshell-maybe-replace-by-alias): * lisp/eshell/em-glob.el (eshell-glob-convert): * lisp/eshell/em-pred.el (eshell-pred-user-or-group) (eshell-pred-file-time, eshell-pred-file-type) (eshell-pred-file-mode, eshell-pred-file-links) (eshell-pred-file-size): * lisp/eshell/em-prompt.el (eshell-forward-paragraph) (eshell-next-prompt): * lisp/eshell/esh-arg.el (eshell-resolve-current-argument): * lisp/eshell/esh-cmd.el (eshell-do-eval, eshell/which) (eshell-plain-command--which, eshell-plain-command): * lisp/eshell/esh-io.el (eshell-duplicate-handles) (eshell-protect-handles, eshell-get-target, eshell-close-target): * lisp/eshell/esh-proc.el (eshell-sentinel): * lisp/eshell/esh-var.el (eshell-parse-variable-ref) (eshell-get-variable, eshell-set-variable): * lisp/faces.el (face-at-point): * lisp/ffap.el (ffap-in-project): * lisp/filenotify.el (file-notify--rm-descriptor): * lisp/files-x.el (read-dir-locals-file) (connection-local-update-profile-variables) (connection-local-value): * lisp/files.el (file-remote-p, abbreviate-file-name) (set-auto-mode, hack-local-variables) (revert-buffer-restore-read-only): * lisp/find-dired.el (find-dired-sort-by-filename): * lisp/font-lock.el (font-lock--filter-keywords): * lisp/gnus/gnus-art.el (article-emojize-symbols): * lisp/gnus/gnus-int.el (gnus-close-server): * lisp/gnus/gnus-search.el (gnus-search-transform) (gnus-search-indexed-parse-output, gnus-search-server-to-engine): * lisp/gnus/gnus-sum.el (gnus-collect-urls, gnus-shorten-url): * lisp/gnus/gnus.el (gnus-check-backend-function): * lisp/gnus/message.el (message-send-mail): * lisp/gnus/mml.el (mml-generate-mime, mml-insert-mime-headers): * lisp/gnus/nnatom.el (nnatom--read-feed, nnatom--read-article) (nnatom--read-article-or-group-authors, nnatom--read-publish) (nnatom--read-update, nnatom--read-links): * lisp/gnus/nnfeed.el (nnfeed--read-server, nnfeed--write-server) (nnfeed--parse-feed, nnfeed--group-data, nnfeed-retrieve-article) (nnfeed-retrieve-headers, nnfeed--print-part) (nnfeed-request-article, nnfeed-request-group) (nnfeed-request-list, nnfeed--group-description) (nnfeed-request-group-description) (nnfeed-request-list-newsgroups, nnfeed-request-rename-group): * lisp/gnus/nnmh.el (nnmh-update-gnus-unreads): * lisp/help-fns.el (help-find-source) (help-fns--insert-menu-bindings, help-fns--mention-first-release) (help-fns--mention-shortdoc-groups) (help-fns--customize-variable-version) (help-fns--face-custom-version-info, describe-mode): * lisp/help-mode.el (help-make-xrefs): * lisp/help.el (help-key-description, help--describe-command): * lisp/hfy-cmap.el (htmlfontify-load-rgb-file): * lisp/ibuf-ext.el (ibuffer-jump-to-filter-group) (ibuffer-kill-filter-group, ibuffer-kill-line) (ibuffer-save-filter-groups, ibuffer-save-filters, filename) (basename, file-extension, ibuffer-diff-buffer-with-file-1) (ibuffer-mark-by-file-name-regexp) (ibuffer-mark-by-content-regexp): * lisp/ibuf-macs.el (ibuffer-aif, ibuffer-awhen): * lisp/ibuffer.el (ibuffer-mouse-toggle-mark) (ibuffer-toggle-marks, ibuffer-mark-interactive) (ibuffer-compile-format, process, ibuffer-map-lines): * lisp/image.el (image--compute-map) (image--compute-original-map): * lisp/image/exif.el (exif-parse-buffer): * lisp/image/image-converter.el (image-convert-p, image-convert) (image-converter--find-converter): * lisp/image/image-dired-util.el (image-dired-file-name-at-point): * lisp/image/image-dired.el (image-dired-track-original-file) (image-dired--on-file-in-dired-buffer) (image-dired--with-thumbnail-buffer) (image-dired-jump-original-dired-buffer) (image-dired--slideshow-step, image-dired-display-image): * lisp/image/wallpaper.el (wallpaper--init-action-kill) (wallpaper--find-setter, wallpaper--find-command) (wallpaper--find-command-args, wallpaper--x-monitor-name): * lisp/info-look.el (info-lookup-interactive-arguments) (info-complete)::(:mode): * lisp/info.el (info-pop-to-buffer, Info-read-node-name-1): * lisp/international/emoji.el (emoji--adjust-displayable-1) (emoji--add-recent): * lisp/jsonrpc.el (jsonrpc--call-deferred) (jsonrpc--process-sentinel, jsonrpc--remove): * lisp/keymap.el (keymap-local-lookup): * lisp/mail/emacsbug.el (report-emacs-bug-hook) (submit-emacs-patch): * lisp/mail/ietf-drums.el (ietf-drums-parse-addresses): * lisp/mail/mailclient.el (mailclient-send-it): * lisp/mail/rfc6068.el (rfc6068-parse-mailto-url): * lisp/mail/undigest.el (rmail-digest-parse-mixed-mime): * lisp/minibuffer.el (completion-metadata-get) (completions--after-change) (minibuffer-visible-completions--filter): * lisp/net/browse-url.el (browse-url-url-at-point) (browse-url-file-url, browse-url-emacs): * lisp/net/dbus.el (dbus-byte-array-to-string) (dbus-monitor-goto-serial): * lisp/net/dictionary.el (dictionary-search): * lisp/net/eww.el (eww--download-directory) (eww-auto-rename-buffer, eww-open-in-new-buffer, eww-submit) (eww-follow-link, eww-read-alternate-url) (eww-copy-alternate-url): * lisp/net/goto-addr.el (goto-address-at-point): * lisp/net/mailcap.el (mailcap-mime-info): * lisp/net/rcirc.el (rcirc, rcirc-connect, rcirc-send-string) (rcirc-kill-buffer-hook, rcirc-print, rcirc-when) (rcirc-color-attributes, rcirc-handler-NICK) (rcirc-handler-TAGMSG, rcirc-handler-BATCH): * lisp/net/shr.el (shr-descend, shr-adaptive-fill-function) (shr-correct-dom-case, shr-tag-a): * lisp/net/sieve.el (sieve-manage-quit): * lisp/outline.el (outline-cycle-buffer): * lisp/pcmpl-git.el (pcmpl-git--tracked-file-predicate): * lisp/proced.el (proced-auto-update-timer): * lisp/progmodes/bug-reference.el (bug-reference-try-setup-from-vc): * lisp/progmodes/c-ts-common.el (c-ts-common--fill-paragraph): * lisp/progmodes/c-ts-mode.el (c-ts-mode--preproc-offset) (c-ts-mode--anchor-prev-sibling, c-ts-mode-indent-defun): * lisp/progmodes/compile.el (compilation-error-properties) (compilation-find-file-1): * lisp/progmodes/eglot.el (eglot--check-object) (eglot--read-server, eglot-upgrade-eglot) (eglot-handle-notification, eglot--CompletionParams) (eglot-completion-at-point, eglot--sig-info) (eglot-register-capability): * lisp/progmodes/elisp-mode.el (emacs-lisp-native-compile-and-load) (elisp-eldoc-var-docstring-with-value): * lisp/progmodes/erts-mode.el (erts-mode--goto-start-of-test): * lisp/progmodes/flymake.el (flymake--update-eol-overlays) (flymake-eldoc-function): * lisp/progmodes/gdb-mi.el (gdb-breakpoints-list-handler-custom) (gdb-frame-handler): * lisp/progmodes/go-ts-mode.el (go-ts-mode-docstring) (go-ts-mode--comment-on-previous-line-p) (go-ts-mode--get-test-regexp-at-point) (go-ts-mode-test-this-file): * lisp/progmodes/grep.el (lgrep, rgrep-default-command) (grep-file-at-point): * lisp/progmodes/perl-mode.el (perl--end-of-format-p): * lisp/progmodes/php-ts-mode.el (php-ts-mode--anchor-prev-sibling, php-ts-mode--indent-defun): * lisp/progmodes/project.el (project--other-place-command) (project--find-default-from, project--transplant-file-name) (project-prefixed-buffer-name, project--remove-from-project-list) (project-prompt-project-name, project-remember-projects-under) (project--switch-project-command) (project-uniquify-dirname-transform, project-mode-line-format): * lisp/progmodes/python.el (python-font-lock-keywords-maximum-decoration) (python--treesit-fontify-union-types) (python-shell-get-process-name, python-shell-restart) (python-shell-completion-at-point, python-ffap-module-path) (python-util-comint-end-of-output-p, python--import-sources) (python-add-import, python-remove-import, python-fix-imports): * lisp/progmodes/xref.el (xref--add-log-current-defun): * lisp/repeat.el (repeat-echo-message-string): * lisp/saveplace.el (save-place-dired-hook): * lisp/server.el (server-save-buffers-kill-terminal): * lisp/shadowfile.el (shadow-make-fullname) (shadow-contract-file-name, shadow-define-literal-group): * lisp/shell.el (shell-highlight-undef-mode): * lisp/simple.el (command-completion-using-modes-p) (command-execute, file-user-uid, file-group-gid) (first-completion, last-completion, switch-to-completions): * lisp/startup.el (startup--load-user-init-file): * lisp/tab-line.el (tab-line-tabs-buffer-group-by-project): * lisp/tar-mode.el (tar-goto-file, tar-next-file-displayer): * lisp/term/android-win.el (android-encode-select-string) (gui-backend-set-selection): * lisp/term/haiku-win.el (haiku-dnd-convert-string) (haiku-select-encode-xstring, haiku-select-encode-utf-8-string): * lisp/textmodes/emacs-news-mode.el (emacs-news--buttonize): * lisp/textmodes/ispell.el (ispell-completion-at-point): * lisp/textmodes/sgml-mode.el (sgml-validate) (html-mode--complete-at-point): * lisp/textmodes/tex-mode.el (tex-recenter-output-buffer) (xref-backend-references): * lisp/thingatpt.el (thing-at-point-file-at-point) (thing-at-point-face-at-point): * lisp/thread.el (thread-list--get-status): * lisp/time.el (world-clock-copy-time-as-kill, world-clock): * lisp/touch-screen.el (touch-screen-handle-touch): * lisp/treesit.el (treesit-language-at, treesit-node-at) (treesit-node-on, treesit-buffer-root-node) (treesit-node-field-name, treesit-local-parsers-at) (treesit-local-parsers-on, treesit--cleanup-local-range-overlays) (treesit-font-lock-recompute-features) (treesit-font-lock-fontify-region, treesit-transpose-sexps) (treesit-add-log-current-defun, treesit-major-mode-setup) (treesit--explorer-refresh, treesit-install-language-grammar): * lisp/url/url.el (url-retrieve-synchronously): * lisp/vc/smerge-mode.el (smerge-diff): * lisp/vc/vc-dir.el (vc-dir): * lisp/vc/vc-dispatcher.el (vc-do-async-command): * lisp/vc/vc-git.el (vc-git-dir--branch-headers) (vc-git-dir--stash-headers, vc-git--log-edit-summary-check) (vc-git-stash-list): * lisp/vc/vc.el (vc-responsible-backend, vc-buffer-sync-fileset) (vc-clone): * lisp/visual-wrap.el (visual-wrap--apply-to-line): * lisp/wid-edit.el (widget-text) (widget-editable-list-insert-before): * lisp/window-tool-bar.el (window-tool-bar--keymap-entry-to-string): * lisp/window.el (display-buffer, display-buffer-full-frame) (window-point-context-set, window-point-context-use) (window-point-context-use-default-function): * lisp/xdg.el (xdg-current-desktop): * lisp/xwidget.el (xwidget-webkit-callback): * lisp/yank-media.el (yank-media--get-selection) (yank-media-types): * test/lisp/comint-tests.el (comint-tests/test-password-function): * test/lisp/completion-preview-tests.el (completion-preview-tests--capf): * test/lisp/cus-edit-tests.el (with-cus-edit-test): * test/lisp/erc/erc-scenarios-base-local-modules.el (-phony-sblm-): * test/lisp/erc/erc-scenarios-stamp.el (erc-scenarios-stamp--on-post-modify): * test/lisp/erc/erc-services-tests.el (erc-services-tests--asp-parse-entry): * test/lisp/erc/erc-tests.el (erc-modules--internal-property) (erc--find-mode, erc-tests--update-modules): * test/lisp/erc/resources/erc-d/erc-d-i.el (erc-d-i--parse-message): * test/lisp/erc/resources/erc-d/erc-d-t.el (erc-d-t-kill-related-buffers, erc-d-t-with-cleanup): * test/lisp/erc/resources/erc-d/erc-d-tests.el (erc-d-i--parse-message--irc-parser-tests): * test/lisp/erc/resources/erc-d/erc-d-u.el (erc-d-u--read-exchange-slowly): * test/lisp/erc/resources/erc-d/erc-d.el (erc-d--expire) (erc-d--finalize-done, erc-d--command-handle-all): * test/lisp/erc/resources/erc-scenarios-common.el (erc-scenarios-common-with-cleanup): * test/lisp/erc/resources/erc-tests-common.el (erc-tests--common-display-message) (erc-tests-common-create-subprocess): * test/lisp/ibuffer-tests.el (ibuffer-test-Bug25058): * test/lisp/international/mule-tests.el (mule-cmds-tests--ucs-names-missing-names): * test/lisp/progmodes/python-tests.el (python-tests-get-shell-interpreter) (python-tests--get-interpreter-info): * test/lisp/progmodes/ruby-ts-mode-tests.el (ruby-ts-resource-file): * test/lisp/replace-tests.el (replace-tests-with-undo): * test/src/emacs-tests.el (emacs-tests--seccomp-debug): * test/src/process-tests.el (process-tests--emacs-command) (process-tests--emacs-binary, process-tests--dump-file): * test/src/treesit-tests.el (treesit--ert-test-defun-navigation): Replace use of the now-obsolete if-let and when-let.
1284 lines
48 KiB
EmacsLisp
1284 lines
48 KiB
EmacsLisp
;;; treesit-tests.el --- tests for src/treesit.c -*- lexical-binding: t; -*-
|
|
|
|
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; GNU Emacs 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.
|
|
|
|
;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Code:
|
|
|
|
(require 'ert)
|
|
(require 'treesit)
|
|
|
|
(declare-function treesit-language-available-p "treesit.c")
|
|
|
|
(declare-function treesit-parser-root-node "treesit.c")
|
|
(declare-function treesit-parser-set-included-ranges "treesit.c")
|
|
(declare-function treesit-parser-included-ranges "treesit.c")
|
|
|
|
(declare-function treesit-parser-create "treesit.c")
|
|
(declare-function treesit-parser-delete "treesit.c")
|
|
(declare-function treesit-parser-list "treesit.c")
|
|
(declare-function treesit-parser-buffer "treesit.c")
|
|
(declare-function treesit-parser-language "treesit.c")
|
|
|
|
(declare-function treesit-pattern-expand "treesit.c")
|
|
(declare-function treesit-query-expand "treesit.c")
|
|
(declare-function treesit-query-compile "treesit.c")
|
|
(declare-function treesit-query-capture "treesit.c")
|
|
|
|
(declare-function treesit-node-type "treesit.c")
|
|
(declare-function treesit-node-start "treesit.c")
|
|
(declare-function treesit-node-end "treesit.c")
|
|
(declare-function treesit-node-string "treesit.c")
|
|
(declare-function treesit-node-parent "treesit.c")
|
|
(declare-function treesit-node-child "treesit.c")
|
|
(declare-function treesit-node-check "treesit.c")
|
|
(declare-function treesit-node-field-name-for-child "treesit.c")
|
|
(declare-function treesit-node-child-count "treesit.c")
|
|
(declare-function treesit-node-child-by-field-name "treesit.c")
|
|
(declare-function treesit-node-next-sibling "treesit.c")
|
|
(declare-function treesit-node-prev-sibling "treesit.c")
|
|
(declare-function treesit-node-first-child-for-pos "treesit.c")
|
|
(declare-function treesit-node-descendant-for-range "treesit.c")
|
|
(declare-function treesit-node-eq "treesit.c")
|
|
|
|
(declare-function treesit-search-forward "treesit.c")
|
|
(declare-function treesit-search-subtree "treesit.c")
|
|
|
|
;;; Basic API
|
|
|
|
(ert-deftest treesit-basic-parsing ()
|
|
"Test basic parsing routines."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(with-temp-buffer
|
|
(let ((parser (treesit-parser-create 'json)))
|
|
(should
|
|
(eq parser (car (treesit-parser-list))))
|
|
(should
|
|
(equal (treesit-node-string
|
|
(treesit-parser-root-node parser))
|
|
"(document)"))
|
|
|
|
(insert "[1,2,3]")
|
|
(should
|
|
(equal (treesit-node-string
|
|
(treesit-parser-root-node parser))
|
|
"(document (array (number) (number) (number)))"))
|
|
|
|
(goto-char (point-min))
|
|
(forward-char 3)
|
|
(insert "{\"name\": \"Bob\"},")
|
|
(should
|
|
(equal
|
|
(treesit-node-string
|
|
(treesit-parser-root-node parser))
|
|
"(document (array (number) (object (pair key: (string (string_content)) value: (string (string_content)))) (number) (number)))")))))
|
|
|
|
(ert-deftest treesit-node-api ()
|
|
"Tests for node API."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(with-temp-buffer
|
|
(let (parser root-node doc-node object-node pair-node)
|
|
(progn
|
|
(insert "[1,2,{\"name\": \"Bob\"},3]")
|
|
(setq parser (treesit-parser-create 'json))
|
|
(setq root-node (treesit-parser-root-node
|
|
parser)))
|
|
;; `treesit-node-type'.
|
|
(should (equal "document" (treesit-node-type root-node)))
|
|
;; `treesit-node-check'.
|
|
(should (eq t (treesit-node-check root-node 'named)))
|
|
(should (eq nil (treesit-node-check root-node 'missing)))
|
|
(should (eq nil (treesit-node-check root-node 'extra)))
|
|
(should (eq nil (treesit-node-check root-node 'has-error)))
|
|
(should (eq t (treesit-node-check root-node 'live)))
|
|
;; `treesit-node-child'.
|
|
(setq doc-node (treesit-node-child root-node 0))
|
|
(should (equal "array" (treesit-node-type doc-node)))
|
|
(should (equal (treesit-node-string doc-node)
|
|
"(array (number) (number) (object (pair key: (string (string_content)) value: (string (string_content)))) (number))"))
|
|
;; `treesit-node-child-count'.
|
|
(should (eql 9 (treesit-node-child-count doc-node)))
|
|
(should (eql 4 (treesit-node-child-count doc-node t)))
|
|
;; `treesit-node-field-name-for-child'.
|
|
(setq object-node (treesit-node-child doc-node 2 t))
|
|
(setq pair-node (treesit-node-child object-node 0 t))
|
|
(should (equal "object" (treesit-node-type object-node)))
|
|
(should (equal "pair" (treesit-node-type pair-node)))
|
|
(should (equal "key"
|
|
(treesit-node-field-name-for-child
|
|
pair-node 0)))
|
|
;; `treesit-node-child-by-field-name'.
|
|
(should (equal "(string (string_content))"
|
|
(treesit-node-string
|
|
(treesit-node-child-by-field-name
|
|
pair-node "key"))))
|
|
;; `treesit-node-next-sibling'.
|
|
(should (equal "(number)"
|
|
(treesit-node-string
|
|
(treesit-node-next-sibling object-node t))))
|
|
(should (equal "(\",\")"
|
|
(treesit-node-string
|
|
(treesit-node-next-sibling object-node))))
|
|
;; `treesit-node-prev-sibling'.
|
|
(should (equal "(number)"
|
|
(treesit-node-string
|
|
(treesit-node-prev-sibling object-node t))))
|
|
(should (equal "(\",\")"
|
|
(treesit-node-string
|
|
(treesit-node-prev-sibling object-node))))
|
|
;; `treesit-node-first-child-for-pos'.
|
|
(should (equal "(number)"
|
|
(treesit-node-string
|
|
(treesit-node-first-child-for-pos
|
|
doc-node 3 t))))
|
|
(should (equal "(\",\")"
|
|
(treesit-node-string
|
|
(treesit-node-first-child-for-pos
|
|
doc-node 3))))
|
|
(should-error (treesit-node-first-child-for-pos doc-node 100)
|
|
:type 'args-out-of-range)
|
|
;; `treesit-node-descendant-for-range'.
|
|
(should (equal "(\"{\")"
|
|
(treesit-node-string
|
|
(treesit-node-descendant-for-range
|
|
root-node 6 7))))
|
|
(should (equal "(object (pair key: (string (string_content)) value: (string (string_content))))"
|
|
(treesit-node-string
|
|
(treesit-node-descendant-for-range
|
|
root-node 6 7 t))))
|
|
(should-error (treesit-node-descendant-for-range
|
|
root-node 100 101)
|
|
:type 'args-out-of-range)
|
|
;; `treesit-node-eq'.
|
|
(should (treesit-node-eq root-node root-node))
|
|
(should (not (treesit-node-eq root-node doc-node)))
|
|
;; `treesit-node-enclosed-p'
|
|
(should (treesit-node-enclosed-p '(1 . 3) '(1 . 4)))
|
|
(should (treesit-node-enclosed-p '(1 . 3) '(1 . 3)))
|
|
(should (not (treesit-node-enclosed-p '(1 . 3) '(1 . 4) t)))
|
|
(should (treesit-node-enclosed-p '(1 . 3) '(1 . 4) 'partial))
|
|
(should (treesit-node-enclosed-p '(2 . 3) '(1 . 4) t))
|
|
(should (treesit-node-enclosed-p object-node root-node))
|
|
|
|
;; Further test for `treesit-node-check'.
|
|
(treesit-parser-delete parser)
|
|
(should (equal nil (treesit-node-check root-node 'live)))
|
|
;; Recreate parser.
|
|
(setq parser (treesit-parser-create 'json))
|
|
(setq root-node (treesit-parser-root-node
|
|
parser))
|
|
(should (equal t (treesit-node-check root-node 'live)))
|
|
(kill-buffer)
|
|
(should-error (treesit-node-check root-node 'live)
|
|
:type 'treesit-node-buffer-killed))))
|
|
|
|
;;; Indirect buffer
|
|
|
|
(ert-deftest treesit-indirect-buffer ()
|
|
"Tests for indirect buffers."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(let ((base (get-buffer-create "*treesit test*"))
|
|
parser indirect)
|
|
(unwind-protect
|
|
(progn
|
|
(with-current-buffer base
|
|
(setq indirect (clone-indirect-buffer "*treesit test 1*" nil)))
|
|
(with-current-buffer indirect
|
|
(setq parser (treesit-parser-create 'json))
|
|
(should (equal (list parser) (treesit-parser-list))))
|
|
;; 1. Parser created in the indirect buffer should not appear
|
|
;; in the base buffer.
|
|
(with-current-buffer base
|
|
(should (equal nil
|
|
(treesit-parser-list)))
|
|
(treesit-parser-create 'json)
|
|
(insert "[1,2,3]"))
|
|
;; Change in the base buffer should be reflected in the
|
|
;; indirect buffer.
|
|
(with-current-buffer indirect
|
|
(should (eq (treesit-node-end
|
|
(treesit-buffer-root-node))
|
|
8))
|
|
(erase-buffer))
|
|
;; Change in the indirect buffer should be reflected in the
|
|
;; base buffer.
|
|
(with-current-buffer base
|
|
(should (eq (treesit-node-end
|
|
(treesit-buffer-root-node))
|
|
1))
|
|
(erase-buffer)))
|
|
(kill-buffer base)
|
|
(kill-buffer indirect))))
|
|
|
|
;;; Tree traversal
|
|
|
|
(ert-deftest treesit-search-subtree ()
|
|
"Test `treesit-search-subtree'."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(with-temp-buffer
|
|
(let (parser root array)
|
|
(progn
|
|
(insert "[[1,2,3], [1,2,3], [1,2,3]]")
|
|
(setq parser (treesit-parser-create 'json))
|
|
(setq root (treesit-parser-root-node parser))
|
|
(setq array (treesit-node-child root 0)))
|
|
(dolist (subarray (treesit-node-children array t))
|
|
;; Find named node forward.
|
|
(should (equal "1" (treesit-node-text
|
|
(treesit-search-subtree
|
|
subarray "number"))))
|
|
;; Find named node backward.
|
|
(should (equal "3" (treesit-node-text
|
|
(treesit-search-subtree
|
|
subarray "number" t))))
|
|
;; Find anonymous node forward.
|
|
(should (equal "[" (treesit-node-text
|
|
(treesit-search-subtree
|
|
subarray "\\[" nil t))))
|
|
;; Find anonymous node backward.
|
|
(should (equal "]" (treesit-node-text
|
|
(treesit-search-subtree
|
|
subarray "\\]" t t))))
|
|
;; If ALL=nil, it shouldn't find anonymous node.
|
|
(should (eq nil (treesit-node-text
|
|
(treesit-search-subtree
|
|
subarray "\\["))))
|
|
;; If ALL=t, searching for number should still find the
|
|
;; numbers.
|
|
(should (equal "1" (treesit-node-text
|
|
(treesit-search-subtree
|
|
subarray "number" nil t))))
|
|
;; Find named node backward.
|
|
(should (equal "3" (treesit-node-text
|
|
(treesit-search-subtree
|
|
subarray "number" t t))))
|
|
))))
|
|
|
|
(defmacro treesit--ert-search-setup (&rest body)
|
|
"Setup macro used by `treesit-search-forward' and friends.
|
|
BODY is the test body."
|
|
(declare (debug (&rest form)))
|
|
`(with-temp-buffer
|
|
(let (parser root array)
|
|
(progn
|
|
(insert "[[1,2,3], [4,5,6], [7,8,9]]")
|
|
(setq parser (treesit-parser-create 'json))
|
|
(setq root (treesit-parser-root-node
|
|
parser))
|
|
(setq array (treesit-node-child root 0)))
|
|
,@body)))
|
|
|
|
(ert-deftest treesit-search-forward ()
|
|
"Test `treesit-search-forward'."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(treesit--ert-search-setup
|
|
(cl-loop for cursor = (treesit-node-child array 0)
|
|
then (treesit-search-forward cursor "" nil t)
|
|
for text in '("[" "[" "1" "," "2" "," "3" "]"
|
|
"[1,2,3]" ","
|
|
"[" "4" "," "5" "," "6" "]"
|
|
"[4,5,6]" ","
|
|
"[" "7" "," "8" "," "9" "]"
|
|
"[7,8,9]" "]"
|
|
"[[1,2,3], [4,5,6], [7,8,9]]")
|
|
while cursor
|
|
do (should (equal (treesit-node-text cursor)
|
|
text)))))
|
|
|
|
(ert-deftest treesit-search-forward-named-only ()
|
|
"Test `treesit-search-forward'."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(treesit--ert-search-setup
|
|
(cl-loop for cursor = (treesit-node-child
|
|
(treesit-node-child array 1) 1)
|
|
then (treesit-search-forward cursor "")
|
|
for text in '("1" "2" "3" "[1,2,3]"
|
|
"4" "5" "6" "[4,5,6]"
|
|
"7" "8" "9" "[7,8,9]"
|
|
"[[1,2,3], [4,5,6], [7,8,9]]")
|
|
while cursor
|
|
do (should (equal (treesit-node-text cursor)
|
|
text)))))
|
|
|
|
(ert-deftest treesit-search-backward ()
|
|
"Test `treesit-search-forward'."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(treesit--ert-search-setup
|
|
(cl-loop for cursor = (treesit-node-child array -1)
|
|
then (treesit-search-forward cursor "" t t)
|
|
for text in (reverse '("[[1,2,3], [4,5,6], [7,8,9]]"
|
|
"[" "[1,2,3]"
|
|
"[" "1" "," "2" "," "3" "]"
|
|
"," "[4,5,6]"
|
|
"[" "4" "," "5" "," "6" "]"
|
|
"," "[7,8,9]"
|
|
"[" "7" "," "8" "," "9" "]"
|
|
"]"))
|
|
while cursor
|
|
do (should (equal (treesit-node-text cursor)
|
|
text)))))
|
|
|
|
(ert-deftest treesit-search-backward-named-only ()
|
|
"Test `treesit-search-forward'."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(treesit--ert-search-setup
|
|
(cl-loop for cursor = (treesit-node-child
|
|
(treesit-node-child array -1 t) -1 t)
|
|
then (treesit-search-forward cursor "" t)
|
|
for text in (reverse '("[[1,2,3], [4,5,6], [7,8,9]]"
|
|
"[1,2,3]" "1" "2" "3"
|
|
"[4,5,6]" "4" "5" "6"
|
|
"[7,8,9]" "7" "8" "9"))
|
|
while cursor
|
|
do (should (equal (treesit-node-text cursor)
|
|
text)))))
|
|
|
|
(ert-deftest treesit-search-forward-predicate ()
|
|
"Test various form of supported predicates in search functions."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(treesit--ert-search-setup
|
|
;; The following tests are adapted from `treesit-search-forward'.
|
|
|
|
;; Test `or'
|
|
(cl-loop for cursor = (treesit-node-child array 0)
|
|
then (treesit-search-forward cursor `(or "number" ,(rx "["))
|
|
nil t)
|
|
for text in '("[" "[" "1" "2" "3"
|
|
"[" "4" "5" "6"
|
|
"[" "7" "8" "9")
|
|
while cursor
|
|
do (should (equal (treesit-node-text cursor) text)))
|
|
;; Test `not' and `or'
|
|
(cl-loop for cursor = (treesit-node-child array 0)
|
|
then (treesit-search-forward cursor
|
|
`(not (or "number" ,(rx "[")))
|
|
nil t)
|
|
for text in '("[" "," "," "]"
|
|
"[1,2,3]" ","
|
|
"," "," "]"
|
|
"[4,5,6]" ","
|
|
"," "," "]"
|
|
"[7,8,9]" "]"
|
|
"[[1,2,3], [4,5,6], [7,8,9]]")
|
|
while cursor
|
|
do (should (equal (treesit-node-text cursor) text)))
|
|
;; Test (regexp . function)
|
|
(let ((is-odd (lambda (node)
|
|
(let ((string (treesit-node-text node)))
|
|
(and (eq 1 (length string))
|
|
(cl-oddp (string-to-number string)))))))
|
|
(cl-loop for cursor = (treesit-node-child array 0)
|
|
then (treesit-search-forward cursor `("number" . ,is-odd)
|
|
nil t)
|
|
for text in '("[" "1" "3" "5" "7" "9")
|
|
while cursor
|
|
do (should (equal (treesit-node-text cursor) text))))))
|
|
|
|
(ert-deftest treesit-search-forward-predicate-invalid-predicate ()
|
|
"Test tree-sitter's ability to detect invalid predicates."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(treesit--ert-search-setup
|
|
(dolist (pred '( 1 (not 1) (not "2" "3") (or) (or 1) 'a))
|
|
(should-error (treesit-search-forward (treesit-node-child array 0)
|
|
pred)
|
|
:type 'treesit-invalid-predicate))
|
|
(should-error (treesit-search-forward (treesit-node-child array 0)
|
|
(lambda (node) (car node)))
|
|
:type 'wrong-type-argument)))
|
|
|
|
(ert-deftest treesit-cursor-helper-with-missing-node ()
|
|
"Test treesit_cursor_helper with a missing node."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(treesit--ert-search-setup
|
|
(delete-char -1)
|
|
(setq root (treesit-buffer-root-node))
|
|
(setq array (treesit-node-child root 0))
|
|
;; If everything works, this should not hang.
|
|
(let ((missing-bracket (treesit-node-child array -1)))
|
|
(treesit-search-forward missing-bracket "" t))))
|
|
|
|
;;; Query
|
|
|
|
(defun treesit--ert-pred-last-sibling (node)
|
|
(null (treesit-node-next-sibling node t)))
|
|
|
|
(ert-deftest treesit-query-api ()
|
|
"Tests for query API."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(with-temp-buffer
|
|
(let (parser root-node)
|
|
(progn
|
|
(insert "[1,2,{\"name\": \"Bob\"},3]")
|
|
(setq parser (treesit-parser-create 'json))
|
|
(setq root-node (treesit-parser-root-node
|
|
parser)))
|
|
|
|
(should-error (treesit-query-capture root-node "" 100 101)
|
|
:type 'args-out-of-range)
|
|
|
|
;; Test `treesit-query-capture' on string, sexp and compiled
|
|
;; queries.
|
|
(dolist (query1
|
|
;; String query.
|
|
'("(string) @string
|
|
(pair key: (_) @keyword)
|
|
((_) @bob (#match \"\\\\`B.b\\\\'\" @bob))
|
|
(number) @number
|
|
((number) @n3 (#equal \"3\" @n3))
|
|
((number) @n3p (#pred treesit--ert-pred-last-sibling @n3p))"
|
|
;; Sexp query.
|
|
((string) @string
|
|
(pair key: (_) @keyword)
|
|
((_) @bob (:match "\\`B.b\\'" @bob))
|
|
(number) @number
|
|
((number) @n3 (:equal "3" @n3))
|
|
((number) @n3p (:pred treesit--ert-pred-last-sibling
|
|
@n3p)))))
|
|
;; Test `treesit-query-compile'.
|
|
(dolist (query (list query1
|
|
(treesit-query-compile 'json query1)))
|
|
(should
|
|
(equal
|
|
'((number . "1") (number . "2")
|
|
(keyword . "\"name\"")
|
|
(string . "\"name\"")
|
|
(string . "\"Bob\"")
|
|
(bob . "Bob")
|
|
(number . "3")
|
|
(n3 . "3")
|
|
(n3p . "3"))
|
|
(mapcar (lambda (entry)
|
|
(cons (car entry)
|
|
(treesit-node-text
|
|
(cdr entry))))
|
|
(treesit-query-capture root-node query))))))
|
|
;; Test `treesit-query-expand'.
|
|
(should
|
|
(equal
|
|
"(type field: (_) @capture .) ? * + \"return\""
|
|
(treesit-query-expand
|
|
'((type field: (_) @capture :anchor)
|
|
:? :* :+ "return"))))
|
|
|
|
;; Test string conversion in `treesit-pattern-expand'.
|
|
(should (equal
|
|
(treesit-pattern-expand "a\nb\rc\td\0e\"f\1g\\h\fi")
|
|
"\"a\\nb\\rc\\td\\0e\\\"f\1g\\\\h\fi\"")))))
|
|
|
|
;;; Narrow
|
|
|
|
(ert-deftest treesit-narrow ()
|
|
"Tests if narrowing works."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(with-temp-buffer
|
|
(let (parser)
|
|
(progn
|
|
(insert "xxx[1,{\"name\": \"Bob\"},2,3]xxx")
|
|
(narrow-to-region (+ (point-min) 3) (- (point-max) 3))
|
|
(setq parser (treesit-parser-create 'json))
|
|
(treesit-parser-root-node parser))
|
|
;; This test is from the basic test.
|
|
(should
|
|
(equal
|
|
(treesit-node-string
|
|
(treesit-parser-root-node parser))
|
|
"(document (array (number) (object (pair key: (string (string_content)) value: (string (string_content)))) (number) (number)))"))
|
|
|
|
(widen)
|
|
(goto-char (point-min))
|
|
(insert "ooo")
|
|
(should (equal "oooxxx[1,{\"name\": \"Bob\"},2,3]xxx"
|
|
(buffer-string)))
|
|
(delete-region 10 26)
|
|
(should (equal "oooxxx[1,2,3]xxx"
|
|
(buffer-string)))
|
|
(narrow-to-region (+ (point-min) 6) (- (point-max) 3))
|
|
;; This test is also from the basic test.
|
|
(should
|
|
(equal (treesit-node-string
|
|
(treesit-parser-root-node parser))
|
|
"(document (array (number) (number) (number)))"))
|
|
(widen)
|
|
(goto-char (point-max))
|
|
(insert "[1,2]")
|
|
(should (equal "oooxxx[1,2,3]xxx[1,2]"
|
|
(buffer-string)))
|
|
(narrow-to-region (- (point-max) 5) (point-max))
|
|
(should
|
|
(equal (treesit-node-string
|
|
(treesit-parser-root-node parser))
|
|
"(document (array (number) (number)))"))
|
|
(widen)
|
|
(goto-char (point-min))
|
|
(insert "[1]")
|
|
(should (equal "[1]oooxxx[1,2,3]xxx[1,2]"
|
|
(buffer-string)))
|
|
(narrow-to-region (point-min) (+ (point-min) 3))
|
|
(should
|
|
(equal (treesit-node-string
|
|
(treesit-parser-root-node parser))
|
|
"(document (array (number)))")))))
|
|
|
|
(ert-deftest treesit-cross-boundary ()
|
|
"Tests for cross-boundary edits.
|
|
Cross-boundary means crossing visible_beg and visible_end. We
|
|
don't test if parser parses correctly, instead we just check
|
|
edits like this don't produce assertion errors. (I inserted a
|
|
bunch of assertions that checks e.g. visible_beg <=
|
|
visible_end.)"
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(with-temp-buffer
|
|
(let (parser)
|
|
(progn
|
|
(insert "xxx[1,{\"name\": \"Bob\"},2,3]xxx")
|
|
(narrow-to-region (+ (point-min) 3) (- (point-max) 3))
|
|
(setq parser (treesit-parser-create 'json))
|
|
;; Now visible_beg/end = visible boundary.
|
|
(treesit-parser-root-node parser))
|
|
;; Now parser knows the content of the visible region.
|
|
(widen)
|
|
;; Now visible_beg/end don't change, but visible region expanded.
|
|
(delete-region 1 7)
|
|
;; (1) This change is across visible_beg. I expect
|
|
;; ts_record_change to receive (start=1, old_end=7, new_end=1).
|
|
(treesit-parser-root-node parser)
|
|
;; Above form forces a parse which calls
|
|
;; `ts_ensure_position_synced'. Now visible_beg/end matches the
|
|
;; visible region (whole buffer). We want to test that this
|
|
;; doesn't cause assertion error.
|
|
|
|
(should (equal "{\"name\": \"Bob\"},2,3]xxx" (buffer-string)))
|
|
(narrow-to-region 1 16)
|
|
(should (equal "{\"name\": \"Bob\"}" (buffer-string)))
|
|
(treesit-parser-root-node parser)
|
|
;; Call `ts_ensure_position_synced' again to update visible_beg/end.
|
|
(widen)
|
|
(goto-char 14)
|
|
(insert "by")
|
|
;; (2) This change is inside [visible_beg, visible_end].
|
|
(should (equal "{\"name\": \"Bobby\"},2,3]xxx" (buffer-string)))
|
|
(delete-region 14 23)
|
|
;; This delete is across visible_end.
|
|
(should (equal "{\"name\": \"Bobxxx" (buffer-string)))
|
|
(treesit-parser-root-node parser)
|
|
;; visible_beg/end synced.
|
|
|
|
(narrow-to-region 3 7)
|
|
(should (equal "name" (buffer-string)))
|
|
(treesit-parser-root-node parser)
|
|
;; visible_beg/end synced.
|
|
(widen)
|
|
(goto-char (point-min))
|
|
(insert "zzz")
|
|
(should (equal "zzz{\"name\": \"Bobxxx" (buffer-string)))
|
|
;; (3) Test inserting before visible_beg.
|
|
(treesit-parser-root-node parser)
|
|
;; visible_beg/end synced.
|
|
|
|
(narrow-to-region 4 11)
|
|
(should (equal "{\"name\"" (buffer-string)))
|
|
(treesit-parser-root-node parser)
|
|
;; visible_beg/end synced.
|
|
(widen)
|
|
(goto-char (point-max))
|
|
(insert "yyy")
|
|
;; (4) This change is after visible_end.
|
|
(treesit-parser-root-node parser)
|
|
;; Sync up visible_beg/end.
|
|
(should (equal "zzz{\"name\": \"Bobxxxyyy" (buffer-string)))
|
|
|
|
(narrow-to-region 1 17)
|
|
(should (equal "zzz{\"name\": \"Bob" (buffer-string)))
|
|
(treesit-parser-root-node parser)
|
|
;; Sync up visible_beg/end.
|
|
(widen)
|
|
(delete-region 13 (point-max))
|
|
(treesit-parser-root-node parser)
|
|
;; Sync up visible_beg/end.
|
|
(should (equal "zzz{\"name\": " (buffer-string)))
|
|
;; Ideally we want to also test the case where we delete and
|
|
;; insert simultaneously, but the only such use is in
|
|
;; `casify_region', all others either only inserts or only
|
|
;; deletes. I'll leave it to someone to try to write a test
|
|
;; that calls that.
|
|
)))
|
|
|
|
;;; Range
|
|
|
|
(ert-deftest treesit-range ()
|
|
"Tests if range works."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(with-temp-buffer
|
|
(let (parser)
|
|
(progn
|
|
(insert "[[1],oooxxx[1,2,3],xxx[1,2]]")
|
|
(setq parser (treesit-parser-create 'json))
|
|
(treesit-parser-root-node parser))
|
|
|
|
(should (eq (treesit-parser-included-ranges parser) nil))
|
|
|
|
(should-error
|
|
(treesit-parser-set-included-ranges
|
|
parser '((1 . 6) (5 . 20)))
|
|
:type '(treesit-range-invalid))
|
|
|
|
(treesit-parser-set-included-ranges
|
|
parser '((1 . 6) (12 . 20) (23 . 29)))
|
|
(should (equal '((1 . 6) (12 . 20) (23 . 29))
|
|
(treesit-parser-included-ranges parser)))
|
|
(should (equal "(document (array (array (number)) (array (number) (number) (number)) (array (number) (number))))"
|
|
(treesit-node-string
|
|
(treesit-parser-root-node parser))))
|
|
|
|
(treesit-parser-set-included-ranges parser nil)
|
|
(should (eq (treesit-parser-included-ranges parser) nil))
|
|
|
|
;; `treesit--merge-ranges'.
|
|
(let ((old-ranges '((1 . 10) ; (1) -- before (a)
|
|
(20 . 30); (2) -- intersect with (b)
|
|
(42 . 46) (47 . 48) ; (3) -- inside (c)
|
|
(55 . 65) (70 . 75) ; (4) -- intersect start-end
|
|
(80 . 90) ; (4)
|
|
))
|
|
(new-ranges '((10 . 15) ; (a)
|
|
(18 . 25) (26 . 28) ; (b)
|
|
(40 . 50) ; (c)
|
|
(90 . 100) ; (d) -- after (4)
|
|
))
|
|
(result '((1 . 10) ; (1)
|
|
(10 . 15) ; (a)
|
|
(18 . 25) (26 . 28) ; (b)
|
|
(40 . 50) ; (c)
|
|
(80 . 90) ; (4)
|
|
(90 . 100) ; (d)
|
|
)))
|
|
(should (equal (treesit--merge-ranges
|
|
old-ranges new-ranges 60 75)
|
|
result)))
|
|
;; TODO: More tests.
|
|
)))
|
|
|
|
(ert-deftest treesit-range-offset ()
|
|
"Tests if range offsets work."
|
|
(skip-unless (treesit-language-available-p 'javascript))
|
|
(with-temp-buffer
|
|
(let ((query '(((call_expression (identifier) @_html_template_fn
|
|
(template_string) @capture)
|
|
(:equal "html" @_html_template_fn)))))
|
|
(progn
|
|
(insert "const x = html`<p>Hello</p>`;")
|
|
(treesit-parser-create 'javascript))
|
|
(should (equal '((15 . 29)) (treesit-query-range 'javascript query)))
|
|
(should (equal '((16 . 28)) (treesit-query-range
|
|
'javascript query nil nil '(1 . -1)))))))
|
|
|
|
(ert-deftest treesit-range-merge ()
|
|
"Test merging ranges."
|
|
(should (equal (treesit--merge-ranges '((1 . 1) (3 . 483)) nil 1 488)
|
|
nil)))
|
|
|
|
(ert-deftest treesit-range-fixup-after-edit ()
|
|
"Tests if Emacs can fix OOB ranges after deleting text or narrowing."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(with-temp-buffer
|
|
(let ((parser (treesit-parser-create 'json)))
|
|
(insert "11111111111111111111")
|
|
(treesit-parser-set-included-ranges parser '((1 . 20)))
|
|
(treesit-parser-root-node parser)
|
|
(should (equal (treesit-parser-included-ranges parser)
|
|
'((1 . 20))))
|
|
|
|
(narrow-to-region 5 15)
|
|
(should (equal (treesit-parser-included-ranges parser)
|
|
'((5 . 15))))
|
|
|
|
(widen)
|
|
;; Trickier ranges
|
|
;; 11111111111111111111
|
|
;; [ ] [ ]
|
|
;; { narrow }
|
|
(treesit-parser-set-included-ranges parser '((1 . 7) (10 . 15)))
|
|
(should (equal (treesit-parser-included-ranges parser)
|
|
'((1 . 7) (10 . 15))))
|
|
(narrow-to-region 5 13)
|
|
(should (equal (treesit-parser-included-ranges parser)
|
|
'((5 . 7) (10 . 13))))
|
|
|
|
;; Narrow in front, and discard the last one.
|
|
(widen)
|
|
(treesit-parser-set-included-ranges
|
|
parser '((4 . 10) (12 . 14) (16 . 20)))
|
|
;; 11111111111111111111
|
|
;; [ ] [ ] [ ]
|
|
;; { } narrow
|
|
(narrow-to-region 1 8)
|
|
(should (equal (treesit-parser-included-ranges parser)
|
|
'((4 . 8))))
|
|
|
|
;; Narrow in back, and discard the first one.
|
|
(widen)
|
|
(treesit-parser-set-included-ranges
|
|
parser '((1 . 5) (7 . 9) (11 . 17)))
|
|
;; 11111111111111111111
|
|
;; [ ] [ ] [ ]
|
|
;; { } narrow
|
|
(narrow-to-region 15 20)
|
|
(should (equal (treesit-parser-included-ranges parser)
|
|
'((15 . 17))))
|
|
|
|
;; No overlap
|
|
(widen)
|
|
(treesit-parser-set-included-ranges parser '((15 . 20)))
|
|
;; 11111111111111111111
|
|
;; [ ]
|
|
;; { } narrow
|
|
(narrow-to-region 1 10)
|
|
(should (equal (treesit-parser-included-ranges parser)
|
|
'((1 . 1)))))))
|
|
|
|
;;; Multiple language
|
|
|
|
(ert-deftest treesit-multi-lang ()
|
|
"Tests if parsing multiple language works."
|
|
(skip-unless (and (treesit-language-available-p 'html)
|
|
(treesit-language-available-p 'css)
|
|
(treesit-language-available-p 'javascript)))
|
|
(with-temp-buffer
|
|
(let (css js css-range js-range)
|
|
(progn
|
|
(insert "<html><script>1</script><style>body {}</style></html>")
|
|
(treesit-parser-create 'html)
|
|
(setq css (treesit-parser-create 'css))
|
|
(setq js (treesit-parser-create 'javascript)))
|
|
;; JavaScript.
|
|
(setq js-range
|
|
(treesit-query-range
|
|
'html
|
|
'((script_element (raw_text) @capture))))
|
|
(should (equal '((15 . 16)) js-range))
|
|
(treesit-parser-set-included-ranges js js-range)
|
|
(should (equal "(program (expression_statement (number)))"
|
|
(treesit-node-string
|
|
(treesit-parser-root-node js))))
|
|
;; CSS.
|
|
(setq css-range
|
|
(treesit-query-range
|
|
'html
|
|
'((style_element (raw_text) @capture))))
|
|
(should (equal '((32 . 39)) css-range))
|
|
(treesit-parser-set-included-ranges css css-range)
|
|
(should
|
|
(equal "(stylesheet (rule_set (selectors (tag_name)) (block)))"
|
|
(treesit-node-string
|
|
(treesit-parser-root-node css))))
|
|
;; TODO: More tests.
|
|
)))
|
|
|
|
;;; Supplemental functions
|
|
|
|
(ert-deftest treesit-parser-supplemental ()
|
|
"Supplemental node functions."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
;; `treesit-parse-string'.
|
|
(should (equal (treesit-node-string
|
|
(treesit-parse-string
|
|
"[1,2,{\"name\": \"Bob\"},3]"
|
|
'json))
|
|
"(document (array (number) (number) (object (pair key: (string (string_content)) value: (string (string_content)))) (number)))"))
|
|
(with-temp-buffer
|
|
(let (parser root-node)
|
|
(progn
|
|
(insert "[1,2,{\"name\": \"Bob\"},3]")
|
|
(setq parser (treesit-parser-create 'json))
|
|
(setq root-node (treesit-parser-root-node
|
|
parser))
|
|
(treesit-node-child root-node 0))
|
|
)))
|
|
|
|
(ert-deftest treesit-node-supplemental ()
|
|
"Supplemental node functions."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(let (parser root-node doc-node)
|
|
(progn
|
|
(insert "[1,2,{\"name\": \"Bob\"},3]")
|
|
(setq parser (treesit-parser-create 'json))
|
|
(setq root-node (treesit-parser-root-node
|
|
parser))
|
|
(setq doc-node (treesit-node-child root-node 0)))
|
|
;; `treesit-node-buffer'.
|
|
(should (equal (treesit-node-buffer root-node)
|
|
(current-buffer)))
|
|
;; `treesit-node-language'.
|
|
(should (eq (treesit-node-language root-node)
|
|
'json))
|
|
;; `treesit-node-at'.
|
|
(should (equal (treesit-node-string
|
|
(treesit-node-at 1 'json))
|
|
"(\"[\")"))
|
|
;; `treesit-node-on'
|
|
(should (equal (treesit-node-string
|
|
(treesit-node-on 1 2 'json))
|
|
"(\"[\")"))
|
|
;; `treesit-buffer-root-node'.
|
|
(should (treesit-node-eq
|
|
(treesit-buffer-root-node 'json)
|
|
root-node))
|
|
;; `treesit-filter-child'.
|
|
(should (equal (mapcar
|
|
(lambda (node)
|
|
(treesit-node-type node))
|
|
(treesit-filter-child
|
|
doc-node (lambda (node)
|
|
(treesit-node-check node 'named))))
|
|
'("number" "number" "object" "number")))
|
|
;; `treesit-node-text'.
|
|
(should (equal (treesit-node-text doc-node)
|
|
"[1,2,{\"name\": \"Bob\"},3]"))
|
|
;; `treesit-node-index'.
|
|
(should (eq (treesit-node-index doc-node)
|
|
0))
|
|
;; TODO:
|
|
;; `treesit-parent-until'
|
|
;; `treesit-parent-while'
|
|
;; `treesit-node-children'
|
|
;; `treesit-node-field-name'
|
|
;; `treesit-search-forward-goto'
|
|
))
|
|
|
|
(ert-deftest treesit-node-at ()
|
|
"Test `treesit-node-at'."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(let (parser)
|
|
(progn
|
|
(insert "[1, 2, 3,4] ")
|
|
(setq parser (treesit-parser-create 'json))
|
|
(treesit-parser-root-node parser))
|
|
;; Point at ",", should return ",".
|
|
(goto-char (point-min))
|
|
(search-forward "1")
|
|
(should (equal (treesit-node-text
|
|
(treesit-node-at (point)))
|
|
","))
|
|
;; Point behind ",", should still return the ",".
|
|
(search-forward ",")
|
|
(should (equal (treesit-node-text
|
|
(treesit-node-at (point)))
|
|
","))
|
|
;; Point between "," and "2", should return 2.
|
|
(forward-char)
|
|
(should (equal (treesit-node-text
|
|
(treesit-node-at (point)))
|
|
"2"))
|
|
;; EOF, should return the last leaf node "]".
|
|
(goto-char (point-max))
|
|
(should (equal (treesit-node-text
|
|
(treesit-node-at (point)))
|
|
"]"))))
|
|
|
|
(ert-deftest treesit-node-check ()
|
|
"Test `treesit-node-check'."
|
|
(skip-unless (treesit-language-available-p 'json))
|
|
(let (parser root-node array-node comment-node)
|
|
(progn
|
|
(insert "/* comment */ [1, 2, 3,4 ")
|
|
(setq parser (treesit-parser-create 'json))
|
|
(setq root-node (treesit-parser-root-node
|
|
parser))
|
|
(setq comment-node (treesit-node-child root-node 0))
|
|
(setq array-node (treesit-node-child root-node 1)))
|
|
|
|
(should (treesit-node-check comment-node 'extra))
|
|
(should (treesit-node-check array-node 'has-error))
|
|
(should-error (treesit-node-check array-node 'xxx))
|
|
(should (treesit-node-check (treesit-node-child array-node -1)
|
|
'missing))
|
|
(goto-char (point-max))
|
|
(insert "]")
|
|
(treesit-parser-root-node parser)
|
|
(should (treesit-node-check array-node 'outdated))))
|
|
|
|
;;; Defun navigation
|
|
;;
|
|
;; I've setup a framework for easier testing of defun navigation.
|
|
;;
|
|
;; To use it for a particular language, first write a test program
|
|
;; similar to `treesit--ert-defun-navigation-python-program', and
|
|
;; insert markers. Markers that marks BOLs are defined as follows:
|
|
;;
|
|
;; 100 Before 1st parent
|
|
;; 101 Beg of 1st parent
|
|
;; 102 End of 1st parent
|
|
;; 103 Beg of 2nd parent
|
|
;; 104 Beg of 1st method
|
|
;; 105 End of 1st method
|
|
;; 106 Beg of 2nd method
|
|
;; 107 End of 2nd method
|
|
;; 108 End of 2nd parent
|
|
;; 109 Beg of 3rd parent
|
|
;; 110 End of 3rd parent
|
|
;; 999 Dummy markers
|
|
;;
|
|
;; Then add marker 0-9 following the definition given in
|
|
;; `treesit--ert-defun-navigation-nested-master'. Then you can use
|
|
;; `treesit--ert-test-defun-navigation', pass the test program you
|
|
;; just wrote, and the appropriate master:
|
|
;;
|
|
;; - `treesit--ert-defun-navigation-nested-master' for nested defun
|
|
;; - `treesit--ert-defun-navigation-top-level-master' for top-level
|
|
|
|
|
|
(defun treesit--ert-insert-and-parse-marker (opening closing text)
|
|
"Insert TEXT and parse the marker positions in it.
|
|
|
|
TEXT should be a string in which contains position markings
|
|
like (1). OPENING and CLOSING are position marking's delimiters,
|
|
for (1), OPENING and CLOSING should be \"(\" and \")\",
|
|
respectively.
|
|
|
|
This function inserts TEXT, parses and removes all the markings,
|
|
and returns an alist of (NUMBER . POS), where number is each
|
|
marking's number, and POS is each marking's position."
|
|
(declare (indent 2))
|
|
(let (result)
|
|
(insert text)
|
|
(goto-char (point-min))
|
|
(while (re-search-forward
|
|
(rx-to-string `(seq ,opening (group (+ digit)) ,closing))
|
|
nil t)
|
|
(let ((idx (string-to-number (match-string 1))))
|
|
(push (cons idx (match-beginning 0)) result)
|
|
(delete-region (match-beginning 0) (match-end 0))))
|
|
(nreverse result)))
|
|
|
|
(defun treesit--ert-collect-positions (positions functions)
|
|
"Collect positions after calling each function in FUNCTIONS.
|
|
|
|
POSITIONS should be a list of buffer positions, FUNCTIONS should
|
|
be a list of functions. This function collects the return value
|
|
of each function in FUNCTIONS starting at each position in
|
|
POSITIONS.
|
|
|
|
Return a list of (POS...) where each POS corresponds to a
|
|
function in FUNCTIONS. For example, if buffer content is
|
|
\"123\", POSITIONS is (2 3), FUNCTIONS is (point-min point-max),
|
|
the return value is ((1 3) (1 3))."
|
|
(cl-loop for pos in positions
|
|
collect (cl-loop for fn in functions
|
|
collect (progn
|
|
(goto-char pos)
|
|
(funcall fn)))))
|
|
|
|
(defun treesit--ert-test-defun-navigation
|
|
(init program master tactic &optional opening closing)
|
|
"Run defun navigation tests on PROGRAM and MASTER.
|
|
|
|
INIT is a setup function that runs right after this function
|
|
creates a temporary buffer. It should take no argument.
|
|
|
|
PROGRAM is a program source in string, MASTER is a list of
|
|
\(START PREV-BEG NEXT-END PREV-END NEXT-BEG), where START is the
|
|
starting marker position, and the rest are marker positions the
|
|
corresponding navigation should stop at (after running
|
|
`treesit-defun-skipper').
|
|
|
|
TACTIC is the same as in `treesit-navigate-thing'.
|
|
|
|
OPENING and CLOSING are the same as in
|
|
`treesit--ert-insert-and-parse-marker', by default they are \"[\"
|
|
and \"]\"."
|
|
(with-temp-buffer
|
|
(funcall init)
|
|
(pcase-let*
|
|
((opening (or opening "["))
|
|
(closing (or closing "]"))
|
|
;; Insert program and parse marker positions.
|
|
(marker-alist (treesit--ert-insert-and-parse-marker
|
|
opening closing program))
|
|
;; Translate marker positions into buffer positions.
|
|
(decoded-master
|
|
(cl-loop for record in master
|
|
collect
|
|
(cl-loop for pos in record
|
|
collect (alist-get pos marker-alist))))
|
|
;; Collect positions each function returns.
|
|
(positions
|
|
(treesit--ert-collect-positions
|
|
;; The first column of DECODED-MASTER.
|
|
(mapcar #'car decoded-master)
|
|
;; Four functions: next-end, prev-beg, next-beg, prev-end.
|
|
(mapcar (lambda (conf)
|
|
(lambda ()
|
|
(if-let* ((pos (funcall
|
|
#'treesit-navigate-thing
|
|
(point) (car conf) (cdr conf)
|
|
treesit-defun-type-regexp tactic)))
|
|
(save-excursion
|
|
(goto-char pos)
|
|
(funcall treesit-defun-skipper)
|
|
(point)))))
|
|
'((-1 . beg)
|
|
(1 . end)
|
|
(-1 . end)
|
|
(1 . beg))))))
|
|
;; Verify each position.
|
|
(cl-loop for record in decoded-master
|
|
for orig-record in master
|
|
for poss in positions
|
|
for name = (format "marker %d" (car orig-record))
|
|
do (should (equal (cons name (cdr record))
|
|
(cons name poss)))))))
|
|
|
|
(defvar treesit--ert-defun-navigation-python-program
|
|
"[100]
|
|
[101]class Class1():
|
|
[999] prop = 0
|
|
[102]
|
|
[103]class Class2():[0]
|
|
[104] [1]def method1():
|
|
[999] [2]return 0[3]
|
|
[105] [4]
|
|
[106] [5]def method2():
|
|
[999] [6]return 0[7]
|
|
[107] [8]
|
|
[999] prop = 0[9]
|
|
[108]
|
|
[109]class Class3():
|
|
[999] prop = 0[10]
|
|
[110]
|
|
"
|
|
"Python source for navigation test.")
|
|
|
|
(defvar treesit--ert-defun-navigation-js-program
|
|
"[100]
|
|
[101]class Class1 {
|
|
[999]}
|
|
[102]
|
|
[103]class Class2 {[0]
|
|
[104] [1]method1() {
|
|
[999] [2]return 0;
|
|
[999] }[3]
|
|
[105] [4]
|
|
[106] [5]method2() {
|
|
[999] [6]return 0;
|
|
[999] }[7]
|
|
[107][8]
|
|
[999]}[9]
|
|
[108]
|
|
[109]class class3 {
|
|
[999]}[10]
|
|
[110]
|
|
"
|
|
"Javascript source for navigation test.")
|
|
|
|
(defvar treesit--ert-defun-navigation-bash-program
|
|
"[100]
|
|
[101]parent1 () {
|
|
[999]}
|
|
[102]
|
|
[103]parent2 () {[0]
|
|
[104] [1]sibling1 () {
|
|
[999] [2]echo hi
|
|
[999] }[3]
|
|
[105] [4]
|
|
[106] [5]sibling2 () {
|
|
[999] [6]echo hi
|
|
[999] }[7]
|
|
[107][8]
|
|
[999]}[9]
|
|
[108]
|
|
[109]parent3 () {
|
|
[999]}
|
|
[110]
|
|
"
|
|
"Bash source for navigation test.")
|
|
|
|
(defvar treesit--ert-defun-navigation-elixir-program
|
|
"[100]
|
|
[101]def bar() do
|
|
[999]end
|
|
[102]
|
|
[103]defmodule Example do[0]
|
|
[999] @impl true
|
|
[104] [1]def bar() do[2]
|
|
[999] end[3]
|
|
[105] [4]
|
|
[106] [5]def baz() do[6]
|
|
[999] end[7]
|
|
[107] [8]
|
|
[999]end[9]
|
|
[108]
|
|
[109]def bar() do
|
|
[999]end
|
|
[110]
|
|
"
|
|
"Elixir source for navigation test.")
|
|
|
|
(defvar treesit--ert-defun-navigation-nested-master
|
|
;; START PREV-BEG NEXT-END PREV-END NEXT-BEG
|
|
'((0 103 105 102 104) ; Between Beg of parent & 1st sibling.
|
|
(1 103 105 102 106) ; Beg of 1st sibling.
|
|
(2 104 105 102 106) ; Inside 1st sibling.
|
|
(3 104 107 102 106) ; End of 1st sibling.
|
|
(4 104 107 105 106) ; Between 1st sibling & 2nd sibling.
|
|
(5 104 107 105 109) ; Beg of 2nd sibling.
|
|
(6 106 107 105 109) ; Inside 2nd sibling.
|
|
(7 106 108 105 109) ; End of 2nd sibling.
|
|
(8 106 108 107 109) ; Between 2nd sibling & end of parent.
|
|
(9 103 110 102 109) ; End of parent.
|
|
|
|
(100 nil 102 nil 101) ; Before 1st parent.
|
|
(101 nil 102 nil 103) ; Beg of 1st parent.
|
|
(102 101 108 102 103) ; Between 1st & 2nd parent.
|
|
(103 101 108 102 109) ; Beg of 2nd parent.
|
|
(110 109 nil 110 nil) ; After 3rd parent.
|
|
)
|
|
"Master of nested navigation test.
|
|
|
|
This basically says, e.g., \"start with point on marker 0, go to
|
|
the prev-beg, now point should be at marker 103\", etc.")
|
|
|
|
(defvar treesit--ert-defun-navigation-top-level-master
|
|
;; START PREV-BEG NEXT-END PREV-END NEXT-BEG
|
|
'((0 103 108 102 109) ; Between Beg of parent & 1st sibling.
|
|
(1 103 108 102 109) ; Beg of 1st sibling.
|
|
(2 103 108 102 109) ; Inside 1st sibling.
|
|
(3 103 108 102 109) ; End of 1st sibling.
|
|
(4 103 108 102 109) ; Between 1st sibling & 2nd sibling.
|
|
(5 103 108 102 109) ; Beg of 2nd sibling.
|
|
(6 103 108 102 109) ; Inside 2nd sibling.
|
|
(7 103 108 102 109) ; End of 2nd sibling.
|
|
(8 103 108 102 109) ; Between 2nd sibling & end of parent.
|
|
(9 103 110 102 109) ; End of parent.
|
|
|
|
;; Top-level defuns should be identical to the nested test.
|
|
(100 nil 102 nil 101) ; Before 1st parent.
|
|
(101 nil 102 nil 103) ; Beg of 1st parent.
|
|
(102 101 108 102 103) ; Between 1st & 2nd parent.
|
|
(103 101 108 102 109) ; Beg of 2nd parent.
|
|
(110 109 nil 110 nil) ; After 3rd parent.
|
|
)
|
|
"Master of top-level navigation test.")
|
|
|
|
(ert-deftest treesit-defun-navigation-nested-1 ()
|
|
"Test defun navigation."
|
|
(skip-unless (treesit-language-available-p 'python))
|
|
;; Nested defun navigation
|
|
(require 'python)
|
|
(treesit--ert-test-defun-navigation
|
|
'python-ts-mode
|
|
treesit--ert-defun-navigation-python-program
|
|
treesit--ert-defun-navigation-nested-master
|
|
'nested))
|
|
|
|
(ert-deftest treesit-defun-navigation-nested-2 ()
|
|
"Test defun navigation using `js-ts-mode'."
|
|
(skip-unless (treesit-language-available-p 'javascript))
|
|
;; Nested defun navigation
|
|
(require 'js)
|
|
(treesit--ert-test-defun-navigation
|
|
'js-ts-mode
|
|
treesit--ert-defun-navigation-js-program
|
|
treesit--ert-defun-navigation-nested-master
|
|
'nested))
|
|
|
|
(ert-deftest treesit-defun-navigation-nested-3 ()
|
|
"Test defun navigation using `bash-ts-mode'."
|
|
(skip-unless (treesit-language-available-p 'bash))
|
|
;; Nested defun navigation
|
|
(treesit--ert-test-defun-navigation
|
|
(lambda ()
|
|
(treesit-parser-create 'bash)
|
|
(setq-local treesit-defun-type-regexp "function_definition"))
|
|
treesit--ert-defun-navigation-bash-program
|
|
treesit--ert-defun-navigation-nested-master
|
|
'nested))
|
|
|
|
(ert-deftest treesit-defun-navigation-nested-4 ()
|
|
"Test defun navigation using Elixir.
|
|
This tests bug#60355."
|
|
(skip-unless (treesit-language-available-p 'elixir))
|
|
;; Nested defun navigation
|
|
(let ((pred (lambda (node)
|
|
(member (treesit-node-text
|
|
(treesit-node-child-by-field-name node "target"))
|
|
'("def" "defmodule")))))
|
|
(treesit--ert-test-defun-navigation
|
|
(lambda ()
|
|
(treesit-parser-create 'elixir)
|
|
(setq-local treesit-defun-type-regexp `("call" . ,pred)))
|
|
treesit--ert-defun-navigation-elixir-program
|
|
treesit--ert-defun-navigation-nested-master
|
|
'nested)))
|
|
|
|
(ert-deftest treesit-defun-navigation-top-level ()
|
|
"Test top-level only defun navigation."
|
|
(skip-unless (treesit-language-available-p 'python))
|
|
;; Nested defun navigation
|
|
(require 'python)
|
|
(treesit--ert-test-defun-navigation
|
|
'python-ts-mode
|
|
treesit--ert-defun-navigation-python-program
|
|
treesit--ert-defun-navigation-top-level-master
|
|
'top-level))
|
|
|
|
(ert-deftest treesit-search-subtree-forward-1 ()
|
|
"Test search subtree forward."
|
|
(skip-unless (treesit-language-available-p 'python))
|
|
(require 'python)
|
|
(python-ts-mode)
|
|
(insert "Temp(1, 2)")
|
|
(goto-char (point-min))
|
|
(pcase-let* ((`((,_ . ,call-node))
|
|
(treesit-query-capture (treesit-buffer-root-node)
|
|
'((call) @c)))
|
|
(node (treesit-search-subtree
|
|
call-node
|
|
(lambda (n) (equal (treesit-node-type n) "integer")))))
|
|
|
|
(should node)
|
|
(should (equal (treesit-node-text node) "1"))))
|
|
|
|
(ert-deftest treesit-search-subtree-backward-1 ()
|
|
"Test search subtree with backward=t."
|
|
(skip-unless (treesit-language-available-p 'python))
|
|
(require 'python)
|
|
(python-ts-mode)
|
|
(insert "Temp(1, 2)")
|
|
(goto-char (point-min))
|
|
(pcase-let* ((`((,_ . ,call-node))
|
|
(treesit-query-capture (treesit-buffer-root-node)
|
|
'((call) @c)))
|
|
(node (treesit-search-subtree
|
|
call-node
|
|
(lambda (n) (equal (treesit-node-type n) "integer"))
|
|
t)))
|
|
|
|
(should node)
|
|
(should (equal (treesit-node-text node) "2"))))
|
|
|
|
|
|
;; TODO
|
|
;; - Functions in treesit.el
|
|
;; - treesit-load-name-override-list
|
|
;; - treesit-search-subtree
|
|
;; - treesit-search-forward
|
|
;; - treesit-induce-sparse-tree
|
|
;; - treesit-search-forward
|
|
|
|
|
|
(provide 'treesit-tests)
|
|
;;; treesit-tests.el ends here
|