├── .github └── workflows │ └── ci.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── doc └── treesj.txt ├── lua └── treesj │ ├── chold │ └── init.lua │ ├── format.lua │ ├── init.lua │ ├── langs │ ├── bash.lua │ ├── c.lua │ ├── cpp.lua │ ├── css.lua │ ├── dart.lua │ ├── default_preset.lua │ ├── elixir.lua │ ├── go.lua │ ├── haskell.lua │ ├── html.lua │ ├── init.lua │ ├── java.lua │ ├── javascript.lua │ ├── json.lua │ ├── json5.lua │ ├── jsonc.lua │ ├── julia.lua │ ├── kotlin.lua │ ├── lua.lua │ ├── nix.lua │ ├── perl.lua │ ├── php.lua │ ├── php_only.lua │ ├── pug.lua │ ├── python.lua │ ├── r.lua │ ├── ruby.lua │ ├── rust.lua │ ├── scss.lua │ ├── sql.lua │ ├── starlark.lua │ ├── svelte.lua │ ├── terraform.lua │ ├── toml.lua │ ├── tsx.lua │ ├── typescript.lua │ ├── utils.lua │ ├── vue.lua │ ├── yaml.lua │ └── zig.lua │ ├── notify.lua │ ├── search.lua │ ├── settings.lua │ ├── treesj │ ├── init.lua │ └── utils.lua │ └── utils.lua ├── stylua.toml └── tests ├── README.md ├── chold ├── cursor.js ├── cursor.lua ├── end_join_spec.lua ├── end_split_spec.lua ├── hold_join_spec.lua ├── hold_split_recursive_spec.lua ├── hold_split_spec.lua ├── start_join_spec.lua └── start_split_spec.lua ├── langs ├── bash │ ├── join_spec.lua │ └── split_spec.lua ├── c │ ├── join_spec.lua │ └── split_spec.lua ├── cpp │ ├── join_spec.lua │ └── split_spec.lua ├── css │ ├── join_spec.lua │ └── split_spec.lua ├── dart │ ├── join_spec.lua │ └── split_spec.lua ├── elixir │ ├── join_spec.lua │ └── split_spec.lua ├── go │ ├── join_spec.lua │ └── split_spec.lua ├── haskell │ ├── join_spec.lua │ └── split_spec.lua ├── html │ ├── html_last_indent_spec.lua │ ├── html_no_empty_spec.lua │ └── html_spec.lua ├── java │ ├── join_spec.lua │ └── split_spec.lua ├── javascript │ ├── join_spec.lua │ ├── jsx_last_indent_spec.lua │ ├── jsx_spec.lua │ ├── split_recursive_spec.lua │ └── split_spec.lua ├── json │ ├── join_spec.lua │ └── split_spec.lua ├── json5 │ ├── join_spec.lua │ └── split_spec.lua ├── jsonc │ ├── join_spec.lua │ └── split_spec.lua ├── julia │ ├── join_spec.lua │ └── split_spec.lua ├── kotlin │ ├── join_spec.lua │ ├── recursive_spec.lua │ └── split_spec.lua ├── lua │ ├── join_spec.lua │ ├── lua_no_empty_spec.lua │ ├── lua_rec_spec.lua │ ├── split_spec.lua │ └── with_tab_spec.lua ├── nix │ ├── join_spec.lua │ └── split_spec.lua ├── perl │ ├── join_spec.lua │ └── split_spec.lua ├── php │ ├── join_spec.lua │ └── split_spec.lua ├── pug │ ├── join_spec.lua │ └── split_spec.lua ├── python │ ├── python_join_spec.lua │ └── python_split_spec.lua ├── r │ ├── r_join_spec.lua │ └── r_split_spec.lua ├── ruby │ ├── join_spec.lua │ └── split_spec.lua ├── rust │ ├── rust_join_spec.lua │ └── rust_split_spec.lua ├── scss │ ├── join_spec.lua │ └── split_spec.lua ├── sql │ ├── join_spec.lua │ └── split_spec.lua ├── starlark │ ├── starlark_join_spec.lua │ └── starlark_split_spec.lua ├── svelte │ ├── join_spec.lua │ └── split_spec.lua ├── template │ ├── join_spec.lua │ └── split_spec.lua ├── terraform │ ├── join_spec.lua │ └── split_spec.lua ├── toml │ ├── join_spec.lua │ └── split_spec.lua ├── typescript │ ├── tsx_spec.lua │ └── typescript_spec.lua ├── vue │ ├── join_spec.lua │ └── split_spec.lua ├── yaml │ ├── join_spec.lua │ └── split_spec.lua └── zig │ ├── join_spec.lua │ └── split_spec.lua ├── minimal.lua ├── sample ├── index.R ├── index.c ├── index.cpp ├── index.css ├── index.dart ├── index.ex ├── index.go ├── index.hs ├── index.html ├── index.java ├── index.jl ├── index.js ├── index.json ├── index.json5 ├── index.jsonc ├── index.jsx ├── index.kt ├── index.lua ├── index.nix ├── index.php ├── index.pl ├── index.pug ├── index.py ├── index.rb ├── index.rs ├── index.scss ├── index.sh ├── index.sql ├── index.star ├── index.svelte ├── index.tf ├── index.toml ├── index.ts ├── index.tsx ├── index.vue ├── index.yml ├── index.zig ├── index_recursive.js ├── index_recursive.kt └── index_tab.lua └── utils.lua /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | pull_request: 5 | 6 | jobs: 7 | tests: 8 | strategy: 9 | matrix: 10 | os: [ubuntu-latest] 11 | runs-on: ${{ matrix.os }} 12 | steps: 13 | - uses: actions/checkout@v3 14 | - name: Install Neovim 15 | shell: bash 16 | run: | 17 | mkdir -p /tmp/nvim 18 | wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim-linux-x86_64.appimage -O /tmp/nvim/nvim.appimage 19 | cd /tmp/nvim 20 | chmod a+x ./nvim.appimage 21 | ./nvim.appimage --appimage-extract 22 | echo "/tmp/nvim/squashfs-root/usr/bin/" >> $GITHUB_PATH 23 | - name: Run Tests 24 | run: | 25 | nvim --version 26 | [ ! -d tests ] && exit 0 27 | nvim --headless -u tests/minimal.lua -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal.lua', sequential = true}" 28 | docs: 29 | runs-on: ubuntu-latest 30 | needs: tests 31 | if: ${{ github.ref == 'refs/heads/main' }} 32 | steps: 33 | - uses: actions/checkout@v3 34 | - name: panvimdoc 35 | uses: kdheepak/panvimdoc@main 36 | with: 37 | vimdoc: treesj 38 | version: "Neovim >= 0.8.0" 39 | demojify: true 40 | treesitter: true 41 | - name: Push changes 42 | uses: stefanzweifel/git-auto-commit-action@v4 43 | with: 44 | commit_message: "docs: auto-generate vimdoc" 45 | commit_user_name: "github-actions[bot]" 46 | commit_user_email: "github-actions[bot]@users.noreply.github.com" 47 | commit_author: "github-actions[bot] " 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /plugin 3 | todo.md 4 | /.tests 5 | **/**/tmp.* 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ivan Smirnov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | preinstall-ts-parsers: 2 | nvim --headless -u tests/minimal.lua -c "TSUpdate | qa" 3 | 4 | # LP string = language path 5 | test-langs: 6 | nvim --headless -u tests/minimal.lua -c "PlenaryBustedDirectory tests/langs/${LP} { minimal_init = 'tests/minimal.lua' }" 7 | 8 | test-chold: 9 | nvim --headless -u tests/minimal.lua -c "PlenaryBustedDirectory tests/chold {minimal_init = 'tests/minimal.lua'}" 10 | 11 | # M string = mode 'start'|'end'|'hold' 12 | test-chold-m: 13 | nvim --headless -u tests/minimal.lua -c "PlenaryBustedDirectory tests/chold/${M}_spec.lua {minimal_init = 'tests/minimal.lua'}" 14 | 15 | test-chold-r: 16 | nvim --headless -u tests/minimal.lua -c "PlenaryBustedDirectory tests/chold/hold_split_recursive_spec.lua {minimal_init = 'tests/minimal.lua'}" 17 | 18 | test: 19 | make test-langs && make test-chold 20 | 21 | lint-fix: 22 | stylua ./lua/treesj ./tests/langs/ 23 | 24 | docs: 25 | ~/projects/code/github/panvimdoc/panvimdoc.sh \ 26 | --project-name treesj \ 27 | --input-file ./README.md \ 28 | --vim-version 0.8.0 \ 29 | --toc true \ 30 | --description "" \ 31 | --dedup-subheadings true \ 32 | --demojify false \ 33 | --treesitter true \ 34 | --ignore-rawblocks false \ 35 | --doc-mapping true \ 36 | --doc-mapping-project-name true \ 37 | --shift-heading-level-by 0 \ 38 | --increment-heading-level-by 0 \ 39 | -------------------------------------------------------------------------------- /lua/treesj/init.lua: -------------------------------------------------------------------------------- 1 | local settings = require('treesj.settings') 2 | 3 | local M = { 4 | _mode_to_use = nil, 5 | _preset_to_use = nil, 6 | } 7 | 8 | M.setup = function(opts) 9 | settings._update_settings(opts) 10 | settings._set_default_keymaps() 11 | settings._create_commands() 12 | end 13 | 14 | M.__format = function() 15 | require('treesj.format')._format(M._mode_to_use, M._preset_to_use) 16 | end 17 | 18 | local function perform(mode, preset) 19 | M._mode_to_use = mode 20 | M._preset_to_use = preset 21 | 22 | if settings.settings.dot_repeat then 23 | vim.opt.operatorfunc = "v:lua.require'treesj'.__format" 24 | vim.api.nvim_feedkeys('g@l', 'nix', true) 25 | else 26 | M.__format() 27 | end 28 | end 29 | 30 | M.toggle = function(preset) 31 | perform(nil, preset) 32 | end 33 | 34 | M.join = function(preset) 35 | perform("join", preset) 36 | end 37 | 38 | M.split = function(preset) 39 | perform("split", preset) 40 | end 41 | 42 | return M 43 | -------------------------------------------------------------------------------- /lua/treesj/langs/bash.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | local statement = lang_utils.set_preset_for_statement({ 4 | join = { 5 | force_insert = ';', 6 | }, 7 | split = { 8 | format_tree = function(tsj) 9 | tsj:remove_child(';') 10 | end, 11 | }, 12 | }) 13 | 14 | return { 15 | array = lang_utils.set_preset_for_list({ 16 | both = { 17 | separator = '', 18 | last_separator = false, 19 | }, 20 | join = { 21 | space_in_brackets = false, 22 | }, 23 | }), 24 | compound_statement = statement, 25 | do_group = statement, 26 | if_statement = vim.tbl_deep_extend('force', statement, { 27 | both = { 28 | enable = function(tsn) 29 | return not lang_utils.helpers.contains({ 30 | 'elif_clause', 31 | 'else_clause', 32 | })(tsn) 33 | end, 34 | shrink_node = { from = 'then' }, 35 | }, 36 | }), 37 | variable_assignment = { 38 | target_nodes = { 'array' }, 39 | }, 40 | for_statement = { 41 | target_nodes = { 'do_group', 'compound_statement' }, 42 | }, 43 | } 44 | -------------------------------------------------------------------------------- /lua/treesj/langs/c.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | parameter_list = lang_utils.set_preset_for_args(), 5 | argument_list = lang_utils.set_preset_for_args(), 6 | initializer_list = lang_utils.set_preset_for_list(), 7 | compound_statement = lang_utils.set_preset_for_statement({ 8 | both = { 9 | no_format_with = { 'compound_statement' }, 10 | recursive = false, 11 | }, 12 | join = { 13 | force_insert = ';', 14 | }, 15 | }), 16 | enumerator_list = lang_utils.set_preset_for_list(), 17 | if_statement = { target_nodes = { 'compound_statement' } }, 18 | declaration = { 19 | target_nodes = { 'parameter_list', 'argument_list', 'initializer_list' }, 20 | }, 21 | call_expression = { target_nodes = { 'argument_list' } }, 22 | enum_specifier = { target_nodes = { 'enumerator_list' } }, 23 | } 24 | -------------------------------------------------------------------------------- /lua/treesj/langs/cpp.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | local c = require('treesj.langs.c') 3 | 4 | return lang_utils.merge_preset(c, { 5 | template_argument_list = lang_utils.set_preset_for_args(), 6 | template_parameter_list = lang_utils.set_preset_for_args(), 7 | template_declaration = { target_nodes = { 'template_parameter_list' } }, 8 | template_type = { target_nodes = { 'template_argument_list' } }, 9 | }) 10 | -------------------------------------------------------------------------------- /lua/treesj/langs/css.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | block = lang_utils.set_preset_for_statement({ 5 | join = { 6 | force_insert = '', 7 | }, 8 | }), 9 | keyframe_block_list = lang_utils.set_preset_for_statement({ 10 | join = { 11 | force_insert = '', 12 | }, 13 | }), 14 | arguments = lang_utils.set_preset_for_args(), 15 | call_expression = { 16 | target_nodes = { 'arguments' }, 17 | }, 18 | rule_set = { 19 | target_nodes = { 'block' }, 20 | }, 21 | media_statement = { 22 | target_nodes = { 'block' }, 23 | }, 24 | keyframes_statement = { 25 | target_nodes = { 'keyframe_block_list' }, 26 | }, 27 | supports_statement = { 28 | target_nodes = { 'block' }, 29 | }, 30 | at_rule = { 31 | target_nodes = { 'block' }, 32 | }, 33 | } 34 | -------------------------------------------------------------------------------- /lua/treesj/langs/dart.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | list_literal = lang_utils.set_preset_for_list({ 5 | both = { 6 | shrink_node = { from = '[', to = ']' }, 7 | }, 8 | }), 9 | set_or_map_literal = lang_utils.set_preset_for_dict(), 10 | block = lang_utils.set_preset_for_statement(), 11 | arguments = lang_utils.set_preset_for_args(), 12 | formal_parameter_list = lang_utils.set_preset_for_args(), 13 | static_final_declaration = { 14 | target_nodes = { 15 | 'list_literal', 16 | 'set_or_map_literal', 17 | }, 18 | }, 19 | initialized_identifier = { 20 | target_nodes = { 21 | 'list_literal', 22 | 'set_or_map_literal', 23 | }, 24 | }, 25 | } 26 | -------------------------------------------------------------------------------- /lua/treesj/langs/go.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | literal_value = lang_utils.set_preset_for_list(), 5 | parameter_list = lang_utils.set_preset_for_args({ 6 | split = { 7 | last_separator = true, 8 | }, 9 | }), 10 | argument_list = lang_utils.set_preset_for_args({ 11 | split = { 12 | last_separator = true, 13 | }, 14 | }), 15 | block = lang_utils.set_preset_for_statement({ 16 | join = { 17 | no_insert_if = { 18 | lang_utils.helpers.if_penultimate, 19 | }, 20 | }, 21 | }), 22 | import_spec = lang_utils.set_preset_for_args({ 23 | both = { 24 | enable = function(tsn) 25 | return tsn:parent():type() ~= 'import_spec_list' 26 | end, 27 | }, 28 | split = { 29 | format_tree = function(tsj) 30 | tsj:wrap({ left = '(', right = ')' }) 31 | end, 32 | }, 33 | }), 34 | import_spec_list = lang_utils.set_preset_for_args({ 35 | join = { 36 | enable = function(tsn) 37 | return tsn:named_child_count() < 2 38 | end, 39 | format_tree = function(tsj) 40 | tsj:remove_child({ '(', ')' }) 41 | end, 42 | }, 43 | }), 44 | import_declaration = { target_nodes = { 'import_spec', 'import_spec_list' } }, 45 | function_declaration = { 46 | target_nodes = { 'block' }, 47 | }, 48 | if_statement = { 49 | target_nodes = { 'block' }, 50 | }, 51 | short_var_declaration = { target_nodes = { 'literal_value' } }, 52 | var_declaration = { target_nodes = { 'literal_value' } }, 53 | } 54 | -------------------------------------------------------------------------------- /lua/treesj/langs/haskell.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | list = { 5 | both = { 6 | separator = ',', 7 | last_separator = false, 8 | }, 9 | split = { 10 | -- Maintain necessary whitespace: https://github.com/Wansmer/treesj/discussions/163 11 | format_tree = function(tsj) 12 | local len = tsj:child(1):range()[2] -- index of first character of first node 13 | for child in tsj:iter_children() do 14 | if not (child:is_first() or child:is_omit()) then 15 | local indent = not child:is_last() 16 | and (' '):rep(len + vim.fn.shiftwidth()) 17 | or (' '):rep(len) 18 | child:update_text(indent .. child:text()) 19 | end 20 | end 21 | end, 22 | }, 23 | }, 24 | } 25 | -------------------------------------------------------------------------------- /lua/treesj/langs/html.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | start_tag = lang_utils.set_default_preset({ 5 | both = { 6 | omit = { 'tag_name' }, 7 | }, 8 | }), 9 | self_closing_tag = lang_utils.set_default_preset({ 10 | both = { 11 | omit = { 'tag_name' }, 12 | no_format_with = {}, 13 | }, 14 | }), 15 | element = lang_utils.set_default_preset({ 16 | join = { 17 | space_separator = false, 18 | }, 19 | }), 20 | } 21 | -------------------------------------------------------------------------------- /lua/treesj/langs/init.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | M.configured_langs = { 4 | 'javascript', 5 | 'typescript', 6 | 'lua', 7 | 'html', 8 | 'json', 9 | 'jsonc', 10 | 'json5', 11 | 'vue', 12 | 'css', 13 | 'scss', 14 | 'tsx', 15 | 'perl', 16 | 'php', 17 | 'php_only', 18 | 'ruby', 19 | 'go', 20 | 'java', 21 | 'pug', 22 | 'svelte', 23 | 'rust', 24 | 'python', 25 | 'starlark', 26 | 'r', 27 | 'cpp', 28 | 'c', 29 | 'toml', 30 | 'yaml', 31 | 'nix', 32 | 'kotlin', 33 | 'bash', 34 | 'sql', 35 | 'dart', 36 | 'elixir', 37 | 'haskell', 38 | 'zig', 39 | 'julia', 40 | 'terraform', 41 | } 42 | 43 | M.presets = {} 44 | 45 | for _, lang in ipairs(M.configured_langs) do 46 | M.presets[lang] = require('treesj.langs.' .. lang) 47 | end 48 | 49 | return M 50 | -------------------------------------------------------------------------------- /lua/treesj/langs/java.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | argument_list = lang_utils.set_preset_for_args(), 5 | formal_parameters = lang_utils.set_preset_for_args(), 6 | block = lang_utils.set_preset_for_statement(), 7 | constructor_body = lang_utils.set_preset_for_statement(), 8 | array_initializer = lang_utils.set_preset_for_list(), 9 | annotation_argument_list = lang_utils.set_preset_for_args(), 10 | enum_body = lang_utils.set_preset_for_dict(), 11 | enum_declaration = { 12 | target_nodes = { 'enum_body' }, 13 | }, 14 | if_statement = { 15 | target_nodes = { 'block' }, 16 | }, 17 | annotation = { 18 | target_nodes = { 'annotation_argument_list' }, 19 | }, 20 | method_declaration = { 21 | target_nodes = { 'block' }, 22 | }, 23 | variable_declarator = { 24 | target_nodes = { 'array_initializer' }, 25 | }, 26 | constructor_declaration = { 27 | target_nodes = { 'constructor_body' }, 28 | }, 29 | } 30 | -------------------------------------------------------------------------------- /lua/treesj/langs/json.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | object = lang_utils.set_preset_for_dict({ 5 | split = { 6 | last_separator = false, 7 | }, 8 | }), 9 | array = lang_utils.set_preset_for_list({ 10 | split = { 11 | last_separator = false, 12 | }, 13 | }), 14 | pair = { target_nodes = { 'object', 'array' } }, 15 | } 16 | -------------------------------------------------------------------------------- /lua/treesj/langs/json5.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | local json = require('treesj.langs.json') 3 | 4 | return lang_utils.merge_preset(json, {}) 5 | -------------------------------------------------------------------------------- /lua/treesj/langs/jsonc.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | local json = require('treesj.langs.json') 3 | 4 | return lang_utils.merge_preset(json, {}) 5 | -------------------------------------------------------------------------------- /lua/treesj/langs/julia.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | local using = { 4 | both = { 5 | space_in_brackets = true, 6 | omit = { 7 | lang_utils.helpers.by_index(1), 8 | lang_utils.helpers.by_index(2), 9 | ',', 10 | }, 11 | }, 12 | split = { 13 | last_indent = 'inner', 14 | }, 15 | } 16 | 17 | return { 18 | argument_list = lang_utils.set_preset_for_args({ 19 | split = { last_separator = true }, 20 | }), 21 | vector_expression = lang_utils.set_preset_for_list({ 22 | join = { space_in_brackets = false }, 23 | }), 24 | matrix_expression = lang_utils.set_preset_for_statement({ 25 | join = { 26 | space_in_brackets = false, 27 | no_insert_if = { lang_utils.helpers.if_penultimate }, 28 | }, 29 | split = { 30 | format_tree = function(tsj) 31 | tsj:remove_child(';') 32 | end, 33 | }, 34 | }), 35 | tuple_expression = lang_utils.set_preset_for_list({ 36 | join = { 37 | space_in_brackets = false, 38 | format_tree = function(tsj) 39 | if 40 | tsj:tsnode():parent():type() == 'assignment' 41 | -- Check if the tuple_expression is the left side in the assignment 42 | and tsj:tsnode():parent():child(0):equal(tsj:tsnode()) 43 | then 44 | tsj:remove_child({ '(', ')' }) 45 | tsj:update_preset({ space_in_brackets = true }, 'join') 46 | end 47 | end, 48 | }, 49 | }), 50 | comprehension_expression = lang_utils.set_preset_for_list({ 51 | both = { 52 | separator = '', 53 | }, 54 | join = { 55 | space_in_brackets = false, 56 | }, 57 | }), 58 | call_expression = { target_nodes = { 'argument_list' } }, 59 | using_statement = using, 60 | selected_import = using, 61 | open_tuple = lang_utils.set_preset_for_args({ 62 | split = { 63 | last_separator = true, 64 | format_tree = function(tsj) 65 | tsj:create_child({ text = '(' }, 1) 66 | tsj:create_child({ text = ')' }, #tsj:children() + 1) 67 | local penult = tsj:child(-2) 68 | penult:update_text(penult:text() .. ',') 69 | end, 70 | }, 71 | join = { 72 | disable = true, 73 | }, 74 | }), 75 | } 76 | -------------------------------------------------------------------------------- /lua/treesj/langs/kotlin.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | collection_literal = lang_utils.set_default_preset({ 5 | both = { 6 | separator = ',', 7 | }, 8 | }), 9 | value_arguments = lang_utils.set_default_preset({ 10 | both = { 11 | separator = ',', 12 | }, 13 | }), 14 | statements = lang_utils.set_preset_for_non_bracket({ 15 | split = { 16 | recursive_ignore = { 17 | 'value_arguments', 18 | 'function_value_parameters', 19 | }, 20 | }, 21 | join = { 22 | force_insert = ';', 23 | no_insert_if = { 24 | lang_utils.helpers.if_penultimate, 25 | }, 26 | }, 27 | }), 28 | lambda_literal = { 29 | target_nodes = { 30 | 'statements', 31 | }, 32 | }, 33 | function_body = { 34 | target_nodes = { 35 | 'statements', 36 | }, 37 | }, 38 | property_declaration = { 39 | target_nodes = { 40 | 'collection_literal', 41 | 'value_arguments', 42 | }, 43 | }, 44 | function_value_parameters = lang_utils.set_preset_for_args(), 45 | } 46 | -------------------------------------------------------------------------------- /lua/treesj/langs/lua.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | local split_recursive_ignore = { 4 | split = { recursive_ignore = { 'arguments', 'parameters' } }, 5 | } 6 | 7 | return { 8 | table_constructor = lang_utils.set_preset_for_dict(split_recursive_ignore), 9 | arguments = lang_utils.set_preset_for_args(), 10 | parameters = lang_utils.set_preset_for_args(), 11 | block = lang_utils.set_preset_for_non_bracket(split_recursive_ignore), 12 | variable_declaration = { 13 | target_nodes = { 'table_constructor', 'block' }, 14 | }, 15 | assignment_statement = { 16 | target_nodes = { 'table_constructor', 'block' }, 17 | }, 18 | if_statement = { target_nodes = { 'block' } }, 19 | else_statement = { target_nodes = { 'block' } }, 20 | function_declaration = { target_nodes = { 'block' } }, 21 | function_definition = { target_nodes = { 'block' } }, 22 | } 23 | -------------------------------------------------------------------------------- /lua/treesj/langs/nix.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | list_expression = lang_utils.set_preset_for_list({ 5 | both = { 6 | separator = '', 7 | }, 8 | }), 9 | attrset_expression = { 10 | target_nodes = { 'binding_set' }, 11 | }, 12 | binding_set = lang_utils.set_preset_for_dict({ 13 | both = { 14 | non_bracket_node = true, 15 | separator = '', 16 | force_insert = ';', 17 | }, 18 | }), 19 | formals = lang_utils.set_preset_for_args({ 20 | both = { 21 | omit = { 'formal', 'ellipses' }, 22 | }, 23 | split = { 24 | separator = '', 25 | inner_indent = 'normal', 26 | }, 27 | join = { 28 | separator = ',', 29 | space_in_brackets = true, 30 | }, 31 | }), 32 | let_expression = lang_utils.set_default_preset({ 33 | both = { 34 | omit = { 'binding_set' }, 35 | }, 36 | split = { 37 | recursive = true, 38 | inner_indent = 'normal', 39 | last_indent = 'inner', 40 | }, 41 | join = { 42 | space_in_brackets = true, 43 | space_separator = true, 44 | }, 45 | }), 46 | } 47 | -------------------------------------------------------------------------------- /lua/treesj/langs/perl.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | list_expression = lang_utils.set_preset_for_non_bracket({ 5 | both = { 6 | last_separator = false, 7 | }, 8 | split = { 9 | separator = ',', 10 | omit = { 11 | '=>', 12 | function(child) 13 | local prev = child:prev() 14 | return prev and prev:type() == '=>' 15 | end, 16 | }, 17 | }, 18 | join = { 19 | space_in_brackets = false, 20 | }, 21 | }), 22 | anonymous_array_expression = { target_nodes = { 'list_expression' } }, 23 | anonymous_hash_expression = { target_nodes = { 'list_expression' } }, 24 | block = lang_utils.set_preset_for_statement({ 25 | both = { 26 | omit = { 'semi_colon' }, 27 | }, 28 | }), 29 | variable_declaration = { 30 | target_nodes = { 'array', 'array_ref', 'hash_ref' }, 31 | }, 32 | array = lang_utils.set_preset_for_args({ -- Not relevant. Left for compatibility with previous versions of the parser 33 | split = { 34 | omit = { 35 | '=>', 36 | function(child) 37 | local prev = child:prev() 38 | return prev and prev:type() == '=>' 39 | end, 40 | }, 41 | }, 42 | }), 43 | hash_ref = lang_utils.set_preset_for_dict({ -- Not relevant. Left for compatibility with previous versions of the parser 44 | join = { 45 | space_in_brackets = false, 46 | }, 47 | }), 48 | array_ref = lang_utils.set_preset_for_dict({ -- Not relevant. Left for compatibility with previous versions of the parser 49 | join = { 50 | space_in_brackets = false, 51 | }, 52 | }), 53 | } 54 | -------------------------------------------------------------------------------- /lua/treesj/langs/php.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | array_creation_expression = lang_utils.set_preset_for_dict({ 5 | join = { 6 | space_in_brackets = false, 7 | }, 8 | }), 9 | arguments = lang_utils.set_preset_for_args({ 10 | split = { 11 | last_separator = true, 12 | }, 13 | }), 14 | formal_parameters = lang_utils.set_preset_for_args({ 15 | split = { 16 | last_separator = true, 17 | }, 18 | }), 19 | compound_statement = lang_utils.set_preset_for_statement({ 20 | join = { 21 | no_insert_if = { 22 | 'function_definition', 23 | 'if_statement', 24 | 'try_statement', 25 | }, 26 | }, 27 | }), 28 | assignment_expression = { 29 | target_nodes = { 'array_creation_expression', 'arguments' }, 30 | }, 31 | if_statement = { 32 | target_nodes = { 'compound_statement' }, 33 | }, 34 | else_clause = { 35 | target_nodes = { 'compound_statement' }, 36 | }, 37 | try_statement = { 38 | target_nodes = { 'compound_statement' }, 39 | }, 40 | catch_clause = { 41 | target_nodes = { 'compound_statement' }, 42 | }, 43 | anonymous_function_creation_expression = { 44 | target_nodes = { 'compound_statement' }, 45 | }, 46 | function_definition = { 47 | target_nodes = { 'compound_statement' }, 48 | }, 49 | method_declaration = { 50 | target_nodes = { 'compound_statement' }, 51 | }, 52 | arrow_function = { 53 | target_nodes = { 'formal_parameters' }, 54 | }, 55 | function_call_expression = { 56 | target_nodes = { 'arguments' }, 57 | }, 58 | scoped_call_expression = { 59 | target_nodes = { 'arguments' }, 60 | }, 61 | member_call_expression = { 62 | target_nodes = { 'arguments' }, 63 | }, 64 | object_creation_expression = { 65 | target_nodes = { 'arguments' }, 66 | }, 67 | } 68 | -------------------------------------------------------------------------------- /lua/treesj/langs/php_only.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | local php = require('treesj.langs.php') 3 | 4 | return lang_utils.merge_preset(php, {}) 5 | -------------------------------------------------------------------------------- /lua/treesj/langs/pug.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | attributes = lang_utils.set_default_preset(), 5 | tag = { 6 | target_nodes = { 'attributes' }, 7 | }, 8 | } 9 | -------------------------------------------------------------------------------- /lua/treesj/langs/r.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | arguments = lang_utils.set_preset_for_args({ 5 | both = { 6 | separator = 'comma', 7 | }, 8 | split = { 9 | recursive_ignore = { 'subset' }, 10 | }, 11 | }), 12 | 13 | parameters = lang_utils.set_preset_for_args({ 14 | both = { 15 | separator = 'comma', 16 | }, 17 | split = { 18 | recursive_ignore = { 'subset' }, 19 | }, 20 | }), 21 | 22 | left_assignment = { 23 | target_nodes = { 24 | 'arguments', 25 | 'parameters', 26 | }, 27 | }, 28 | 29 | super_assignment = { 30 | target_nodes = { 31 | 'arguments', 32 | 'parameters', 33 | }, 34 | }, 35 | 36 | right_assignment = { 37 | target_nodes = { 38 | 'arguments', 39 | 'parameters', 40 | }, 41 | }, 42 | 43 | super_right_assignment = { 44 | target_nodes = { 45 | 'arguments', 46 | 'parameters', 47 | }, 48 | }, 49 | 50 | equals_assignment = { 51 | target_nodes = { 52 | 'arguments', 53 | 'parameters', 54 | }, 55 | }, 56 | 57 | function_definition = { 58 | target_nodes = { 'parameters' }, 59 | }, 60 | 61 | call = { 62 | target_nodes = { 'arguments' }, 63 | }, 64 | 65 | binary_operator = { 66 | target_nodes = { 'arguments', 'parameters' }, 67 | }, 68 | 69 | pipe = { 70 | target_nodes = { 'arguments' }, 71 | }, 72 | } 73 | -------------------------------------------------------------------------------- /lua/treesj/langs/rust.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | field_declaration_list = lang_utils.set_preset_for_dict(), 5 | declaration_list = lang_utils.set_preset_for_statement({ 6 | join = { 7 | force_insert = '', 8 | }, 9 | }), 10 | field_initializer_list = lang_utils.set_preset_for_dict(), 11 | struct_pattern = lang_utils.set_preset_for_dict({ 12 | both = { 13 | omit = { '{' }, 14 | }, 15 | }), 16 | parameters = lang_utils.set_preset_for_args({ 17 | split = { 18 | last_separator = true, 19 | }, 20 | }), 21 | arguments = lang_utils.set_preset_for_args({ 22 | split = { 23 | last_separator = true, 24 | }, 25 | }), 26 | tuple_type = lang_utils.set_preset_for_args({ 27 | split = { 28 | last_separator = true, 29 | }, 30 | }), 31 | enum_variant_list = lang_utils.set_preset_for_list(), 32 | tuple_expression = lang_utils.set_preset_for_args({ 33 | split = { 34 | last_separator = true, 35 | }, 36 | }), 37 | block = lang_utils.set_preset_for_statement({ 38 | join = { 39 | no_insert_if = { 40 | lang_utils.helpers.if_penultimate, 41 | 'function_item', 42 | }, 43 | format_tree = function(tsj) 44 | local node = tsj:tsnode() 45 | local parents = { 'match_arm', 'closure_expression' } 46 | local has_parent = vim.tbl_contains(parents, node:parent():type()) 47 | if has_parent and node:named_child_count() == 1 then 48 | tsj:remove_child({ '{', '}' }) 49 | end 50 | end, 51 | }, 52 | }), 53 | value = lang_utils.set_preset_for_statement({ 54 | split = { 55 | format_tree = function(tsj) 56 | if tsj:type() ~= 'block' then 57 | tsj:wrap({ left = '{', right = '}' }) 58 | end 59 | end, 60 | }, 61 | join = { 62 | no_insert_if = { lang_utils.helpers.if_penultimate }, 63 | format_tree = function(tsj) 64 | local node = tsj:tsnode() 65 | local parents = { 'match_arm', 'closure_expression' } 66 | local has_parent = vim.tbl_contains(parents, node:parent():type()) 67 | if has_parent and node:named_child_count() == 1 then 68 | tsj:remove_child({ '{', '}' }) 69 | end 70 | end, 71 | }, 72 | }), 73 | match_arm = { 74 | target_nodes = { 'value' }, 75 | }, 76 | closure_expression = { 77 | target_nodes = { ['body'] = 'value' }, 78 | }, 79 | use_list = lang_utils.set_preset_for_list(), 80 | array_expression = lang_utils.set_preset_for_list(), 81 | parenthesized_expression = lang_utils.set_preset_for_args(), 82 | let_declaration = { 83 | target_nodes = { 84 | 'field_declaration_list', 85 | 'field_initializer_list', 86 | 'array_expression', 87 | }, 88 | }, 89 | function_item = { 90 | target_nodes = { 91 | 'parameters', 92 | }, 93 | }, 94 | enum_item = { 95 | target_nodes = { 96 | 'enum_variant_list', 97 | }, 98 | }, 99 | use_declaration = { 100 | target_nodes = { 101 | 'use_list', 102 | }, 103 | }, 104 | trait_item = { 105 | target_nodes = { 106 | 'declaration_list', 107 | }, 108 | }, 109 | } 110 | -------------------------------------------------------------------------------- /lua/treesj/langs/scss.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | local css = require('treesj.langs.css') 3 | 4 | return lang_utils.merge_preset(css, {}) 5 | -------------------------------------------------------------------------------- /lua/treesj/langs/sql.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | column_definitions = lang_utils.set_preset_for_args(), 5 | ordered_columns = lang_utils.set_preset_for_args(), 6 | list = lang_utils.set_preset_for_args(), 7 | select_expression = { 8 | both = { 9 | separator = ',', 10 | last_separator = true, 11 | }, 12 | split = { 13 | inner_indent = 'normal', 14 | format_resulted_lines = function(lines, tsn) 15 | local _, sc = tsn:range() 16 | for i, line in ipairs(lines) do 17 | if i > 1 then 18 | lines[i] = (' '):rep(sc) .. line 19 | end 20 | end 21 | return lines 22 | end, 23 | }, 24 | join = { 25 | space_in_brackets = true, 26 | }, 27 | }, 28 | } 29 | -------------------------------------------------------------------------------- /lua/treesj/langs/starlark.lua: -------------------------------------------------------------------------------- 1 | local u = require('treesj.langs.utils') 2 | 3 | -- Copy of `python.lua` 4 | -- As starlark is syntactically equivalent. 5 | -- With only small modifications: 6 | -- * sets do not exist. 7 | -- * function decorators do not exist. 8 | -- * the raise keyword does not exist. 9 | 10 | local no_space_in_brackets = u.set_preset_for_list({ 11 | join = { 12 | space_in_brackets = false, 13 | }, 14 | }) 15 | 16 | return { 17 | dictionary = no_space_in_brackets, 18 | list = no_space_in_brackets, 19 | tuple = u.set_preset_for_list({ 20 | join = { 21 | space_in_brackets = false, 22 | last_separator = true, 23 | }, 24 | }), 25 | argument_list = u.set_preset_for_args(), 26 | parameters = u.set_preset_for_args(), 27 | parenthesized_expression = u.set_preset_for_args({}), 28 | list_comprehension = u.set_preset_for_args(), 29 | dictionary_comprehension = u.set_preset_for_args(), 30 | assignment = { 31 | target_nodes = { 32 | 'tuple', 33 | 'list', 34 | 'dictionary', 35 | 'argument_list', 36 | 'list_comprehension', 37 | 'dictionary_comprehension', 38 | }, 39 | }, 40 | call = { 41 | target_nodes = { 42 | 'argument_list', 43 | }, 44 | }, 45 | } 46 | -------------------------------------------------------------------------------- /lua/treesj/langs/svelte.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | local html = require('treesj.langs.html') 3 | 4 | return lang_utils.merge_preset(html, {}) 5 | -------------------------------------------------------------------------------- /lua/treesj/langs/terraform.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | tuple = lang_utils.set_preset_for_list({ 5 | join = { 6 | space_in_brackets = false, 7 | }, 8 | }), 9 | object = lang_utils.set_preset_for_dict({ 10 | split = { 11 | separator = '', 12 | format_tree = function(tsj) 13 | tsj:remove_child(',') 14 | end, 15 | }, 16 | join = { 17 | space_in_brackets = false, 18 | force_insert = ',', 19 | no_insert_if = { lang_utils.helpers.if_penultimate }, 20 | }, 21 | }), 22 | function_call = { 23 | target_nodes = { 'function_arguments' }, 24 | }, 25 | function_arguments = lang_utils.set_preset_for_args({ 26 | both = { 27 | non_bracket_node = true, 28 | }, 29 | join = { 30 | recursive = true, 31 | }, 32 | split = { 33 | last_separator = true, 34 | }, 35 | }), 36 | } 37 | -------------------------------------------------------------------------------- /lua/treesj/langs/toml.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | array = lang_utils.set_preset_for_list({ 5 | split = { 6 | last_separator = false, 7 | }, 8 | }), 9 | } 10 | -------------------------------------------------------------------------------- /lua/treesj/langs/tsx.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | local ts = require('treesj.langs.typescript') 3 | 4 | return lang_utils.merge_preset(ts, {}) 5 | -------------------------------------------------------------------------------- /lua/treesj/langs/typescript.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | local js = require('treesj.langs.javascript') 3 | 4 | return lang_utils.merge_preset(js, { 5 | object_type = lang_utils.set_preset_for_dict({ 6 | both = { separator = ';', last_separator = true }, 7 | }), 8 | object_pattern = lang_utils.set_preset_for_dict(), 9 | tuple_type = lang_utils.set_preset_for_dict(), 10 | enum_body = lang_utils.set_preset_for_dict(), 11 | type_parameters = lang_utils.set_preset_for_args({ 12 | split = { last_separator = true }, 13 | join = { space_in_brackets = false }, 14 | }), 15 | type_arguments = lang_utils.set_preset_for_args({ 16 | split = { last_separator = true }, 17 | join = { space_in_brackets = false }, 18 | }), 19 | ambient_declaration = { 20 | target_nodes = { 'object_type', 'statement_block' }, 21 | }, 22 | export_statement = { 23 | target_nodes = { 'export_clause', 'object_type', 'statement_block' }, 24 | }, 25 | lexical_declaration = { 26 | target_nodes = { 'object_type', 'statement_block' }, 27 | }, 28 | type_alias_declaration = { 29 | target_nodes = { 30 | 'tuple_type', 31 | 'object', 32 | 'array', 33 | 'object_type', 34 | 'statement_block', 35 | }, 36 | }, 37 | enum_declaration = { 38 | target_nodes = { 'enum_body' }, 39 | }, 40 | }) 41 | -------------------------------------------------------------------------------- /lua/treesj/langs/vue.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | local html = require('treesj.langs.html') 3 | 4 | return lang_utils.merge_preset(html, { 5 | element = { 6 | join = { 7 | recursive = false, 8 | }, 9 | }, 10 | }) 11 | -------------------------------------------------------------------------------- /lua/treesj/langs/yaml.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | flow_sequence = { 5 | join = { enable = false }, 6 | split = { 7 | non_bracket_node = true, 8 | last_separator = false, 9 | last_indent = 'inner', 10 | no_insert_if = { lang_utils.helpers.if_penultimate }, 11 | format_tree = function(tsj) 12 | tsj:remove_child({ ',', '[', ']' }) 13 | for _, flow_node in ipairs(tsj:children({ 'flow_node' })) do 14 | flow_node:update_text('- ' .. flow_node:text()) 15 | end 16 | tsj:remove_child(-1) 17 | end, 18 | }, 19 | }, 20 | flow_mapping = { 21 | join = { enable = false }, 22 | split = { 23 | non_bracket_node = true, 24 | recursive = true, 25 | last_indent = 'inner', 26 | format_tree = function(tsj) 27 | tsj:remove_child({ ',', '{', '}' }) 28 | tsj:remove_child(-1) 29 | end, 30 | }, 31 | }, 32 | block_sequence = { 33 | split = { enable = false }, 34 | join = { 35 | space_in_brackets = true, 36 | non_bracket_node = { left = ' [', right = ']' }, 37 | force_insert = ',', 38 | no_insert_if = { lang_utils.helpers.if_penultimate }, 39 | format_tree = function(tsj) 40 | local items = tsj:children({ 'block_sequence_item' }) 41 | for _, item in ipairs(items) do 42 | if item:will_be_formatted() then 43 | item:remove_child('-') 44 | else 45 | local text = item:text():gsub('^- ', '') 46 | item:update_text(text) 47 | end 48 | end 49 | end, 50 | }, 51 | }, 52 | block_mapping = { 53 | split = { enable = false }, 54 | join = { 55 | space_in_brackets = true, 56 | non_bracket_node = { left = ' {', right = '}' }, 57 | force_insert = ',', 58 | no_insert_if = { lang_utils.helpers.if_penultimate }, 59 | }, 60 | }, 61 | } 62 | -------------------------------------------------------------------------------- /lua/treesj/langs/zig.lua: -------------------------------------------------------------------------------- 1 | local lang_utils = require('treesj.langs.utils') 2 | 3 | return { 4 | parameters = lang_utils.set_preset_for_args({ 5 | split = { 6 | last_separator = true, 7 | }, 8 | }), 9 | arguments = lang_utils.set_preset_for_args(), 10 | initializer_list = lang_utils.set_preset_for_list(), 11 | struct_declaration = lang_utils.set_preset_for_list({ 12 | both = { 13 | omit = { '{' }, 14 | }, 15 | }), 16 | enum_declaration = lang_utils.set_preset_for_list({ 17 | both = { 18 | omit = { '{' }, 19 | }, 20 | }), 21 | call_expression = lang_utils.set_preset_for_args({ 22 | both = { 23 | omit = { '(' }, 24 | }, 25 | join = { 26 | format_resulted_lines = function(lines) 27 | lines[3] = lines[3]:gsub('^%s+', '') 28 | return lines 29 | end, 30 | }, 31 | split = { 32 | last_separator = true, 33 | format_resulted_lines = function(lines) 34 | lines[1] = lines[1]:gsub('%(,$', '(') 35 | return lines 36 | end, 37 | }, 38 | }), 39 | } 40 | -------------------------------------------------------------------------------- /lua/treesj/notify.lua: -------------------------------------------------------------------------------- 1 | local notify_ok, _ = pcall(require, 'notify') 2 | local settings = require('treesj.settings').settings 3 | 4 | local PLUGIN_NAME = notify_ok and 'TreeSJ: split/join code block' or 'TreeSJ' 5 | 6 | local M = {} 7 | 8 | M.msg = { 9 | no_detect_node = 'No detected node at cursor', 10 | no_configured_lang = 'Language "%s" is not configured', 11 | contains_error = 'The node "%s" or its descendants contain a syntax error and cannot be %s', 12 | no_configured_node = 'Node "%s" for lang "%s" is not configured', 13 | no_contains_target_node = 'Node "%s" has no contains descendants for split/join', 14 | no_format_with = 'Cannot %s "%s" containing node from one of this: %s', 15 | extra_longer = 'Cannot "join" node longer than %s symbols. Check your settings to change it.', 16 | version_not_support = 'Current version of neovim is "0.%s". TreeSJ requires version "0.8" or higher', 17 | node_not_received = 'Node not received', 18 | node_is_disable = 'Action "%s" for node "%s" is disabled in preset', 19 | custom_func = 'Something went wrong in function "%s" from preset for "%s": %s', 20 | wrong_resut = 'Function "%s" from preset for "%s" returned wrong format for new lines', 21 | no_ts_parser = 'Treesitter parser not found for current buffer', 22 | node_is_already_joined = 'The current node is already joined', 23 | node_is_already_splitted = 'The current node is already splitted', 24 | } 25 | 26 | ---Wraper for vim.notify and nvim-notify 27 | ---@param msg string Message for nofification 28 | ---@param level number vim.levels[level] 29 | ---@vararg string Strings for substitute 30 | M.notify = function(msg, level, ...) 31 | local orig_msg = msg 32 | 33 | if settings.notify then 34 | msg = msg:format(...) 35 | level = level or vim.log.levels.INFO 36 | 37 | if notify_ok then 38 | vim.notify(msg, level, { 39 | title = PLUGIN_NAME, 40 | }) 41 | else 42 | vim.notify(('[%s]: %s'):format(PLUGIN_NAME, msg), level) 43 | end 44 | end 45 | 46 | if type(settings.on_error) == 'function' then 47 | settings.on_error(orig_msg, level, ...) 48 | end 49 | end 50 | 51 | M.error = function(msg, ...) 52 | M.notify(msg, vim.log.levels.ERROR, ...) 53 | end 54 | 55 | M.warn = function(msg, ...) 56 | M.notify(msg, vim.log.levels.WARN, ...) 57 | end 58 | 59 | M.info = function(msg, ...) 60 | M.notify(msg, vim.log.levels.INFO, ...) 61 | end 62 | 63 | return M 64 | -------------------------------------------------------------------------------- /lua/treesj/settings.lua: -------------------------------------------------------------------------------- 1 | local langs = require('treesj.langs') 2 | local lu = require('treesj.langs.utils') 3 | 4 | local M = {} 5 | 6 | local DEFAULT_SETTINGS = { 7 | ---@type boolean Use default keymaps (m - toggle, j - join, s - split) 8 | use_default_keymaps = true, 9 | ---@type boolean Node with syntax error will not be formatted 10 | check_syntax_error = true, 11 | ---If line after join will be longer than max value, 12 | ---@type number If line after join will be longer than max value, node will not be formatted 13 | max_join_length = 120, 14 | ---Cursor behavior: 15 | ---hold - cursor follows the node/place on which it was called 16 | ---start - cursor jumps to the first symbol of the node being formatted 17 | ---end - cursor jumps to the last symbol of the node being formatted 18 | ---@type 'hold'|'start'|'end' 19 | cursor_behavior = 'hold', 20 | ---@type boolean Notify about possible problems or not 21 | notify = true, 22 | ---@type table Presets for languages 23 | langs = lu._prepare_presets(langs.presets), 24 | ---@type boolean Use `dot` for repeat action 25 | dot_repeat = true, 26 | ---@type nil|function Callback for treesj error handler. func (err_text, level, ...) 27 | on_error = nil, 28 | } 29 | 30 | local commands = { 31 | { 32 | name = 'TSJToggle', 33 | desc = 'Split or Join code block with autodetect', 34 | func = 'toggle', 35 | keys = 'm', 36 | mode = 'n', 37 | }, 38 | { 39 | name = 'TSJSplit', 40 | desc = 'Split code block', 41 | func = 'split', 42 | keys = 's', 43 | mode = 'n', 44 | }, 45 | { 46 | name = 'TSJJoin', 47 | desc = 'Join code block', 48 | func = 'join', 49 | keys = 'j', 50 | mode = 'n', 51 | }, 52 | } 53 | 54 | M.settings = DEFAULT_SETTINGS 55 | 56 | local function merge_settings(default_settings, opts) 57 | opts = opts or {} 58 | 59 | if opts.langs then 60 | for lang, presets in pairs(opts.langs) do 61 | for node, preset in pairs(presets) do 62 | local info = { lang = lang, node = node, mode = 'both' } 63 | presets[node] = lu._premerge(preset, info) 64 | end 65 | opts.langs[lang] = presets 66 | end 67 | end 68 | 69 | local settings = vim.tbl_deep_extend('force', default_settings, opts) 70 | settings.langs = lu._prepare_presets(settings.langs) 71 | settings.langs = lu._skip_disabled(settings.langs) 72 | return settings 73 | end 74 | 75 | M._create_commands = function() 76 | local treesj = require('treesj') 77 | for _, cmd in ipairs(commands) do 78 | vim.api.nvim_create_user_command(cmd.name, function() 79 | treesj[cmd.func]() 80 | end, { desc = cmd.desc }) 81 | end 82 | end 83 | 84 | M._set_default_keymaps = function() 85 | if M.settings and M.settings.use_default_keymaps then 86 | local treesj = require('treesj') 87 | for _, cmd in ipairs(commands) do 88 | vim.keymap.set(cmd.mode, cmd.keys, treesj[cmd.func], { desc = cmd.desc }) 89 | end 90 | end 91 | end 92 | 93 | M._update_settings = function(opts) 94 | M.settings = merge_settings(M.settings, opts) 95 | end 96 | 97 | return M 98 | -------------------------------------------------------------------------------- /lua/treesj/utils.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | M.is_list = vim.fn.has('nvim-0.10') == 1 and vim.islist or vim.tbl_islist 4 | 5 | M.flatten = (function() 6 | if vim.fn.has('nvim-0.11') == 1 then 7 | return function(t) 8 | return vim.iter(t):flatten():totable() 9 | end 10 | else 11 | return function(t) 12 | return vim.tbl_flatten(t) 13 | end 14 | end 15 | end)() 16 | 17 | ---Convert any type to boolean 18 | ---@param val any 19 | ---@return boolean 20 | function M.tobool(val) 21 | return val and true or false 22 | end 23 | 24 | ---Checking if the string or table is is is empty 25 | ---@param val string|table 26 | ---@return boolean 27 | function M.is_empty(val) 28 | if type(val) == 'table' then 29 | return vim.tbl_isempty(val) 30 | elseif type(val) == 'string' then 31 | return val == '' 32 | else 33 | return false 34 | end 35 | end 36 | 37 | ---Checking if every item of list meets the condition. 38 | ---Empty list or non-list table, returning false. 39 | ---@param tbl table List-like table 40 | ---@param cb function Callback for checking every item 41 | ---@return boolean 42 | function M.every(tbl, cb) 43 | if type(tbl) ~= 'table' or not M.is_list(tbl) or M.is_empty(tbl) then 44 | return false 45 | end 46 | 47 | for _, item in ipairs(tbl) do 48 | if not cb(item) then 49 | return false 50 | end 51 | end 52 | 53 | return true 54 | end 55 | 56 | ---Checking if some item of list meets the condition. 57 | ---Empty list or non-list table, returning false. 58 | ---@param tbl table List-like table 59 | ---@param cb function Callback for checking every item 60 | ---@return boolean 61 | function M.some(tbl, cb) 62 | if not M.is_list(tbl) or M.is_empty(tbl) then 63 | return false 64 | end 65 | 66 | for _, item in ipairs(tbl) do 67 | if cb(item) then 68 | return true 69 | end 70 | end 71 | 72 | return false 73 | end 74 | 75 | ---Recursively finding key in table and return its value if found or nil 76 | ---@param tbl table|nil Dict-like table 77 | ---@param target_key string Name of target key 78 | ---@return any|nil 79 | function M.get_nested_key_value(tbl, target_key) 80 | if not tbl or M.is_list(tbl) then 81 | return nil 82 | end 83 | local found 84 | for key, val in pairs(tbl) do 85 | if key == target_key then 86 | return val 87 | end 88 | if type(val) == 'table' and not M.is_list(val) then 89 | found = M.get_nested_key_value(val, target_key) 90 | end 91 | if found then 92 | return found 93 | end 94 | end 95 | return nil 96 | end 97 | 98 | function M.is_string(el) 99 | return type(el) == 'string' 100 | end 101 | 102 | function M.is_table(el) 103 | return type(el) == 'table' 104 | end 105 | 106 | return M 107 | -------------------------------------------------------------------------------- /stylua.toml: -------------------------------------------------------------------------------- 1 | # https://github.com/JohnnyMorganz/StyLua 2 | 3 | column_width = 80 4 | line_endings = "Unix" 5 | indent_type = "Spaces" 6 | indent_width = 2 7 | quote_style = "AutoPreferSingle" 8 | call_parentheses = "Always" 9 | collapse_simple_statement = "Never" 10 | -------------------------------------------------------------------------------- /tests/chold/cursor.js: -------------------------------------------------------------------------------- 1 | /* Test format */ 2 | 3 | // RESULT OF JOIN (node "object", preset default) 4 | const obj = { one: 'one', two: [ 1, 2 ], three: { one: 'one', two: [ 1, 2 ] } }; 5 | 6 | // RESULT OF SPLIT (node "object", preset default) 7 | const obj = { 8 | one: 'one', 9 | two: [ 1, 2 ], 10 | three: { one: 'one', two: [ 1, 2 ] }, 11 | }; 12 | 13 | // RESULT OF JOIN (node "object") 14 | const arr = [ [ 1, 2, 3 ], [ 3, 2, 1 ], [ 1, 2, 3 ], [ 3, 2, 1 ] ]; 15 | 16 | // RESULT OF SPLIT (node "object") 17 | const arr = [ 18 | [ 19 | 1, 20 | 2, 21 | 3, 22 | ], 23 | [ 24 | 3, 25 | 2, 26 | 1, 27 | ], 28 | [ 29 | 1, 30 | 2, 31 | 3, 32 | ], 33 | [ 34 | 3, 35 | 2, 36 | 1, 37 | ], 38 | ]; 39 | 40 | // RESULT OF JOIN (node "array", preset preset with recursive = true) 41 | someArr.push(...new Set([ ...someFunc(1, 2), 1 ])); 42 | 43 | // RESULT OF SPLIT (node "array", preset preset with recursive = true) 44 | someArr.push(...new Set([ 45 | ...someFunc(1, 2), 46 | 1, 47 | ])); 48 | -------------------------------------------------------------------------------- /tests/chold/cursor.lua: -------------------------------------------------------------------------------- 1 | -- RESULT OF JOIN (node "block" in function_declaration), preset default 2 | function foo () local test = { one = 'one', two = 'two' } return test end 3 | 4 | -- RESULT OF SPLIT (node "block" in function_declaration), preset default 5 | function foo () 6 | local test = { one = 'one', two = 'two' } 7 | return test 8 | end 9 | 10 | -- RESULT OF JOIN (node "block" in if_statement), preset default 11 | if true then return false end 12 | 13 | -- RESULT OF SPLIT (node "block" in if_statement), preset default 14 | if true then 15 | return false 16 | end 17 | -------------------------------------------------------------------------------- /tests/chold/end_join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | local PATH = './tests/chold/cursor.js' 3 | 4 | local data = { 5 | { 6 | path = PATH, 7 | mode = 'join', 8 | desc = 'cursor_behavior = "end", mode = "%s", pos inside block', 9 | cursor = { 8, 4 }, 10 | expected = { 7, 78 }, 11 | result = {}, 12 | }, 13 | { 14 | path = PATH, 15 | mode = 'join', 16 | desc = 'cursor_behavior = "end", mode = "%s", pos before block', 17 | cursor = { 7, 0 }, 18 | expected = { 7, 78 }, 19 | result = {}, 20 | }, 21 | { 22 | path = PATH, 23 | mode = 'join', 24 | desc = 'cursor_behavior = "end", mode = "%s", pos on first symbol of block', 25 | cursor = { 7, 12 }, 26 | expected = { 7, 78 }, 27 | result = {}, 28 | }, 29 | { 30 | path = PATH, 31 | mode = 'join', 32 | desc = 'cursor_behavior = "end", mode = "%s", pos on last symbol of block', 33 | cursor = { 11, 0 }, 34 | expected = { 7, 78 }, 35 | result = {}, 36 | }, 37 | } 38 | 39 | local treesj = require('treesj') 40 | treesj.setup({ 41 | cursor_behavior = 'end' 42 | }) 43 | 44 | describe('TreeSJ CHOLD:', function() 45 | for _, value in ipairs(data) do 46 | tu._test_chold(value, treesj) 47 | end 48 | end) 49 | -------------------------------------------------------------------------------- /tests/chold/end_split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | local PATH = './tests/chold/cursor.js' 3 | 4 | local data = { 5 | { 6 | path = PATH, 7 | mode = 'split', 8 | desc = 'cursor_behavior = "end", mode = "%s", pos inside block', 9 | cursor = { 4, 16 }, 10 | expected = { 8, 0 }, 11 | result = {}, 12 | }, 13 | { 14 | path = PATH, 15 | mode = 'split', 16 | desc = 'cursor_behavior = "end", mode = "%s", pos before block', 17 | cursor = { 4, 0 }, 18 | expected = { 8, 0 }, 19 | result = {}, 20 | }, 21 | { 22 | path = PATH, 23 | mode = 'split', 24 | desc = 'cursor_behavior = "end", mode = "%s", pos on first symbol of block', 25 | cursor = { 4, 12 }, 26 | expected = { 8, 0 }, 27 | result = {}, 28 | }, 29 | { 30 | path = PATH, 31 | mode = 'split', 32 | desc = 'cursor_behavior = "end", mode = "%s", pos on last symbol of block', 33 | cursor = { 4, 78 }, 34 | expected = { 8, 0 }, 35 | result = {}, 36 | }, 37 | } 38 | 39 | local treesj = require('treesj') 40 | treesj.setup({ 41 | cursor_behavior = 'end', 42 | }) 43 | 44 | describe('TreeSJ CHOLD:', function() 45 | for _, value in ipairs(data) do 46 | tu._test_chold(value, treesj) 47 | end 48 | end) 49 | -------------------------------------------------------------------------------- /tests/chold/hold_join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | local PATH_JS = './tests/chold/cursor.js' 3 | local PATH_LUA = './tests/chold/cursor.lua' 4 | 5 | local data = { 6 | { 7 | path = PATH_JS, 8 | mode = 'join', 9 | desc = 'cursor_behavior = "hold", mode = "%s", pos inside block', 10 | cursor = { 8, 4 }, 11 | expected = { 7, 16 }, 12 | result = {}, 13 | }, 14 | { 15 | path = PATH_JS, 16 | mode = 'join', 17 | desc = 'cursor_behavior = "hold", mode = "%s", pos before block', 18 | cursor = { 7, 3 }, 19 | expected = { 7, 3 }, 20 | result = {}, 21 | }, 22 | { 23 | path = PATH_JS, 24 | mode = 'join', 25 | desc = 'cursor_behavior = "hold", mode = "%s", pos on first sym of block', 26 | cursor = { 7, 12 }, 27 | expected = { 7, 12 }, 28 | result = {}, 29 | }, 30 | { 31 | path = PATH_JS, 32 | mode = 'join', 33 | desc = 'cursor_behavior = "hold", mode = "%s", pos on last sym of block', 34 | cursor = { 11, 0 }, 35 | expected = { 7, 78 }, 36 | result = {}, 37 | }, 38 | { 39 | path = PATH_JS, 40 | mode = 'join', 41 | desc = 'cursor_behavior = "hold", mode = "%s", pos on penultimate symbol of block', 42 | cursor = { 10, 38 }, 43 | expected = { 7, 77 }, 44 | result = {}, 45 | }, 46 | { 47 | path = PATH_JS, 48 | mode = 'join', 49 | desc = 'cursor_behavior = "hold", mode = "%s", pos after block', 50 | cursor = { 11, 1 }, 51 | expected = { 7, 79 }, 52 | result = {}, 53 | }, 54 | { 55 | path = PATH_LUA, 56 | mode = 'join', 57 | desc = 'cursor_behavior = "hold", mode = "%s", pos inside non-bracket block', 58 | cursor = { 7, 5 }, 59 | expected = { 5, 61 }, 60 | result = {}, 61 | }, 62 | { 63 | path = PATH_LUA, 64 | mode = 'join', 65 | -- TODO: redescribe, it is not last elem, it is after 66 | desc = 'cursor_behavior = "hold", mode = "%s", pos on last element of non-bracket block', 67 | cursor = { 16, 1 }, 68 | expected = { 14, 27 }, 69 | result = {}, 70 | }, 71 | } 72 | 73 | local treesj = require('treesj') 74 | treesj.setup({ cursor_behavior = 'hold' }) 75 | 76 | describe('TreeSJ CHOLD:', function() 77 | for _, value in ipairs(data) do 78 | tu._test_chold(value, treesj) 79 | end 80 | end) 81 | -------------------------------------------------------------------------------- /tests/chold/hold_split_recursive_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | local PATH = './tests/chold/cursor.js' 3 | 4 | local settings = { 5 | cursor_behavior = 'hold', 6 | langs = { 7 | javascript = { 8 | object = { 9 | split = { 10 | recursive = true, 11 | }, 12 | }, 13 | array = { 14 | split = { 15 | recursive = true, 16 | }, 17 | }, 18 | }, 19 | }, 20 | } 21 | 22 | local data = { 23 | { 24 | path = PATH, 25 | mode = 'split', 26 | desc = 'cursor_behavior = "hold", mode = "%s" + resursive, pos inside object', 27 | cursor = { 4, 77 }, 28 | expected = { 17, 0 }, 29 | result = {}, 30 | }, 31 | { 32 | path = PATH, 33 | mode = 'split', 34 | desc = 'cursor_behavior = "hold", mode = "%s" + resursive, pos in nested object', 35 | cursor = { 4, 75 }, 36 | expected = { 10, 0 }, 37 | result = {}, 38 | }, 39 | { 40 | path = PATH, 41 | mode = 'split', 42 | desc = 'cursor_behavior = "hold", mode = "%s" + resursive, pos after first array', 43 | cursor = { 14, 25 }, 44 | expected = { 19, 3 }, 45 | result = {}, 46 | }, 47 | { 48 | path = PATH, 49 | mode = 'split', 50 | desc = 'cursor_behavior = "hold", mode = "%s" + resursive, pos after second array', 51 | cursor = { 14, 38 }, 52 | expected = { 24, 3 }, 53 | result = {}, 54 | }, 55 | { 56 | path = PATH, 57 | mode = 'split', 58 | desc = 'cursor_behavior = "hold", mode = "%s" + resursive, pos after third array', 59 | cursor = { 14, 51 }, 60 | expected = { 29, 3 }, 61 | result = {}, 62 | }, 63 | { 64 | path = PATH, 65 | mode = 'split', 66 | desc = 'cursor_behavior = "hold", mode = "%s" + resursive, pos on penult sym', 67 | cursor = { 14, 64 }, 68 | expected = { 35, 0 }, 69 | result = {}, 70 | }, 71 | { 72 | path = PATH, 73 | mode = 'split', 74 | desc = 'cursor_behavior = "hold", mode = "%s" + resursive, pos on destructing array', 75 | cursor = { 41, 33 }, 76 | expected = { 42, 9 }, 77 | result = {}, 78 | }, 79 | { 80 | path = PATH, 81 | mode = 'join', 82 | desc = 'cursor_behavior = "hold", mode = "%s" + resursive, pos on last sep', 83 | cursor = { 37, 3 }, 84 | expected = { 17, 64 }, 85 | result = {}, 86 | }, 87 | } 88 | 89 | local treesj = require('treesj') 90 | treesj.setup(settings) 91 | 92 | describe('TreeSJ CHOLD:', function() 93 | for _, value in ipairs(data) do 94 | tu._test_chold(value, treesj) 95 | end 96 | end) 97 | -------------------------------------------------------------------------------- /tests/chold/hold_split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | local PATH_JS = './tests/chold/cursor.js' 3 | local PATH_LUA = './tests/chold/cursor.lua' 4 | 5 | local data = { 6 | { 7 | path = PATH_JS, 8 | mode = 'split', 9 | desc = 'cursor_behavior = "hold", mode = "%s", pos inside block', 10 | cursor = { 4, 16 }, 11 | expected = { 5, 4 }, 12 | result = {}, 13 | }, 14 | { 15 | path = PATH_JS, 16 | mode = 'split', 17 | desc = 'cursor_behavior = "hold", mode = "%s", pos before block', 18 | cursor = { 4, 0 }, 19 | expected = { 4, 0 }, 20 | result = {}, 21 | }, 22 | { 23 | path = PATH_JS, 24 | mode = 'split', 25 | desc = 'cursor_behavior = "hold", mode = "%s", pos on first sym of block', 26 | cursor = { 4, 12 }, 27 | expected = { 4, 12 }, 28 | result = {}, 29 | }, 30 | { 31 | path = PATH_JS, 32 | mode = 'split', 33 | desc = 'cursor_behavior = "hold", mode = "%s", pos on last sym of block', 34 | cursor = { 4, 78 }, 35 | expected = { 8, 0 }, 36 | result = {}, 37 | }, 38 | { 39 | path = PATH_JS, 40 | mode = 'split', 41 | desc = 'cursor_behavior = "hold", mode = "%s", pos on penultimate symbol of block', 42 | cursor = { 4, 77 }, 43 | expected = { 8, 0 }, 44 | result = {}, 45 | }, 46 | { 47 | path = PATH_JS, 48 | mode = 'split', 49 | desc = 'cursor_behavior = "hold", mode = "%s", pos after block', 50 | cursor = { 4, 79 }, 51 | expected = { 8, 1 }, 52 | result = {}, 53 | }, 54 | { 55 | path = PATH_LUA, 56 | mode = 'split', 57 | desc = 'cursor_behavior = "hold", mode = "%s", pos inside non-bracket block', 58 | cursor = { 2, 63 }, 59 | expected = { 4, 7 }, 60 | result = {}, 61 | }, 62 | { 63 | path = PATH_LUA, 64 | mode = 'split', 65 | desc = 'cursor_behavior = "hold", mode = "%s", pos on last element of non-bracket block', 66 | cursor = { 11, 27 }, 67 | expected = { 13, 1 }, 68 | result = {}, 69 | }, 70 | { 71 | path = PATH_LUA, 72 | mode = 'split', 73 | desc = 'cursor_behavior = "hold", mode = "%s", pos on space before first element of non-bracket block', 74 | cursor = { 11, 12 }, 75 | expected = { 12, 1 }, 76 | result = {}, 77 | }, 78 | } 79 | 80 | local treesj = require('treesj') 81 | treesj.setup({ cursor_behavior = 'hold' }) 82 | 83 | describe('TreeSJ CHOLD:', function() 84 | for _, value in ipairs(data) do 85 | tu._test_chold(value, treesj) 86 | end 87 | end) 88 | -------------------------------------------------------------------------------- /tests/chold/start_join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | local PATH = './tests/chold/cursor.js' 3 | 4 | local data = { 5 | { 6 | path = PATH, 7 | mode = 'join', 8 | desc = 'cursor_behavior = "start", mode = "%s", pos inside block', 9 | cursor = { 8, 4 }, 10 | expected = { 7, 12 }, 11 | result = {}, 12 | }, 13 | { 14 | path = PATH, 15 | mode = 'join', 16 | desc = 'cursor_behavior = "start", mode = "%s", pos before block', 17 | cursor = { 7, 0 }, 18 | expected = { 7, 12 }, 19 | result = {}, 20 | }, 21 | { 22 | path = PATH, 23 | mode = 'join', 24 | desc = 'cursor_behavior = "start", mode = "%s", pos on first sym of block', 25 | cursor = { 7, 12 }, 26 | expected = { 7, 12 }, 27 | result = {}, 28 | }, 29 | { 30 | path = PATH, 31 | mode = 'join', 32 | desc = 'cursor_behavior = "start", mode = "%s", pos on last sym of block', 33 | cursor = { 11, 0 }, 34 | expected = { 7, 12 }, 35 | result = {}, 36 | }, 37 | } 38 | 39 | local treesj = require('treesj') 40 | treesj.setup({ cursor_behavior = 'start' }) 41 | 42 | describe('TreeSJ CHOLD:', function() 43 | for _, value in ipairs(data) do 44 | tu._test_chold(value, treesj) 45 | end 46 | end) 47 | -------------------------------------------------------------------------------- /tests/chold/start_split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | local PATH = './tests/chold/cursor.js' 3 | 4 | local data = { 5 | { 6 | path = PATH, 7 | mode = 'split', 8 | desc = 'cursor_behavior = "start", mode = "%s", pos inside block', 9 | cursor = { 4, 16 }, 10 | expected = { 4, 12 }, 11 | result = {}, 12 | }, 13 | { 14 | path = PATH, 15 | mode = 'split', 16 | desc = 'cursor_behavior = "start", mode = "%s", pos before block', 17 | cursor = { 4, 0 }, 18 | expected = { 4, 12 }, 19 | result = {}, 20 | }, 21 | { 22 | path = PATH, 23 | mode = 'split', 24 | desc = 'cursor_behavior = "start", mode = "%s", pos on first sym of block', 25 | cursor = { 4, 12 }, 26 | expected = { 4, 12 }, 27 | result = {}, 28 | }, 29 | { 30 | path = PATH, 31 | mode = 'split', 32 | desc = 'cursor_behavior = "start", mode = "%s", pos on last sym of block', 33 | cursor = { 4, 78 }, 34 | expected = { 4, 12 }, 35 | result = {}, 36 | }, 37 | } 38 | 39 | local treesj = require('treesj') 40 | treesj.setup({ cursor_behavior = 'start' }) 41 | 42 | describe('TreeSJ CHOLD:', function() 43 | for _, value in ipairs(data) do 44 | tu._test_chold(value, treesj) 45 | end 46 | end) 47 | -------------------------------------------------------------------------------- /tests/langs/bash/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.sh' 4 | local LANG = 'bash' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "array", preset default', 12 | cursor = { 6, 9 }, 13 | expected = { 3, 4 }, 14 | result = { 5, 6 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "compound_statement", preset default', 21 | cursor = { 15, 7 }, 22 | expected = { 12, 13 }, 23 | result = { 14, 15 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "do_group", preset default', 30 | cursor = { 23, 1 }, 31 | expected = { 20, 21 }, 32 | result = { 22, 23 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "if_statement", preset default', 39 | cursor = { 30, 1 }, 40 | expected = { 27, 28 }, 41 | result = { 29, 30 }, 42 | }, 43 | } 44 | 45 | local treesj = require('treesj') 46 | local opts = {} 47 | treesj.setup(opts) 48 | 49 | describe('TreeSJ JOIN:', function() 50 | for _, value in ipairs(data_for_join) do 51 | tu._test_format(value, treesj) 52 | end 53 | end) 54 | -------------------------------------------------------------------------------- /tests/langs/bash/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.sh' 4 | local LANG = 'bash' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "array", preset default', 12 | cursor = { 4, 9 }, 13 | expected = { 5, 10 }, 14 | result = { 3, 8 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "compound_statement", preset default', 21 | cursor = { 13, 7 }, 22 | expected = { 14, 18 }, 23 | result = { 12, 16 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "do_group", preset default', 30 | cursor = { 21, 1 }, 31 | expected = { 22, 25 }, 32 | result = { 20, 23 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "if_statement", preset default', 39 | cursor = { 28, 1 }, 40 | expected = { 29, 32 }, 41 | result = { 27, 30 }, 42 | }, 43 | } 44 | 45 | local treesj = require('treesj') 46 | local opts = {} 47 | treesj.setup(opts) 48 | 49 | describe('TreeSJ SPLIT:', function() 50 | for _, value in ipairs(data_for_split) do 51 | tu._test_format(value, treesj) 52 | end 53 | end) 54 | -------------------------------------------------------------------------------- /tests/langs/c/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.c' 4 | local LANG = 'c' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "parameter_list", preset default', 12 | cursor = { 4, 0 }, 13 | expected = { 1, 2 }, 14 | result = { 3, 4 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "argument_list", preset default', 21 | cursor = { 13, 0 }, 22 | expected = { 10, 11 }, 23 | result = { 12, 13 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "initializer_list", preset default', 30 | cursor = { 22, 0 }, 31 | expected = { 19, 20 }, 32 | result = { 21, 22 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "compound_statement", preset default', 39 | cursor = { 33, 12 }, 40 | expected = { 30, 31 }, 41 | result = { 32, 33 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'join', 46 | lang = LANG, 47 | desc = 'lang "%s", node "enumerator_list", preset default', 48 | cursor = { 40, 0 }, 49 | expected = { 37, 38 }, 50 | result = { 39, 40 }, 51 | }, 52 | } 53 | 54 | local treesj = require('treesj') 55 | local opts = {} 56 | treesj.setup(opts) 57 | 58 | describe('TreeSJ JOIN:', function() 59 | for _, value in ipairs(data_for_join) do 60 | tu._test_format(value, treesj) 61 | end 62 | end) 63 | -------------------------------------------------------------------------------- /tests/langs/c/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.c' 4 | local LANG = 'c' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "parameter_list", preset default', 12 | cursor = { 2, 0 }, 13 | expected = { 3, 8 }, 14 | result = { 1, 6 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "argument_list", preset default', 21 | cursor = { 11, 0 }, 22 | expected = { 12, 17 }, 23 | result = { 10, 15 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "initializer_list", preset default', 30 | cursor = { 20, 0 }, 31 | expected = { 21, 28 }, 32 | result = { 19, 26 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "compound_statement", preset default', 39 | cursor = { 31, 12 }, 40 | expected = { 32, 35 }, 41 | result = { 30, 33 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", node "enumerator_list", preset default', 48 | cursor = { 38, 0 }, 49 | expected = { 39, 44 }, 50 | result = { 37, 42 }, 51 | }, 52 | } 53 | 54 | local treesj = require('treesj') 55 | local opts = {} 56 | treesj.setup(opts) 57 | 58 | describe('TreeSJ SPLIT:', function() 59 | for _, value in ipairs(data_for_split) do 60 | tu._test_format(value, treesj) 61 | end 62 | end) 63 | -------------------------------------------------------------------------------- /tests/langs/cpp/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.cpp' 4 | local LANG = 'cpp' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "parameter_list", preset default', 12 | cursor = { 4, 0 }, 13 | expected = { 1, 2 }, 14 | result = { 3, 4 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "argument_list", preset default', 21 | cursor = { 13, 0 }, 22 | expected = { 10, 11 }, 23 | result = { 12, 13 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "template_parameter_list", preset default', 30 | cursor = { 23, 0 }, 31 | expected = { 19, 21 }, 32 | result = { 22, 24 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "template_argument_list", preset default', 39 | cursor = { 32, 0 }, 40 | expected = { 29, 30 }, 41 | result = { 31, 32 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'join', 46 | lang = LANG, 47 | desc = 'lang "%s", node "enumerator_list", preset default', 48 | cursor = { 40, 0 }, 49 | expected = { 37, 38 }, 50 | result = { 39, 40 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'join', 55 | lang = LANG, 56 | desc = 'lang "%s", node "initializer_list", preset default', 57 | cursor = { 49, 0 }, 58 | expected = { 46, 47 }, 59 | result = { 48, 49 }, 60 | }, 61 | { 62 | path = PATH, 63 | mode = 'join', 64 | lang = LANG, 65 | desc = 'lang "%s", node "compound_statement", preset default', 66 | cursor = { 60, 12 }, 67 | expected = { 57, 58 }, 68 | result = { 59, 60 }, 69 | }, 70 | } 71 | 72 | local treesj = require('treesj') 73 | local opts = {} 74 | treesj.setup(opts) 75 | 76 | describe('TreeSJ JOIN:', function() 77 | for _, value in ipairs(data_for_join) do 78 | tu._test_format(value, treesj) 79 | end 80 | end) 81 | -------------------------------------------------------------------------------- /tests/langs/cpp/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.cpp' 4 | local LANG = 'cpp' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "parameter_list", preset default', 12 | cursor = { 2, 0 }, 13 | expected = { 3, 8 }, 14 | result = { 1, 6 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "argument_list", preset default', 21 | cursor = { 11, 0 }, 22 | expected = { 12, 17 }, 23 | result = { 10, 15 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "template_parameter_list", preset default', 30 | cursor = { 20, 0 }, 31 | expected = { 22, 27 }, 32 | result = { 19, 24 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "template_argument_list", preset default', 39 | cursor = { 30, 0 }, 40 | expected = { 31, 35 }, 41 | result = { 29, 33 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", node "enumerator_list", preset default', 48 | cursor = { 38, 0 }, 49 | expected = { 39, 44 }, 50 | result = { 37, 42 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'split', 55 | lang = LANG, 56 | desc = 'lang "%s", node "initializer_list", preset default', 57 | cursor = { 47, 0 }, 58 | expected = { 48, 55 }, 59 | result = { 46, 53 }, 60 | }, 61 | { 62 | path = PATH, 63 | mode = 'split', 64 | lang = LANG, 65 | desc = 'lang "%s", node "compound_statement", preset default', 66 | cursor = { 58, 12 }, 67 | expected = { 59, 62 }, 68 | result = { 57, 60 }, 69 | }, 70 | } 71 | 72 | local treesj = require('treesj') 73 | local opts = {} 74 | treesj.setup(opts) 75 | 76 | describe('TreeSJ SPLIT:', function() 77 | for _, value in ipairs(data_for_split) do 78 | tu._test_format(value, treesj) 79 | end 80 | end) 81 | -------------------------------------------------------------------------------- /tests/langs/css/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.css' 4 | local LANG = 'css' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "block", preset default', 12 | cursor = { 6, 9 }, 13 | expected = { 1, 2 }, 14 | result = { 4, 5 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "keyframe_block_list", preset default', 21 | cursor = { 17, 4 }, 22 | expected = { 12, 13 }, 23 | result = { 15, 16 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "arguments", preset default', 30 | cursor = { 33, 4 }, 31 | expected = { 24, 25 }, 32 | result = { 30, 31 }, 33 | }, 34 | } 35 | 36 | local treesj = require('treesj') 37 | local opts = {} 38 | treesj.setup(opts) 39 | 40 | describe('TreeSJ JOIN:', function() 41 | for _, value in ipairs(data_for_join) do 42 | tu._test_format(value, treesj) 43 | end 44 | end) 45 | -------------------------------------------------------------------------------- /tests/langs/css/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.css' 4 | local LANG = 'css' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "block", preset default', 12 | cursor = { 2, 20 }, 13 | expected = { 4, 10 }, 14 | result = { 1, 7 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "keyframe_block_list", preset default', 21 | cursor = { 13, 25 }, 22 | expected = { 15, 20 }, 23 | result = { 12, 17 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "arguments", preset default', 30 | cursor = { 25, 23 }, 31 | expected = { 30, 48 }, 32 | result = { 24, 42 }, 33 | }, 34 | } 35 | 36 | local treesj = require('treesj') 37 | local opts = {} 38 | treesj.setup(opts) 39 | 40 | describe('TreeSJ SPLIT:', function() 41 | for _, value in ipairs(data_for_split) do 42 | tu._test_format(value, treesj) 43 | end 44 | end) 45 | -------------------------------------------------------------------------------- /tests/langs/dart/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.dart' 4 | local LANG = 'dart' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "list_literal", preset default', 12 | cursor = { 4, 13 }, 13 | expected = { 1, 2 }, 14 | result = { 3, 4 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "list_literal" with const, preset default', 21 | cursor = { 13, 13 }, 22 | expected = { 10, 11 }, 23 | result = { 12, 13 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "set_or_map_literal", preset default', 30 | cursor = { 21, 12 }, 31 | expected = { 18, 19 }, 32 | result = { 20, 21 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "block", preset default', 39 | cursor = { 30, 2 }, 40 | expected = { 26, 27 }, 41 | result = { 28, 29 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'join', 46 | lang = LANG, 47 | desc = 'lang "%s", node "arguments", preset default', 48 | cursor = { 37, 5 }, 49 | expected = { 34, 35 }, 50 | result = { 36, 37 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'join', 55 | lang = LANG, 56 | desc = 'lang "%s", node "formal_parameter_list", preset default', 57 | cursor = { 45, 5 }, 58 | expected = { 42, 43 }, 59 | result = { 44, 45 }, 60 | }, 61 | } 62 | 63 | local treesj = require('treesj') 64 | local opts = {} 65 | treesj.setup(opts) 66 | 67 | describe('TreeSJ JOIN:', function() 68 | for _, value in ipairs(data_for_join) do 69 | tu._test_format(value, treesj) 70 | end 71 | end) 72 | -------------------------------------------------------------------------------- /tests/langs/dart/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.dart' 4 | local LANG = 'dart' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "list_literal", preset default', 12 | cursor = { 2, 15 }, 13 | expected = { 3, 8 }, 14 | result = { 1, 6 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "list_literal" with const, preset default', 21 | cursor = { 11, 7 }, 22 | expected = { 12, 16 }, 23 | result = { 10, 14 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "set_or_map_literal", preset default', 30 | cursor = { 19, 27 }, 31 | expected = { 20, 24 }, 32 | result = { 18, 22 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "block", preset default', 39 | cursor = { 27, 26 }, 40 | expected = { 28, 32 }, 41 | result = { 26, 30 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", node "arguments", preset default', 48 | cursor = { 35, 5 }, 49 | expected = { 36, 40 }, 50 | result = { 34, 38 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'split', 55 | lang = LANG, 56 | desc = 'lang "%s", node "formal_parameter_list", preset default', 57 | cursor = { 43, 9 }, 58 | expected = { 44, 48 }, 59 | result = { 42, 46 }, 60 | }, 61 | } 62 | 63 | local treesj = require('treesj') 64 | local opts = {} 65 | treesj.setup(opts) 66 | 67 | describe('TreeSJ SPLIT:', function() 68 | for _, value in ipairs(data_for_split) do 69 | tu._test_format(value, treesj) 70 | end 71 | end) 72 | -------------------------------------------------------------------------------- /tests/langs/elixir/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.ex' 4 | local LANG = 'elixir' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "list", preset default', 12 | cursor = { 8, 4 }, 13 | expected = { 1, 2 }, 14 | result = { 4, 5 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "map", preset default', 21 | cursor = { 18, 15 }, 22 | expected = { 13, 14 }, 23 | result = { 16, 17 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "arguments", preset default', 30 | cursor = { 28, 3 }, 31 | expected = { 23, 24 }, 32 | result = { 26, 27 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "arguments", preset default', 39 | cursor = { 37, 3 }, 40 | expected = { 32, 33 }, 41 | result = { 35, 36 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'join', 46 | lang = LANG, 47 | desc = 'lang "%s", node "tuple", preset default', 48 | cursor = { 46, 2 }, 49 | expected = { 41, 42 }, 50 | result = { 44, 45 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'join', 55 | lang = LANG, 56 | desc = 'lang "%s", node "keywords", preset default', 57 | cursor = { 57, 6 }, 58 | expected = { 52, 53 }, 59 | result = { 55, 56 }, 60 | }, 61 | { 62 | path = PATH, 63 | mode = 'join', 64 | lang = LANG, 65 | desc = 'lang "%s", node "map" with "keywords" and "map_content", preset default', 66 | cursor = { 68, 8 }, 67 | expected = { 64, 65 }, 68 | result = { 67, 68 }, 69 | }, 70 | { 71 | path = PATH, 72 | mode = 'join', 73 | lang = LANG, 74 | desc = 'lang "%s", node "list" with "keywords" and "map", preset default', 75 | cursor = { 79, 4 }, 76 | expected = { 74, 75 }, 77 | result = { 77, 78 }, 78 | }, 79 | { 80 | path = PATH, 81 | mode = 'join', 82 | lang = LANG, 83 | desc = 'lang "%s", node "map" nested "keywords" and "maps", preset default', 84 | cursor = { 90, 10 }, 85 | expected = { 85, 86 }, 86 | result = { 88, 89 }, 87 | }, 88 | { 89 | path = PATH, 90 | mode = 'join', 91 | lang = LANG, 92 | desc = 'lang "%s", node "call", preset default', 93 | cursor = { 102, 1 }, 94 | expected = { 98, 99 }, 95 | result = { 101, 102 }, 96 | }, 97 | } 98 | 99 | local treesj = require('treesj') 100 | local opts = {} 101 | treesj.setup(opts) 102 | 103 | describe('TreeSJ JOIN:', function() 104 | for _, value in ipairs(data_for_join) do 105 | tu._test_format(value, treesj) 106 | end 107 | end) 108 | -------------------------------------------------------------------------------- /tests/langs/elixir/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.ex' 4 | local LANG = 'elixir' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "list", preset default', 12 | cursor = { 2, 13 }, 13 | expected = { 4, 11 }, 14 | result = { 1, 8 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "map", preset default', 21 | cursor = { 14, 17 }, 22 | expected = { 16, 21 }, 23 | result = { 13, 18 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "arguments", preset default', 30 | cursor = { 24, 11 }, 31 | expected = { 26, 30 }, 32 | result = { 23, 27 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "arguments", preset default', 39 | cursor = { 33, 7 }, 40 | expected = { 35, 39 }, 41 | result = { 32, 36 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", node "tuple", preset default', 48 | cursor = { 42, 5 }, 49 | expected = { 44, 50 }, 50 | result = { 41, 47 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'split', 55 | lang = LANG, 56 | desc = 'lang "%s", node "keywords", preset default', 57 | cursor = { 53, 9 }, 58 | expected = { 55, 62 }, 59 | result = { 52, 59 }, 60 | }, 61 | { 62 | path = PATH, 63 | mode = 'split', 64 | lang = LANG, 65 | desc = 'lang "%s", node "map" with "keywords" and "map_content", preset default', 66 | cursor = { 65, 8 }, 67 | expected = { 67, 74 }, 68 | result = { 64, 71 }, 69 | }, 70 | { 71 | path = PATH, 72 | mode = 'split', 73 | lang = LANG, 74 | desc = 'lang "%s", node "list" with "keywords" and "map", preset default', 75 | cursor = { 77, 9 }, 76 | expected = { 79, 85 }, 77 | result = { 76, 82 }, 78 | }, 79 | { 80 | path = PATH, 81 | mode = 'split', 82 | lang = LANG, 83 | desc = 'lang "%s", node "map" nested "keywords" and "maps", preset default', 84 | cursor = { 88, 15 }, 85 | expected = { 90, 96 }, 86 | result = { 87, 93 }, 87 | }, 88 | { 89 | path = PATH, 90 | mode = 'split', 91 | lang = LANG, 92 | desc = 'lang "%s", node "call", preset default', 93 | cursor = { 99, 3 }, 94 | expected = { 101, 104 }, 95 | result = { 98, 101 }, 96 | }, 97 | } 98 | 99 | local treesj = require('treesj') 100 | local opts = {} 101 | treesj.setup(opts) 102 | 103 | describe('TreeSJ SPLIT:', function() 104 | for _, value in ipairs(data_for_split) do 105 | tu._test_format(value, treesj) 106 | end 107 | end) 108 | -------------------------------------------------------------------------------- /tests/langs/go/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.go' 4 | local LANG = 'go' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", block "literal_value" list, preset default', 12 | cursor = { 10, 3 }, 13 | expected = { 3, 4 }, 14 | result = { 6, 7 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", block "literal_value" dict, preset default', 21 | cursor = { 19, 9 }, 22 | expected = { 15, 16 }, 23 | result = { 18, 19 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", block "block", preset default', 30 | cursor = { 28, 12 }, 31 | expected = { 24, 25 }, 32 | result = { 27, 28 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", block "parameter_list", preset default', 39 | cursor = { 40, 10 }, 40 | expected = { 33, 36 }, 41 | result = { 38, 41 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'join', 46 | lang = LANG, 47 | desc = 'lang "%s", block "argument_list", preset default', 48 | cursor = { 54, 3 }, 49 | expected = { 47, 48 }, 50 | result = { 50, 51 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'join', 55 | lang = LANG, 56 | desc = 'lang "%s", block "import_spec_list to import_spec", preset default', 57 | cursor = { 61, 8 }, 58 | expected = { 57, 58 }, 59 | result = { 60, 61 }, 60 | }, 61 | } 62 | 63 | local treesj = require('treesj') 64 | local opts = {} 65 | treesj.setup(opts) 66 | 67 | describe('TreeSJ JOIN:', function() 68 | for _, value in ipairs(data_for_join) do 69 | tu._test_format(value, treesj) 70 | end 71 | end) 72 | -------------------------------------------------------------------------------- /tests/langs/go/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.go' 4 | local LANG = 'go' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", block "literal_value" list, preset default', 12 | cursor = { 4, 19 }, 13 | expected = { 6, 13 }, 14 | result = { 3, 10 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", block "literal_value" dict, preset default', 21 | cursor = { 16, 2 }, 22 | expected = { 18, 22 }, 23 | result = { 15, 19 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", block "block", preset default', 30 | cursor = { 25, 12 }, 31 | expected = { 27, 31 }, 32 | result = { 24, 28 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", block "parameter_list", preset default', 39 | cursor = { 34, 27 }, 40 | expected = { 38, 45 }, 41 | result = { 33, 40 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", block "argument_list", preset default', 48 | cursor = { 48, 22 }, 49 | expected = { 50, 55 }, 50 | result = { 47, 52 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'split', 55 | lang = LANG, 56 | desc = 'lang "%s", block "import_spec to import_spec_list", preset default', 57 | cursor = { 58, 11 }, 58 | expected = { 60, 63 }, 59 | result = { 57, 60 }, 60 | }, 61 | } 62 | 63 | local treesj = require('treesj') 64 | local opts = {} 65 | treesj.setup(opts) 66 | 67 | describe('TreeSJ SPLIT:', function() 68 | for _, value in ipairs(data_for_split) do 69 | tu._test_format(value, treesj) 70 | end 71 | end) 72 | -------------------------------------------------------------------------------- /tests/langs/haskell/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.hs' 4 | local LANG = 'haskell' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "list", preset default', 12 | cursor = { 5, 0 }, 13 | expected = { 1, 2 }, 14 | result = { 3, 4 }, 15 | }, 16 | } 17 | 18 | local treesj = require('treesj') 19 | local opts = {} 20 | treesj.setup(opts) 21 | 22 | describe('TreeSJ JOIN:', function() 23 | for _, value in ipairs(data_for_join) do 24 | tu._test_format(value, treesj) 25 | end 26 | end) 27 | -------------------------------------------------------------------------------- /tests/langs/haskell/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.hs' 4 | local LANG = 'haskell' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "list", preset default', 12 | cursor = { 2, 12 }, 13 | expected = { 3, 8 }, 14 | result = { 1, 6 }, 15 | }, 16 | } 17 | 18 | local treesj = require('treesj') 19 | local opts = {} 20 | treesj.setup(opts) 21 | 22 | describe('TreeSJ SPLIT:', function() 23 | for _, value in ipairs(data_for_split) do 24 | tu._test_format(value, treesj) 25 | end 26 | end) 27 | -------------------------------------------------------------------------------- /tests/langs/html/html_last_indent_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.html' 4 | local LANG = 'html' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "start_tag" with last_indent = "inner"', 12 | cursor = { 78, 10 }, 13 | expected = { 79, 82 }, 14 | result = { 77, 80 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "self_closing_tag" with last_indent = "inner"', 21 | cursor = { 85, 29 }, 22 | expected = { 86, 89 }, 23 | result = { 84, 87 }, 24 | }, 25 | } 26 | 27 | local data_for_join = { 28 | { 29 | path = PATH, 30 | mode = 'join', 31 | lang = LANG, 32 | desc = 'lang "%s", node "start_tag" with last_indent = "inner"', 33 | cursor = { 81, 19 }, 34 | expected = { 77, 78 }, 35 | result = { 79, 80 }, 36 | }, 37 | { 38 | path = PATH, 39 | mode = 'join', 40 | lang = LANG, 41 | desc = 'lang "%s", node "self_closing_tag" with last_indent = "inner"', 42 | cursor = { 88, 19 }, 43 | expected = { 84, 85 }, 44 | result = { 86, 87 }, 45 | }, 46 | } 47 | 48 | local treesj = require('treesj') 49 | local opts = { 50 | langs = { 51 | html = { 52 | start_tag = { 53 | split = { 54 | omit = { 'tag_name', '>' }, 55 | last_indent = 'inner', 56 | }, 57 | }, 58 | self_closing_tag = { 59 | split = { 60 | omit = { 'tag_name', '/>' }, 61 | last_indent = 'inner', 62 | }, 63 | }, 64 | }, 65 | }, 66 | } 67 | treesj.setup(opts) 68 | 69 | describe('TreeSJ SPLIT:', function() 70 | for _, value in ipairs(data_for_split) do 71 | tu._test_format(value, treesj) 72 | end 73 | end) 74 | 75 | describe('TreeSJ JOIN:', function() 76 | for _, value in ipairs(data_for_join) do 77 | tu._test_format(value, treesj) 78 | end 79 | end) 80 | -------------------------------------------------------------------------------- /tests/langs/html/html_no_empty_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.html' 4 | local LANG = 'html' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "element" is empty, preset witn format_empty_node = false', 12 | cursor = { 57, 15 }, 13 | expected = { 56, 57 }, 14 | result = { 56, 57 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "start_tag" is empty, preset witn format_empty_node = false', 21 | cursor = { 64, 6 }, 22 | expected = { 63, 64 }, 23 | result = { 63, 64 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "self_closing_tag" is empty, preset witn format_empty_node = false', 30 | cursor = { 71, 9 }, 31 | expected = { 70, 71 }, 32 | result = { 70, 71 }, 33 | }, 34 | } 35 | 36 | local data_for_join = { 37 | { 38 | path = PATH, 39 | mode = 'join', 40 | lang = LANG, 41 | desc = 'lang "%s", node "element" is empty, preset witn format_empty_node = false', 42 | cursor = { 61, 8 }, 43 | expected = { 59, 61 }, 44 | result = { 59, 61 }, 45 | }, 46 | { 47 | path = PATH, 48 | mode = 'join', 49 | lang = LANG, 50 | desc = 'lang "%s", node "start_tag" is empty, preset witn format_empty_node = false', 51 | cursor = { 68, 7 }, 52 | expected = { 66, 68 }, 53 | result = { 66, 68 }, 54 | }, 55 | { 56 | path = PATH, 57 | mode = 'join', 58 | lang = LANG, 59 | desc = 'lang "%s", node "self_closing_tag" is empty, preset witn format_empty_node = false', 60 | cursor = { 74, 6 }, 61 | expected = { 73, 75 }, 62 | result = { 73, 75 }, 63 | }, 64 | } 65 | 66 | local treesj = require('treesj') 67 | local opts = { 68 | langs = { 69 | html = { 70 | element = { 71 | both = { 72 | format_empty_node = false, 73 | }, 74 | }, 75 | start_tag = { 76 | both = { 77 | format_empty_node = false, 78 | }, 79 | }, 80 | self_closing_tag = { 81 | both = { 82 | format_empty_node = false, 83 | }, 84 | }, 85 | }, 86 | }, 87 | } 88 | treesj.setup(opts) 89 | 90 | describe('TreeSJ SPLIT:', function() 91 | for _, value in ipairs(data_for_split) do 92 | tu._test_format(value, treesj) 93 | end 94 | end) 95 | 96 | describe('TreeSJ JOIN:', function() 97 | for _, value in ipairs(data_for_join) do 98 | tu._test_format(value, treesj) 99 | end 100 | end) 101 | -------------------------------------------------------------------------------- /tests/langs/java/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.java' 4 | local LANG = 'java' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "array_initializer", preset default', 12 | cursor = { 10, 5 }, 13 | expected = { 5, 6 }, 14 | result = { 8, 9 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "formal_parameters", preset default', 21 | cursor = { 24, 9 }, 22 | expected = { 15, 19 }, 23 | result = { 21, 25 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "constructor_body", preset default', 30 | cursor = { 37, 25 }, 31 | expected = { 32, 33 }, 32 | result = { 35, 36 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "block", preset default', 39 | cursor = { 46, 7 }, 40 | expected = { 41, 42 }, 41 | result = { 44, 45 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'join', 46 | lang = LANG, 47 | desc = 'lang "%s", node "argument_list", preset default', 48 | cursor = { 55, 18 }, 49 | expected = { 50, 51 }, 50 | result = { 53, 54 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'join', 55 | lang = LANG, 56 | desc = 'lang "%s", node "annotation_argument_list", preset default', 57 | cursor = { 67, 14 }, 58 | expected = { 61, 63 }, 59 | result = { 65, 67 }, 60 | }, 61 | { 62 | path = PATH, 63 | mode = 'join', 64 | lang = LANG, 65 | desc = 'lang "%s", node "enum_body", preset default', 66 | cursor = { 78, 6 }, 67 | expected = { 72, 73 }, 68 | result = { 75, 76 }, 69 | }, 70 | } 71 | 72 | local treesj = require('treesj') 73 | local opts = {} 74 | treesj.setup(opts) 75 | 76 | describe('TreeSJ JOIN:', function() 77 | for _, value in ipairs(data_for_join) do 78 | tu._test_format(value, treesj) 79 | end 80 | end) 81 | -------------------------------------------------------------------------------- /tests/langs/java/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.java' 4 | local LANG = 'java' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "array_initializer", preset default', 12 | cursor = { 6, 16 }, 13 | expected = { 8, 13 }, 14 | result = { 5, 10 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "formal_parameters", preset default', 21 | cursor = { 16, 33 }, 22 | expected = { 21, 30 }, 23 | result = { 15, 24 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "constructor_body", preset default', 30 | cursor = { 33, 85 }, 31 | expected = { 35, 39 }, 32 | result = { 32, 36 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "block", preset default', 39 | cursor = { 42, 7 }, 40 | expected = { 44, 47 }, 41 | result = { 41, 44 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", node "argument_list", preset default', 48 | cursor = { 51, 30 }, 49 | expected = { 53, 57 }, 50 | result = { 50, 54 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'split', 55 | lang = LANG, 56 | desc = 'lang "%s", node "annotation_argument_list", preset default', 57 | cursor = { 62, 24 }, 58 | expected = { 65, 70 }, 59 | result = { 61, 66 }, 60 | }, 61 | { 62 | path = PATH, 63 | mode = 'split', 64 | lang = LANG, 65 | desc = 'lang "%s", node "enum_body", preset default', 66 | cursor = { 73, 26 }, 67 | expected = { 75, 80 }, 68 | result = { 72, 77 }, 69 | }, 70 | } 71 | 72 | local treesj = require('treesj') 73 | local opts = {} 74 | treesj.setup(opts) 75 | 76 | describe('TreeSJ SPLIT:', function() 77 | for _, value in ipairs(data_for_split) do 78 | tu._test_format(value, treesj) 79 | end 80 | end) 81 | -------------------------------------------------------------------------------- /tests/langs/javascript/jsx_last_indent_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.jsx' 4 | local LANG = 'jsx' 5 | 6 | local settings = { 7 | langs = { 8 | javascript = { 9 | jsx_self_closing_element = { 10 | split = { 11 | omit = { 'identifier', 'nested_identifier', '/', '>', '/>' }, 12 | last_indent = 'inner', 13 | }, 14 | }, 15 | }, 16 | }, 17 | } 18 | 19 | local data_for_split = { 20 | { 21 | path = PATH, 22 | mode = 'split', 23 | lang = LANG, 24 | desc = 'lang "%s", node "jsx_self_closing_element", preset with last_indent = "inner"', 25 | cursor = { 48, 32 }, 26 | expected = { 49, 54 }, 27 | result = { 47, 52 }, 28 | }, 29 | } 30 | 31 | local data_for_join = { 32 | { 33 | path = PATH, 34 | mode = 'join', 35 | lang = LANG, 36 | desc = 'lang "%s", node "jsx_self_closing_element", preset with last_indent = "inner"', 37 | cursor = { 52, 25 }, 38 | expected = { 47, 48 }, 39 | result = { 49, 50 }, 40 | }, 41 | } 42 | 43 | local treesj = require('treesj') 44 | local opts = { 45 | langs = { 46 | javascript = { 47 | jsx_self_closing_element = { 48 | split = { 49 | omit = { 'identifier', 'nested_identifier', '/', '>', '/>' }, 50 | last_indent = 'inner', 51 | }, 52 | }, 53 | }, 54 | }, 55 | } 56 | treesj.setup(opts) 57 | 58 | describe('TreeSJ SPLIT:', function() 59 | for _, value in ipairs(data_for_split) do 60 | tu._test_format(value, treesj) 61 | end 62 | end) 63 | 64 | describe('TreeSJ JOIN:', function() 65 | for _, value in ipairs(data_for_join) do 66 | tu._test_format(value, treesj) 67 | end 68 | end) 69 | -------------------------------------------------------------------------------- /tests/langs/javascript/split_recursive_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index_recursive.js' 4 | local LANG = 'javascript' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "object", preset with recursive = true', 12 | cursor = { 2, 17 }, 13 | expected = { 4, 16 }, 14 | result = { 1, 13 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "statement_block", preset with recursive = true', 21 | cursor = { 19, 15 }, 22 | expected = { 21, 30 }, 23 | result = { 18, 27 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "statement_block", preset with recursive = true', 30 | cursor = { 33, 1 }, 31 | expected = { 35, 40 }, 32 | result = { 32, 37 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "array", preset with recursive = true', 39 | cursor = { 43, 25 }, 40 | expected = { 45, 48 }, 41 | result = { 42, 45 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", field "body" in "arrow_function" with "parenthesized_expression", preset with recursive = true', 48 | cursor = { 51, 23 }, 49 | expected = { 53, 58 }, 50 | result = { 50, 55 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'split', 55 | lang = LANG, 56 | desc = 'lang "%s", field "body" in "arrow_function" with "array", preset with recursive = true', 57 | cursor = { 61, 23 }, 58 | expected = { 63, 70 }, 59 | result = { 60, 67 }, 60 | }, 61 | } 62 | 63 | local treesj = require('treesj') 64 | 65 | local recursive = { 66 | split = { 67 | recursive = true, 68 | recursive_ignore = { 69 | 'arguments', 70 | 'parameters', 71 | 'formal_parameters', 72 | }, 73 | }, 74 | } 75 | 76 | local opts = { 77 | langs = { 78 | javascript = { 79 | object = { 80 | split = recursive.split, 81 | }, 82 | statement_block = { 83 | split = recursive.split, 84 | }, 85 | body = { 86 | split = recursive.split, 87 | }, 88 | }, 89 | }, 90 | } 91 | treesj.setup(opts) 92 | 93 | describe('TreeSJ SPLIT:', function() 94 | for _, value in ipairs(data_for_split) do 95 | tu._test_format(value, treesj) 96 | end 97 | end) 98 | -------------------------------------------------------------------------------- /tests/langs/json/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.json' 4 | local LANG = 'json' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "object", preset default', 12 | cursor = { 6, 18 }, 13 | expected = { 18, 19 }, 14 | result = { 4, 5 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "array", preset default', 21 | cursor = { 10, 12 }, 22 | expected = { 19, 20 }, 23 | result = { 8, 9 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "pair with target object", preset default', 30 | cursor = { 5, 6 }, 31 | expected = { 18, 19 }, 32 | result = { 4, 5 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "array", preset default', 39 | cursor = { 9, 6 }, 40 | expected = { 19, 20 }, 41 | result = { 8, 9 }, 42 | }, 43 | } 44 | 45 | local treesj = require('treesj') 46 | local opts = {} 47 | treesj.setup(opts) 48 | 49 | describe('TreeSJ JOIN:', function() 50 | for _, value in ipairs(data_for_join) do 51 | tu._test_format(value, treesj) 52 | end 53 | end) 54 | -------------------------------------------------------------------------------- /tests/langs/json/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.json' 4 | local LANG = 'json' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "object", preset default', 12 | cursor = { 19, 28 }, 13 | expected = { 4, 8 }, 14 | result = { 18, 22 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "array", preset default', 21 | cursor = { 20, 28 }, 22 | expected = { 8, 12 }, 23 | result = { 19, 23 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "paif with target object", preset default', 30 | cursor = { 19, 6 }, 31 | expected = { 4, 8 }, 32 | result = { 18, 22 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "pair with target array", preset default', 39 | cursor = { 20, 6 }, 40 | expected = { 8, 12 }, 41 | result = { 19, 23 }, 42 | }, 43 | } 44 | 45 | local treesj = require('treesj') 46 | local opts = {} 47 | treesj.setup(opts) 48 | 49 | describe('TreeSJ SPLIT:', function() 50 | for _, value in ipairs(data_for_split) do 51 | tu._test_format(value, treesj) 52 | end 53 | end) 54 | -------------------------------------------------------------------------------- /tests/langs/json5/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.json5' 4 | local LANG = 'json5' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "object", preset default', 12 | cursor = { 6, 18 }, 13 | expected = { 16, 17 }, 14 | result = { 4, 5 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "array", preset default', 21 | cursor = { 10, 12 }, 22 | expected = { 17, 18 }, 23 | result = { 8, 9 }, 24 | }, 25 | } 26 | 27 | local treesj = require('treesj') 28 | local opts = {} 29 | treesj.setup(opts) 30 | 31 | describe('TreeSJ JOIN:', function() 32 | for _, value in ipairs(data_for_join) do 33 | tu._test_format(value, treesj) 34 | end 35 | end) 36 | -------------------------------------------------------------------------------- /tests/langs/json5/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.json5' 4 | local LANG = 'json5' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "object", preset default', 12 | cursor = { 17, 19 }, 13 | expected = { 4, 8 }, 14 | result = { 16, 20 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "array", preset default', 21 | cursor = { 18, 28 }, 22 | expected = { 8, 12 }, 23 | result = { 17, 21 }, 24 | }, 25 | } 26 | 27 | local treesj = require('treesj') 28 | local opts = {} 29 | treesj.setup(opts) 30 | 31 | describe('TreeSJ SPLIT:', function() 32 | for _, value in ipairs(data_for_split) do 33 | tu._test_format(value, treesj) 34 | end 35 | end) 36 | -------------------------------------------------------------------------------- /tests/langs/jsonc/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.jsonc' 4 | local LANG = 'jsonc' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "object", preset default', 12 | cursor = { 6, 18 }, 13 | expected = { 16, 17 }, 14 | result = { 4, 5 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "array", preset default', 21 | cursor = { 10, 12 }, 22 | expected = { 17, 18 }, 23 | result = { 8, 9 }, 24 | }, 25 | } 26 | 27 | local treesj = require('treesj') 28 | local opts = {} 29 | treesj.setup(opts) 30 | 31 | describe('TreeSJ JOIN:', function() 32 | for _, value in ipairs(data_for_join) do 33 | tu._test_format(value, treesj) 34 | end 35 | end) 36 | -------------------------------------------------------------------------------- /tests/langs/jsonc/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.jsonc' 4 | local LANG = 'jsonc' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "object", preset default', 12 | cursor = { 17, 19 }, 13 | expected = { 4, 8 }, 14 | result = { 16, 20 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "array", preset default', 21 | cursor = { 18, 28 }, 22 | expected = { 8, 12 }, 23 | result = { 17, 21 }, 24 | }, 25 | } 26 | 27 | local treesj = require('treesj') 28 | local opts = {} 29 | treesj.setup(opts) 30 | 31 | describe('TreeSJ SPLIT:', function() 32 | for _, value in ipairs(data_for_split) do 33 | tu._test_format(value, treesj) 34 | end 35 | end) 36 | -------------------------------------------------------------------------------- /tests/langs/julia/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.jl' 4 | local LANG = 'julia' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "argument_list", preset default', 12 | cursor = { 4, 16 }, 13 | expected = { 1, 2 }, 14 | result = { 3, 4 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "vector_expression", preset default', 21 | cursor = { 14, 3 }, 22 | expected = { 10, 11 }, 23 | result = { 12, 13 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "matrix_expression", preset default', 30 | cursor = { 23, 6 }, 31 | expected = { 19, 20 }, 32 | result = { 21, 22 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "tuple_expression", preset default', 39 | cursor = { 30, 6 }, 40 | expected = { 27, 28 }, 41 | result = { 29, 30 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'join', 46 | lang = LANG, 47 | desc = 'lang "%s", node "argument_list" in "function_definition", preset default', 48 | cursor = { 43, 21 }, 49 | expected = { 36, 41 }, 50 | result = { 42, 47 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'join', 55 | lang = LANG, 56 | desc = 'lang "%s", node "comprehension_expression", preset default', 57 | cursor = { 55, 5 }, 58 | expected = { 51, 52 }, 59 | result = { 53, 54 }, 60 | }, 61 | { 62 | path = PATH, 63 | mode = 'join', 64 | lang = LANG, 65 | desc = 'lang "%s", node "call_expression", preset default', 66 | cursor = { 62, 12 }, 67 | expected = { 59, 60 }, 68 | result = { 61, 62 }, 69 | }, 70 | { 71 | path = PATH, 72 | mode = 'join', 73 | lang = LANG, 74 | desc = 'lang "%s", node "using_statement", preset default', 75 | cursor = { 71, 12 }, 76 | expected = { 66, 67 }, 77 | result = { 68, 69 }, 78 | }, 79 | { 80 | path = PATH, 81 | mode = 'join', 82 | lang = LANG, 83 | desc = 'lang "%s", node "selected_import", preset default', 84 | cursor = { 78, 3 }, 85 | expected = { 73, 74 }, 86 | result = { 75, 76 }, 87 | }, 88 | { 89 | path = PATH, 90 | mode = 'join', 91 | lang = LANG, 92 | desc = 'lang "%s", node "tuple_expression" as left side of assignment, preset default', 93 | cursor = { 86, 4 }, 94 | expected = { 81, 82 }, 95 | result = { 83, 84 }, 96 | }, 97 | } 98 | 99 | local treesj = require('treesj') 100 | local opts = {} 101 | treesj.setup(opts) 102 | 103 | describe('TreeSJ JOIN:', function() 104 | for _, value in ipairs(data_for_join) do 105 | tu._test_format(value, treesj) 106 | end 107 | end) 108 | -------------------------------------------------------------------------------- /tests/langs/julia/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.jl' 4 | local LANG = 'julia' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "argument_list", preset default', 12 | cursor = { 2, 33 }, 13 | expected = { 3, 8 }, 14 | result = { 1, 6 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "vector_expression", preset default', 21 | cursor = { 11, 20 }, 22 | expected = { 12, 17 }, 23 | result = { 10, 15 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "matrix_expression", preset default', 30 | cursor = { 20, 25 }, 31 | expected = { 21, 25 }, 32 | result = { 19, 23 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "tuple_expression", preset default', 39 | cursor = { 28, 11 }, 40 | expected = { 29, 34 }, 41 | result = { 27, 32 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", node "argument_list" in "function_definition", preset default', 48 | cursor = { 37, 24 }, 49 | expected = { 42, 49 }, 50 | result = { 36, 43 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'split', 55 | lang = LANG, 56 | desc = 'lang "%s", node "comprehension_expression", preset default', 57 | cursor = { 52, 24 }, 58 | expected = { 53, 57 }, 59 | result = { 51, 55 }, 60 | }, 61 | { 62 | path = PATH, 63 | mode = 'split', 64 | lang = LANG, 65 | desc = 'lang "%s", node "call_expression", preset default', 66 | cursor = { 60, 12 }, 67 | expected = { 61, 64 }, 68 | result = { 59, 62 }, 69 | }, 70 | { 71 | path = PATH, 72 | mode = 'split', 73 | lang = LANG, 74 | desc = 'lang "%s", node "using_statement", preset default', 75 | cursor = { 67, 24 }, 76 | expected = { 68, 71 }, 77 | result = { 66, 69 }, 78 | }, 79 | { 80 | path = PATH, 81 | mode = 'split', 82 | lang = LANG, 83 | desc = 'lang "%s", node "selected_import", preset default', 84 | cursor = { 74, 24 }, 85 | expected = { 75, 79 }, 86 | result = { 73, 77 }, 87 | }, 88 | { 89 | path = PATH, 90 | mode = 'split', 91 | lang = LANG, 92 | desc = 'lang "%s", node "open_tuple", preset default', 93 | cursor = { 82, 6 }, 94 | expected = { 83, 88 }, 95 | result = { 81, 86 }, 96 | }, 97 | } 98 | 99 | local treesj = require('treesj') 100 | local opts = {} 101 | treesj.setup(opts) 102 | 103 | describe('TreeSJ SPLIT:', function() 104 | for _, value in ipairs(data_for_split) do 105 | tu._test_format(value, treesj) 106 | end 107 | end) 108 | -------------------------------------------------------------------------------- /tests/langs/kotlin/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.kt' 4 | local LANG = 'kotlin' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "collection_literal", preset default', 12 | cursor = { 6, 25 }, 13 | expected = { 3, 4 }, 14 | result = { 5, 6 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "value_arguments", preset default', 21 | cursor = { 17, 3 }, 22 | expected = { 12, 13 }, 23 | result = { 14, 15 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "statements", preset default', 30 | cursor = { 24, 24 }, 31 | expected = { 21, 22 }, 32 | result = { 23, 24 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "function_declaration" (parameters), preset default', 39 | cursor = { 38, 10 }, 40 | expected = { 29, 33 }, 41 | result = { 35, 39 }, 42 | }, 43 | } 44 | 45 | local treesj = require('treesj') 46 | local opts = {} 47 | treesj.setup(opts) 48 | 49 | describe('TreeSJ JOIN:', function() 50 | for _, value in ipairs(data_for_join) do 51 | tu._test_format(value, treesj) 52 | end 53 | end) 54 | -------------------------------------------------------------------------------- /tests/langs/kotlin/recursive_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index_recursive.kt' 4 | local LANG = 'kotlin' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "statements" with child with "shrink_node" option, preset default', 12 | cursor = { 2, 24 }, 13 | expected = { 3, 10 }, 14 | result = { 1, 8 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "statements" with child with "shrink_node" option, preset default', 21 | cursor = { 4, 24 }, 22 | expected = { 1, 2 }, 23 | result = { 3, 4 }, 24 | }, 25 | } 26 | 27 | local treesj = require('treesj') 28 | local opts = { 29 | langs = { 30 | kotlin = { 31 | statements = { 32 | split = { 33 | recursive = true, 34 | recursive_ignore = { 35 | 'value_arguments', 36 | 'function_value_parameters', 37 | }, 38 | }, 39 | }, 40 | }, 41 | }, 42 | } 43 | treesj.setup(opts) 44 | 45 | describe('TreeSJ SPLIT:', function() 46 | for _, value in ipairs(data_for_split) do 47 | tu._test_format(value, treesj) 48 | end 49 | end) 50 | -------------------------------------------------------------------------------- /tests/langs/kotlin/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.kt' 4 | local LANG = 'kotlin' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "collection_literal", preset default', 12 | cursor = { 4, 27 }, 13 | expected = { 5, 10 }, 14 | result = { 3, 8 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "value_arguments", preset default', 21 | cursor = { 13, 5 }, 22 | expected = { 14, 19 }, 23 | result = { 12, 17 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "statements", preset default', 30 | cursor = { 22, 25 }, 31 | expected = { 23, 27 }, 32 | result = { 21, 25 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "function_declaration (parameters)", preset default', 39 | cursor = { 30, 22 }, 40 | expected = { 35, 42 }, 41 | result = { 29, 36 }, 42 | }, 43 | } 44 | 45 | local treesj = require('treesj') 46 | local opts = {} 47 | treesj.setup(opts) 48 | 49 | describe('TreeSJ SPLIT:', function() 50 | for _, value in ipairs(data_for_split) do 51 | tu._test_format(value, treesj) 52 | end 53 | end) 54 | -------------------------------------------------------------------------------- /tests/langs/lua/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.lua' 4 | local LANG = 'lua' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "table_constructor" (list), preset default', 12 | cursor = { 8, 4 }, 13 | expected = { 3, 4 }, 14 | result = { 6, 7 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "table_constructor" (dict), preset default', 21 | cursor = { 19, 4 }, 22 | expected = { 14, 15 }, 23 | result = { 17, 18 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "table_constructor" (mixed type), preset default', 30 | cursor = { 30, 5 }, 31 | expected = { 25, 26 }, 32 | result = { 28, 29 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "arguments", preset default', 39 | cursor = { 42, 7 }, 40 | expected = { 37, 38 }, 41 | result = { 37, 38 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'join', 46 | lang = LANG, 47 | desc = 'lang "%s", node "parameters", preset default', 48 | cursor = { 54, 4 }, 49 | expected = { 46, 47 }, 50 | result = { 51, 52 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'join', 55 | lang = LANG, 56 | desc = 'lang "%s", node "block" in function_declaration contains nested functions, preset default', 57 | cursor = { 83, 15 }, 58 | expected = { 79, 80 }, 59 | result = { 82, 83 }, 60 | }, 61 | { 62 | path = PATH, 63 | mode = 'join', 64 | lang = LANG, 65 | desc = 'lang "%s", node "table_constructor" is empty, preset default', 66 | cursor = { 125, 0 }, 67 | expected = { 120, 121 }, 68 | result = { 123, 124 }, 69 | }, 70 | { 71 | path = PATH, 72 | mode = 'join', 73 | lang = LANG, 74 | desc = 'lang "%s", node "table_constructor" with empty table, preset default', 75 | cursor = { 137, 14 }, 76 | expected = { 134, 135 }, 77 | result = { 136, 137 }, 78 | }, 79 | } 80 | 81 | local treesj = require('treesj') 82 | local opts = {} 83 | treesj.setup(opts) 84 | 85 | describe('TreeSJ JOIN:', function() 86 | for _, value in ipairs(data_for_join) do 87 | tu._test_format(value, treesj) 88 | end 89 | end) 90 | -------------------------------------------------------------------------------- /tests/langs/lua/lua_no_empty_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.lua' 4 | local LANG = 'lua' 5 | 6 | local settings = { 7 | langs = { 8 | lua = { 9 | table_constructor = { 10 | both = { 11 | format_empty_node = false, 12 | }, 13 | }, 14 | }, 15 | }, 16 | } 17 | 18 | local data_for_split = { 19 | { 20 | path = PATH, 21 | mode = 'split', 22 | lang = LANG, 23 | desc = 'lang "%s", node "table_constructor" is empty, preset with format_empty_node = false', 24 | cursor = { 128, 14 }, 25 | expected = { 127, 128 }, 26 | result = { 127, 128 }, 27 | }, 28 | } 29 | 30 | local data_for_join = { 31 | { 32 | path = PATH, 33 | mode = 'join', 34 | lang = LANG, 35 | desc = 'lang "%s", node "table_constructor" is empty, preset with format_empty_node = false', 36 | cursor = { 132, 0 }, 37 | expected = { 130, 132 }, 38 | result = { 130, 132 }, 39 | }, 40 | } 41 | 42 | local treesj = require('treesj') 43 | local opts = { 44 | langs = { 45 | lua = { 46 | table_constructor = { 47 | both = { 48 | format_empty_node = false, 49 | }, 50 | }, 51 | }, 52 | }, 53 | } 54 | treesj.setup(opts) 55 | 56 | describe('TreeSJ SPLIT:', function() 57 | for _, value in ipairs(data_for_split) do 58 | tu._test_format(value, treesj) 59 | end 60 | end) 61 | 62 | describe('TreeSJ JOIN:', function() 63 | for _, value in ipairs(data_for_join) do 64 | tu._test_format(value, treesj) 65 | end 66 | end) 67 | -------------------------------------------------------------------------------- /tests/langs/lua/lua_rec_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.lua' 4 | local LANG = 'lua' 5 | 6 | local recursive = { 7 | split = { 8 | recursive = true, 9 | recursive_ignore = { 10 | 'arguments', 11 | 'parameters', 12 | }, 13 | }, 14 | } 15 | 16 | local settings = { 17 | langs = { 18 | lua = { 19 | block = { 20 | split = recursive.split, 21 | }, 22 | table_constructor = { 23 | split = recursive.split, 24 | }, 25 | }, 26 | }, 27 | } 28 | 29 | local data_for_split = { 30 | { 31 | path = PATH, 32 | mode = 'split', 33 | lang = LANG, 34 | desc = 'lang "%s", node "block" in function_declaration contains nested functions, preset with recursive', 35 | cursor = { 80, 15 }, 36 | expected = { 82, 92 }, 37 | result = { 79, 89 }, 38 | }, 39 | { 40 | path = PATH, 41 | mode = 'split', 42 | lang = LANG, 43 | desc = 'lang "%s", node "table_constructor" with nested "block", preset with recursive', 44 | cursor = { 95, 13 }, 45 | expected = { 97, 104 }, 46 | result = { 94, 101 }, 47 | }, 48 | { 49 | path = PATH, 50 | mode = 'split', 51 | lang = LANG, 52 | desc = 'lang "%s", node "table_constructor" with nested "table_constructor", preset with recursive', 53 | cursor = { 107, 13 }, 54 | expected = { 109, 118 }, 55 | result = { 106, 115 }, 56 | }, 57 | } 58 | 59 | local treesj = require('treesj') 60 | local opts = { 61 | langs = { 62 | lua = { 63 | block = { 64 | split = recursive.split, 65 | }, 66 | table_constructor = { 67 | split = recursive.split, 68 | }, 69 | }, 70 | }, 71 | } 72 | treesj.setup(opts) 73 | 74 | describe('TreeSJ SPLIT:', function() 75 | for _, value in ipairs(data_for_split) do 76 | tu._test_format(value, treesj) 77 | end 78 | end) 79 | -------------------------------------------------------------------------------- /tests/langs/lua/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.lua' 4 | local LANG = 'lua' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "table_constructor" (list), preset default', 12 | cursor = { 4, 16 }, 13 | expected = { 6, 11 }, 14 | result = { 3, 8 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "table_constructor" (dict), preset default', 21 | cursor = { 15, 18 }, 22 | expected = { 17, 23 }, 23 | result = { 14, 20 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "table_constructor" (mixed type), preset default', 30 | cursor = { 26, 19 }, 31 | expected = { 28, 35 }, 32 | result = { 25, 32 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "arguments", preset default', 39 | cursor = { 38, 12 }, 40 | expected = { 40, 44 }, 41 | result = { 37, 41 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", node "parameters", preset default', 48 | cursor = { 47, 23 }, 49 | expected = { 51, 56 }, 50 | result = { 46, 51 }, 51 | }, 52 | { 53 | path = PATH, 54 | mode = 'split', 55 | lang = LANG, 56 | desc = 'lang "%s", node "block" in if_statement, preset default', 57 | cursor = { 61, 15 }, 58 | expected = { 63, 68 }, 59 | result = { 60, 65 }, 60 | }, 61 | { 62 | path = PATH, 63 | mode = 'split', 64 | lang = LANG, 65 | desc = 'lang "%s", node "block" in function_declaration, preset default', 66 | cursor = { 71, 15 }, 67 | expected = { 73, 77 }, 68 | result = { 70, 74 }, 69 | }, 70 | { 71 | path = PATH, 72 | mode = 'split', 73 | lang = LANG, 74 | desc = 'lang "%s", node "table_constructor" is empty, preset default', 75 | cursor = { 121, 14 }, 76 | expected = { 123, 125 }, 77 | result = { 120, 122 }, 78 | }, 79 | { 80 | path = PATH, 81 | mode = 'split', 82 | lang = LANG, 83 | desc = 'lang "%s", node "table_constructor" with empty table, preset default', 84 | cursor = { 135, 14 }, 85 | expected = { 136, 140 }, 86 | result = { 134, 138 }, 87 | }, 88 | } 89 | 90 | local treesj = require('treesj') 91 | local opts = {} 92 | treesj.setup(opts) 93 | 94 | describe('TreeSJ SPLIT:', function() 95 | for _, value in ipairs(data_for_split) do 96 | tu._test_format(value, treesj) 97 | end 98 | end) 99 | -------------------------------------------------------------------------------- /tests/langs/lua/with_tab_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index_tab.lua' 4 | local LANG = 'lua' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "block" (with noexpandtab), preset default', 12 | cursor = { 2, 14 }, 13 | expected = { 4, 7 }, 14 | result = { 1, 4 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "table_constructor" (with noexpandtab), preset default', 21 | cursor = { 10, 15 }, 22 | expected = { 12, 19 }, 23 | result = { 9, 16 }, 24 | }, 25 | } 26 | 27 | local data_for_join = { 28 | { 29 | path = PATH, 30 | mode = 'join', 31 | lang = LANG, 32 | desc = 'lang "%s", node "block" (with noexpandtab), preset default', 33 | cursor = { 5, 14 }, 34 | expected = { 1, 2 }, 35 | result = { 4, 5 }, 36 | }, 37 | { 38 | path = PATH, 39 | mode = 'join', 40 | lang = LANG, 41 | desc = 'lang "%s", node "table_constructor" (with noexpandtab), preset default', 42 | cursor = { 13, 15 }, 43 | expected = { 9, 10 }, 44 | result = { 12, 13 }, 45 | }, 46 | } 47 | 48 | local treesj = require('treesj') 49 | local opts = {} 50 | treesj.setup(opts) 51 | 52 | vim.opt.expandtab = false 53 | 54 | describe('TreeSJ SPLIT:', function() 55 | for _, value in ipairs(data_for_split) do 56 | tu._test_format(value, treesj) 57 | end 58 | end) 59 | 60 | describe('TreeSJ JOIN:', function() 61 | for _, value in ipairs(data_for_join) do 62 | tu._test_format(value, treesj) 63 | end 64 | end) 65 | -------------------------------------------------------------------------------- /tests/langs/nix/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.nix' 4 | local LANG = 'nix' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "list_expression", preset default', 12 | cursor = { 10, 5 }, 13 | expected = { 4, 5 }, 14 | result = { 7, 8 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "binding_set", preset default', 21 | cursor = { 23, 7 }, 22 | expected = { 17, 18 }, 23 | result = { 20, 21 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "formals", preset default', 30 | cursor = { 37, 3 }, 31 | expected = { 30, 31 }, 32 | result = { 35, 36 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "let_expression", preset default', 39 | cursor = { 49, 6 }, 40 | expected = { 44, 45 }, 41 | result = { 48, 49 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'join', 46 | lang = LANG, 47 | desc = 'lang "%s", node "let_expression" with "attrset_expression", preset default', 48 | cursor = { 61, 6 }, 49 | expected = { 56, 57 }, 50 | result = { 60, 61 }, 51 | }, 52 | } 53 | 54 | local treesj = require('treesj') 55 | local opts = {} 56 | treesj.setup(opts) 57 | 58 | describe('TreeSJ JOIN:', function() 59 | for _, value in ipairs(data_for_join) do 60 | tu._test_format(value, treesj) 61 | end 62 | end) 63 | -------------------------------------------------------------------------------- /tests/langs/nix/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.nix' 4 | local LANG = 'nix' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "list_expression", preset default', 12 | cursor = { 5, 12 }, 13 | expected = { 7, 15 }, 14 | result = { 4, 12 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "binding_set", preset default', 21 | cursor = { 18, 12 }, 22 | expected = { 20, 25 }, 23 | result = { 17, 22 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "formals", preset default', 30 | cursor = { 31, 10 }, 31 | expected = { 35, 41 }, 32 | result = { 30, 36 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "let_expression", preset default', 39 | cursor = { 45, 6 }, 40 | expected = { 48, 53 }, 41 | result = { 44, 49 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", node "let_expression" with "attrset_expression", preset default', 48 | cursor = { 57, 6 }, 49 | expected = { 60, 69 }, 50 | result = { 56, 65 }, 51 | }, 52 | } 53 | 54 | local treesj = require('treesj') 55 | local opts = {} 56 | treesj.setup(opts) 57 | 58 | describe('TreeSJ SPLIT:', function() 59 | for _, value in ipairs(data_for_split) do 60 | tu._test_format(value, treesj) 61 | end 62 | end) 63 | -------------------------------------------------------------------------------- /tests/langs/perl/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.pl' 4 | local LANG = 'perl' 5 | local MODE = 'join' 6 | 7 | local data = { 8 | { 9 | path = PATH, 10 | mode = MODE, 11 | lang = LANG, 12 | desc = 'lang "%s", node "list_expression", preset default', 13 | cursor = { 7, 7 }, 14 | expected = { 3, 4 }, 15 | result = { 5, 6 }, 16 | }, 17 | { 18 | path = PATH, 19 | mode = MODE, 20 | lang = LANG, 21 | desc = 'lang "%s", "list_expression" with "=>" syntax, preset default', 22 | cursor = { 16, 7 }, 23 | expected = { 12, 13 }, 24 | result = { 14, 15 }, 25 | }, 26 | { 27 | path = PATH, 28 | mode = MODE, 29 | lang = LANG, 30 | desc = 'lang "%s", node "list_expression", preset default', 31 | cursor = { 24, 7 }, 32 | expected = { 20, 21 }, 33 | result = { 22, 23 }, 34 | }, 35 | { 36 | path = PATH, 37 | mode = MODE, 38 | lang = LANG, 39 | desc = 'lang "%s", node "list_expression", preset default', 40 | cursor = { 32, 7 }, 41 | expected = { 28, 29 }, 42 | result = { 30, 31 }, 43 | }, 44 | { 45 | path = PATH, 46 | mode = MODE, 47 | lang = LANG, 48 | desc = 'lang "%s", node "block", preset default', 49 | cursor = { 40, 7 }, 50 | expected = { 36, 37 }, 51 | result = { 38, 39 }, 52 | }, 53 | } 54 | 55 | local treesj = require('treesj') 56 | local opts = {} 57 | treesj.setup(opts) 58 | 59 | describe('TreeSJ ' .. MODE:upper() .. ':', function() 60 | for _, value in ipairs(data) do 61 | tu._test_format(value, treesj) 62 | end 63 | end) 64 | -------------------------------------------------------------------------------- /tests/langs/perl/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.pl' 4 | local LANG = 'perl' 5 | local MODE = 'split' 6 | 7 | local data = { 8 | { 9 | path = PATH, 10 | mode = MODE, 11 | lang = LANG, 12 | desc = 'lang "%s", node "list_expression", preset default', 13 | cursor = { 4, 20 }, 14 | expected = { 5, 10 }, 15 | result = { 3, 8 }, 16 | }, 17 | { 18 | path = PATH, 19 | mode = MODE, 20 | lang = LANG, 21 | desc = 'lang "%s", "list_expression" with "=>" syntax, preset default', 22 | cursor = { 13, 22 }, 23 | expected = { 14, 18 }, 24 | result = { 12, 16 }, 25 | }, 26 | { 27 | path = PATH, 28 | mode = MODE, 29 | lang = LANG, 30 | desc = 'lang "%s", node "list_expression", preset default', 31 | cursor = { 21, 22 }, 32 | expected = { 22, 26 }, 33 | result = { 20, 24 }, 34 | }, 35 | { 36 | path = PATH, 37 | mode = MODE, 38 | lang = LANG, 39 | desc = 'lang "%s", node "list_expression", preset default', 40 | cursor = { 29, 24 }, 41 | expected = { 30, 34 }, 42 | result = { 28, 32 }, 43 | }, 44 | { 45 | path = PATH, 46 | mode = MODE, 47 | lang = LANG, 48 | desc = 'lang "%s", node "block", preset default', 49 | cursor = { 37, 24 }, 50 | expected = { 38, 41 }, 51 | result = { 36, 39 }, 52 | }, 53 | } 54 | 55 | local treesj = require('treesj') 56 | local opts = {} 57 | treesj.setup(opts) 58 | 59 | describe('TreeSJ ' .. MODE:upper() .. ':', function() 60 | for _, value in ipairs(data) do 61 | tu._test_format(value, treesj) 62 | end 63 | end) 64 | -------------------------------------------------------------------------------- /tests/langs/php/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.php' 4 | local LANG = 'php' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "array_creation_expression", preset default', 12 | cursor = { 9, 2 }, 13 | expected = { 4, 5 }, 14 | result = { 7, 8 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "arguments", preset default', 21 | cursor = { 19, 2 }, 22 | expected = { 14, 15 }, 23 | result = { 17, 18 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "formal_parameters", preset default', 30 | cursor = { 31, 2 }, 31 | expected = { 24, 27 }, 32 | result = { 29, 32 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "compound_statement", preset default', 39 | cursor = { 42, 27 }, 40 | expected = { 38, 39 }, 41 | result = { 41, 42 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'join', 46 | lang = LANG, 47 | desc = 'lang "%s", node "expression_statement" with target "array_creation_expression", preset default', 48 | cursor = { 53, 0 }, 49 | expected = { 49, 50 }, 50 | result = { 52, 53 }, 51 | }, 52 | } 53 | 54 | local treesj = require('treesj') 55 | local opts = {} 56 | treesj.setup(opts) 57 | 58 | describe('TreeSJ JOIN:', function() 59 | for _, value in ipairs(data_for_join) do 60 | tu._test_format(value, treesj) 61 | end 62 | end) 63 | -------------------------------------------------------------------------------- /tests/langs/php/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.php' 4 | local LANG = 'php' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "array_creation_expression", preset default', 12 | cursor = { 5, 9 }, 13 | expected = { 7, 12 }, 14 | result = { 4, 9 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "arguments", preset default', 21 | cursor = { 15, 4 }, 22 | expected = { 17, 22 }, 23 | result = { 14, 19 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "formal_parameters", preset default', 30 | cursor = { 25, 13 }, 31 | expected = { 29, 36 }, 32 | result = { 24, 31 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "compound_statement", preset default', 39 | cursor = { 39, 27 }, 40 | expected = { 41, 47 }, 41 | result = { 38, 44 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", node "expression_statement" with target "array_creation_expression", preset default', 48 | cursor = { 50, 0 }, 49 | expected = { 52, 57 }, 50 | result = { 49, 54 }, 51 | }, 52 | } 53 | 54 | local treesj = require('treesj') 55 | local opts = {} 56 | treesj.setup(opts) 57 | 58 | describe('TreeSJ SPLIT:', function() 59 | for _, value in ipairs(data_for_split) do 60 | tu._test_format(value, treesj) 61 | end 62 | end) 63 | -------------------------------------------------------------------------------- /tests/langs/pug/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.pug' 4 | local LANG = 'pug' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "attributes", preset default', 12 | cursor = { 6, 21 }, 13 | expected = { 1, 2 }, 14 | result = { 4, 5 }, 15 | }, 16 | } 17 | 18 | local treesj = require('treesj') 19 | local opts = {} 20 | treesj.setup(opts) 21 | 22 | describe('TreeSJ JOIN:', function() 23 | for _, value in ipairs(data_for_join) do 24 | tu._test_format(value, treesj) 25 | end 26 | end) 27 | -------------------------------------------------------------------------------- /tests/langs/pug/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.pug' 4 | local LANG = 'pug' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "attributes", preset default', 12 | cursor = { 2, 26 }, 13 | expected = { 4, 8 }, 14 | result = { 1, 5 }, 15 | }, 16 | } 17 | 18 | local treesj = require('treesj') 19 | local opts = {} 20 | treesj.setup(opts) 21 | 22 | describe('TreeSJ SPLIT:', function() 23 | for _, value in ipairs(data_for_split) do 24 | tu._test_format(value, treesj) 25 | end 26 | end) 27 | -------------------------------------------------------------------------------- /tests/langs/r/r_join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.R' 4 | local LANG = 'R' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "arguments", cursor at arguments', 12 | cursor = { 6, 2 }, 13 | expected = { 1, 2 }, 14 | result = { 4, 5 }, 15 | }, 16 | 17 | { 18 | path = PATH, 19 | mode = 'join', 20 | lang = LANG, 21 | desc = 'lang "%s", node "arguments", cursor at subset', 22 | cursor = { 16, 2 }, 23 | expected = { 11, 12 }, 24 | result = { 14, 15 }, 25 | }, 26 | 27 | { 28 | path = PATH, 29 | mode = 'join', 30 | lang = LANG, 31 | desc = 'lang "%s", node "parameters"', 32 | cursor = { 26, 0 }, 33 | expected = { 20, 23 }, 34 | result = { 25, 28 }, 35 | }, 36 | 37 | { 38 | path = PATH, 39 | mode = 'join', 40 | lang = LANG, 41 | desc = 'lang "%s", node "left_assignment"', 42 | cursor = { 37, 7 }, 43 | expected = { 33, 34 }, 44 | result = { 36, 37 }, 45 | }, 46 | 47 | { 48 | path = PATH, 49 | mode = 'join', 50 | lang = LANG, 51 | desc = 'lang "%s", node "super_assignment"', 52 | cursor = { 49, 1 }, 53 | expected = { 45, 46 }, 54 | result = { 48, 49 }, 55 | }, 56 | 57 | { 58 | path = PATH, 59 | mode = 'join', 60 | lang = LANG, 61 | desc = 'lang "%s", node "right_assignment"', 62 | cursor = { 64, 5 }, 63 | expected = { 55, 56 }, 64 | result = { 58, 59 }, 65 | }, 66 | 67 | { 68 | path = PATH, 69 | mode = 'join', 70 | lang = LANG, 71 | desc = 'lang "%s", node "super_right_assignment"', 72 | cursor = { 74, 8 }, 73 | expected = { 66, 67 }, 74 | result = { 69, 70 }, 75 | }, 76 | 77 | { 78 | path = PATH, 79 | mode = 'join', 80 | lang = LANG, 81 | desc = 'lang "%s", node "equals_assignment"', 82 | cursor = { 80, 0 }, 83 | expected = { 76, 77 }, 84 | result = { 79, 80 }, 85 | }, 86 | 87 | { 88 | path = PATH, 89 | mode = 'join', 90 | lang = LANG, 91 | desc = 'lang "%s", node "function_definition"', 92 | cursor = { 94, 10 }, 93 | expected = { 86, 91 }, 94 | result = { 93, 98 }, 95 | }, 96 | 97 | { 98 | path = PATH, 99 | mode = 'join', 100 | lang = LANG, 101 | desc = 'lang "%s", node "call"', 102 | cursor = { 108, 2 }, 103 | expected = { 104, 105 }, 104 | result = { 107, 108 }, 105 | }, 106 | 107 | { 108 | path = PATH, 109 | mode = 'join', 110 | lang = LANG, 111 | desc = 'lang "%s", node "binary_operator"', 112 | cursor = { 118, 0 }, 113 | expected = { 112, 114 }, 114 | result = { 116, 118 }, 115 | }, 116 | 117 | { 118 | path = PATH, 119 | mode = 'join', 120 | lang = LANG, 121 | desc = 'lang "%s", node "pipe"', 122 | cursor = { 128, 0 }, 123 | expected = { 122, 124 }, 124 | result = { 126, 128 }, 125 | }, 126 | } 127 | 128 | local treesj = require('treesj') 129 | local opts = {} 130 | treesj.setup(opts) 131 | 132 | describe('TreeSJ JOIN:', function() 133 | for _, value in ipairs(data_for_join) do 134 | tu._test_format(value, treesj) 135 | end 136 | end) 137 | -------------------------------------------------------------------------------- /tests/langs/scss/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.scss' 4 | local LANG = 'scss' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "block", preset default', 12 | cursor = { 6, 9 }, 13 | expected = { 1, 2 }, 14 | result = { 4, 5 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "keyframe_block_list", preset default', 21 | cursor = { 17, 4 }, 22 | expected = { 12, 13 }, 23 | result = { 15, 16 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "arguments", preset default', 30 | cursor = { 33, 4 }, 31 | expected = { 24, 25 }, 32 | result = { 30, 31 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "block" (nested), preset default', 39 | cursor = { 56, 9 }, 40 | expected = { 51, 52 }, 41 | result = { 54, 55 }, 42 | }, 43 | } 44 | 45 | local treesj = require('treesj') 46 | local opts = {} 47 | treesj.setup(opts) 48 | 49 | describe('TreeSJ JOIN:', function() 50 | for _, value in ipairs(data_for_join) do 51 | tu._test_format(value, treesj) 52 | end 53 | end) 54 | -------------------------------------------------------------------------------- /tests/langs/scss/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.scss' 4 | local LANG = 'scss' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "block", preset default', 12 | cursor = { 2, 20 }, 13 | expected = { 4, 10 }, 14 | result = { 1, 7 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "keyframe_block_list", preset default', 21 | cursor = { 13, 25 }, 22 | expected = { 15, 20 }, 23 | result = { 12, 17 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "arguments", preset default', 30 | cursor = { 25, 23 }, 31 | expected = { 30, 48 }, 32 | result = { 24, 42 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "block" (nested), preset default', 39 | cursor = { 52, 18 }, 40 | expected = { 54, 58 }, 41 | result = { 51, 55 }, 42 | }, 43 | } 44 | 45 | local treesj = require('treesj') 46 | local opts = {} 47 | treesj.setup(opts) 48 | 49 | describe('TreeSJ SPLIT:', function() 50 | for _, value in ipairs(data_for_split) do 51 | tu._test_format(value, treesj) 52 | end 53 | end) 54 | -------------------------------------------------------------------------------- /tests/langs/sql/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.sql' 4 | local LANG = 'sql' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "column_definitions", preset default', 12 | cursor = { 4, 22 }, 13 | expected = { 1, 2 }, 14 | result = { 3, 4 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "list", preset default', 21 | cursor = { 13, 4 }, 22 | expected = { 9, 10 }, 23 | result = { 11, 12 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "select_expression", preset default', 30 | cursor = { 21, 10 }, 31 | expected = { 17, 19 }, 32 | result = { 20, 22 }, 33 | }, 34 | } 35 | 36 | local treesj = require('treesj') 37 | local opts = {} 38 | treesj.setup(opts) 39 | 40 | describe('TreeSJ JOIN:', function() 41 | for _, value in ipairs(data_for_join) do 42 | tu._test_format(value, treesj) 43 | end 44 | end) 45 | -------------------------------------------------------------------------------- /tests/langs/sql/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.sql' 4 | local LANG = 'sql' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "column_definitions", preset default', 12 | cursor = { 2, 25 }, 13 | expected = { 3, 7 }, 14 | result = { 1, 5 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "list", preset default', 21 | cursor = { 10, 25 }, 22 | expected = { 11, 15 }, 23 | result = { 9, 13 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "select_expression", preset default', 30 | cursor = { 18, 23 }, 31 | expected = { 20, 24 }, 32 | result = { 17, 21 }, 33 | }, 34 | } 35 | 36 | local treesj = require('treesj') 37 | local opts = {} 38 | treesj.setup(opts) 39 | 40 | describe('TreeSJ SPLIT:', function() 41 | for _, value in ipairs(data_for_split) do 42 | tu._test_format(value, treesj) 43 | end 44 | end) 45 | -------------------------------------------------------------------------------- /tests/langs/svelte/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.svelte' 4 | local LANG = 'svelte' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "self_closing_tag", preset default', 12 | cursor = { 7, 11 }, 13 | expected = { 3, 4 }, 14 | result = { 6, 7 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "element", preset default', 21 | cursor = { 16, 6 }, 22 | expected = { 11, 12 }, 23 | result = { 14, 15 }, 24 | }, 25 | } 26 | 27 | local treesj = require('treesj') 28 | local opts = {} 29 | treesj.setup(opts) 30 | 31 | describe('TreeSJ JOIN:', function() 32 | for _, value in ipairs(data_for_join) do 33 | tu._test_format(value, treesj) 34 | end 35 | end) 36 | -------------------------------------------------------------------------------- /tests/langs/svelte/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.svelte' 4 | local LANG = 'svelte' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "self_closing_tag", preset default', 12 | cursor = { 4, 10 }, 13 | expected = { 6, 9 }, 14 | result = { 3, 6 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "element", preset default', 21 | cursor = { 12, 10 }, 22 | expected = { 14, 17 }, 23 | result = { 11, 14 }, 24 | }, 25 | } 26 | 27 | local treesj = require('treesj') 28 | local opts = {} 29 | treesj.setup(opts) 30 | 31 | describe('TreeSJ SPLIT:', function() 32 | for _, value in ipairs(data_for_split) do 33 | tu._test_format(value, treesj) 34 | end 35 | end) 36 | -------------------------------------------------------------------------------- /tests/langs/template/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.TYPE_OF_FILE' 4 | local LANG = 'NAME_OF_LANGUAGE' 5 | local MODE = 'join' 6 | 7 | local data = { 8 | { 9 | path = PATH, 10 | mode = MODE, 11 | lang = LANG, 12 | desc = 'lang "%s", node "array", preset default', 13 | cursor = { 1, 0 }, 14 | expected = { 0, 0 }, 15 | result = { 0, 0 }, 16 | }, 17 | } 18 | 19 | local treesj = require('treesj') 20 | local opts = {} 21 | treesj.setup(opts) 22 | 23 | describe('TreeSJ ' .. MODE:upper() .. ':', function() 24 | for _, value in ipairs(data) do 25 | tu._test_format(value, treesj) 26 | end 27 | end) 28 | -------------------------------------------------------------------------------- /tests/langs/template/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.TYPE_OF_FILE' 4 | local LANG = 'NAME_OF_LANGUAGE' 5 | local MODE = 'split' 6 | 7 | local data = { 8 | { 9 | path = PATH, 10 | mode = MODE, 11 | lang = LANG, 12 | desc = 'lang "%s", node "array", preset default', 13 | cursor = { 1, 0 }, 14 | expected = { 0, 0 }, 15 | result = { 0, 0 }, 16 | }, 17 | } 18 | 19 | local treesj = require('treesj') 20 | local opts = {} 21 | treesj.setup(opts) 22 | 23 | describe('TreeSJ ' .. MODE:upper() .. ':', function() 24 | for _, value in ipairs(data) do 25 | tu._test_format(value, treesj) 26 | end 27 | end) 28 | -------------------------------------------------------------------------------- /tests/langs/terraform/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.tf' 4 | local LANG = 'terraform' 5 | local MODE = 'join' 6 | 7 | local data = { 8 | { 9 | path = PATH, 10 | mode = MODE, 11 | lang = LANG, 12 | desc = 'lang "%s", node "tuple", preset default', 13 | result = { 5, 6 }, 14 | cursor = { 7, 5 }, 15 | expected = { 2, 3 }, 16 | }, 17 | { 18 | path = PATH, 19 | mode = MODE, 20 | lang = LANG, 21 | desc = 'lang "%s", node "object", preset default', 22 | cursor = { 18, 10 }, 23 | result = { 15, 16 }, 24 | expected = { 12, 13 }, 25 | }, 26 | { 27 | path = PATH, 28 | mode = MODE, 29 | lang = LANG, 30 | desc = 'lang "%s", node "function_call", preset default', 31 | cursor = { 26, 11 }, 32 | result = { 25, 26 }, 33 | expected = { 22, 23 }, 34 | }, 35 | { 36 | path = PATH, 37 | mode = MODE, 38 | lang = LANG, 39 | desc = 'lang "%s", node "function_arguments", preset default', 40 | cursor = { 27, 8 }, 41 | result = { 25, 26 }, 42 | expected = { 22, 23 }, 43 | }, 44 | } 45 | 46 | local treesj = require('treesj') 47 | local opts = {} 48 | treesj.setup(opts) 49 | 50 | describe('TreeSJ ' .. MODE:upper() .. ':', function() 51 | for _, value in ipairs(data) do 52 | tu._test_format(value, treesj) 53 | end 54 | end) 55 | -------------------------------------------------------------------------------- /tests/langs/terraform/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.tf' 4 | local LANG = 'terraform' 5 | local MODE = 'split' 6 | 7 | local data = { 8 | { 9 | path = PATH, 10 | mode = MODE, 11 | lang = LANG, 12 | desc = 'lang "%s", node "tuple", preset default', 13 | cursor = { 3, 12}, 14 | result = { 2, 7 }, 15 | expected = { 5, 10}, 16 | }, 17 | { 18 | path = PATH, 19 | mode = MODE, 20 | lang = LANG, 21 | desc = 'lang "%s", node "object", preset default', 22 | cursor = { 13, 33 }, 23 | result = { 12, 17 }, 24 | expected = { 15, 20 }, 25 | }, 26 | { 27 | path = PATH, 28 | mode = MODE, 29 | lang = LANG, 30 | desc = 'lang "%s", node "function_call", preset default', 31 | cursor = { 23, 11 }, 32 | result = { 22, 27 }, 33 | expected = { 25, 30 }, 34 | }, 35 | { 36 | path = PATH, 37 | mode = MODE, 38 | lang = LANG, 39 | desc = 'lang "%s", node "function_arguments", preset default', 40 | cursor = { 23, 18 }, 41 | result = { 22, 27 }, 42 | expected = { 25, 30 }, 43 | }, 44 | } 45 | 46 | local treesj = require('treesj') 47 | local opts = {} 48 | treesj.setup(opts) 49 | 50 | describe('TreeSJ ' .. MODE:upper() .. ':', function() 51 | for _, value in ipairs(data) do 52 | tu._test_format(value, treesj) 53 | end 54 | end) 55 | -------------------------------------------------------------------------------- /tests/langs/toml/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.toml' 4 | local LANG = 'toml' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "array", preset default', 12 | cursor = { 4, 11 }, 13 | expected = { 1, 2 }, 14 | result = { 3, 4 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "array" (mix type), preset default', 21 | cursor = { 16, 10 }, 22 | expected = { 13, 14 }, 23 | result = { 15, 16 }, 24 | }, 25 | } 26 | 27 | local treesj = require('treesj') 28 | local opts = {} 29 | treesj.setup(opts) 30 | 31 | describe('TreeSJ JOIN:', function() 32 | for _, value in ipairs(data_for_join) do 33 | tu._test_format(value, treesj) 34 | end 35 | end) 36 | -------------------------------------------------------------------------------- /tests/langs/toml/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.toml' 4 | local LANG = 'toml' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "array", preset default', 12 | cursor = { 2, 13 }, 13 | expected = { 3, 11 }, 14 | result = { 1, 9 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "array" (mix type), preset default', 21 | cursor = { 14, 10 }, 22 | expected = { 15, 19 }, 23 | result = { 13, 17 }, 24 | }, 25 | } 26 | 27 | local treesj = require('treesj') 28 | local opts = {} 29 | treesj.setup(opts) 30 | 31 | describe('TreeSJ SPLIT:', function() 32 | for _, value in ipairs(data_for_split) do 33 | tu._test_format(value, treesj) 34 | end 35 | end) 36 | -------------------------------------------------------------------------------- /tests/langs/typescript/tsx_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.tsx' 4 | local LANG = 'tsx' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "object_pattern", preset default', 12 | cursor = { 3, 19 }, 13 | expected = { 4, 12 }, 14 | result = { 2, 10 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "array", preset default', 21 | cursor = { 14, 17 }, 22 | expected = { 15, 20 }, 23 | result = { 13, 18 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "jsx_self_closing_element", preset default', 30 | cursor = { 24, 20 }, 31 | expected = { 25, 31 }, 32 | result = { 23, 29 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "jsx_opening_element", preset default', 39 | cursor = { 33, 16 }, 40 | expected = { 34, 40 }, 41 | result = { 32, 38 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", node "jsx_element", preset default', 48 | cursor = { 42, 83 }, 49 | expected = { 43, 46 }, 50 | result = { 41, 44 }, 51 | }, 52 | } 53 | 54 | local data_for_join = { 55 | { 56 | path = PATH, 57 | mode = 'join', 58 | lang = LANG, 59 | desc = 'lang "%s", node "object_pattern", preset default', 60 | cursor = { 6, 8 }, 61 | expected = { 2, 3 }, 62 | result = { 4, 5 }, 63 | }, 64 | { 65 | path = PATH, 66 | mode = 'join', 67 | lang = LANG, 68 | desc = 'lang "%s", node "array", preset default', 69 | cursor = { 17, 4 }, 70 | expected = { 13, 14 }, 71 | result = { 15, 16 }, 72 | }, 73 | { 74 | path = PATH, 75 | mode = 'join', 76 | lang = LANG, 77 | desc = 'lang "%s", node "jsx_self_closing_element", preset default', 78 | cursor = { 27, 12 }, 79 | expected = { 23, 24 }, 80 | result = { 25, 26 }, 81 | }, 82 | { 83 | path = PATH, 84 | mode = 'join', 85 | lang = LANG, 86 | desc = 'lang "%s", node "jsx_opening_element", preset default', 87 | cursor = { 36, 14 }, 88 | expected = { 32, 33 }, 89 | result = { 34, 35 }, 90 | }, 91 | { 92 | path = PATH, 93 | mode = 'join', 94 | lang = LANG, 95 | desc = 'lang "%s", node "jsx_element", preset default', 96 | cursor = { 45, 9 }, 97 | expected = { 41, 42 }, 98 | result = { 43, 44 }, 99 | }, 100 | } 101 | 102 | local treesj = require('treesj') 103 | local opts = {} 104 | treesj.setup(opts) 105 | 106 | describe('TreeSJ SPLIT:', function() 107 | for _, value in ipairs(data_for_split) do 108 | tu._test_format(value, treesj) 109 | end 110 | end) 111 | 112 | describe('TreeSJ JOIN:', function() 113 | for _, value in ipairs(data_for_join) do 114 | tu._test_format(value, treesj) 115 | end 116 | end) 117 | -------------------------------------------------------------------------------- /tests/langs/vue/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.vue' 4 | local LANG = 'vue' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "start_tag", preset default', 12 | cursor = { 8, 9 }, 13 | expected = { 3, 4 }, 14 | result = { 6, 7 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "self_closing_tag", preset default', 21 | cursor = { 17, 8 }, 22 | expected = { 12, 13 }, 23 | result = { 15, 16 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "element", preset default', 30 | cursor = { 26, 6 }, 31 | expected = { 21, 22 }, 32 | result = { 24, 25 }, 33 | }, 34 | } 35 | 36 | local treesj = require('treesj') 37 | local opts = {} 38 | treesj.setup(opts) 39 | 40 | describe('TreeSJ JOIN:', function() 41 | for _, value in ipairs(data_for_join) do 42 | tu._test_format(value, treesj) 43 | end 44 | end) 45 | -------------------------------------------------------------------------------- /tests/langs/vue/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.vue' 4 | local LANG = 'vue' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "start_tag", preset default', 12 | cursor = { 4, 18 }, 13 | expected = { 6, 10 }, 14 | result = { 3, 7 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "self_closing_tag", preset default', 21 | cursor = { 13, 17 }, 22 | expected = { 15, 19 }, 23 | result = { 12, 16 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "element", preset default', 30 | cursor = { 22, 59 }, 31 | expected = { 24, 27 }, 32 | result = { 21, 24 }, 33 | }, 34 | } 35 | 36 | local treesj = require('treesj') 37 | local opts = {} 38 | treesj.setup(opts) 39 | 40 | describe('TreeSJ SPLIT:', function() 41 | for _, value in ipairs(data_for_split) do 42 | tu._test_format(value, treesj) 43 | end 44 | end) 45 | -------------------------------------------------------------------------------- /tests/langs/yaml/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.yml' 4 | local LANG = 'yaml' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "block_mapping", preset default', 12 | cursor = { 4, 8 }, 13 | expected = { 0, 1 }, 14 | result = { 2, 3 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "block_sequence", preset default', 21 | cursor = { 10, 5 }, 22 | expected = { 6, 7 }, 23 | result = { 8, 9 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "block_mapping" (mixed), preset default', 30 | cursor = { 16, 7 }, 31 | expected = { 12, 13 }, 32 | result = { 14, 15 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "block_sequence" (mixed), preset default', 39 | cursor = { 24, 7 }, 40 | expected = { 20, 21 }, 41 | result = { 22, 23 }, 42 | }, 43 | } 44 | 45 | local treesj = require('treesj') 46 | local opts = {} 47 | treesj.setup(opts) 48 | 49 | describe('TreeSJ JOIN:', function() 50 | for _, value in ipairs(data_for_join) do 51 | tu._test_format(value, treesj) 52 | end 53 | end) 54 | -------------------------------------------------------------------------------- /tests/langs/yaml/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.yml' 4 | local LANG = 'yaml' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "flow_mapping", preset default', 12 | cursor = { 1, 6 }, 13 | expected = { 2, 5 }, 14 | result = { 0, 3 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "flow_sequence", preset default', 21 | cursor = { 7, 8 }, 22 | expected = { 8, 11 }, 23 | result = { 6, 9 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "flow_mapping" (mixed), preset default', 30 | cursor = { 13, 8 }, 31 | expected = { 14, 19 }, 32 | result = { 12, 17 }, 33 | }, 34 | } 35 | 36 | local treesj = require('treesj') 37 | local opts = {} 38 | treesj.setup(opts) 39 | 40 | describe('TreeSJ SPLIT:', function() 41 | for _, value in ipairs(data_for_split) do 42 | tu._test_format(value, treesj) 43 | end 44 | end) 45 | -------------------------------------------------------------------------------- /tests/langs/zig/join_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.zig' 4 | local LANG = 'zig' 5 | 6 | local data_for_join = { 7 | { 8 | path = PATH, 9 | mode = 'join', 10 | lang = LANG, 11 | desc = 'lang "%s", node "parameter_list", preset default', 12 | cursor = { 5, 1 }, 13 | expected = { 1, 2 }, 14 | result = { 3, 4 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'join', 19 | lang = LANG, 20 | desc = 'lang "%s", node "argument_list", preset default', 21 | cursor = { 14, 1 }, 22 | expected = { 10, 11 }, 23 | result = { 12, 13 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'join', 28 | lang = LANG, 29 | desc = 'lang "%s", node "initializer_list", preset default', 30 | cursor = { 23, 1 }, 31 | expected = { 19, 20 }, 32 | result = { 21, 22 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'join', 37 | lang = LANG, 38 | desc = 'lang "%s", node "enumerator_list", preset default', 39 | cursor = { 34, 1 }, 40 | expected = { 30, 31 }, 41 | result = { 32, 33 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'join', 46 | lang = LANG, 47 | desc = 'lang "%s", node "struct_declaration", preset default', 48 | cursor = { 44, 1 }, 49 | expected = { 40, 41 }, 50 | result = { 42, 43 }, 51 | }, 52 | } 53 | 54 | local treesj = require('treesj') 55 | local opts = {} 56 | treesj.setup(opts) 57 | 58 | describe('TreeSJ JOIN:', function() 59 | for _, value in ipairs(data_for_join) do 60 | tu._test_format(value, treesj) 61 | end 62 | end) 63 | -------------------------------------------------------------------------------- /tests/langs/zig/split_spec.lua: -------------------------------------------------------------------------------- 1 | local tu = require('tests.utils') 2 | 3 | local PATH = './tests/sample/index.zig' 4 | local LANG = 'zig' 5 | 6 | local data_for_split = { 7 | { 8 | path = PATH, 9 | mode = 'split', 10 | lang = LANG, 11 | desc = 'lang "%s", node "parameter_list", preset default', 12 | cursor = { 2, 7 }, 13 | expected = { 3, 8 }, 14 | result = { 1, 6 }, 15 | }, 16 | { 17 | path = PATH, 18 | mode = 'split', 19 | lang = LANG, 20 | desc = 'lang "%s", node "argument_list", preset default', 21 | cursor = { 11, 14 }, 22 | expected = { 12, 17 }, 23 | result = { 10, 15 }, 24 | }, 25 | { 26 | path = PATH, 27 | mode = 'split', 28 | lang = LANG, 29 | desc = 'lang "%s", node "initializer_list", preset default', 30 | cursor = { 20, 25 }, 31 | expected = { 21, 28 }, 32 | result = { 19, 26 }, 33 | }, 34 | { 35 | path = PATH, 36 | mode = 'split', 37 | lang = LANG, 38 | desc = 'lang "%s", node "enumerator_list", preset default', 39 | cursor = { 31, 24 }, 40 | expected = { 32, 38 }, 41 | result = { 30, 36 }, 42 | }, 43 | { 44 | path = PATH, 45 | mode = 'split', 46 | lang = LANG, 47 | desc = 'lang "%s", node "struct_declaration", preset default', 48 | cursor = { 41, 22 }, 49 | expected = { 42, 47 }, 50 | result = { 40, 45 }, 51 | }, 52 | } 53 | 54 | local treesj = require('treesj') 55 | local opts = {} 56 | treesj.setup(opts) 57 | 58 | describe('TreeSJ SPLIT:', function() 59 | for _, value in ipairs(data_for_split) do 60 | tu._test_format(value, treesj) 61 | end 62 | end) 63 | -------------------------------------------------------------------------------- /tests/minimal.lua: -------------------------------------------------------------------------------- 1 | -- Based on https://github.com/folke/lazy.nvim/blob/3bde7b5ba8b99941b314a75d8650a0a6c8552144/tests/init.lua 2 | 3 | local CWD = vim.loop.cwd() .. '/' 4 | 5 | vim.opt.shiftwidth = 2 6 | vim.opt.writebackup = false 7 | vim.opt.swapfile = false 8 | vim.opt.shadafile = 'NONE' 9 | vim.opt.expandtab = true 10 | 11 | vim.cmd([[set runtimepath=$VIMRUNTIME]]) 12 | vim.opt.runtimepath:append(CWD) 13 | vim.opt.packpath = { CWD .. '.tests/site' } 14 | 15 | local dependencies = { 16 | 'nvim-lua/plenary.nvim', 17 | 'nvim-treesitter/nvim-treesitter', 18 | } 19 | 20 | local function install_dep(plugin) 21 | local name = plugin:match('.*/(.*)') 22 | local package_root = CWD .. '.tests/site/pack/deps/start/' 23 | if not vim.loop.fs_stat(package_root .. name) then 24 | vim.fn.mkdir(package_root, 'p') 25 | vim.fn.system({ 26 | 'git', 27 | 'clone', 28 | '--depth=1', 29 | 'https://github.com/' .. plugin .. '.git', 30 | package_root .. '/' .. name, 31 | }) 32 | end 33 | end 34 | 35 | for _, plugin in ipairs(dependencies) do 36 | install_dep(plugin) 37 | end 38 | 39 | vim.api.nvim_create_autocmd('FileType', { 40 | callback = function() 41 | if vim.bo.filetype == 'go' then 42 | vim.bo.expandtab = false 43 | end 44 | end, 45 | }) 46 | 47 | require('plenary.busted') 48 | require('nvim-treesitter.configs').setup({ 49 | ensure_installed = require('treesj.langs').configured_langs, 50 | sync_install = true, 51 | }) 52 | -------------------------------------------------------------------------------- /tests/sample/index.R: -------------------------------------------------------------------------------- 1 | # RESULT OF JOIN (node "arguments", cursor at arguments) 2 | c(1, 2, 3) 3 | 4 | # RESULT OF SPLIT (node "arguments", cursor at arguments) 5 | c( 6 | 1, 7 | 2, 8 | 3 9 | ) 10 | 11 | # RESULT OF JOIN (node "arguments", cursor at subset) 12 | mean(x[, 1], na.rm = TRUE) 13 | 14 | # RESULT OF SPLIT (node "arguments", cursor at subset) 15 | mean( 16 | x[, 1], 17 | na.rm = TRUE 18 | ) 19 | 20 | # RESULT OF JOIN (node "parameters") 21 | my_func <- function(xs = x[, 1], ys = y[, 2]) { 22 | sum(xs, ys) 23 | } 24 | 25 | # RESULT OF SPLIT (node "parameters") 26 | my_func <- function( 27 | xs = x[, 1], 28 | ys = y[, 2] 29 | ) { 30 | sum(xs, ys) 31 | } 32 | 33 | # RESULT OF JOIN (node "left_assignment") 34 | mylist <- list(r = "red", g = "green", b = "blue", c(1, 2, 3), matrix(1:9, nrow = 3)) 35 | 36 | # RESULT OF SPLIT (node "left_assignment") 37 | mylist <- list( 38 | r = "red", 39 | g = "green", 40 | b = "blue", 41 | c(1, 2, 3), 42 | matrix(1:9, nrow = 3) 43 | ) 44 | 45 | # RESULT OF JOIN (node "super_assignment") 46 | sa <<- c(1, 2, 3) 47 | 48 | # RESULT OF SPLIT (node "super_assignment") 49 | sa <<- c( 50 | 1, 51 | 2, 52 | 3 53 | ) 54 | 55 | # RESULT OF JOIN (node "right_assignment") 56 | c(1, 2, 3, 4) -> ra 57 | 58 | # RESULT OF SPLIT (node "right_assignment") 59 | c( 60 | 1, 61 | 2, 62 | 3, 63 | 4 64 | ) -> ra 65 | 66 | # RESULT OF JOIN (node "super_right_assignment") 67 | c("a", "b", "c") ->> sra 68 | 69 | # RESULT OF SPLIT (node "super_right_assignment") 70 | c( 71 | "a", 72 | "b", 73 | "c" 74 | ) ->> sra 75 | 76 | # RESULT OF JOIN (node "equals_assignment") 77 | ea = c(1, 2, 3) 78 | 79 | # RESULT OF SPLIT (node "equals_assignment") 80 | ea = c( 81 | 1, 82 | 2, 83 | 3 84 | ) 85 | 86 | # RESULT OF JOIN (node "function_definition") 87 | max_by <- function(data, var, by) { 88 | data %>% 89 | group_by({{ by }}) %>% 90 | summarise(maximum = max({{ var }}, na.rm = TRUE)) 91 | } 92 | 93 | # RESULT OF SPLIT (node "function_definition") 94 | max_by <- function( 95 | data, 96 | var, 97 | by 98 | ) { 99 | data %>% 100 | group_by({{ by }}) %>% 101 | summarise(maximum = max({{ var }}, na.rm = TRUE)) 102 | } 103 | 104 | # RESULT OF JOIN (node "call") 105 | ggplot(aes(x = Sepal.Width, y = Sepal.Length)) 106 | 107 | # RESULT OF SPLIT (node "call") 108 | ggplot( 109 | aes(x = Sepal.Width, y = Sepal.Length) 110 | ) 111 | 112 | # RESULT OF JOIN (node "binary_operator") 113 | b %>% 114 | sum(c(4, 5, 6)) 115 | 116 | # RESULT OF SPLIT (node "binary_operator") 117 | b %>% 118 | sum( 119 | c(4, 5, 6) 120 | ) 121 | 122 | # RESULT OF JOIN (node "pipe") 123 | b |> 124 | sum(c(4, 5, 6)) 125 | 126 | # RESULT OF SPLIT (node "pipe") 127 | b |> 128 | sum( 129 | c(4, 5, 6) 130 | ) 131 | -------------------------------------------------------------------------------- /tests/sample/index.c: -------------------------------------------------------------------------------- 1 | // RESULT OF JOIN (node "parameter_list", preset default) 2 | void foo(int x, int y, int z); 3 | // RESULT OF SPLIT (node "parameter_list", preset default) 4 | void foo( 5 | int x, 6 | int y, 7 | int z 8 | ); 9 | 10 | // RESULT OF JOIN (node "argument_list", preset default) 11 | foo(1, 2, 3); 12 | // RESULT OF SPLIT (node "argument_list", preset default) 13 | foo( 14 | 1, 15 | 2, 16 | 3 17 | ); 18 | 19 | // RESULT OF JOIN (node "initializer_list", preset default) 20 | int arr[] = { 1, 2, 3, 4, 5 }; 21 | // RESULT OF SPLIT (node "initializer_list", preset default) 22 | int arr[] = { 23 | 1, 24 | 2, 25 | 3, 26 | 4, 27 | 5, 28 | }; 29 | 30 | // RESULT OF JOIN (node "compound_statement") 31 | void bar() { return; } 32 | // RESULT OF SPLIT (node "compound_statement") 33 | void bar() { 34 | return; 35 | } 36 | 37 | // RESULT OF JOIN (node "enumerator_list", preset default) 38 | enum Color { Red, Green, Blue }; 39 | // RESULT OF SPLIT (node "enumerator_list", preset default) 40 | enum Color { 41 | Red, 42 | Green, 43 | Blue, 44 | }; 45 | -------------------------------------------------------------------------------- /tests/sample/index.cpp: -------------------------------------------------------------------------------- 1 | // RESULT OF JOIN (node "parameter_list", preset default) 2 | void foo(int x, int y, int z); 3 | // RESULT OF SPLIT (node "parameter_list", preset default) 4 | void foo( 5 | int x, 6 | int y, 7 | int z 8 | ); 9 | 10 | // RESULT OF JOIN (node "argument_list", preset default) 11 | foo(1, 2, 3); 12 | // RESULT OF SPLIT (node "argument_list", preset default) 13 | foo( 14 | 1, 15 | 2, 16 | 3 17 | ); 18 | 19 | // RESULT OF JOIN (node "template_parameter_list", preset default) 20 | template 21 | struct Foo {}; 22 | // RESULT OF SPLIT (node "template_parameter_list", preset default) 23 | template < 24 | class T, 25 | class U 26 | > 27 | struct Foo {}; 28 | 29 | // RESULT OF JOIN (node "template_argument_list", preset default) 30 | Foo foo; 31 | // RESULT OF SPLIT (node "template_argument_list", preset default) 32 | Foo< 33 | int, 34 | float 35 | > foo; 36 | 37 | // RESULT OF JOIN (node "enumerator_list", preset default) 38 | enum class Color { Red, Green, Blue }; 39 | // RESULT OF SPLIT (node "enumerator_list", preset default) 40 | enum class Color { 41 | Red, 42 | Green, 43 | Blue, 44 | }; 45 | 46 | // RESULT OF JOIN (node "initializer_list", preset default) 47 | int arr[] = { 1, 2, 3, 4, 5 }; 48 | // RESULT OF SPLIT (node "initializer_list", preset default) 49 | int arr[] = { 50 | 1, 51 | 2, 52 | 3, 53 | 4, 54 | 5, 55 | }; 56 | 57 | // RESULT OF JOIN (node "compound_statement") 58 | void bar() { return; } 59 | // RESULT OF SPLIT (node "compound_statement") 60 | void bar() { 61 | return; 62 | } 63 | -------------------------------------------------------------------------------- /tests/sample/index.css: -------------------------------------------------------------------------------- 1 | /* RESULT OF JOIN (node "block", preset default) */ 2 | .container { display: flex; flex-direction: column; justify-content: space-between; align-items: start; } 3 | 4 | /* RESULT OF SPLIT (node "block", preset default) */ 5 | .container { 6 | display: flex; 7 | flex-direction: column; 8 | justify-content: space-between; 9 | align-items: start; 10 | } 11 | 12 | /* RESULT OF JOIN (node "keyframe_block_list", preset default) */ 13 | @keyframes animation { from { margin-top: 50px; } 50% { margin-top: 150px !important; } to { margin-top: 100px; } } 14 | 15 | /* RESULT OF SPLIT (node "keyframe_block_list", preset default) */ 16 | @keyframes animation { 17 | from { margin-top: 50px; } 18 | 50% { margin-top: 150px !important; } 19 | to { margin-top: 100px; } 20 | } 21 | 22 | /* RESULT OF JOIN (node "arguments", preset default) */ 23 | div { 24 | background: repeating-linear-gradient(red, orange, 50px); 25 | clip-path: polygon(50%, 0%, 60%, 40%, 100%, 50%, 60%, 60%, 50%, 100%, 40%, 60%, 0%, 50%, 40%, 40%); 26 | } 27 | 28 | /* RESULT OF SPLIT (node "arguments", preset default) */ 29 | div { 30 | background: repeating-linear-gradient(red, orange, 50px); 31 | clip-path: polygon( 32 | 50%, 33 | 0%, 34 | 60%, 35 | 40%, 36 | 100%, 37 | 50%, 38 | 60%, 39 | 60%, 40 | 50%, 41 | 100%, 42 | 40%, 43 | 60%, 44 | 0%, 45 | 50%, 46 | 40%, 47 | 40% 48 | ); 49 | } 50 | -------------------------------------------------------------------------------- /tests/sample/index.dart: -------------------------------------------------------------------------------- 1 | // RESULT OF JOIN (node "list_literal", preset default) 2 | const list = [ "1", "2", "3" ]; 3 | // RESULT OF SPLIT (node "list_literal", preset default) 4 | const list = [ 5 | "1", 6 | "2", 7 | "3", 8 | ]; 9 | 10 | // RESULT OF JOIN (node "list_literal" with const, preset default) 11 | var list2 = const [ "a", "b" ]; 12 | // RESULT OF SPLIT (node "list_literal" with const, preset default) 13 | var list2 = const [ 14 | "a", 15 | "b", 16 | ]; 17 | 18 | // RESULT OF JOIN (node "set_or_map_literal", preset default) 19 | const map = { "key": "value", "key2": "value2" }; 20 | // RESULT OF SPLIT (node "set_or_map_literal", preset default) 21 | const map = { 22 | "key": "value", 23 | "key2": "value2", 24 | }; 25 | 26 | // RESULT OF JOIN (node "block", preset default) 27 | func() { print(map["key"]); print(list[0]); } 28 | // RESULT OF SPLIT (node "block", preset default) 29 | func() { 30 | print(map["key"]); 31 | print(list[0]); 32 | } 33 | 34 | // RESULT OF JOIN (node "arguments", preset default) 35 | print(a, b); 36 | // RESULT OF SPLIT (node "arguments", preset default) 37 | print( 38 | a, 39 | b 40 | ); 41 | 42 | // RESULT OF JOIN (node "formal_parameter_list", preset default) 43 | func2(one, two) { print(one, two); } 44 | // RESULT OF JOIN (node "formal_parameter_list", preset default) 45 | func2( 46 | one, 47 | two 48 | ) { print(one, two); } 49 | -------------------------------------------------------------------------------- /tests/sample/index.ex: -------------------------------------------------------------------------------- 1 | # RESULT OF JOIN (node "list", preset default) 2 | list = [1, 2, 3, [1, 2], [3, 4]] 3 | 4 | # RESULT OF SPLIT (node "list", preset default) 5 | list = [ 6 | 1, 7 | 2, 8 | 3, 9 | [1, 2], 10 | [3, 4] 11 | ] 12 | 13 | # RESULT OF JOIN (node "map_content", preset default) 14 | map = %{:foo => "foo", :bar => "bar", [1, 2] => 2} 15 | 16 | # RESULT OF SPLIT (node "map_content", preset default) 17 | map = %{ 18 | :foo => "foo", 19 | :bar => "bar", 20 | [1, 2] => 2 21 | } 22 | 23 | # RESULT OF JOIN (node "arguments", preset default) 24 | def test(a, b), do: :ok 25 | 26 | # RESULT OF SPLIT (node "arguments", preset default) 27 | def test( 28 | a, 29 | b 30 | ), do: :ok 31 | 32 | # RESULT OF JOIN (node "arguments", preset default) 33 | test(a, b) 34 | 35 | # RESULT OF SPLIT (node "arguments", preset default) 36 | test( 37 | a, 38 | b 39 | ) 40 | 41 | # RESULT OF JOIN (node "tuple", preset default) 42 | {a, b, 123, {c, d}} 43 | 44 | # RESULT OF SPLIT (node "tuple", preset default) 45 | { 46 | a, 47 | b, 48 | 123, 49 | {c, d} 50 | } 51 | 52 | # RESULT OF JOIN (node "keywords", preset default) 53 | map = %{foo: "bar", baz: [], abc: %{}, def: {}, hij: a(1) + 1} 54 | 55 | # RESULT OF SPLIT (node "keywords", preset default) 56 | map = %{ 57 | foo: "bar", 58 | baz: [], 59 | abc: %{}, 60 | def: {}, 61 | hij: a(1) + 1 62 | } 63 | 64 | # RESULT OF JOIN (node "map" with "keywords" and "map_content", preset default) 65 | map = %{"key" => "value", "baz" => [], abc: %{}, def: {}, hij: a(1) + 1} 66 | 67 | # RESULT OF SPLIT (node "map" with "keywords" and "map_content", preset default) 68 | map = %{ 69 | "key" => "value", 70 | "baz" => [], 71 | abc: %{}, 72 | def: {}, 73 | hij: a(1) + 1 74 | } 75 | 76 | # RESULT OF JOIN (node "list" with "keywords" and "map", preset default) 77 | list = [1, 2, %{"a" => "b", key: "value", foo: "bar"}, abc: "123", def: "456"] 78 | 79 | # RESULT OF SPLIT (node "list" with "keywords" and "map", preset default) 80 | list = [ 81 | 1, 82 | 2, 83 | %{"a" => "b", key: "value", foo: "bar"}, 84 | abc: "123", def: "456" 85 | ] 86 | 87 | # RESULT OF JOIN (node "map" nested "keywords" and "maps"", preset default) 88 | map = %{"map" => %{"key" => "value"}, foo: "bar", map: %{"key" => "value"}, baz: "bar"} 89 | 90 | # RESULT OF SPLIT (node "map" nested "keywords" and "maps", preset default) 91 | map = %{ 92 | "map" => %{"key" => "value"}, 93 | foo: "bar", 94 | map: %{"key" => "value"}, 95 | baz: "bar" 96 | } 97 | 98 | # RESULT OF JOIN (node "call", preset default) 99 | def foo(a, b), do: a + b 100 | 101 | # RESULT OF SPLIT (node "call", preset default) 102 | def foo(a, b) do 103 | a + b 104 | end 105 | -------------------------------------------------------------------------------- /tests/sample/index.go: -------------------------------------------------------------------------------- 1 | // code examples from https://learnxinyminutes.com/docs/go/ and stackoverflow 2 | 3 | // RESULT OF JOIN (block "literal_value" list, preset default) 4 | a5 := [...]int{ 3, 1, 5, 10, 100 } 5 | 6 | // RESULT OF SPLIT (block "literal_value" list, preset default) 7 | a5 := [...]int{ 8 | 3, 9 | 1, 10 | 5, 11 | 10, 12 | 100, 13 | } 14 | 15 | // RESULT OF JOIN (block "literal_value" dict, preset default) 16 | joe := person{ name: "Doe, John", age: 32 } 17 | 18 | // RESULT OF SPLIT (block "literal_value" dict, preset default) 19 | joe := person{ 20 | name: "Doe, John", 21 | age: 32, 22 | } 23 | 24 | // RESULT OF JOIN (block "block", preset default) 25 | func main() { fmt.Println("Hello world!"); beyondHello() } 26 | 27 | // RESULT OF SPLIT (block "block", preset default) 28 | func main() { 29 | fmt.Println("Hello world!"); 30 | beyondHello() 31 | } 32 | 33 | // RESULT OF JOIN (block "parameter_list", preset default) 34 | func learnMultiple(x, y int, z, some) (sum, prod int, x, y) { 35 | return x + y, x * y 36 | } 37 | 38 | // RESULT OF SPLIT (block "parameter_list", preset default) 39 | func learnMultiple( 40 | x, y int, 41 | z, 42 | some, 43 | ) (sum, prod int, x, y) { 44 | return x + y, x * y 45 | } 46 | 47 | // RESULT OF JOIN (block "argument_list", preset default) 48 | learnErrorHandling(1, 2, 3) 49 | 50 | // RESULT OF JOIN (block "argument_list", preset default) 51 | learnErrorHandling( 52 | 1, 53 | 2, 54 | 3, 55 | ) 56 | 57 | // RESULT OF JOIN (block "import_spec_list to import_spec", preset default) 58 | import "fmt" 59 | 60 | // RESULT OF SPLIT (block "import_spec to import_spec_list", preset default) 61 | import ( 62 | "fmt" 63 | ) 64 | -------------------------------------------------------------------------------- /tests/sample/index.hs: -------------------------------------------------------------------------------- 1 | -- RESULT OF JOIN (node "list", preset default) 2 | let x = [1, 2, 3] 3 | -- RESULT OF SPLIT (node "list", preset default) 4 | let x = [ 5 | 1, 6 | 2, 7 | 3 8 | ] 9 | -------------------------------------------------------------------------------- /tests/sample/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

Text

14 | 15 |

Text

19 | 20 | 21 | pretty kitty 22 | 23 | pretty kitty 27 | 28 | 29 | Text 30 | 31 | 32 | Text 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |

44 | 45 | 46 |

48 | 49 | 50 | 51 | 52 | 53 | 55 | 56 | 57 | 58 | 59 | 60 | 62 | 63 | 64 |

65 | 66 | 67 |

69 | 70 | 71 | 72 | 73 | 74 | 76 | 77 | 78 | 79 | 80 | 83 | 84 | 85 | 34 | // result of SPLIT (node 'jsx_opening_element') 35 | 41 | // result of JOIN (node 'jsx_element') 42 | 43 | // result of SPLIT (node 'jsx_element') 44 | 47 | // result of JOIN (node 'jsx_self_closing_element' with last_indent = 'inner') 48 | 34 | // result of SPLIT (node 'jsx_opening_element') 35 | 41 | // result of JOIN (node 'jsx_element') 42 | 43 | // result of SPLIT (node 'jsx_element') 44 | 47 | 48 | ); 49 | }; 50 | -------------------------------------------------------------------------------- /tests/sample/index.vue: -------------------------------------------------------------------------------- 1 | 30 | -------------------------------------------------------------------------------- /tests/sample/index.yml: -------------------------------------------------------------------------------- 1 | obj: { one: one, two: two } 2 | 3 | obj: 4 | one: one 5 | two: two 6 | 7 | array: [ one, two ] 8 | 9 | array: 10 | - one 11 | - two 12 | 13 | mixed: { pair: true, array: [ value1, value2 ] } 14 | 15 | mixed: 16 | pair: true 17 | array: 18 | - value1 19 | - value2 20 | 21 | no-empty: [ warn, { allowEmptyCatch: true } ] 22 | 23 | no-empty: 24 | - warn 25 | - allowEmptyCatch: true 26 | -------------------------------------------------------------------------------- /tests/sample/index.zig: -------------------------------------------------------------------------------- 1 | // RESULT OF JOIN (node "parameter_list", preset default) 2 | fn foo(x: i32, y: i32, z: i32) void {} 3 | // RESULT OF SPLIT (node "parameter_list", preset default) 4 | fn foo( 5 | x: i32, 6 | y: i32, 7 | z: i32, 8 | ) void {} 9 | 10 | // RESULT OF JOIN (node "argument_list", preset default) 11 | var bar = foo(1, 2, 3); 12 | // RESULT OF SPLIT (node "argument_list", preset default) 13 | var bar = foo( 14 | 1, 15 | 2, 16 | 3, 17 | ); 18 | 19 | // RESULT OF JOIN (node "initializer_list", preset default) 20 | var arr: [5]u32 = [5]u32{ 1, 2, 3, 4, 5 }; 21 | // RESULT OF SPLIT (node "initializer_list", preset default) 22 | var arr: [5]u32 = [5]u32{ 23 | 1, 24 | 2, 25 | 3, 26 | 4, 27 | 5, 28 | }; 29 | 30 | // RESULT OF JOIN (node "enumerator_list", preset default) 31 | const Direction = enum { north, south, east, west }; 32 | // RESULT OF SPLIT (node "enumerator_list", preset default) 33 | const Direction = enum { 34 | north, 35 | south, 36 | east, 37 | west, 38 | }; 39 | 40 | // RESULT OF JOIN (node "struct_declaration", preset default) 41 | const Point = struct { x: i32, y: i32 = 0, z: i32 }; 42 | // RESULT OF SPLIT (node "struct_declaration", preset default) 43 | const Point = struct { 44 | x: i32, 45 | y: i32 = 0, 46 | z: i32, 47 | }; 48 | -------------------------------------------------------------------------------- /tests/sample/index_recursive.js: -------------------------------------------------------------------------------- 1 | // RESULT OF JOIN (node "block", preset with recursive = true) 2 | const object = { one: 'one', two: 'two', three: function(x) { console.log(x); }, four: [ 1, 2, 3 ] }; 3 | 4 | // RESULT OF SPLIT (node "block", preset with recursive = true) 5 | const object = { 6 | one: 'one', 7 | two: 'two', 8 | three: function(x) { 9 | console.log(x); 10 | }, 11 | four: [ 12 | 1, 13 | 2, 14 | 3, 15 | ], 16 | }; 17 | 18 | // RESULT OF JOIN (node "statement_block", preset with recursive = true) 19 | function trycatch(test) { try { console.log('try'); } catch (e) { console.log(e); } finally { console.log('Done!'); } } 20 | 21 | // RESULT OF SPLIT (node "statement_block", preset with recursive = true) 22 | function trycatch(test) { 23 | try { 24 | console.log('try'); 25 | } catch (e) { 26 | console.log(e); 27 | } finally { 28 | console.log('Done!'); 29 | } 30 | } 31 | 32 | // RESULT OF JOIN (node "statement_block", preset preset with recursive = true) 33 | if (b <= a) { 1 + 2; add(2, 1) + sum(2, 1); return (console.log(1), 1) >= 1; } 34 | 35 | // RESULT OF SPLIT (node "statement_block", preset preset with recursive = true) 36 | if (b <= a) { 37 | 1 + 2; 38 | add(2, 1) + sum(2, 1); 39 | return (console.log(1), 1) >= 1; 40 | } 41 | 42 | // RESULT OF JOIN (node "array", preset preset with recursive = true) 43 | cell.siblings = [ ...new Set([ ...cell.siblings, ...currentPlaceSiblings ]) ]; 44 | 45 | // RESULT OF SPLIT (node "array", preset preset with recursive = true) 46 | cell.siblings = [ 47 | ...new Set([ ...cell.siblings, ...currentPlaceSiblings ]), 48 | ]; 49 | 50 | // RESULT OF JOIN (field "body" in "arrow_function" with "parenthesized_expression", preset with recursive = true) 51 | const myFunc = (param) => ({ one: 'one' }); 52 | 53 | // RESULT OF SPLIT (field "body" in "arrow_function" with "parenthesized_expression", preset with recursive = true) 54 | const myFunc = (param) => { 55 | return { 56 | one: 'one', 57 | } 58 | }; 59 | 60 | // RESULT OF JOIN (field "body" in "arrow_function" with "array", preset with recursive = true) 61 | const myFunc = (param) => [ 1, 2, 3 ]; 62 | 63 | // RESULT OF SPLIT (field "body" in "arrow_function" with "array", preset with recursive = true) 64 | const myFunc = (param) => { 65 | return [ 66 | 1, 67 | 2, 68 | 3, 69 | ] 70 | }; 71 | -------------------------------------------------------------------------------- /tests/sample/index_recursive.kt: -------------------------------------------------------------------------------- 1 | // RESULT OF JOIN (node "statements" with child with "shrink_node" option, preset default) 2 | call_expression("arg1") { call1(1, 2); fun test(a: String, b: String) { val var1 = 1; val var2 = 2 } } 3 | // RESULT OF SPLIT (node "statements" with child with "shrink_node" option, preset default) 4 | call_expression("arg1") { 5 | call1(1, 2) 6 | fun test(a: String, b: String) { 7 | val var1 = 1 8 | val var2 = 2 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/sample/index_tab.lua: -------------------------------------------------------------------------------- 1 | -- RESULT OF JOIN (node "block" (with noexpandtab), preset default) 2 | if 1 == 1 then print('beep') end 3 | 4 | -- RESULT OF SPLIT (node "block" (with noexpandtab), preset default) 5 | if 1 == 1 then 6 | print('beep') 7 | end 8 | 9 | -- RESULT OF JOIN (node "table_constructor" (with noexpandtab), preset default) 10 | local mixed = { 'one', two = 'two', 'three', dict, four = { 'four', 'five' } } 11 | 12 | -- RESULT OF SPLIT (node "table_constructor" (with noexpandtab), preset default) 13 | local mixed = { 14 | 'one', 15 | two = 'two', 16 | 'three', 17 | dict, 18 | four = { 'four', 'five' }, 19 | } 20 | -------------------------------------------------------------------------------- /tests/utils.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | local a = vim.api 4 | 5 | local function open_ang_get_buf(path) 6 | vim.cmd(':e ' .. path) 7 | return a.nvim_get_current_buf() 8 | end 9 | 10 | function M._test_format(v, treesj) 11 | local desc = v.desc:format(v.lang) 12 | 13 | it(desc, function() 14 | local bufnf = open_ang_get_buf(v.path) 15 | local expected = 16 | a.nvim_buf_get_lines(bufnf, v.expected[1], v.expected[2], true) 17 | a.nvim_win_set_cursor(0, v.cursor) 18 | treesj[v.mode]() 19 | local result = a.nvim_buf_get_lines(bufnf, v.result[1], v.result[2], true) 20 | a.nvim_buf_delete(bufnf, { force = true }) 21 | assert.are.same(expected, result) 22 | end) 23 | end 24 | 25 | function M._test_chold(v, treesj) 26 | -- local treesj = require('treesj') 27 | -- treesj.setup(v.settings) 28 | local desc = v.desc:format(v.mode) 29 | 30 | it(desc, function() 31 | local bufnf = open_ang_get_buf(v.path) 32 | a.nvim_win_set_cursor(0, v.cursor) 33 | treesj[v.mode]() 34 | local result = a.nvim_win_get_cursor(0) 35 | a.nvim_buf_delete(bufnf, { force = true }) 36 | assert.are.same(v.expected, result) 37 | end) 38 | end 39 | 40 | return M 41 | --------------------------------------------------------------------------------