├── .github └── workflows │ └── vader.yml ├── .gitignore ├── .luacheckrc ├── LICENSE ├── README.md ├── after ├── ftplugin │ └── puppet.vim └── plugin │ └── gutentags.vim ├── autoload └── puppet │ ├── align.vim │ ├── ctags.vim │ └── format.vim ├── compiler └── puppet-lint.vim ├── ctags ├── puppet.ctags └── puppet_u.ctags ├── ftdetect ├── puppet.lua └── puppet.vim ├── ftplugin ├── epuppet.vim ├── puppet.vim └── puppet_tagbar.vim ├── indent └── puppet.vim ├── syntax ├── epuppet.vim └── puppet.vim └── test ├── filetype ├── epuppet.vader ├── puppet.vader └── puppetfile.vader ├── format ├── hashrocket.vader └── textwidth.vader ├── indent ├── basic.vader ├── comments_strings.vader └── include.vader ├── init.vim ├── run-tests.sh ├── syntax ├── array.vader ├── boolean.vader ├── epuppet.vader ├── error.vader ├── fold.vader ├── number.vader ├── regex.vader ├── strings.vader ├── variable.vader └── variable_in_string.vader └── test-files ├── Puppetfile ├── etc └── apache2 │ └── test.conf.epp ├── simple.pp ├── test_perl_with_shebang.epp ├── test_php_with_extension.php.epp ├── test_shell_with_extension.sh.epp ├── test_shell_with_shebang.epp └── test_with_leading_tag.epp /.github/workflows/vader.yml: -------------------------------------------------------------------------------- 1 | name: Tests on vim and neovim 2 | 3 | # Controls when the workflow will run 4 | on: 5 | # Triggers the workflow on push or pull request events but only for the master branch 6 | push: 7 | branches: [ master ] 8 | pull_request: 9 | branches: [ master ] 10 | 11 | jobs: 12 | lint: 13 | name: Lint code with Vint and shellcheck 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | # There exists a vint github action but it can't install the alpha 18 | # version. vint has not been moving since 2020 and we need to use the 19 | # alpha release since it fixed some things wrt the latest stable release. 20 | - uses: actions/setup-python@v5 21 | with: 22 | python-version: '3.10' 23 | - name: Install vint 24 | run: pip install --pre vim-vint 25 | - name: Lint vimscript files 26 | run: vint --warning --enable-neovim ./after ./autoload ./compiler ./ftdetect ./ftplugin ./indent ./syntax 27 | - uses: lunarmodules/luacheck@v1 28 | - uses: ludeeus/action-shellcheck@master 29 | 30 | tests: 31 | runs-on: ubuntu-latest 32 | needs: lint 33 | strategy: 34 | fail-fast: false 35 | matrix: 36 | # bullseye: vim 8.2.2434 neovim 0.4.4 37 | # bookworm: vim 9.0.1378 neovim 0.7.2 38 | # trixie: vim 9.1.0496 neovim 0.9.5 39 | # jammy: vim 8.2.3995 neovim 0.6.1 <- vim version currently used by github action as vim-stable 40 | # mantic: vim 9.0.1672 neovim 0.7.2 41 | # noble: vim 9.1.0016 neovim 0.9.5 42 | # mageia 9: vim 9.1.071 neovim 0.9.5 43 | # mageia cauldron: vim 9.1.0719 neovim 0.10.1 44 | # epuppet detestion added in filetype.vim in vim 8.2.2402 45 | # neovim pulled this epuppet detection in nvim 0.5.0 46 | # filetype detection done with filetype.lua from neovim 0.8.0 47 | # neovim < 0.9.0 segfaut on github action (even the one installed from apt) 48 | editor: ["vim-v8.0.0000", "vim-stable", "vim-v9.1.0719", "nvim-v0.9.0", "nvim-v0.9.5", "nvim-v0.10.1"] 49 | 50 | steps: 51 | - uses: actions/checkout@v4 52 | - name: get editor name 53 | env: 54 | EDITORVERSION: ${{matrix.editor}} 55 | id: split 56 | run: | 57 | echo "SELECTEDEDITOR=${EDITORVERSION%%-*}" >> $GITHUB_ENV 58 | echo "SELECTEDVERSION=${EDITORVERSION##*-}" >> $GITHUB_ENV 59 | - name: Setup ${{ matrix.editor }} 60 | uses: rhysd/action-setup-vim@v1 61 | id: vim 62 | with: 63 | neovim: ${{ env.SELECTEDEDITOR == 'nvim' }} 64 | version: ${{ env.SELECTEDVERSION }} 65 | - name: Run Vader unit tests 66 | run: | 67 | TESTVIM=${{ env.SELECTEDEDITOR }} 68 | export TESTVIM 69 | ./test/run-tests.sh 70 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vader.vim 2 | -------------------------------------------------------------------------------- /.luacheckrc: -------------------------------------------------------------------------------- 1 | -- vim: ft=lua tw=80 2 | 3 | -- Global objects defined by the C code 4 | read_globals = { 5 | vim = { 6 | other_fields = true, 7 | fields = { 8 | b = { 9 | fields = { 10 | epuppet_subtype = { 11 | read_only = false, 12 | } 13 | } 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 Tim Sharpe 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | vim-puppet 2 | ========== 3 | 4 | [![Build 5 | Status](https://secure.travis-ci.org/rodjek/vim-puppet.png)](http://travis-ci.org/rodjek/vim-puppet) 6 | 7 | Make vim more Puppet friendly! 8 | 9 | Provides 10 | -------- 11 | 12 | * Formatting based on the latest Puppetlabs Style Guide 13 | * Syntax highlighting compatible with puppet 4.x 14 | * by default, highlights errors: mixing spaces and tabs and bad names. If you 15 | don't want this highlighting, add `let g:puppet_display_errors = 0` to your 16 | vimrc. 17 | * Automatic => alignment 18 | * If you don't like that, add `let g:puppet_align_hashes = 0` to your vimrc. 19 | * Ctags support 20 | * gutentags integration 21 | * You can enable loading tags with gutentags by setting 22 | `g:gutentags_dont_load = 1` in your vimrc 23 | * Doesn't require a bloated JRE 24 | * Doesn't take minutes to open 25 | 26 | Additional useful plugins 27 | ------------------------- 28 | 29 | * [vim-yardoc](https://github.com/noprompt/vim-yardoc) Syntax coloration for 30 | YARD tags and directives. It can also colorize the tags and directives in 31 | puppet files. 32 | * [syntastic](https://github.com/scrooloose/syntastic) plugin for automatic 33 | syntax checking while in vim. 34 | * [vim-snippets](https://github.com/honza/vim-snippets) is a library of 35 | snippets for multiple languages, including Puppet. Works with both 36 | [snipmate](https://github.com/garbas/vim-snipmate) and 37 | [ultisnips](https://github.com/SirVer/ultisnips). 38 | * [Tagbar](https://github.com/majutsushi/tagbar) plugin for Ctags support. 39 | 40 | Installation 41 | ------------ 42 | 43 | With [Vim 8 packages](http://vimhelp.appspot.com/repeat.txt.html#packages): 44 | 45 | git clone https://github.com/rodjek/vim-puppet.git ~/.vim/pack/plugins/start/vim-puppet 46 | 47 | With [Pathogen](https://github.com/tpope/vim-pathogen): 48 | 49 | If you're using [pathogen](https://github.com/tpope/vim-pathogen) to manage 50 | your vim modules (and if you're not, why aren't you), you can simply add this 51 | as a submodule in your `~/.vim/bundle/` directory. 52 | 53 | My entire home directory is a git repository, so for me it's simply a case of 54 | 55 | git submodule add -f git://github.com/rodjek/vim-puppet.git .vim/bundle/puppet 56 | 57 | If you're not using pathogen, you can just manually place the files in the 58 | appropriate places under `~/.vim/` 59 | 60 | With [Plug](https://github.com/junegunn/vim-plug) 61 | 62 | In your ~/.vimrc (or stdpath('config') . '/init.vim' for Neovim) 63 | 64 | call plug#begin() 65 | rodjek/vim-puppet 66 | call plug#end() 67 | 68 | Testing 69 | ------- 70 | 71 | Testing is based on vader.vim testing framework, see: 72 | . To run full test suit use 73 | `./test/run-tests.sh`, this will also download vader.vim plugin to project's 74 | folder. 75 | -------------------------------------------------------------------------------- /after/ftplugin/puppet.vim: -------------------------------------------------------------------------------- 1 | if !exists('g:puppet_align_hashes') 2 | let g:puppet_align_hashes = 1 3 | endif 4 | 5 | if g:puppet_align_hashes 6 | inoremap => =>:call puppet#align#AlignHashrockets()$a 7 | endif 8 | -------------------------------------------------------------------------------- /after/plugin/gutentags.vim: -------------------------------------------------------------------------------- 1 | if (!exists('g:gutentags_enabled') && (!exists('g:gutentags_dont_load') || g:gutentags_dont_load != 0 )) 2 | finish 3 | endif 4 | 5 | call add(g:gutentags_project_info, {'type': 'puppet', 'file': 'Puppetfile'}) 6 | 7 | let s:ctags_options = puppet#ctags#OptionFile() 8 | if exists('g:gutentags_ctags_extra_args') 9 | call add(g:gutentags_ctags_extra_args, '--options=' . s:ctags_options) 10 | else 11 | let g:gutentags_ctags_extra_args = ['--options=' . s:ctags_options] 12 | endif 13 | unlet s:ctags_options 14 | 15 | -------------------------------------------------------------------------------- /autoload/puppet/align.vim: -------------------------------------------------------------------------------- 1 | function! puppet#align#IndentLevel(lnum) abort 2 | return indent(a:lnum) / &shiftwidth 3 | endfunction 4 | 5 | function! puppet#align#LinesInBlock(lnum) abort 6 | let lines = [] 7 | let indent_level = puppet#align#IndentLevel(a:lnum) 8 | 9 | let marker = a:lnum - 1 10 | while marker >= 1 11 | let line_text = getline(marker) 12 | 13 | if line_text =~? '\v\S' 14 | let line_indent = puppet#align#IndentLevel(marker) 15 | if line_indent < indent_level 16 | break 17 | elseif line_indent == indent_level 18 | call add(lines, marker) 19 | endif 20 | endif 21 | 22 | let marker -= 1 23 | endwhile 24 | 25 | let marker = a:lnum 26 | while marker <= line('$') 27 | let line_text = getline(marker) 28 | 29 | if line_text =~? '\v\S' 30 | let line_indent = puppet#align#IndentLevel(marker) 31 | if line_indent < indent_level 32 | break 33 | elseif line_indent == indent_level 34 | call add(lines, marker) 35 | endif 36 | endif 37 | 38 | let marker += 1 39 | endwhile 40 | 41 | return lines 42 | endfunction 43 | 44 | "" 45 | " Format lines with hashrocket (=>) 46 | " @param a:1 a line where function should search for first hashrocket 47 | " expression, if param is not given, line with active cursor is used 48 | function! puppet#align#AlignHashrockets(...) abort 49 | let l:lnum = get(a:, 1, line('.')) 50 | let lines_in_block = puppet#align#LinesInBlock(l:lnum) 51 | let max_left_len = 0 52 | let indent_str = printf('%' . indent(l:lnum) . 's', '') 53 | 54 | for line_num in lines_in_block 55 | let text_line = getline(line_num) 56 | " skip comment lines 57 | if matchstr(text_line, '\S') ==# '#' 58 | continue 59 | endif 60 | 61 | let data = matchlist(text_line, '^\s*\(.\{-}\S\)\s*=>\s*\(.*\)$') 62 | if !empty(data) 63 | let max_left_len = max([max_left_len, strlen(data[1])]) 64 | endif 65 | endfor 66 | 67 | for line_num in lines_in_block 68 | let text_line = getline(line_num) 69 | " skip comment lines 70 | if matchstr(text_line, '\S') ==# '#' 71 | continue 72 | endif 73 | 74 | let data = matchlist(text_line, '^\s*\(.\{-}\S\)\s*=>\s*\(.*\)$') 75 | if !empty(data) 76 | let new_line = printf('%s%-' . max_left_len . 's => %s', indent_str, data[1], data[2]) 77 | call setline(line_num, new_line) 78 | endif 79 | endfor 80 | 81 | return lines_in_block 82 | endfunction 83 | -------------------------------------------------------------------------------- /autoload/puppet/ctags.vim: -------------------------------------------------------------------------------- 1 | 2 | if !exists('s:ctags_type') 3 | let s:ctags_type = 0 4 | endif 5 | 6 | let s:ctags_options_dir = expand(':p:h:h:h') . '/ctags/' 7 | 8 | " Return full path to option file for ctags application 9 | function! puppet#ctags#OptionFile() abort 10 | 11 | if puppet#ctags#Type() ==? 'universal' 12 | let l:ctags_options = 'puppet_u.ctags' 13 | else 14 | let l:ctags_options = 'puppet.ctags' 15 | endif 16 | return s:ctags_options_dir . l:ctags_options 17 | endfunction 18 | 19 | " Return type of installed ctags application, 20 | " can be 'universal' or 'exuberant' 21 | function! puppet#ctags#Type() abort 22 | 23 | if !s:ctags_type 24 | let l:version = system('ctags --version') 25 | if l:version =~? 'Universal Ctags' 26 | let s:ctags_type = 'universal' 27 | elseif l:version =~? 'Exuberant Ctags' 28 | let s:ctags_type = 'exuberant' 29 | else 30 | echoerr 'Unknown version of Ctags' 31 | endif 32 | endif 33 | 34 | return s:ctags_type 35 | endfunction 36 | 37 | -------------------------------------------------------------------------------- /autoload/puppet/format.vim: -------------------------------------------------------------------------------- 1 | " 2 | " Simple format using puppet's l:indents and align hashrockets function 3 | function! puppet#format#Format() abort 4 | " only allow reformatting through the gq command 5 | " (e.g. Vim is in normal mode) 6 | if mode() !=# 'n' 7 | " do not fall back to internal formatting 8 | return 0 9 | endif 10 | 11 | let l:start_lnum = v:lnum 12 | let l:end_lnum = v:lnum + v:count - 1 13 | 14 | call puppet#format#Indention(l:start_lnum, l:end_lnum) 15 | call puppet#format#Hashrocket(l:start_lnum, l:end_lnum) 16 | call puppet#format#Fallback(l:start_lnum, l:end_lnum) 17 | 18 | " explicitly avoid falling back to default formatting 19 | return 0 20 | endfunction 21 | 22 | "" 23 | " Format hashrockets expressions in every line in range start_lnum and 24 | " end_lnum, both ends included 25 | " 26 | function! puppet#format#Hashrocket(start_lnum, end_lnum) abort 27 | let l:lnum = a:start_lnum 28 | let processed_lines = [] 29 | while l:lnum <= a:end_lnum 30 | if index(processed_lines, l:lnum) ==# -1 31 | let line_text = getline(l:lnum) 32 | if line_text =~? '\v\S' 33 | let processed_lines += puppet#align#AlignHashrockets(l:lnum) 34 | else 35 | " empty lines make puppet#align#AlignHashrockets reprocess blocks with 36 | " indentation that were already processed so we just skip them 37 | call add(processed_lines, l:lnum) 38 | endif 39 | endif 40 | let l:lnum += 1 41 | endwhile 42 | endfunction 43 | 44 | "" 45 | " Format indention in every line in range start_lnum and end_lnum, both ends 46 | " included 47 | " 48 | function! puppet#format#Indention(start_lnum, end_lnum) abort 49 | execute 'normal! ' . a:start_lnum . 'gg=' . a:end_lnum . 'gg' 50 | endfunction 51 | 52 | "" 53 | " Use internal vim default autoformat method for every line in range, only 54 | " lines which exeed &widthline are formated 55 | " 56 | function! puppet#format#Fallback(start_lnum, end_lnum) abort 57 | " We shouldn't wrap lines based on textwidth if it is disabled 58 | if &textwidth == 0 59 | return 60 | endif 61 | 62 | " I'm using it to check if autoformat expand range 63 | let l:eof_lnum = line('$') 64 | let l:lnum = a:start_lnum 65 | let l:end_lnum = a:end_lnum 66 | 67 | while l:lnum <= l:end_lnum 68 | if strlen(getline(l:lnum)) > &textwidth 69 | call cursor(l:lnum) 70 | execute 'normal! gww' 71 | " Checking if autoformat expand number of lines if yes, I will extend 72 | " range too 73 | if l:eof_lnum < line('$') 74 | let l:end_lnum += line('$') - l:eof_lnum 75 | let l:eof_lnum = line('$') 76 | endif 77 | endif 78 | let l:lnum += 1 79 | endwhile 80 | 81 | endfunction 82 | 83 | -------------------------------------------------------------------------------- /compiler/puppet-lint.vim: -------------------------------------------------------------------------------- 1 | " Vim compiler file 2 | " Compiler: puppet-lint 3 | " Maintainer: Doug Kearns 4 | 5 | if exists('current_compiler') 6 | finish 7 | endif 8 | let current_compiler = 'puppet-lint' 9 | 10 | if exists(':CompilerSet') != 2 " older Vim always used :setlocal 11 | command -nargs=* CompilerSet setlocal 12 | endif 13 | 14 | let s:cpo_save = &cpo 15 | set cpo&vim 16 | 17 | CompilerSet makeprg=puppet-lint\ --with-filename 18 | CompilerSet errorformat=%f\ -\ %tRROR:\ %m\ on\ line\ %l, 19 | \%f\ -\ %tARNING:\ %m\ on\ line\ %l, 20 | \%-G%.%# 21 | 22 | let &cpo = s:cpo_save 23 | unlet s:cpo_save 24 | -------------------------------------------------------------------------------- /ctags/puppet.ctags: -------------------------------------------------------------------------------- 1 | --langdef=puppet 2 | --langmap=puppet:.pp 3 | --regex-puppet=/^[[:space:]]*class[[:space:]]*([a-z][a-zA-Z0-9_:\-]+)/::\1/c,class/ 4 | --regex-puppet=/^[[:space:]]*class[[:space:]]*([a-z][a-zA-Z0-9_:\-]+)/\1/c,class/ 5 | --regex-puppet=/^[[:space:]]*site[[:space:]]*([a-zA-Z0-9_\-]+)/\1/s,site/ 6 | --regex-puppet=/^[[:space:]]*node[[:space:]]*[\'|\"]*([a-zA-Z0-9_\.\-]+)[\'|\"]*/\1/n,node/ 7 | --regex-puppet=/^[[:space:]]*define[[:space:]]*([a-z][a-zA-Z0-9_:\-]+)/\1/d,definition/ 8 | --regex-puppet=/^[[:space:]]*(include|require)[[:space:]]*:{0,2}([a-zA-Z0-9_:]+)/\1 ::\2/i,include/ 9 | --regex-puppet=/^[[:space:]]*([\$][a-zA-Z0-9_:]+)[[:space:]]*=/\1/v,variable/ 10 | --regex-puppet=/^[[:space:]]*[~|\-]?>?[[:space:]]*([a-z][a-zA-Z0-9_:]+)[[:space:]]*\{ *(.*):/\1[\2]/r,resource/ 11 | --regex-puppet=/([A-Z][a-zA-Z0-9_:]+)[[:space:]]*\{/\1/f,default/ 12 | --regex-puppet=/^[[:space:]]*type[[:space:]]*([A-Z][a-zA-Z0-9_:]*)[[:space:]]*=/\1/t,type/ 13 | --regex-puppet=/^[[:space:]]*function[[:space:]]*([a-zA-Z0-9_:]*)[[:space:]]*/\1/u,function/ 14 | -------------------------------------------------------------------------------- /ctags/puppet_u.ctags: -------------------------------------------------------------------------------- 1 | --langdef=puppet 2 | --map-puppet=+.pp 3 | --regex-puppet=/^[[:space:]]*node[[:space:]]*[\'|\"]*([a-zA-Z0-9_\.\-]+)[\'|\"]*/\1/n,node/{scope=set} 4 | --regex-puppet=/^[[:space:]]*class[[:space:]]*([a-z][a-zA-Z0-9_:\-]+)[[:space:]]*\{*/\1/c,class,classes/{scope=set} 5 | --regex-puppet=/^[[:space:]]*define[[:space:]]*([a-z][a-zA-Z0-9_:\-]+)/\1/d,definition/{scope=set} 6 | --regex-puppet=/^[[:space:]]*(include|require)[[:space:]]*([a-zA-Z0-9_:]+)/\1 \2/i,include,includes/{scope=ref} 7 | --regex-puppet=/^[[:space:]]*[~|\-]?>?[[:space:]]*([a-z][a-zA-Z0-9_:]+)[[:space:]]*\{[[:space:]]*(.*):/\1[\2]/r,resource/{scope=ref} 8 | --regex-puppet=/^[[:space:]]*([\$][a-zA-Z0-9_:]+)[[:space:]]*=/\1/v,variable/{scope=ref} 9 | --regex-puppet=/([A-Z][a-zA-Z0-9_:]+)[[:space:]]*\{/\1/f,default/ 10 | --regex-puppet=/^[[:space:]]*site[[:space:]]*([a-zA-Z0-9_\-]+)/\1/s,site/ 11 | --regex-puppet=/^[[:space:]]*type[[:space:]]*([A-Z][a-zA-Z0-9_:]*)[[:space:]]*=/\1/t,type/ 12 | --regex-puppet=/^[[:space:]]*function[[:space:]]*([a-zA-Z0-9_:]*)[[:space:]]*/\1/u,function/ 13 | -------------------------------------------------------------------------------- /ftdetect/puppet.lua: -------------------------------------------------------------------------------- 1 | -- Some epp files may get marked as "mason" type before this script is reached. 2 | -- Vim's own scripts.vim forces the type if it detects a `<%` at the start of 3 | -- the file. All files ending in .epp should be epuppet 4 | vim.filetype.add({ 5 | extension = { 6 | epp = 7 | function(path, bufnr) 8 | local path_wo_epp = path:sub(1,-5) 9 | local matched = vim.filetype.match({ buf = bufnr, filename = path_wo_epp }) 10 | if matched ~= nil and matched ~= 'mason' then 11 | vim.b.epuppet_subtype = matched 12 | end 13 | return 'epuppet' 14 | end, 15 | } 16 | }) 17 | -------------------------------------------------------------------------------- /ftdetect/puppet.vim: -------------------------------------------------------------------------------- 1 | " vint: -ProhibitAutocmdWithNoGroup 2 | " Vim has fixed puppet vs pascal detection in patch 8.2.2334 so we can rely on 3 | " their type detection from that point on. 4 | if !has('patch-8.2.2334') && !has('nvim-0.5.0') 5 | " Vim's own filetypes.vim runs before all ftdetect scripts (why?) and matches 6 | " detects the .pp extension as being a 'pascal' file. Since the script uses 7 | " `setf`, we can nullify the filetype detection by removing all commands bound 8 | " to BufRead and BufNewFile for .pp files with `au!`. Hopefully, if there were 9 | " any other commands set they were associated with the pascal type and we want 10 | " to get rid of them. 11 | " However, this has the effect of completely nullifying pascal type detection 12 | " for .pp files. 13 | au! BufRead,BufNewFile *.pp setfiletype puppet 14 | endif 15 | " Vim now has autodetection for epuppet and Puppetfile. We only need to add 16 | " autocommands for older versions of vim / neovim 17 | if !has('patch-8.2.2402') && !has('nvim-0.5.0') 18 | " Some epp files may get marked as "mason" type before this script is reached. 19 | " Vim's own scripts.vim forces the type if it detects a `<%` at the start of 20 | " the file. All files ending in .epp should be epuppet 21 | au! BufRead,BufNewFile *.epp setf epuppet 22 | au BufRead,BufNewFile Puppetfile setfiletype ruby 23 | endif 24 | -------------------------------------------------------------------------------- /ftplugin/epuppet.vim: -------------------------------------------------------------------------------- 1 | " Vim filetype plugin 2 | " Language: embedded puppet 3 | " Maintainer: Gabriel Filion 4 | " URL: https://github.com/rodjek/vim-puppet 5 | " Last Change: 2019-09-01 6 | 7 | " Only do this when not done yet for this buffer 8 | if exists('b:did_ftplugin') 9 | finish 10 | endif 11 | 12 | let s:save_cpo = &cpo 13 | set cpo-=C 14 | 15 | " Define some defaults in case the included ftplugins don't set them. 16 | let s:undo_ftplugin = '' 17 | if has('win32') 18 | let s:browsefilter = "All Files (*.*)\t*.*\n" 19 | else 20 | let s:browsefilter = "All Files (*)\t*\n" 21 | endif 22 | let s:match_words = '' 23 | 24 | if !exists('g:epuppet_default_subtype') 25 | let g:epuppet_default_subtype = 'sh' 26 | endif 27 | 28 | if &filetype =~# '^epuppet\.' 29 | let b:epuppet_subtype = matchstr(&filetype,'^epuppet\.\zs\w\+') 30 | elseif !exists('b:epuppet_subtype') 31 | let b:epuppet_subtype = matchstr(substitute(expand('%:t'),'\c\%(\.epp\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$') 32 | " TODO instead of listing exceptions like this, can we instead recognize 33 | " extension -> type mapping? 34 | if b:epuppet_subtype ==? 'rhtml' 35 | let b:epuppet_subtype = 'html' 36 | elseif b:epuppet_subtype ==? 'rb' 37 | let b:epuppet_subtype = 'ruby' 38 | elseif b:epuppet_subtype ==? 'yml' 39 | let b:epuppet_subtype = 'yaml' 40 | elseif b:epuppet_subtype ==? 'js' 41 | let b:epuppet_subtype = 'javascript' 42 | elseif b:epuppet_subtype ==? 'txt' 43 | " Conventional; not a real file type 44 | let b:epuppet_subtype = 'text' 45 | elseif b:epuppet_subtype ==? 'py' 46 | let b:epuppet_subtype = 'python' 47 | elseif b:epuppet_subtype ==? 'rs' 48 | let b:epuppet_subtype = 'rust' 49 | elseif b:epuppet_subtype ==?'' 50 | let b:epuppet_subtype = g:epuppet_default_subtype 51 | endif 52 | endif 53 | 54 | if exists('b:epuppet_subtype') && b:epuppet_subtype != '' && b:epuppet_subtype !=? 'epuppet' 55 | exe 'runtime! ftplugin/'.b:epuppet_subtype.'.vim ftplugin/'.b:epuppet_subtype.'_*.vim ftplugin/'.b:epuppet_subtype.'/*.vim' 56 | endif 57 | unlet! b:did_ftplugin 58 | 59 | runtime! ftplugin/sh.vim 60 | unlet! b:did_ftplugin 61 | 62 | " Override our defaults if these were set by an included ftplugin. 63 | if exists('b:undo_ftplugin') 64 | let s:undo_ftplugin = b:undo_ftplugin 65 | unlet b:undo_ftplugin 66 | endif 67 | if exists('b:browsefilter') 68 | let s:browsefilter = b:browsefilter 69 | unlet b:browsefilter 70 | endif 71 | if exists('b:match_words') 72 | let s:match_words = b:match_words 73 | unlet b:match_words 74 | endif 75 | 76 | let s:include = &l:include 77 | let s:path = &l:path 78 | let s:suffixesadd = &l:suffixesadd 79 | 80 | runtime! ftplugin/puppet.vim 81 | let b:did_ftplugin = 1 82 | 83 | " Combine the new set of values with those previously included. 84 | if exists('b:undo_ftplugin') 85 | let s:undo_ftplugin = b:undo_ftplugin . ' | ' . s:undo_ftplugin 86 | endif 87 | if exists ('b:browsefilter') 88 | let s:browsefilter = substitute(b:browsefilter,'\cAll Files (\*\.\*)\t\*\.\*\n','','') . s:browsefilter 89 | endif 90 | if exists('b:match_words') 91 | let s:match_words = b:match_words . ',' . s:match_words 92 | endif 93 | 94 | if len(s:include) 95 | let &l:include = s:include 96 | endif 97 | let &l:path = s:path . (s:path =~# ',$\|^$' ? '' : ',') . &l:path 98 | let &l:suffixesadd = s:suffixesadd . (s:suffixesadd =~# ',$\|^$' ? '' : ',') . &l:suffixesadd 99 | unlet s:include s:path s:suffixesadd 100 | 101 | " Load the combined list of match_words for matchit.vim 102 | if exists('loaded_matchit') 103 | let b:match_words = s:match_words 104 | endif 105 | 106 | " TODO: comments= 107 | setlocal commentstring=<%#%s%> 108 | 109 | let b:undo_ftplugin = 'setl cms< ' 110 | \ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin 111 | 112 | let &cpo = s:save_cpo 113 | unlet s:save_cpo 114 | 115 | -------------------------------------------------------------------------------- /ftplugin/puppet.vim: -------------------------------------------------------------------------------- 1 | " Vim filetype plugin 2 | " Language: Puppet 3 | " Maintainer: Tim Sharpe 4 | " URL: https://github.com/rodjek/vim-puppet 5 | " Last Change: 2019-08-31 6 | 7 | if (exists('b:did_ftplugin')) 8 | finish 9 | endif 10 | let b:did_ftplugin = 1 11 | 12 | setlocal tabstop=2 13 | setlocal softtabstop=2 14 | setlocal shiftwidth=2 15 | setlocal expandtab 16 | setlocal keywordprg=puppet\ describe\ --providers 17 | setlocal comments=sr:/*,mb:*,ex:*/,b:# 18 | setlocal commentstring=#\ %s 19 | " adding : to iskeyword is tempting in order to make word movements skip over a 20 | " full resource name, however since : is used in many non-keyword contexts it 21 | " is a bad idea to add it to the option. 22 | 23 | setlocal formatexpr=puppet#format#Format() 24 | 25 | let b:undo_ftplugin = ' 26 | \ setlocal tabstop< tabstop< softtabstop< shiftwidth< expandtab< 27 | \| setlocal keywordprg< iskeyword< comments< commentstring< 28 | \| setlocal formatexpr< 29 | \' 30 | -------------------------------------------------------------------------------- /ftplugin/puppet_tagbar.vim: -------------------------------------------------------------------------------- 1 | " Puppet set up for Tagbar plugin 2 | " (https://github.com/majutsushi/tagbar). 3 | 4 | if !exists(':Tagbar') 5 | finish 6 | endif 7 | 8 | let g:tagbar_type_puppet = { 9 | \ 'ctagstype': 'puppet', 10 | \ 'kinds': [ 11 | \ 'c:Classes', 12 | \ 's:Sites', 13 | \ 'n:Nodes', 14 | \ 'v:Variables', 15 | \ 'i:Includes', 16 | \ 'd:Definitions', 17 | \ 'r:Resources', 18 | \ 'f:Defaults', 19 | \ 't:Types', 20 | \ 'u:Functions', 21 | \], 22 | \} 23 | 24 | if puppet#ctags#Type() ==? 'universal' 25 | " There no sense to split objects by colon 26 | let g:tagbar_type_puppet.sro = '__' 27 | let g:tagbar_type_puppet.kind2scope = { 28 | \ 'd': 'definition', 29 | \ 'c': 'class', 30 | \ 'r': 'resource', 31 | \ 'i': 'include', 32 | \ 'v': 'variable', 33 | \} 34 | let g:tagbar_type_puppet.scope2kind = { 35 | \ 'definition' : 'd', 36 | \ 'class' : 'c', 37 | \ 'resource' : 'r', 38 | \ 'include' : 'i', 39 | \ 'variable' : 'v', 40 | \} 41 | endif 42 | 43 | let g:tagbar_type_puppet.deffile = puppet#ctags#OptionFile() 44 | 45 | -------------------------------------------------------------------------------- /indent/puppet.vim: -------------------------------------------------------------------------------- 1 | " Vim indent file 2 | " Language: Puppet 3 | " Maintainer: Todd Zullinger 4 | " Last Change: 2009 Aug 19 5 | " vim: set sw=4 sts=4: 6 | 7 | if exists('b:did_indent') 8 | finish 9 | endif 10 | let b:did_indent = 1 11 | 12 | setlocal autoindent smartindent 13 | setlocal indentexpr=GetPuppetIndent() 14 | setlocal indentkeys+=0],0) 15 | 16 | let b:undo_indent = ' 17 | \ setlocal autoindent< smartindent< indentexpr< indentkeys< 18 | \' 19 | 20 | if exists('*GetPuppetIndent') 21 | finish 22 | endif 23 | 24 | " Check if a line is part of an include 'block', e.g.: 25 | " include foo, 26 | " bar, 27 | " baz 28 | function! s:PartOfInclude(lnum) 29 | let lnum = a:lnum 30 | while lnum 31 | let lnum = lnum - 1 32 | let line = getline(lnum) 33 | if line !~ ',$' 34 | break 35 | endif 36 | if line =~# '^\s*include\s\+[^,]\+,$' && line !~ '[=>]>' 37 | return 1 38 | endif 39 | endwhile 40 | return 0 41 | endfunction 42 | 43 | function! s:OpenBrace(lnum) 44 | call cursor(a:lnum, 1) 45 | return searchpair('{\|\[\|(', '', '}\|\]\|)', 'nbW', 46 | \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "comment\\|string"') 47 | endfunction 48 | 49 | function! s:InsideMultilineString(lnum) 50 | return synIDattr(synID(a:lnum, 1, 0), 'name') =~? 'string' 51 | endfunction 52 | 53 | function! s:PrevNonMultilineString(lnum) 54 | let l:lnum = a:lnum 55 | while l:lnum > 0 && s:InsideMultilineString(lnum) 56 | let l:lnum = l:lnum - 1 57 | endwhile 58 | 59 | return l:lnum 60 | endfunction 61 | 62 | "" 63 | " Get indent number for line, line can be given as params, otherwise function 64 | " use line where cursor is 65 | " @param a:1 (optional) line number in current buffer 66 | " @return integer 67 | function! GetPuppetIndent(...) 68 | let l:lnum = get(a:, 1, v:lnum) 69 | 70 | let pnum = prevnonblank(l:lnum - 1) 71 | if pnum == 0 72 | return 0 73 | endif 74 | 75 | let line = getline(l:lnum) 76 | let pline = getline(pnum) 77 | let ind = indent(pnum) 78 | 79 | " Avoid cases of closing braces or parens on the current line: returning 80 | " the same indent here would be premature since for that particular case 81 | " we want to instead get the indent level of the matching opening brace or 82 | " parenthenses. 83 | if pline =~# '^\s*#' && line !~# '^\s*\(}\(,\|;\)\?$\|]:\|],\|}]\|];\?$\|)\)' 84 | return ind 85 | endif 86 | 87 | " We are inside a multi-line string: if we interfere with indentation here 88 | " we're actually changing the contents of of the string! 89 | if s:InsideMultilineString(l:lnum) 90 | return indent(l:lnum) 91 | endif 92 | 93 | " Previous line was inside a multi-line string: we've lost the indent 94 | " level. We need to find this value from the last line that was not inside 95 | " of a multi-line string to restore proper alignment. 96 | if s:InsideMultilineString(pnum) 97 | if pnum - 1 == 0 98 | return ind 99 | endif 100 | 101 | let ind = indent(s:PrevNonMultilineString(pnum - 1)) 102 | endif 103 | 104 | let l:bracketAtEndOfLinePattern = '\({\|\[\|(\|:\)\s*\(#.*\)\?$' 105 | if pline =~ l:bracketAtEndOfLinePattern 106 | let l:i = match(pline, l:bracketAtEndOfLinePattern) 107 | let l:syntaxType = synIDattr(synID(pnum, l:i + 1, 0), 'name') 108 | if l:syntaxType !~# '\(Comment\|String\)$' 109 | let ind += &sw 110 | endif 111 | elseif pline =~ ';$' && pline !~ '[^:]\+:.*[=+]>.*' 112 | let ind -= &sw 113 | elseif pline =~# '^\s*include\s\+.*,$' && pline !~ '[=+]>' 114 | let ind += &sw 115 | endif 116 | 117 | if pline !~ ',$' && s:PartOfInclude(pnum) 118 | let ind -= &sw 119 | endif 120 | 121 | " Match } }, }; ] ]: ], ]; ) 122 | if line =~# '^\s*\(}\(,\|;\)\?$\|]:\|],\|}]\|];\?$\|)\)' 123 | let ind = indent(s:OpenBrace(v:lnum)) 124 | endif 125 | 126 | " Don't actually shift over for } else { 127 | if line =~# '^\s*}\s*els\(e\|if\).*{\s*$' 128 | let ind -= &sw 129 | endif 130 | " Don't indent resources that are one after another with a ->(ordering arrow) 131 | " file {'somefile': 132 | " ... 133 | " } -> 134 | " 135 | " package { 'mycoolpackage': 136 | " ... 137 | " } 138 | if line =~ '->$' 139 | let ind -= &sw 140 | endif 141 | 142 | 143 | return ind 144 | endfunction 145 | -------------------------------------------------------------------------------- /syntax/epuppet.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax plugin 2 | " Language: embedded puppet 3 | " Maintainer: Gabriel Filion 4 | " URL: https://github.com/rodjek/vim-puppet 5 | " Last Change: 2019-09-01 6 | 7 | " quit when a syntax file was already loaded {{{1 8 | if exists('b:current_syntax') 9 | finish 10 | endif 11 | 12 | if !exists('g:epuppet_default_subtype') 13 | let g:epuppet_default_subtype = 'sh' 14 | endif 15 | 16 | if &filetype =~# '^epuppet\.' 17 | let b:epuppet_subtype = matchstr(&filetype,'^epuppet\.\zs\w\+') 18 | elseif !exists('b:epuppet_subtype') 19 | let b:epuppet_subtype = matchstr(substitute(expand('%:t'),'\c\%(\.epp\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$') 20 | " TODO instead of listing exceptions like this, can we instead recognize 21 | " extension -> type mapping? 22 | if b:epuppet_subtype ==? 'rhtml' 23 | let b:epuppet_subtype = 'html' 24 | elseif b:epuppet_subtype ==? 'rb' 25 | let b:epuppet_subtype = 'ruby' 26 | elseif b:epuppet_subtype ==? 'yml' 27 | let b:epuppet_subtype = 'yaml' 28 | elseif b:epuppet_subtype ==? 'js' 29 | let b:epuppet_subtype = 'javascript' 30 | elseif b:epuppet_subtype ==? 'txt' 31 | " Conventional; not a real file type 32 | let b:epuppet_subtype = 'text' 33 | elseif b:epuppet_subtype ==? 'py' 34 | let b:epuppet_subtype = 'python' 35 | elseif b:epuppet_subtype ==? 'rs' 36 | let b:epuppet_subtype = 'rust' 37 | elseif b:epuppet_subtype ==? '' 38 | let b:epuppet_subtype = g:epuppet_default_subtype 39 | endif 40 | endif 41 | 42 | if exists('b:epuppet_subtype') && b:epuppet_subtype != '' && b:epuppet_subtype !=? 'epuppet' 43 | exe 'runtime! syntax/'.b:epuppet_subtype.'.vim' 44 | unlet! b:current_syntax 45 | endif 46 | 47 | syn include @puppetTop syntax/puppet.vim 48 | 49 | syn cluster ePuppetRegions contains=ePuppetBlock,ePuppetExpression,ePuppetComment 50 | 51 | syn region ePuppetBlock matchgroup=ePuppetDelimiter start="<%%\@!-\=" end="[=-]\=%\@" contains=@puppetTop containedin=ALLBUT,@ePuppetRegions keepend 52 | syn region ePuppetExpression matchgroup=ePuppetDelimiter start="<%=\{1,4}" end="[=-]\=%\@" contains=@puppetTop containedin=ALLBUT,@ePuppetRegions keepend 53 | syn region ePuppetComment matchgroup=ePuppetDelimiter start="<%-\=#" end="[=-]\=%\@" contains=puppetTodo,@Spell containedin=ALLBUT,@ePuppetRegions keepend 54 | 55 | " Define the default highlighting. 56 | 57 | hi def link ePuppetDelimiter PreProc 58 | hi def link ePuppetComment Comment 59 | 60 | let b:current_syntax = 'epuppet' 61 | -------------------------------------------------------------------------------- /syntax/puppet.vim: -------------------------------------------------------------------------------- 1 | " Language: Puppet 2 | " Maintainer: Voxpupuli 3 | " URL: https://github.com/voxpupuli/vim-puppet 4 | " 5 | " Thanks to Doug Kearns who maintains the vim syntax file for Ruby. Many constructs, including interpolation 6 | " and heredoc was copied from ruby and then modified to comply with Puppet syntax. 7 | 8 | " Prelude {{{1 9 | if exists('b:current_syntax') 10 | finish 11 | endif 12 | 13 | " this file uses line continuations 14 | let s:cpo_sav = &cpo 15 | set cpo&vim 16 | 17 | if !exists('g:puppet_display_errors') 18 | let g:puppet_display_errors = 1 19 | endif 20 | 21 | syn cluster puppetNotTop contains=@puppetExtendedStringSpecial,@puppetRegexpSpecial,puppetTodo 22 | 23 | syn match puppetSpaceError display excludenl "\s\+$" 24 | syn match puppetSpaceError display " \+\t\+\%( \|\t\)*\|\t\+ \+\%( \|\t\)*" 25 | 26 | " one character operators 27 | syn match puppetOperator "[=><+/*%!.|@:,;?~-]" 28 | 29 | " two character operators 30 | syn match puppetOperator "+=\|-=\|==\|!=\|=\~\|!\~\|>=\|<=\|<-\|<\~\|=>\|+>\|->\|\~>\|<<\||>\|@@" 31 | 32 | " three character operators 33 | syn match puppetOperator "<<|\||>>" 34 | 35 | syn region puppetBracketBlock transparent matchgroup=puppetBracket start="\[" end="]" fold contains=ALLBUT,@puppetNotTop 36 | syn region puppetBraceBlock transparent matchgroup=puppetBrace start="{" end="}" fold contains=ALLBUT,@puppetNotTop 37 | syn region puppetParenBlock transparent matchgroup=puppetParen start="(" end=")" fold contains=ALLBUT,@puppetNotTop 38 | 39 | " Expression Substitution and Backslash Notation {{{1 40 | syn match puppetStringEscape "\\\\\|\\[abefnrstv]\|\\\o\{1,3}\|\\x\x\{1,2}" contained display 41 | syn match puppetStringEscape "\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)" contained display 42 | syn match puppetQuoteEscape "\\[\\']" contained display 43 | 44 | syn region puppetNoInterpolation contained transparent start="\\${" end="}" 45 | syn match puppetNoInterpolation display contained "\\${" 46 | syn match puppetNoInterpolation display contained "\\$\w\+" 47 | syn region puppetInterpolation transparent matchgroup=puppetInterpolationDelimiter start="${" end="}" contained contains=ALLBUT,@puppetNotTop 48 | syn match puppetInterpolation "$\%(::\)\?\w\+" display contained contains=puppetInterpolationDelimiter,puppetVariable 49 | syn match puppetInterpolation "$\$\%(-\w\|\W\)" display contained contains=puppetInterpolationDelimiter,puppetVariable 50 | syn match puppetInterpolationDelimiter "$\ze\$\w\+" display contained 51 | syn match puppetInterpolationDelimiter "$\ze\$\%(-\w\|\W\)" display contained 52 | 53 | syn match puppetDelimiterEscape "\\[(<{\[)>}\]]" transparent display contained contains=NONE 54 | 55 | syn region puppetNestedParentheses start="(" skip="\\\\\|\\)" matchgroup=puppetString end=")" transparent contained 56 | syn region puppetNestedCurlyBraces start="{" skip="\\\\\|\\}" matchgroup=puppetString end="}" transparent contained 57 | syn region puppetNestedAngleBrackets start="<" skip="\\\\\|\\>" matchgroup=puppetString end=">" transparent contained 58 | syn region puppetNestedSquareBrackets start="\[" skip="\\\\\|\\\]" matchgroup=puppetString end="\]" transparent contained 59 | 60 | " Regular Expression Metacharacters {{{1 61 | " These are mostly Oniguruma ready 62 | syn region puppetRegexpComment matchgroup=puppetRegexpSpecial start="(?#" skip="\\)" end=")" contained 63 | syn region puppetRegexpParens matchgroup=puppetRegexpSpecial start="(\(?:\|?<\=[=!]\|?>\|?<[a-z_]\w*>\|?[imx]*-[imx]*:\=\|\%(?#\)\@!\)" skip="\\)" end=")" contained transparent contains=@puppetRegexpSpecial 64 | syn region puppetRegexpBrackets matchgroup=puppetRegexpCharClass start="\[\^\=" skip="\\\]" end="\]" contained transparent contains=puppetStringEscape,puppetRegexpEscape,puppetRegexpCharClass oneline 65 | syn match puppetRegexpCharClass "\\[DdHhSsWw]" contained display 66 | syn match puppetRegexpCharClass "\[:\^\=\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|xdigit\):\]" contained 67 | syn match puppetRegexpEscape "\\[].*?+^$|\\/(){}[]" contained 68 | syn match puppetRegexpQuantifier "[*?+][?+]\=" contained display 69 | syn match puppetRegexpQuantifier "{\d\+\%(,\d*\)\=}?\=" contained display 70 | syn match puppetRegexpAnchor "[$^]\|\\[ABbGZz]" contained display 71 | syn match puppetRegexpDot "\." contained display 72 | syn match puppetRegexpSpecial "|" contained display 73 | syn match puppetRegexpSpecial "\\[1-9]\d\=\d\@!" contained display 74 | syn match puppetRegexpSpecial "\\k<\%([a-z_]\w*\|-\=\d\+\)\%([+-]\d\+\)\=>" contained display 75 | syn match puppetRegexpSpecial "\\k'\%([a-z_]\w*\|-\=\d\+\)\%([+-]\d\+\)\='" contained display 76 | syn match puppetRegexpSpecial "\\g<\%([a-z_]\w*\|-\=\d\+\)>" contained display 77 | syn match puppetRegexpSpecial "\\g'\%([a-z_]\w*\|-\=\d\+\)'" contained display 78 | 79 | syn cluster puppetStringSpecial contains=puppetInterpolation,puppetNoInterpolation,puppetStringEscape 80 | syn cluster puppetExtendedStringSpecial contains=@puppetStringSpecial,puppetNestedParentheses,puppetNestedCurlyBraces,puppetNestedAngleBrackets,puppetNestedSquareBrackets 81 | syn cluster puppetRegexpSpecial contains=puppetRegexpSpecial,puppetRegexpEscape,puppetRegexpBrackets,puppetRegexpCharClass,puppetRegexpDot,puppetRegexpQuantifier,puppetRegexpAnchor,puppetRegexpParens,puppetRegexpComment 82 | 83 | syn match puppetInteger "\%(\%(\w\|[]})\"']\s*\)\@" display 84 | syn match puppetInteger "\%(\%(\w\|[]})\"']\s*\)\@" display 85 | syn match puppetInteger "\%(\%(\w\|[]})\"']\s*\)\@" display 86 | syn match puppetFloat "\%(\%(\w\|[]})\"']\s*\)\@" display 87 | syn match puppetFloat "\%(\%(\w\|[]})\"']\s*\)\@" display 88 | " order of matches is important. The following need to be placed after the ones above 89 | syn match puppetInvalidNumber "\%(\%(\w\|[]})\"']\s*\)\@" display 90 | syn match puppetInvalidNumber "\%(\%(\w\|[]})\"']\s*\)\@" display 91 | syn match puppetInvalidNumber "\%(\%(\w\|[]})\"']\s*\)\@" display 92 | 93 | syn match puppetVariable "$\%(::\)\=\w\+\%(::\w\+\)*" display 94 | " resource or function name 95 | syn match puppetName "\%(\%(::\)\=\|\<\)[a-z]\w*\%(::[a-z]\w*\)*\>" display 96 | " resource reference or data type 97 | syn match puppetType "\%(\%(::\)\=\|\<\)[A-Z]\w*\%(::[A-Z]\w*\)*\>" display 98 | " See https://www.puppet.com/docs/puppet/8/lang_data_string#lang_data_string_bare_words 99 | syn match puppetBareWordString "\%(\%(\%(::\)\=\|\<\)\%(_[\w-]*\w\+\)\|\%([a-z]\%(\w*-\)\+\w\+\)\)\+\>" display 100 | " bad name containing combinations of segment starting with lower case and segement starting with upper case (or vice versa) 101 | syn match puppetInvalidName "\%(\%(::\)\=\|\<\)\%(\w\+::\)*\%(\%([a-z]\w*::[A-Z]\w*\)\|\%([A-Z]\w*::[a-z]\w*\)\)\%(::\w\+\)*\>" display 102 | syn cluster puppetNameOrType contains=puppetVariable,puppetName,puppetType,puppetBareWordString,puppetInvalidName 103 | 104 | syn keyword puppetControl case in 105 | syn keyword puppetStructure node class define plan 106 | syn keyword puppetKeyword inherits function type attr private 107 | syn keyword puppetKeyword application consumes produces site component environment unit 108 | syn keyword puppetKeyword present absent purged latest installed running stopped mounted unmounted role configured 109 | syn keyword puppetKeyword directory link on_failure regexp 110 | syn keyword puppetConstant default undef 111 | syn keyword puppetConditional if else elsif unless and or 112 | syn keyword puppetBoolean true false 113 | 114 | " Core functions that include more code 115 | syn keyword puppetIncludeFunction contain create_resources include hiera_include require 116 | 117 | " Core functions 118 | syn keyword puppetConditional then lest 119 | syn keyword puppetRepeat break each map next return reverse_each 120 | syn keyword puppetDebug alert crit debug emerg err fail info notice warning 121 | syn keyword puppetFunction abs all annotate any assert_type binary_file call camelcase capitalize ceiling chomp chop 122 | syn keyword puppetFunction compare convert_to defined dig digest downcase empty epp eyaml_lookup_key file filter 123 | syn keyword puppetFunction find_file find_template flatten floor fqdn_rand generate get getvar group_by hiera 124 | syn keyword puppetFunction hiera_array hiera_hash hocon_data index inline_epp inline_template join json_data keys 125 | syn keyword puppetFunction length lookup lstrip match max md5 min module_directory new partition realize reduce 126 | syn keyword puppetFunction regsubst round rstrip scanf sha1 sha256 shellquote size slice sort split sprintf step 127 | syn keyword puppetFunction strftime strip tag tagged template type unique unwrap upcase values versioncmp with yaml_data 128 | 129 | " deprecated Core functions 130 | syn keyword puppetDeprecated import 131 | 132 | " puppet bolt functions 133 | syn keyword puppetFunction add_facts add_to_group apply apply_prep background catch_errors 134 | syn match puppetFunction "\" 135 | syn match puppetFunction "\" 136 | syn match puppetFunction "\" 137 | syn keyword puppetFunction download_file fail_plan 138 | syn match puppetFunction "\" 139 | syn match puppetFunction "\" 140 | syn match puppetFunction "\" 141 | syn match puppetFunction "\" 142 | syn match puppetFunction "\" 143 | syn match puppetFunction "\" 144 | syn keyword puppetFunction get_resources get_target get_targets 145 | syn match puppetFunction "\" 146 | syn match puppetFunction "\" 147 | syn match puppetFunction "\" 148 | syn match puppetFunction "\" 149 | syn match puppetFunction "\" 150 | syn match puppetFunction "\" 151 | syn match puppetFunction "\" 152 | syn match puppetFunction "\" 153 | syn keyword puppetFunction parallelize prompt 154 | syn match puppetFunction "\" 155 | syn keyword puppetFunction puppetdb_command puppetdb_fact puppetdb_query remove_from_group resolve_references resource 156 | syn keyword puppetFunction run_command run_container run_plan run_script run_task run_task_with set_config set_feature 157 | syn keyword puppetFunction set_resources set_var 158 | syn match puppetFunction "\" 159 | syn keyword puppetFunction upload_file vars wait wait_until_available without_default_logging write_file 160 | 161 | " Stdlib functions 162 | syn keyword puppetStdLibFunction any2array any2bool assert_private base64 basename bool2num bool2str clamp concat 163 | syn keyword puppetStdLibFunction convert_base count deep_merge defined_with_params delete delete_at delete_regex 164 | syn keyword puppetStdLibFunction delete_undef_values delete_values deprecation difference dirname dos2unix enclose_ipv6 165 | syn keyword puppetStdLibFunction ensure_resource ensure_resources fact fqdn_uuid get_module_path getparam glob grep 166 | syn keyword puppetStdLibFunction has_ip_address has_ip_network intersection is_a join_keys_to_values 167 | syn keyword puppetStdLibFunction load_module_metadata loadjson loadyaml member min num2bool parsejson parseyaml pick 168 | syn keyword puppetStdLibFunction pick_default prefix pry range regexpescape reject reverse shell_join shell_split shuffle squeeze 169 | syn match puppetStdLibFunction "\" 170 | syn match puppetStdLibFunction "\" 171 | syn match puppetStdLibFunction "\" 172 | syn match puppetStdLibFunction "\" 173 | syn match puppetStdLibFunction "\" 174 | syn match puppetStdLibFunction "\" 175 | syn match puppetStdLibFunction "\" 176 | syn match puppetStdLibFunction "\" 177 | syn match puppetStdLibFunction "\" 178 | syn match puppetStdLibFunction "\" 179 | syn match puppetStdLibFunction "\" 180 | syn match puppetStdLibFunction "\" 181 | syn match puppetStdLibFunction "\" 182 | syn match puppetStdLibFunction "\" 183 | syn match puppetStdLibFunction "\" 184 | syn match puppetStdLibFunction "\" 185 | syn match puppetStdLibFunction "\" 186 | syn match puppetStdLibFunction "\" 187 | syn match puppetStdLibFunction "\" 188 | syn match puppetStdLibFunction "\" 189 | syn match puppetStdLibFunction "\" 190 | syn match puppetStdLibFunction "\" 191 | syn match puppetStdLibFunction "\" 192 | syn match puppetStdLibFunction "\" 193 | syn match puppetStdLibFunction "\" 194 | syn match puppetStdLibFunction "\" 195 | syn match puppetStdLibFunction "\" 196 | syn match puppetStdLibFunction "\" 197 | syn match puppetStdLibFunction "\" 198 | syn match puppetStdLibFunction "\" 199 | syn match puppetStdLibFunction "\" 200 | syn match puppetStdLibFunction "\" 201 | syn match puppetStdLibFunction "\" 202 | syn match puppetStdLibFunction "\" 203 | syn match puppetStdLibFunction "\" 204 | syn keyword puppetStdLibFunction str2bool str2saltedpbkdf2 str2saltedsha512 suffix swapcase to_bytes union unix2dos 205 | syn keyword puppetStdLibFunction uriescape validate_augeas validate_cmd validate_x509_rsa_key_pair values_at zip 206 | 207 | " Stdlib deprecated functions, as of 9.6.0 208 | syn keyword puppetDeprecated batch_escape ensure_packages fqdn_rand_string fqdn_rotate has_interface_with merge 209 | syn keyword puppetDeprecated os_version_gte parsehocon parsepson powershell_escape seeded_rand seeded_rand_string shell_escape 210 | syn match puppetDeprecated "\" 211 | syn keyword puppetDeprecated time to_json to_json_pretty to_python to_ruby to_toml to_yaml type_of validate_domain_name 212 | syn keyword puppetDeprecated validate_email_address validate_legacy 213 | 214 | " Core data types 215 | syn keyword puppetType Any Array Binary Boolean Callable CatalogEntry Class Collection Data Default Deferred Enum Error 216 | syn keyword puppetType Float Hash Init Integer Iterable Iterator NotUndef Numeric Object Optional Pattern Regexp 217 | syn keyword puppetType Resource RichData Runtime Scalar ScalarData SemVer SemVerRange Sensitive String Struct TimeSpan 218 | syn keyword puppetType Timestamp Tuple Type TypeSet Undef URI Variant 219 | 220 | " Bolt data types 221 | syn keyword puppetType ApplyResult ContainerResult Future ResourceInstance Result ResultSet Target TargetSpec PlanResult 222 | 223 | " Core resource types 224 | syn keyword puppetType exec file filebucket group notify package resources schedule service stage tidy user 225 | 226 | " supported resource types 227 | syn keyword puppetType augeas cron host mount scheduled_task selboolean selmodule ssh_authorized_key sshkey yumrepo zfs zone zpool 228 | 229 | " resource types by Puppet, inc but available on forge 230 | syn keyword puppetType k5login mailalias maillist 231 | 232 | " deprecated resource types 233 | syn keyword puppetDeprecated computer interface macauthorization mcx nagios_command nagios_contact nagios_contactgroup 234 | syn keyword puppetDeprecated nagios_host nagios_hostdependency nagios_hostescalation nagios_hostextinfo 235 | syn keyword puppetDeprecated nagios_hostgroup nagios_service nagios_servicedependency nagios_serviceescalation 236 | syn keyword puppetDeprecated nagios_serviceextinfo nagios_servicegroup nagios_timeperiod router vlan 237 | 238 | " Normal String {{{1 239 | syn region puppetString matchgroup=puppetStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@puppetStringSpecial 240 | syn region puppetString matchgroup=puppetStringDelimiter start="'" end="'" skip="\\\\\|\\'" contains=puppetQuoteEscape 241 | 242 | " Normal Regular Expression {{{1 243 | syn region puppetRegexp matchgroup=puppetRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,{[<>?:*+-]\)\s*\)\zs/" end="/" skip="\\\\\|\\/" contains=@puppetRegexpSpecial 244 | syn region puppetRegexp matchgroup=puppetRegexpDelimiter start="\%(\h\k*\s\+\)\zs/[ \t=]\@!" end="/" skip="\\\\\|\\/" contains=@puppetRegexpSpecial 245 | 246 | " Here Document {{{1 247 | syn region puppetHeredocStart matchgroup=puppetStringDelimiter start=+@(\s*\%("[^"]\+"\|\w\+\)\%(/[nrtsuL$\\]*\)\=)+ end=+$+ oneline contains=ALLBUT,@puppetNotTop 248 | 249 | syn region puppetString start=+@(\s*"\z([^"]\+\)"\%(/[nrtsuL$\\]*\)\=+hs=s+2 matchgroup=puppetStringDelimiter end=+^\s*|\=\s*-\=\s*\zs\z1$+ contains=puppetHeredocStart,@puppetStringSpecial keepend 250 | syn region puppetString start=+@(\s*\z(\w\+\)\%(/[nrtsuL$\\]*\)\=+hs=s+2 matchgroup=puppetStringDelimiter end=+^\s*|\=\s*-\=\s*\zs\z1$+ contains=puppetHeredocStart keepend 251 | 252 | " comments last overriding everything else 253 | syn match puppetComment "\s*#.*$" contains=puppetTodo,puppetSpaceError,@Spell 254 | syn region puppetComment start="/\*" end="\*/" contains=puppetTodo,puppetSpaceError,@Spell extend 255 | syn keyword puppetTodo TODO NOTE FIXME XXX BUG HACK contained 256 | 257 | hi def link puppetStringDelimiter Delimiter 258 | hi def link puppetRegexpDelimiter Delimiter 259 | hi def link puppetRegexp puppetConstant 260 | hi def link puppetConstant Constant 261 | hi def link puppetNoInterpolation puppetString 262 | hi def link puppetString String 263 | hi def link puppetBareWordString String 264 | hi def link puppetFloat Float 265 | hi def link puppetInteger Number 266 | hi def link puppetBoolean Boolean 267 | hi def link puppetType Type 268 | hi def link puppetBracket Operator 269 | hi def link puppetBrace Operator 270 | hi def link puppetParen Operator 271 | hi def link puppetOperator Operator 272 | hi def link puppetStructure Structure 273 | hi def link puppetName puppetIdentifier 274 | hi def link puppetVariable puppetIdentifier 275 | hi def link puppetIdentifier Identifier 276 | hi def link puppetInterpolationDelimiter Identifier 277 | hi def link puppetConditional Conditional 278 | hi def link puppetRepeat Repeat 279 | hi def link puppetControl Label 280 | hi def link puppetKeyword Keyword 281 | hi def link puppetTodo Todo 282 | hi def link puppetComment Comment 283 | hi def link puppetIncludeFunction Include 284 | hi def link puppetStdLibFunction puppetFunction 285 | hi def link puppetFunction Function 286 | hi def link puppetDeprecated Ignore 287 | hi def link puppetDebug Debug 288 | 289 | if g:puppet_display_errors 290 | hi def link puppetInvalidNumber Error 291 | hi def link puppetInvalidName Error 292 | hi def link puppetSpaceError Error 293 | endif 294 | 295 | let b:current_syntax = 'puppet' 296 | -------------------------------------------------------------------------------- /test/filetype/epuppet.vader: -------------------------------------------------------------------------------- 1 | Execute (Filetype detection on a new empty file): 2 | edit foo.epp 3 | AssertEqual &filetype, 'epuppet' 4 | 5 | Execute (epuppet test_with_leading_tag): 6 | edit test/test-files/test_with_leading_tag.epp 7 | AssertEqual &filetype, 'epuppet' 8 | 9 | Execute (TODO: epuppet perl with shebang): 10 | edit test/test-files/test_perl_with_shebang.epp 11 | AssertEqual &filetype, 'epuppet' 12 | AssertEqual b:epuppet_subtype, 'perl' 13 | 14 | # We don't need to parse the shebang for shell since sh is the default subtype 15 | Execute (epuppet default to shell): 16 | edit test/test-files/test_shell_with_shebang.epp 17 | AssertEqual &filetype, 'epuppet' 18 | AssertEqual b:epuppet_subtype, 'sh' 19 | 20 | Execute (epuppet shell with extension): 21 | edit test/test-files/test_shell_with_extension.sh.epp 22 | AssertEqual &filetype, 'epuppet' 23 | AssertEqual b:epuppet_subtype, 'sh' 24 | 25 | Execute (epuppet php with extension): 26 | edit test/test-files/test_php_with_extension.php.epp 27 | AssertEqual &filetype, 'epuppet' 28 | AssertEqual b:epuppet_subtype, 'php' 29 | 30 | Execute (TODO: epuppet apache conf with path and extension): 31 | edit test/test-files/etc/apache2/test.conf.epp 32 | AssertEqual &filetype, 'epuppet' 33 | AssertEqual b:epuppet_subtype, 'apache' 34 | -------------------------------------------------------------------------------- /test/filetype/puppet.vader: -------------------------------------------------------------------------------- 1 | Execute (Load simple puppet file): 2 | edit simple.pp 3 | 4 | Then (Detected simple.pp as a puppet file): 5 | AssertEqual &filetype, 'puppet' 6 | -------------------------------------------------------------------------------- /test/filetype/puppetfile.vader: -------------------------------------------------------------------------------- 1 | Execute (Load Puppetfile): 2 | edit test/test-files/Puppetfile 3 | 4 | Then (Detected Puppetfile as a ruby file): 5 | AssertEqual &filetype, 'ruby' 6 | -------------------------------------------------------------------------------- /test/format/hashrocket.vader: -------------------------------------------------------------------------------- 1 | Given puppet (simple resource without hashrocket alignment): 2 | file { 'foo': 3 | ensure => present, 4 | mode => '0700', 5 | require => Package['this-and-that'], 6 | } 7 | 8 | Do (autoformat resource while adding new parameter): 9 | joforce=>true, 10 | 11 | Expect puppet (formated resource): 12 | file { 'foo': 13 | ensure => present, 14 | force => true, 15 | mode => '0700', 16 | require => Package['this-and-that'], 17 | } 18 | 19 | ------------------------------------------------------------------------------- 20 | 21 | Given puppet (simple resource with gq): 22 | # Short comment 23 | file { 'foo': 24 | ensure => present, 25 | # mode => '0700', 26 | force => true, 27 | } 28 | 29 | Do (format resource): 30 | gqG 31 | 32 | Expect puppet (formated resource): 33 | # Short comment 34 | file { 'foo': 35 | ensure => present, 36 | # mode => '0700', 37 | force => true, 38 | } 39 | 40 | ------------------------------------------------------------------------------- 41 | 42 | Given puppet (comment with code snippet with hashrocket): 43 | # @example: Minimal example for puppet-vim issue 44 | # class { 'example1': 45 | # attr => 'short attribute', 46 | # } 47 | # 48 | # @example2: AlignHashrockets goes nuts 49 | # class { 'example2': 50 | # long_attr 51 | 52 | Do (Add hashrocket in second example): 53 | GA=> 54 | 55 | Expect puppet (example1 untouched): 56 | # @example: Minimal example for puppet-vim issue 57 | # class { 'example1': 58 | # attr => 'short attribute', 59 | # } 60 | # 61 | # @example2: AlignHashrockets goes nuts 62 | # class { 'example2': 63 | # long_attr => 64 | 65 | -------------------------------------------------------------------------------- /test/format/textwidth.vader: -------------------------------------------------------------------------------- 1 | # First let's test that formatting without textwidth set doesn't do unexpected things 2 | 3 | Given puppet (long line): 4 | # Long comment 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 5 | file { 'foo': 6 | ensure => present, 7 | } 8 | 9 | Do (format all text): 10 | gqG 11 | 12 | Expect puppet (nothing changed): 13 | # Long comment 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 14 | file { 'foo': 15 | ensure => present, 16 | } 17 | 18 | ------------------------------------------------------------------------------- 19 | # Now let's check that the plugin does the right thing when textwidth is set. 20 | # 21 | # All of the tests below this point expect to have 'textwidth' set during the test. 22 | Before (set textwidth): 23 | set textwidth=76 24 | 25 | After (unset textwidth): 26 | set textwidth=0 27 | 28 | ------------------------------------------------------------------------------- 29 | # note: using the same fixture as before 30 | Do (format all text with textwidth set): 31 | gqG 32 | 33 | Expect puppet (comment is wrapped into more lines): 34 | # Long comment 123456789 123456789 123456789 123456789 123456789 123456789 35 | # 123456789 123456789 123456789 123456789 123456789 123456789 123456789 36 | # 123456789 37 | file { 'foo': 38 | ensure => present, 39 | } 40 | 41 | ------------------------------------------------------------------------------- 42 | Given puppet (long line before editing): 43 | file { 'foo': 44 | ensure => present, 45 | source => ['puppet:///modules/very_long_module_name_that_will_not_stop'], 46 | } 47 | 48 | Do (type in some more on long line): 49 | jjA mode 50 | 51 | Expect puppet (formatting did not change line): 52 | file { 'foo': 53 | ensure => present, 54 | source => ['puppet:///modules/very_long_module_name_that_will_not_stop'], mode 55 | } 56 | 57 | -------------------------------------------------------------------------------- /test/indent/basic.vader: -------------------------------------------------------------------------------- 1 | Given puppet (class with includes): 2 | class foo::boo { 3 | include foo::moo 4 | include foo::moo::boo 5 | } 6 | 7 | Do (full text indent with '='): 8 | gg=G 9 | 10 | Expect puppet (indented class): 11 | class foo::boo { 12 | include foo::moo 13 | include foo::moo::boo 14 | } 15 | ------------------------------------------------------------------------------- 16 | Given puppet (class with includes): 17 | class foo::boo { 18 | include foo::moo 19 | include foo::moo::boo 20 | } 21 | 22 | Do (full text indent with 'gq' in Visual Mode): 23 | VGgq 24 | 25 | Expect puppet (indented class): 26 | class foo::boo { 27 | include foo::moo 28 | include foo::moo::boo 29 | } 30 | ------------------------------------------------------------------------------- 31 | Given puppet (class with includes and resources): 32 | class foo::boo { 33 | file { 'boo': 34 | ensure => present, 35 | } 36 | include foo::moo 37 | include foo::moo::boo 38 | } 39 | 40 | Do (full text indent by gq with motion): 41 | jgqi{ 42 | 43 | Expect puppet (indented class): 44 | class foo::boo { 45 | file { 'boo': 46 | ensure => present, 47 | } 48 | include foo::moo 49 | include foo::moo::boo 50 | } 51 | -------------------------------------------------------------------------------- /test/indent/comments_strings.vader: -------------------------------------------------------------------------------- 1 | Given puppet (comments before closing brace): 2 | node pizzabox.example.com { 3 | include some::resource 4 | # This comment is very important 5 | } 6 | 7 | Do (full text indent with '='): 8 | gg=G 9 | 10 | Expect puppet (closing brace back aligned with start of resource block): 11 | node pizzabox.example.com { 12 | include some::resource 13 | # This comment is very important 14 | } 15 | ------------------------------------------------------------------------------- 16 | Given puppet (closing brace after comment that contains closing brace): 17 | class something { 18 | #} 19 | } 20 | 21 | Do (full text indent with '='): 22 | gg=G 23 | 24 | Expect puppet (closing brace back aligned with start of resource block): 25 | class something { 26 | #} 27 | } 28 | ------------------------------------------------------------------------------- 29 | Given puppet (multi-line string): 30 | class something { 31 | $var=" 32 | This text on new line 33 | should not move 34 | " 35 | this::defined_type { 'foo': 36 | content => $var, 37 | } 38 | } 39 | 40 | " XXX Redraw the screen to ensure that syntax highlighting has run 41 | Do (full text indent with '='): 42 | \:redraw | normal! gs\ 43 | gg=G 44 | 45 | Expect puppet (multi-line string does not move and line after resumes indentation): 46 | class something { 47 | $var=" 48 | This text on new line 49 | should not move 50 | " 51 | this::defined_type { 'foo': 52 | content => $var, 53 | } 54 | } 55 | 56 | ------------------------------------------------------------------------------- 57 | Given puppet (square bracket and hash sign): 58 | $baz = '[#' 59 | 60 | Do (New line): 61 | A\$qux 62 | 63 | Expect puppet (indent stays the same): 64 | $baz = '[#' 65 | $qux 66 | -------------------------------------------------------------------------------- /test/indent/include.vader: -------------------------------------------------------------------------------- 1 | " We want includes that bring in more than one classes and that span multiple 2 | " lines to be indented until we have the last resource name without a trailing 3 | " comma. 4 | Given puppet (include of multiple classes over multiple lines): 5 | include foo::moo, 6 | foo::moo::boo, 7 | foo::baa 8 | 9 | Do (full text indent with '='): 10 | gg=G 11 | 12 | Expect puppet (indented include): 13 | include foo::moo, 14 | foo::moo::boo, 15 | foo::baa 16 | ------------------------------------------------------------------------------- 17 | " This indentation of includes must not affect resource parameters that are 18 | " named include. 19 | Given puppet (resource with param named include): 20 | some::resouce { 'namehere': 21 | include => ['s1', 's2'], 22 | otherparam => 'value', 23 | 24 | Do (full text indent with '='): 25 | gg=G 26 | 27 | Expect puppet (properly aligned parameters): 28 | some::resouce { 'namehere': 29 | include => ['s1', 's2'], 30 | otherparam => 'value', 31 | ------------------------------------------------------------------------------- 32 | " This case is similar to the one above but would trigger only when the line 33 | " just above the current line (the line affected here would be 34 | " "following::resource ...") was something that didn't end with a trailing 35 | " comma. This would trigger evaluation of PartOfInclude and would end up 36 | " finding the parameter named include which would lead to an indentation error 37 | " for following::resource. 38 | Given puppet (resource with param named include contained in class): 39 | class module::blah { 40 | some::resouce { 'namehere': 41 | include => ['s1', 's2'], 42 | otherparam => 'value', 43 | } 44 | following::resource { 'identifier': 45 | 46 | Do (full text indent with '='): 47 | gg=G 48 | 49 | Expect puppet (second contained resource should align with the first one): 50 | class module::blah { 51 | some::resouce { 'namehere': 52 | include => ['s1', 's2'], 53 | otherparam => 'value', 54 | } 55 | following::resource { 'identifier': 56 | -------------------------------------------------------------------------------- /test/init.vim: -------------------------------------------------------------------------------- 1 | " minimum vim configuration for test runner 2 | set nocompatible 3 | filetype off 4 | set rtp+=vader.vim 5 | set rtp+=. 6 | set rtp+=after 7 | filetype plugin indent on 8 | syntax enable 9 | " Avoid closing up any fold since it results in some tests skipping lines and 10 | " their output ends up diverging from what we expect them to be. 11 | set foldlevel=99 12 | -------------------------------------------------------------------------------- /test/run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Download dependencies for tests and run full test suit 4 | # Can use TESTVIM env variable to choose between vim and nvim (neovim) 5 | # Optional first script argument can be path to vader file (run only one suite) 6 | # 7 | set -x 8 | TEST_FILE=$1 9 | SCRIPT_FOLDER=$(dirname "$(readlink -f "$0")") 10 | 11 | # TESTVIM env variable has precedence over installed programs 12 | # next in row is neovim and last one is vim 13 | if [ "$TESTVIM" == "vim" ]; then 14 | RUNVIM=vim 15 | elif [ "$TESTVIM" == "nvim" ] || [ -x "$(command -v nvim)" ]; then 16 | RUNVIM=nvim 17 | VADER_OUTPUT_FILE=$(mktemp) 18 | export VADER_OUTPUT_FILE 19 | trap 'rm -f ${VADER_OUTPUT_FILE}' EXIT INT QUIT TERM 20 | elif [ -x "$(command -v vim)" ]; then 21 | RUNVIM=vim 22 | else 23 | echo 'Error: vim is not installed.' >&2 24 | exit 1 25 | fi 26 | 27 | cd "${SCRIPT_FOLDER}/.." || exit 28 | 29 | if [ ! -d "vader.vim" ]; then 30 | git clone https://github.com/junegunn/vader.vim.git 31 | fi 32 | 33 | if [ -z "$TEST_FILE" ]; then 34 | TEST_SUITE='test/**/*.vader' 35 | else 36 | TEST_SUITE=$TEST_FILE 37 | fi 38 | 39 | "${RUNVIM}" -u test/init.vim -c "Vader! ${TEST_SUITE}" > /dev/null 40 | vader_exit=$? 41 | [ -n "${VADER_OUTPUT_FILE}" ] && cat "${VADER_OUTPUT_FILE}" 42 | exit $vader_exit 43 | 44 | -------------------------------------------------------------------------------- /test/syntax/array.vader: -------------------------------------------------------------------------------- 1 | Given puppet (simple array): 2 | [ 'one', 'two', 'three' ] 3 | 4 | Execute (syntax is good): 5 | AssertEqual 'puppetBracket', SyntaxAt(1,1), '[, col 1. got: "'.SyntaxAt(1,1).'"' 6 | AssertEqual '', SyntaxAt(1,2), 'space, col 2. got: "'.SyntaxAt(1,2).'"' 7 | AssertEqual 'puppetStringDelimiter', SyntaxAt(1,3), 'quote, col 3. got: "'.SyntaxAt(1,3).'"' 8 | AssertEqual 'puppetString', SyntaxAt(1,4), 'o, col 4. got: "'.SyntaxAt(1,4).'"' 9 | AssertEqual 'puppetString', SyntaxAt(1,5), 'n, col 5. got: "'.SyntaxAt(1,5).'"' 10 | AssertEqual 'puppetString', SyntaxAt(1,6), 'e, col 6. got: "'.SyntaxAt(1,6).'"' 11 | AssertEqual 'puppetStringDelimiter', SyntaxAt(1,7), 'quote, col 7. got: "'.SyntaxAt(1,7).'"' 12 | AssertEqual 'puppetOperator', SyntaxAt(1,8), 'comma, col 8. got: "'.SyntaxAt(1,8).'"' 13 | AssertEqual '', SyntaxAt(1,9), 'space, col 9. got: "'.SyntaxAt(1,9).'"' 14 | AssertEqual 'puppetStringDelimiter', SyntaxAt(1,10), 'quote, col 10. got: "'.SyntaxAt(1,10).'"' 15 | AssertEqual 'puppetString', SyntaxAt(1,11), 't, col 11. got: "'.SyntaxAt(1,11).'"' 16 | AssertEqual 'puppetString', SyntaxAt(1,12), 'w, col 12. got: "'.SyntaxAt(1,12).'"' 17 | AssertEqual 'puppetString', SyntaxAt(1,13), 'o, col 13. got: "'.SyntaxAt(1,13).'"' 18 | AssertEqual 'puppetStringDelimiter', SyntaxAt(1,14), 'quote, col 14. got: "'.SyntaxAt(1,14).'"' 19 | AssertEqual 'puppetOperator', SyntaxAt(1,15), 'comma, col 15. got: "'.SyntaxAt(1,15).'"' 20 | AssertEqual '', SyntaxAt(1,16), 'space, col 16. got: "'.SyntaxAt(1,16).'"' 21 | AssertEqual 'puppetStringDelimiter', SyntaxAt(1,17), 'quote, col 17. got: "'.SyntaxAt(1,17).'"' 22 | AssertEqual 'puppetString', SyntaxAt(1,18), 't, col 18. got: "'.SyntaxAt(1,18).'"' 23 | AssertEqual 'puppetString', SyntaxAt(1,19), 'h, col 19. got: "'.SyntaxAt(1,19).'"' 24 | AssertEqual 'puppetString', SyntaxAt(1,20), 'r, col 20. got: "'.SyntaxAt(1,20).'"' 25 | AssertEqual 'puppetString', SyntaxAt(1,21), 'e, col 21. got: "'.SyntaxAt(1,21).'"' 26 | AssertEqual 'puppetString', SyntaxAt(1,22), 'e, col 22. got: "'.SyntaxAt(1,22).'"' 27 | AssertEqual 'puppetStringDelimiter', SyntaxAt(1,23), 'quote, col 23. got: "'.SyntaxAt(1,23).'"' 28 | AssertEqual '', SyntaxAt(1,24), 'space, col 24. got: "'.SyntaxAt(1,24).'"' 29 | AssertEqual 'puppetBracket', SyntaxAt(1,25), '], col 25. got: "'.SyntaxAt(1,25).'"' 30 | 31 | ------------------------------------------------------------------------------- 32 | 33 | Given puppet (empty array): 34 | [] 35 | 36 | Execute (syntax is good): 37 | AssertEqual 'puppetBracket', SyntaxAt(1,1), '[, col 1. got: "'.SyntaxAt(1,1).'"' 38 | AssertEqual 'puppetBracket', SyntaxAt(1,2), '], col 2. got: "'.SyntaxAt(1,2).'"' 39 | 40 | ------------------------------------------------------------------------------- 41 | 42 | Given puppet (nested array): 43 | ['foo', [ 1,3] ] 44 | 45 | Execute (syntax is good): 46 | AssertEqual 'puppetBracket', SyntaxAt(1,1), '[, col 1. got: "'.SyntaxAt(1,1).'"' 47 | AssertEqual 'puppetStringDelimiter', SyntaxAt(1,2), 'quote, col 2. got: "'.SyntaxAt(1,2).'"' 48 | AssertEqual 'puppetString', SyntaxAt(1,3), 'f, col 3. got: "'.SyntaxAt(1,3).'"' 49 | AssertEqual 'puppetString', SyntaxAt(1,4), 'o, col 4. got: "'.SyntaxAt(1,4).'"' 50 | AssertEqual 'puppetString', SyntaxAt(1,5), 'o, col 5. got: "'.SyntaxAt(1,5).'"' 51 | AssertEqual 'puppetStringDelimiter', SyntaxAt(1,6), 'quote, col 6. got: "'.SyntaxAt(1,6).'"' 52 | AssertEqual 'puppetOperator', SyntaxAt(1,7), 'comma, col 7. got: "'.SyntaxAt(1,7).'"' 53 | AssertEqual '', SyntaxAt(1,8), 'space, col 8. got: "'.SyntaxAt(1,8).'"' 54 | AssertEqual 'puppetBracket', SyntaxAt(1,9), '[, col 9. got: "'.SyntaxAt(1,9).'"' 55 | AssertEqual '', SyntaxAt(1,10), 'space, col 10. got: "'.SyntaxAt(1,10).'"' 56 | AssertEqual 'puppetInteger', SyntaxAt(1,11), '1, col 11. got: "'.SyntaxAt(1,11).'"' 57 | AssertEqual 'puppetOperator', SyntaxAt(1,12), 'comma, col 12. got: "'.SyntaxAt(1,12).'"' 58 | AssertEqual 'puppetInteger', SyntaxAt(1,13), '3, col 13. got: "'.SyntaxAt(1,13).'"' 59 | AssertEqual 'puppetBracket', SyntaxAt(1,14), '], col 14. got: "'.SyntaxAt(1,14).'"' 60 | AssertEqual '', SyntaxAt(1,15), 'space, col 15. got: "'.SyntaxAt(1,15).'"' 61 | AssertEqual 'puppetBracket', SyntaxAt(1,16), '], col 16. got: "'.SyntaxAt(1,16).'"' 62 | 63 | ------------------------------------------------------------------------------- 64 | 65 | Given puppet (array with nested hash): 66 | [1, 2, { 'foo' => 'bar' },] 67 | 68 | Execute (syntax is good): 69 | AssertEqual 'puppetBracket', SyntaxAt(1,1), '[, col 1. got: "'.SyntaxAt(1,1).'"' 70 | AssertEqual 'puppetInteger', SyntaxAt(1,2), '1, col 2. got: "'.SyntaxAt(1,2).'"' 71 | AssertEqual 'puppetOperator', SyntaxAt(1,3), 'comma, col 3. got: "'.SyntaxAt(1,3).'"' 72 | AssertEqual '', SyntaxAt(1,4), 'space, col 4. got: "'.SyntaxAt(1,4).'"' 73 | AssertEqual 'puppetInteger', SyntaxAt(1,5), '2, col 5. got: "'.SyntaxAt(1,5).'"' 74 | AssertEqual 'puppetOperator', SyntaxAt(1,6), 'comma, col 6. got: "'.SyntaxAt(1,6).'"' 75 | AssertEqual '', SyntaxAt(1,7), 'space, col 7. got: "'.SyntaxAt(1,7).'"' 76 | AssertEqual 'puppetBrace', SyntaxAt(1,8), '{, col 8. got: "'.SyntaxAt(1,8).'"' 77 | AssertEqual '', SyntaxAt(1,9), 'space, col 9. got: "'.SyntaxAt(1,9).'"' 78 | AssertEqual 'puppetStringDelimiter', SyntaxAt(1,10), 'quote, col 10. got: "'.SyntaxAt(1,10).'"' 79 | AssertEqual 'puppetString', SyntaxAt(1,11), 'f, col 11. got: "'.SyntaxAt(1,11).'"' 80 | AssertEqual 'puppetString', SyntaxAt(1,12), 'o, col 12. got: "'.SyntaxAt(1,12).'"' 81 | AssertEqual 'puppetString', SyntaxAt(1,13), 'o, col 13. got: "'.SyntaxAt(1,13).'"' 82 | AssertEqual 'puppetStringDelimiter', SyntaxAt(1,14), 'quote, col 14. got: "'.SyntaxAt(1,14).'"' 83 | AssertEqual '', SyntaxAt(1,15), 'space, col 15. got: "'.SyntaxAt(1,15).'"' 84 | AssertEqual 'puppetOperator', SyntaxAt(1,16), '=, col 16. got: "'.SyntaxAt(1,16).'"' 85 | AssertEqual 'puppetOperator', SyntaxAt(1,17), '>, col 17. got: "'.SyntaxAt(1,17).'"' 86 | AssertEqual '', SyntaxAt(1,18), 'space, col 18. got: "'.SyntaxAt(1,18).'"' 87 | AssertEqual 'puppetStringDelimiter', SyntaxAt(1,19), 'quote, col 19. got: "'.SyntaxAt(1,19).'"' 88 | AssertEqual 'puppetString', SyntaxAt(1,20), 'b, col 20. got: "'.SyntaxAt(1,20).'"' 89 | AssertEqual 'puppetString', SyntaxAt(1,21), 'a, col 21. got: "'.SyntaxAt(1,21).'"' 90 | AssertEqual 'puppetString', SyntaxAt(1,22), 'r, col 22. got: "'.SyntaxAt(1,22).'"' 91 | AssertEqual 'puppetStringDelimiter', SyntaxAt(1,23), 'quote, col 23. got: "'.SyntaxAt(1,23).'"' 92 | AssertEqual '', SyntaxAt(1,24), 'space, col 24. got: "'.SyntaxAt(1,24).'"' 93 | AssertEqual 'puppetBrace', SyntaxAt(1,25), '}, col 25. got: "'.SyntaxAt(1,25).'"' 94 | AssertEqual 'puppetOperator', SyntaxAt(1,26), 'comma, col 26. got: "'.SyntaxAt(1,26).'"' 95 | AssertEqual 'puppetBracket', SyntaxAt(1,27), '], col 27. got: "'.SyntaxAt(1,27).'"' 96 | -------------------------------------------------------------------------------- /test/syntax/boolean.vader: -------------------------------------------------------------------------------- 1 | Given puppet (true): 2 | true 3 | 4 | Execute (syntax is good): 5 | AssertEqual SyntaxAt(1,1), 'puppetBoolean' 6 | AssertEqual SyntaxAt(1,2), 'puppetBoolean' 7 | AssertEqual SyntaxAt(1,3), 'puppetBoolean' 8 | AssertEqual SyntaxAt(1,4), 'puppetBoolean' 9 | 10 | ------------------------------------------------------------------------------- 11 | 12 | Given puppet (false): 13 | false 14 | 15 | Execute (syntax is good): 16 | AssertEqual SyntaxAt(1,1), 'puppetBoolean' 17 | AssertEqual SyntaxAt(1,2), 'puppetBoolean' 18 | AssertEqual SyntaxAt(1,3), 'puppetBoolean' 19 | AssertEqual SyntaxAt(1,4), 'puppetBoolean' 20 | AssertEqual SyntaxAt(1,5), 'puppetBoolean' 21 | -------------------------------------------------------------------------------- /test/syntax/epuppet.vader: -------------------------------------------------------------------------------- 1 | Given epuppet (template with litteral content puppet tags): 2 | # Short litteral comment 3 | <% if $variable == '<%%somevalue%%>' { -%> 4 | MYVAR=<%= $variable %> 5 | <%- if $more_variable { 6 | # This is a puppet comment -%> 7 | MOREVAR=true 8 | <%- } %> 9 | <%# epp comment with TODO mark %> 10 | 11 | Execute (litteral content syntax must be correct): 12 | AssertEqual 'shComment', SyntaxOf('litteral comment') 13 | AssertEqual 'shVariable', SyntaxOf('MYVAR') 14 | 15 | Execute (epp delimiter syntax must be correct): 16 | -- The error messages here are super confusing since all of the assertions use 17 | -- the same type. This is a shortcoming of the current vader output. To bypass 18 | -- this, let's define our own message. 19 | AssertEqual 'ePuppetDelimiter', SyntaxOf('<%'), "syntax of <% should be 'ePuppetDelimiter', got '".SyntaxOf('<%')."'" 20 | AssertEqual 'ePuppetDelimiter', SyntaxOf('-%>'), "syntax of -%> should be 'ePuppetDelimiter', got '".SyntaxOf('-%>')."'" 21 | AssertEqual 'ePuppetDelimiter', SyntaxOf('<%-'), "syntax of <%- should be 'ePuppetDelimiter', got '".SyntaxOf('<%-')."'" 22 | AssertEqual 'ePuppetComment', SyntaxOf('epp comment') 23 | -- We're testing for a *puppet* syntax here but that's because it's contained 24 | -- in the ePuppetComment syntax region 25 | AssertEqual 'puppetTodo', SyntaxOf('TODO') 26 | 27 | Execute (puppet syntax must be correct): 28 | AssertEqual 'puppetConditional', SyntaxOf('if') 29 | AssertEqual 'puppetVariable', SyntaxOf('$variable') 30 | -- Again, we're testing multiple times for the same syntaxID. Let's define our 31 | -- message. 32 | AssertEqual 'puppetBrace', SyntaxOf('{'), 'for { in first puppet block, expected "puppetBrace", got "'.SyntaxOf('{').'"' 33 | AssertEqual 'puppetBrace', SyntaxOf('{', 2), 'for { in second puppet block, expected "puppetBrace", got "'.SyntaxOf('{', 2).'"' 34 | " XXX syntax/puppet.vim's region for puppetBrace can't match the opening 35 | " brace, so we're not seeing the right syntax for the closing brace 36 | "AssertEqual 'puppetBrace', SyntaxOf('}'), 'for } in third puppet block, expected "puppetBrace", got "'.SyntaxOf('}').'"' 37 | AssertEqual 'puppetComment', SyntaxOf('puppet comment') 38 | -------------------------------------------------------------------------------- /test/syntax/error.vader: -------------------------------------------------------------------------------- 1 | Given puppet (space errors in and around resource): 2 | file { 'something': 3 | hullo => 'gnah', 4 | name => 'notimportant', 5 | mode => '0123', 6 | } 7 | 8 | Execute (errors identified with syntax): 9 | AssertEqual 'puppetSpaceError', SyntaxAt(1,22), 'at end of "file" line, exected: "puppetSpaceError" got: "'.SyntaxAt(1,22).'"' 10 | " The spaces and the tab characters 11 | AssertEqual 'puppetSpaceError', SyntaxAt(1,1), 'in front of "file", col 1, exected: "puppetSpaceError" got: "'.SyntaxAt(1,1).'"' 12 | AssertEqual 'puppetSpaceError', SyntaxAt(1,2), 'in front of "file", col 2, exected: "puppetSpaceError" got: "'.SyntaxAt(1,2).'"' 13 | AssertEqual 'puppetSpaceError', SyntaxAt(3,1), 'in front of "name", col 1, exected: "puppetSpaceError" got: "'.SyntaxAt(3,1).'"' 14 | AssertEqual 'puppetSpaceError', SyntaxAt(3,3), 'in front of "name", col 3, exected: "puppetSpaceError" got: "'.SyntaxAt(3,3).'"' 15 | AssertEqual 'puppetSpaceError', SyntaxAt(4,1), 'in front of "mode", col 1, exected: "puppetSpaceError" got: "'.SyntaxAt(4,1).'"' 16 | AssertEqual 'puppetSpaceError', SyntaxAt(4,2), 'in front of "mode", col 2, exected: "puppetSpaceError" got: "'.SyntaxAt(4,2).'"' 17 | 18 | -------------------------------------------------- 19 | 20 | Given puppet (space errors inside a class argument list and body, and around comments): 21 | # 22 | # cromment 23 | class filet ( 24 | $arg1, 25 | $arg2, 26 | # blah 27 | ) { 28 | notice('something') 29 | } 30 | 31 | Execute (errors identified with syntax): 32 | AssertEqual 'puppetSpaceError', SyntaxAt(1,2), 'trailing spaces in comment first line, exected: "puppetSpaceError" got: "'.SyntaxAt(1,2).'"' 33 | AssertEqual 'puppetSpaceError', SyntaxAt(2,1), 'in front of comment second line, exected: "puppetSpaceError" got: "'.SyntaxAt(2,1).'"' 34 | AssertEqual 'puppetSpaceError', SyntaxAt(3,15), 'at end of "class" line, exected: "puppetSpaceError" got: "'.SyntaxAt(3,15).'"' 35 | AssertEqual 'puppetSpaceError', SyntaxAt(4,1), 'in front of "$arg1", col 1, exected: "puppetSpaceError" got: "'.SyntaxAt(4,1).'"' 36 | AssertEqual 'puppetSpaceError', SyntaxAt(4,3), 'in front of "$arg1", col 3, exected: "puppetSpaceError" got: "'.SyntaxAt(4,3).'"' 37 | AssertEqual 'puppetSpaceError', SyntaxAt(5,1), 'in front of "$arg2", col 1, exected: "puppetSpaceError" got: "'.SyntaxAt(5,1).'"' 38 | AssertEqual 'puppetSpaceError', SyntaxAt(5,2), 'in front of "$arg2", col 2, exected: "puppetSpaceError" got: "'.SyntaxAt(5,2).'"' 39 | AssertEqual 'puppetSpaceError', SyntaxAt(6,1), 'in front of comment, col 1, exected: "puppetSpaceError" got: "'.SyntaxAt(6,1).'"' 40 | AssertEqual 'puppetSpaceError', SyntaxAt(6,2), 'in front of comment, col 2, exected: "puppetSpaceError" got: "'.SyntaxAt(6,2).'"' 41 | AssertEqual 'puppetSpaceError', SyntaxAt(8,1), 'in front of "notice(", col 1, exected: "puppetSpaceError" got: "'.SyntaxAt(8,1).'"' 42 | AssertEqual 'puppetSpaceError', SyntaxAt(8,3), 'in front of "notice(", col 3, exected: "puppetSpaceError" got: "'.SyntaxAt(8,3).'"' 43 | 44 | -------------------------------------------------- 45 | 46 | Given puppet (space errors within brackets and braces): 47 | $a = [ '1'] 48 | $b = { 'aa' => 3 } 49 | 50 | Execute (errors identified with syntax): 51 | AssertEqual 'puppetSpaceError', SyntaxAt(1,8), 'at beginning of array, exected: "puppetSpaceError" got: "'.SyntaxAt(1,8).'"' 52 | AssertEqual 'puppetSpaceError', SyntaxAt(2,8), 'at beginning of hash, exected: "puppetSpaceError" got: "'.SyntaxAt(2,8).'"' 53 | AssertEqual 'puppetSpaceError', SyntaxAt(2,16), 'after hash rocket, exected: "puppetSpaceError" got: "'.SyntaxAt(2,16).'"' 54 | 55 | -------------------------------------------------- 56 | 57 | Given puppet (invalid resource names): 58 | blah::Mooo { "name": } 59 | blah::Mooo::hello { "name": } 60 | if $this ~= Some::name { notice("this is sad") } 61 | if $this ~= Some::name::Longer { notice("this is sad") } 62 | 63 | Execute (errors identified with syntax): 64 | AssertEqual 'puppetInvalidName', SyntaxAt(1,1), '[blah]::Mooo, exected: "puppetInvalidName" got: "'.SyntaxAt(1,1).'"' 65 | AssertEqual 'puppetInvalidName', SyntaxAt(1,5), 'blah[::]Mooo, exected: "puppetInvalidName" got: "'.SyntaxAt(1,5).'"' 66 | AssertEqual 'puppetInvalidName', SyntaxAt(1,7), 'blah::[Mooo], exected: "puppetInvalidName" got: "'.SyntaxAt(1,7).'"' 67 | 68 | AssertEqual 'puppetInvalidName', SyntaxAt(2,1), '[blah]::Mooo::hello, exected: "puppetInvalidName" got: "'.SyntaxAt(2,1).'"' 69 | AssertEqual 'puppetInvalidName', SyntaxAt(2,5), 'blah[::]Mooo::hello, exected: "puppetInvalidName" got: "'.SyntaxAt(2,5).'"' 70 | AssertEqual 'puppetInvalidName', SyntaxAt(2,7), 'blah::[Mooo]::hello, exected: "puppetInvalidName" got: "'.SyntaxAt(2,7).'"' 71 | AssertEqual 'puppetInvalidName', SyntaxAt(2,11), 'blah::Mooo[::]hello, exected: "puppetInvalidName" got: "'.SyntaxAt(2,11).'"' 72 | AssertEqual 'puppetInvalidName', SyntaxAt(2,13), 'blah::Mooo::[hello], exected: "puppetInvalidName" got: "'.SyntaxAt(2,13).'"' 73 | 74 | AssertEqual 'puppetInvalidName', SyntaxAt(3,13), '[Some]::name, exected: "puppetInvalidName" got: "'.SyntaxAt(3,13).'"' 75 | AssertEqual 'puppetInvalidName', SyntaxAt(3,17), 'Some[::]name, exected: "puppetInvalidName" got: "'.SyntaxAt(3,17).'"' 76 | AssertEqual 'puppetInvalidName', SyntaxAt(3,19), 'Some::[name], exected: "puppetInvalidName" got: "'.SyntaxAt(3,19).'"' 77 | 78 | AssertEqual 'puppetInvalidName', SyntaxAt(4,13), '[Some]::name::Longer, exected: "puppetInvalidName" got: "'.SyntaxAt(4,13).'"' 79 | AssertEqual 'puppetInvalidName', SyntaxAt(4,17), 'Some[::]name::Longer, exected: "puppetInvalidName" got: "'.SyntaxAt(4,17).'"' 80 | AssertEqual 'puppetInvalidName', SyntaxAt(4,19), 'Some::[name]::Longer, exected: "puppetInvalidName" got: "'.SyntaxAt(4,19).'"' 81 | AssertEqual 'puppetInvalidName', SyntaxAt(4,23), 'Some::name[::]Longer, exected: "puppetInvalidName" got: "'.SyntaxAt(4,23).'"' 82 | AssertEqual 'puppetInvalidName', SyntaxAt(4,25), 'Some::name::[Longer], exected: "puppetInvalidName" got: "'.SyntaxAt(4,25).'"' 83 | -------------------------------------------------------------------------------- /test/syntax/fold.vader: -------------------------------------------------------------------------------- 1 | Before: 2 | setlocal foldmethod=syntax 3 | 4 | After: 5 | setlocal foldmethod=manual 6 | 7 | Given puppet (basic class): 8 | class foobar( 9 | $a = true 10 | ) { 11 | $b = true 12 | if $b { 13 | $c = false 14 | } 15 | } 16 | 17 | Execute (fold level # in code block): 18 | AssertEqual foldlevel(1), 1, 'class foobar(' 19 | AssertEqual foldlevel(2), 1, ' $a = true' 20 | AssertEqual foldlevel(3), 1, ') {' 21 | AssertEqual foldlevel(4), 1, ' $b = false' 22 | AssertEqual foldlevel(5), 2, ' if $b {' 23 | AssertEqual foldlevel(6), 2, ' $c = false' 24 | AssertEqual foldlevel(7), 2, ' }' 25 | AssertEqual foldlevel(8), 1, '}' 26 | -------------------------------------------------------------------------------- /test/syntax/number.vader: -------------------------------------------------------------------------------- 1 | Given puppet (hexidecimal): 2 | 0xff 3 | 0xabcdef0123456789 4 | 0x0 5 | 0x123ABC 6 | 7 | Execute (syntax is good): 8 | AssertEqual 'puppetInteger', SyntaxAt(1,1), '0xff, col 1. got: "'.SyntaxAt(1,1).'"' 9 | AssertEqual 'puppetInteger', SyntaxAt(1,2), '0xff, col 2. got: "'.SyntaxAt(1,2).'"' 10 | AssertEqual 'puppetInteger', SyntaxAt(1,3), '0xff, col 3. got: "'.SyntaxAt(1,3).'"' 11 | AssertEqual 'puppetInteger', SyntaxAt(1,4), '0xff, col 4. got: "'.SyntaxAt(1,4).'"' 12 | 13 | AssertEqual 'puppetInteger', SyntaxAt(2,1), '0xabcdef0123456789, col 1. got: "'.SyntaxAt(2,1).'"' 14 | AssertEqual 'puppetInteger', SyntaxAt(2,2), '0xabcdef0123456789, col 2. got: "'.SyntaxAt(2,2).'"' 15 | AssertEqual 'puppetInteger', SyntaxAt(2,3), '0xabcdef0123456789, col 3. got: "'.SyntaxAt(2,3).'"' 16 | AssertEqual 'puppetInteger', SyntaxAt(2,4), '0xabcdef0123456789, col 4. got: "'.SyntaxAt(2,4).'"' 17 | AssertEqual 'puppetInteger', SyntaxAt(2,5), '0xabcdef0123456789, col 5. got: "'.SyntaxAt(2,5).'"' 18 | AssertEqual 'puppetInteger', SyntaxAt(2,6), '0xabcdef0123456789, col 6. got: "'.SyntaxAt(2,6).'"' 19 | AssertEqual 'puppetInteger', SyntaxAt(2,7), '0xabcdef0123456789, col 7. got: "'.SyntaxAt(2,7).'"' 20 | AssertEqual 'puppetInteger', SyntaxAt(2,8), '0xabcdef0123456789, col 8. got: "'.SyntaxAt(2,8).'"' 21 | AssertEqual 'puppetInteger', SyntaxAt(2,9), '0xabcdef0123456789, col 9. got: "'.SyntaxAt(2,9).'"' 22 | AssertEqual 'puppetInteger', SyntaxAt(2,10), '0xabcdef0123456789, col 10. got: "'.SyntaxAt(2,10).'"' 23 | AssertEqual 'puppetInteger', SyntaxAt(2,11), '0xabcdef0123456789, col 11. got: "'.SyntaxAt(2,11).'"' 24 | AssertEqual 'puppetInteger', SyntaxAt(2,12), '0xabcdef0123456789, col 12. got: "'.SyntaxAt(2,12).'"' 25 | AssertEqual 'puppetInteger', SyntaxAt(2,13), '0xabcdef0123456789, col 13. got: "'.SyntaxAt(2,13).'"' 26 | AssertEqual 'puppetInteger', SyntaxAt(2,14), '0xabcdef0123456789, col 14. got: "'.SyntaxAt(2,14).'"' 27 | AssertEqual 'puppetInteger', SyntaxAt(2,15), '0xabcdef0123456789, col 15. got: "'.SyntaxAt(2,15).'"' 28 | AssertEqual 'puppetInteger', SyntaxAt(2,16), '0xabcdef0123456789, col 16. got: "'.SyntaxAt(2,16).'"' 29 | AssertEqual 'puppetInteger', SyntaxAt(2,17), '0xabcdef0123456789, col 17. got: "'.SyntaxAt(2,17).'"' 30 | AssertEqual 'puppetInteger', SyntaxAt(2,18), '0xabcdef0123456789, col 18. got: "'.SyntaxAt(2,18).'"' 31 | 32 | AssertEqual 'puppetInteger', SyntaxAt(3,1), '0x0, col 1. got: "'.SyntaxAt(3,1).'"' 33 | AssertEqual 'puppetInteger', SyntaxAt(3,2), '0x0, col 2. got: "'.SyntaxAt(3,2).'"' 34 | AssertEqual 'puppetInteger', SyntaxAt(3,3), '0x0, col 3. got: "'.SyntaxAt(3,3).'"' 35 | 36 | AssertEqual 'puppetInteger', SyntaxAt(4,1), '0x123ABC, col 1. got: "'.SyntaxAt(4,1).'"' 37 | AssertEqual 'puppetInteger', SyntaxAt(4,2), '0x123ABC, col 2. got: "'.SyntaxAt(4,2).'"' 38 | AssertEqual 'puppetInteger', SyntaxAt(4,3), '0x123ABC, col 3. got: "'.SyntaxAt(4,3).'"' 39 | AssertEqual 'puppetInteger', SyntaxAt(4,4), '0x123ABC, col 4. got: "'.SyntaxAt(4,4).'"' 40 | AssertEqual 'puppetInteger', SyntaxAt(4,5), '0x123ABC, col 5. got: "'.SyntaxAt(4,5).'"' 41 | AssertEqual 'puppetInteger', SyntaxAt(4,6), '0x123ABC, col 6. got: "'.SyntaxAt(4,6).'"' 42 | AssertEqual 'puppetInteger', SyntaxAt(4,7), '0x123ABC, col 7. got: "'.SyntaxAt(4,7).'"' 43 | AssertEqual 'puppetInteger', SyntaxAt(4,8), '0x123ABC, col 8. got: "'.SyntaxAt(4,8).'"' 44 | 45 | ------------------------------------------------------------------------------- 46 | 47 | Given puppet (integer): 48 | 10 49 | 0 50 | -9 51 | 10000 52 | 53 | Execute (syntax is good): 54 | AssertEqual 'puppetInteger', SyntaxAt(1,1), '10, col 1. got: "'.SyntaxAt(1,1).'"' 55 | AssertEqual 'puppetInteger', SyntaxAt(1,2), '10, col 2. got: "'.SyntaxAt(1,2).'"' 56 | 57 | AssertEqual 'puppetInteger', SyntaxAt(2,1), '0. got: "'.SyntaxAt(2,1).'"' 58 | 59 | AssertEqual 'puppetInteger', SyntaxAt(3,1), '-9, col 1. got: "'.SyntaxAt(3,1).'"' 60 | AssertEqual 'puppetInteger', SyntaxAt(3,2), '-9, col 2. got: "'.SyntaxAt(3,2).'"' 61 | 62 | AssertEqual 'puppetInteger', SyntaxAt(4,1), '10000, col 1. got: "'.SyntaxAt(4,1).'"' 63 | AssertEqual 'puppetInteger', SyntaxAt(4,2), '10000, col 2. got: "'.SyntaxAt(4,2).'"' 64 | AssertEqual 'puppetInteger', SyntaxAt(4,3), '10000, col 3. got: "'.SyntaxAt(4,3).'"' 65 | AssertEqual 'puppetInteger', SyntaxAt(4,4), '10000, col 4. got: "'.SyntaxAt(4,4).'"' 66 | AssertEqual 'puppetInteger', SyntaxAt(4,5), '10000, col 5. got: "'.SyntaxAt(4,5).'"' 67 | 68 | ------------------------------------------------------------------------------- 69 | 70 | Given puppet (octal): 71 | 077 72 | 01234567 73 | 00 74 | 75 | Execute (syntax is good): 76 | AssertEqual 'puppetInteger', SyntaxAt(1,1), '077, col 1. got: "'.SyntaxAt(1,1).'"' 77 | AssertEqual 'puppetInteger', SyntaxAt(1,2), '077, col 2. got: "'.SyntaxAt(1,2).'"' 78 | AssertEqual 'puppetInteger', SyntaxAt(1,3), '077, col 3. got: "'.SyntaxAt(1,3).'"' 79 | 80 | AssertEqual 'puppetInteger', SyntaxAt(2,1), '01234567, col 1. got: "'.SyntaxAt(2,1).'"' 81 | AssertEqual 'puppetInteger', SyntaxAt(2,2), '01234567, col 2. got: "'.SyntaxAt(2,2).'"' 82 | AssertEqual 'puppetInteger', SyntaxAt(2,3), '01234567, col 3. got: "'.SyntaxAt(2,3).'"' 83 | AssertEqual 'puppetInteger', SyntaxAt(2,4), '01234567, col 4. got: "'.SyntaxAt(2,4).'"' 84 | AssertEqual 'puppetInteger', SyntaxAt(2,5), '01234567, col 5. got: "'.SyntaxAt(2,5).'"' 85 | AssertEqual 'puppetInteger', SyntaxAt(2,6), '01234567, col 6. got: "'.SyntaxAt(2,6).'"' 86 | AssertEqual 'puppetInteger', SyntaxAt(2,7), '01234567, col 7. got: "'.SyntaxAt(2,7).'"' 87 | AssertEqual 'puppetInteger', SyntaxAt(2,8), '01234567, col 8. got: "'.SyntaxAt(2,8).'"' 88 | 89 | AssertEqual 'puppetInteger', SyntaxAt(3,1), '00, col 1. got: "'.SyntaxAt(3,1).'"' 90 | AssertEqual 'puppetInteger', SyntaxAt(3,2), '00, col 1. got: "'.SyntaxAt(3,2).'"' 91 | 92 | ------------------------------------------------------------------------------- 93 | 94 | Given puppet (floating point): 95 | +1.0e2 96 | -1.0e-2 97 | 1.0 98 | 1.0e0 99 | 5.2E3 100 | 3e5 101 | 102 | Execute (syntax is good): 103 | AssertEqual 'puppetOperator', SyntaxAt(1,1), '+ operator. got: "'.SyntaxAt(1,1).'"' 104 | AssertEqual 'puppetFloat', SyntaxAt(1,2), 'positive float with + and exponent. got: "'.SyntaxAt(1,2).'"' 105 | AssertEqual 'puppetFloat', SyntaxAt(1,3), 'dot in positive float with + and exponent. got: "'.SyntaxAt(1,3).'"' 106 | AssertEqual 'puppetFloat', SyntaxAt(1,4), 'positive float, after dot, with + and exponent. got: "'.SyntaxAt(1,4).'"' 107 | AssertEqual 'puppetFloat', SyntaxAt(1,5), '"e" in positive float with + and exponent. got: "'.SyntaxAt(1,5).'"' 108 | AssertEqual 'puppetFloat', SyntaxAt(1,6), 'exponent number in positive float with + and exponent. got: "'.SyntaxAt(1,6).'"' 109 | 110 | AssertEqual 'puppetFloat', SyntaxAt(2,1), '- operator. got: "'.SyntaxAt(2,1).'"' 111 | AssertEqual 'puppetFloat', SyntaxAt(2,2), 'negative float with negative exponent. got: "'.SyntaxAt(2,2).'"' 112 | AssertEqual 'puppetFloat', SyntaxAt(2,3), 'dot in negative float with negative exponent. got: "'.SyntaxAt(2,3).'"' 113 | AssertEqual 'puppetFloat', SyntaxAt(2,4), 'negative float, after dot, with negative exponent. got: "'.SyntaxAt(2,4).'"' 114 | AssertEqual 'puppetFloat', SyntaxAt(2,5), '"e" in negative float with negative exponent. got: "'.SyntaxAt(2,5).'"' 115 | AssertEqual 'puppetFloat', SyntaxAt(2,6), '- of exponent in negative float with negative exponent. got: "'.SyntaxAt(2,6).'"' 116 | AssertEqual 'puppetFloat', SyntaxAt(2,7), 'exponent number in negative float with negative exponent. got: "'.SyntaxAt(2,7).'"' 117 | 118 | AssertEqual 'puppetFloat', SyntaxAt(3,1), 'positive float. got: "'.SyntaxAt(3,1).'"' 119 | AssertEqual 'puppetFloat', SyntaxAt(3,2), 'dot in positive float. got: "'.SyntaxAt(3,2).'"' 120 | AssertEqual 'puppetFloat', SyntaxAt(3,3), 'positive float, after dot. got: "'.SyntaxAt(3,3).'"' 121 | 122 | AssertEqual 'puppetFloat', SyntaxAt(4,1), 'positive float with exponent. got: "'.SyntaxAt(4,1).'"' 123 | AssertEqual 'puppetFloat', SyntaxAt(4,2), 'dot positive float with exponent. got: "'.SyntaxAt(4,2).'"' 124 | AssertEqual 'puppetFloat', SyntaxAt(4,3), 'positive float, after dot, with exponent. got: "'.SyntaxAt(4,3).'"' 125 | AssertEqual 'puppetFloat', SyntaxAt(4,4), '"e" in positive float with exponent. got: "'.SyntaxAt(4,4).'"' 126 | AssertEqual 'puppetFloat', SyntaxAt(4,5), 'exponent number in positive float with exponent. got: "'.SyntaxAt(4,5).'"' 127 | 128 | AssertEqual 'puppetFloat', SyntaxAt(5,1), 'positive float with capitalized exponent. got: "'.SyntaxAt(5,1).'"' 129 | AssertEqual 'puppetFloat', SyntaxAt(5,2), 'dot in positive float with capitalized exponent. got: "'.SyntaxAt(5,2).'"' 130 | AssertEqual 'puppetFloat', SyntaxAt(5,3), 'positive float, after dot, with capitalized exponent. got: "'.SyntaxAt(5,3).'"' 131 | AssertEqual 'puppetFloat', SyntaxAt(5,4), '"E" in positive float with capitalized exponent. got: "'.SyntaxAt(5,4).'"' 132 | AssertEqual 'puppetFloat', SyntaxAt(5,5), 'exponent number positive float with capitalized exponent. got: "'.SyntaxAt(5,5).'"' 133 | 134 | AssertEqual 'puppetFloat', SyntaxAt(6,1), 'first digit, no dot with exponent. got: "'.SyntaxAt(6,1).'"' 135 | AssertEqual 'puppetFloat', SyntaxAt(6,2), '"e" in no dot with exponent. got: "'.SyntaxAt(6,2).'"' 136 | AssertEqual 'puppetFloat', SyntaxAt(6,3), 'exponent number in no dot with exponent. got: "'.SyntaxAt(6,3).'"' 137 | 138 | ------------------------------------------------------------------------------- 139 | 140 | Given puppet (malformed numbers): 141 | 0x3.4 142 | 07.2 143 | 01239 144 | .42 145 | 146 | Execute (syntax shows error): 147 | AssertEqual 'puppetInvalidNumber', SyntaxAt(1,1), 'hexadecimal with dot. got: "'.SyntaxAt(1,1).'"' 148 | AssertEqual 'puppetInvalidNumber', SyntaxAt(2,1), 'octal with dot. got: "'.SyntaxAt(1,1).'"' 149 | AssertEqual 'puppetInvalidNumber', SyntaxAt(3,1), 'octal with digits out of range. got: "'.SyntaxAt(1,1).'"' 150 | AssertEqual 'puppetInvalidNumber', SyntaxAt(4,1), 'leading dot. got: "'.SyntaxAt(1,1).'"' 151 | -------------------------------------------------------------------------------- /test/syntax/regex.vader: -------------------------------------------------------------------------------- 1 | Given puppet (division operation): 2 | $x = $y / 1 3 | 4 | Execute (syntax is good): 5 | AssertEqual SyntaxAt(1,6), 'puppetVariable' 6 | AssertEqual SyntaxAt(1,7), 'puppetVariable' 7 | AssertEqual SyntaxAt(1,8), '' 8 | AssertEqual SyntaxAt(1,9), 'puppetOperator' 9 | AssertEqual SyntaxAt(1,10), '' 10 | AssertEqual SyntaxAt(1,11), 'puppetInteger' 11 | 12 | ------------------------------------------------------------------------------- 13 | -------------------------------------------------------------------------------- /test/syntax/strings.vader: -------------------------------------------------------------------------------- 1 | Given puppet (heredoc with trailing comma on first line): 2 | class foo { 3 | profile::notes { $title: 4 | notes => @("NOTES"), 5 | A note with an apostrophe in it's midst breaks 6 | highlighting. 7 | |-NOTES 8 | } 9 | 10 | Execute (syntax is undisturbed by trailing comma or apostrophe): 11 | AssertEqual SyntaxOf("apostrophe"), 'puppetString' 12 | AssertEqual SyntaxOf("midst"), 'puppetString' 13 | AssertNotEqual SyntaxOf("NOTES",2), 'puppetString' 14 | AssertNotEqual SyntaxOf("}"), 'puppetString' 15 | ------------------------------------------------------------------------------- 16 | Given puppet (heredoc with simple closing symbol): 17 | $fix_maxpoll = @(END) 18 | grep ^server $ntp_conf | grep -v 'maxpoll 10'| while read -r line; do 19 | 20 | END 21 | 22 | exec { 23 | 24 | Execute (closing symbol properly ends syntax group): 25 | AssertEqual SyntaxOf("END"), 'puppetStringDelimiter' 26 | AssertEqual SyntaxOf("grep"), 'puppetString' 27 | AssertEqual SyntaxOf("END",2), 'puppetStringDelimiter' 28 | AssertNotEqual SyntaxOf("exec"), 'puppetString' 29 | -------------------------------------------------------------------------------- /test/syntax/variable.vader: -------------------------------------------------------------------------------- 1 | Given puppet (local variables): 2 | $foo 3 | $f 4 | 5 | Execute (syntax is good): 6 | AssertEqual SyntaxAt(1,2), 'puppetVariable' 7 | AssertEqual SyntaxAt(2,2), 'puppetVariable' 8 | ------------------------------------------------------------------------------- 9 | Given puppet (global scope variables): 10 | $::foo 11 | $::f 12 | 13 | Execute (syntax is good): 14 | AssertEqual SyntaxAt(1,2), 'puppetVariable' 15 | AssertEqual SyntaxAt(2,2), 'puppetVariable' 16 | ------------------------------------------------------------------------------- 17 | Given puppet (out of scope qualified name variables): 18 | $foo::boo::moo 19 | $::foo::boo::moo 20 | $::f00_::b_OO 21 | 22 | Execute (syntax is good): 23 | AssertEqual SyntaxAt(1,2), 'puppetVariable' 24 | AssertEqual SyntaxAt(2,2), 'puppetVariable' 25 | AssertEqual SyntaxAt(3,2), 'puppetVariable' 26 | -------------------------------------------------------------------------------- /test/syntax/variable_in_string.vader: -------------------------------------------------------------------------------- 1 | Given puppet (interpolated top scope variable): 2 | $foo = "foo${::bar}baz" 3 | 4 | Execute (syntax is good): 5 | AssertEqual SyntaxAt(1,8), 'puppetStringDelimiter' 6 | AssertEqual SyntaxAt(1,9), 'puppetString' 7 | AssertEqual SyntaxAt(1,10), 'puppetString' 8 | AssertEqual SyntaxAt(1,11), 'puppetString' 9 | AssertEqual SyntaxAt(1,12), 'puppetInterpolationDelimiter' 10 | AssertEqual SyntaxAt(1,13), 'puppetInterpolationDelimiter' 11 | AssertEqual SyntaxAt(1,14), 'puppetName' 12 | AssertEqual SyntaxAt(1,15), 'puppetName' 13 | AssertEqual SyntaxAt(1,16), 'puppetName' 14 | AssertEqual SyntaxAt(1,17), 'puppetName' 15 | AssertEqual SyntaxAt(1,18), 'puppetName' 16 | AssertEqual SyntaxAt(1,19), 'puppetInterpolationDelimiter' 17 | AssertEqual SyntaxAt(1,20), 'puppetString' 18 | AssertEqual SyntaxAt(1,21), 'puppetString' 19 | AssertEqual SyntaxAt(1,22), 'puppetString' 20 | AssertEqual SyntaxAt(1,23), 'puppetStringDelimiter' 21 | 22 | ------------------------------------------------------------------------------- 23 | 24 | Given puppet (local variable): 25 | $foo = "foo${bar}baz" 26 | 27 | Execute (syntax is good): 28 | AssertEqual SyntaxAt(1,8), 'puppetStringDelimiter' 29 | AssertEqual SyntaxAt(1,9), 'puppetString' 30 | AssertEqual SyntaxAt(1,10), 'puppetString' 31 | AssertEqual SyntaxAt(1,11), 'puppetString' 32 | AssertEqual SyntaxAt(1,12), 'puppetInterpolationDelimiter' 33 | AssertEqual SyntaxAt(1,13), 'puppetInterpolationDelimiter' 34 | AssertEqual SyntaxAt(1,14), 'puppetName' 35 | AssertEqual SyntaxAt(1,15), 'puppetName' 36 | AssertEqual SyntaxAt(1,16), 'puppetName' 37 | AssertEqual SyntaxAt(1,17), 'puppetInterpolationDelimiter' 38 | AssertEqual SyntaxAt(1,18), 'puppetString' 39 | AssertEqual SyntaxAt(1,19), 'puppetString' 40 | AssertEqual SyntaxAt(1,20), 'puppetString' 41 | AssertEqual SyntaxAt(1,21), 'puppetStringDelimiter' 42 | 43 | ------------------------------------------------------------------------------- 44 | 45 | Given puppet (unenclosed local variable): 46 | $foo = "foo$bar baz" 47 | 48 | Execute (syntax is good): 49 | AssertEqual SyntaxAt(1,8), 'puppetStringDelimiter' 50 | AssertEqual SyntaxAt(1,9), 'puppetString' 51 | AssertEqual SyntaxAt(1,10), 'puppetString' 52 | AssertEqual SyntaxAt(1,11), 'puppetString' 53 | AssertEqual SyntaxAt(1,12), 'puppetVariable' 54 | AssertEqual SyntaxAt(1,13), 'puppetVariable' 55 | AssertEqual SyntaxAt(1,14), 'puppetVariable' 56 | AssertEqual SyntaxAt(1,15), 'puppetVariable' 57 | AssertEqual SyntaxAt(1,16), 'puppetString' 58 | AssertEqual SyntaxAt(1,17), 'puppetString' 59 | AssertEqual SyntaxAt(1,18), 'puppetString' 60 | AssertEqual SyntaxAt(1,19), 'puppetString' 61 | AssertEqual SyntaxAt(1,20), 'puppetStringDelimiter' 62 | 63 | ------------------------------------------------------------------------------- 64 | 65 | Given puppet (unenclosed top scope variable): 66 | $foo = "foo$::bar-baz" 67 | 68 | Execute (syntax is good): 69 | AssertEqual SyntaxAt(1,8), 'puppetStringDelimiter' 70 | AssertEqual SyntaxAt(1,9), 'puppetString' 71 | AssertEqual SyntaxAt(1,10), 'puppetString' 72 | AssertEqual SyntaxAt(1,11), 'puppetString' 73 | AssertEqual SyntaxAt(1,12), 'puppetVariable' 74 | AssertEqual SyntaxAt(1,13), 'puppetVariable' 75 | AssertEqual SyntaxAt(1,14), 'puppetVariable' 76 | AssertEqual SyntaxAt(1,15), 'puppetVariable' 77 | AssertEqual SyntaxAt(1,16), 'puppetVariable' 78 | AssertEqual SyntaxAt(1,17), 'puppetVariable' 79 | AssertEqual SyntaxAt(1,18), 'puppetString' 80 | AssertEqual SyntaxAt(1,19), 'puppetString' 81 | AssertEqual SyntaxAt(1,20), 'puppetString' 82 | AssertEqual SyntaxAt(1,21), 'puppetString' 83 | AssertEqual SyntaxAt(1,22), 'puppetStringDelimiter' 84 | -------------------------------------------------------------------------------- /test/test-files/Puppetfile: -------------------------------------------------------------------------------- 1 | forge "https://forgeapi.puppetlabs.com" 2 | # comment 3 | mod 'username-modulename', '1.2.3' 4 | -------------------------------------------------------------------------------- /test/test-files/etc/apache2/test.conf.epp: -------------------------------------------------------------------------------- 1 | # conf 2 | 3 | ServerName example.com 4 | 5 | -------------------------------------------------------------------------------- /test/test-files/simple.pp: -------------------------------------------------------------------------------- 1 | # comment 2 | class module::thisclass { 3 | # ... do something 4 | } 5 | -------------------------------------------------------------------------------- /test/test-files/test_perl_with_shebang.epp: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use strict; 3 | use warning; 4 | print "<%= $variable %>"; 5 | -------------------------------------------------------------------------------- /test/test-files/test_php_with_extension.php.epp: -------------------------------------------------------------------------------- 1 | "; 7 | } 8 | -------------------------------------------------------------------------------- /test/test-files/test_shell_with_extension.sh.epp: -------------------------------------------------------------------------------- 1 | if [ -t bla ]; then 2 | echo <%= $bla %> 3 | fi 4 | -------------------------------------------------------------------------------- /test/test-files/test_shell_with_shebang.epp: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -t bla ]; then 3 | echo <%= $bla %> 4 | fi 5 | -------------------------------------------------------------------------------- /test/test-files/test_with_leading_tag.epp: -------------------------------------------------------------------------------- 1 | <% if { %> 2 | content 3 | --------------------------------------------------------------------------------