Skip to content

Commit

Permalink
Merge pull request #12 from jonsmithers/write-tests-and-clean-up-inde…
Browse files Browse the repository at this point in the history
…ntation

Write tests and clean up indentation code
  • Loading branch information
jonsmithers committed Dec 17, 2018
2 parents 84dcc75 + 7cb3dcc commit 3499e07
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 293 deletions.
313 changes: 112 additions & 201 deletions after/indent/javascript.vim

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
" This test file is not used for regular testing because the tests here are
" generally very large in scope and thus not helpful in telling you what's
" actually failing.

Before:
set tabstop=2
set shiftwidth=2
Expand Down Expand Up @@ -285,3 +289,81 @@ Expect javascript:
" ${items.map((i) => html`<li>${i}</li>`)}
" </ul>
" `;


Before:
set tabstop=2
set shiftwidth=2
set expandtab

Given javascript (multiple syntaxes on one line);
return html`<style>.mood { color: green; }</style>
Web Components are
<span class="mood">${mood}</span>!`;

Do:
=G

Expect javascript;
return html`<style>.mood { color: green; }</style>
Web Components are
<span class="mood">${mood}</span>!`;

Given javascript (tricky indnetation);
return html`
<div> Files </div>
${!this.fileList ?
html`
<paper-button on-click=${() => this.onFetchBtn()}>
fetch notes
</paper-button>
` : html`
<paper-button on-click=${() => this.onFetchBtn()}>
refresh
</paper-button>
${repeat(this.fileList || [], null, (file) => html`
<paper-item on-click=${() => this.onFileClick(file.path)} data="${file}">${file.name}</paper-item>
`)}
`}
<style>
paper-fab#newFile {
position: fixed;
right: 20px;
bottom: 20px;
background-color: red;
}
</style>
<paper-fab icon="add" id="newFile" on-click=${()=>this.onNewFileClick()}></paper-fab>
`;

Do:
=G

Expect javascript;
return html`
<div> Files </div>
${!this.fileList ?
html`
<paper-button on-click=${() => this.onFetchBtn()}>
fetch notes
</paper-button>
` : html`
<paper-button on-click=${() => this.onFetchBtn()}>
refresh
</paper-button>
${repeat(this.fileList || [], null, (file) => html`
<paper-item on-click=${() => this.onFileClick(file.path)} data="${file}">${file.name}</paper-item>
`)}
`}
<style>
paper-fab#newFile {
position: fixed;
right: 20px;
bottom: 20px;
background-color: red;
}
</style>
<paper-fab icon="add" id="newFile" on-click=${()=>this.onNewFileClick()}></paper-fab>
`;


149 changes: 149 additions & 0 deletions test/indent/html-string-literal-end.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
Before:
set tabstop=2
set shiftwidth=2
set expandtab

" (IT SHOULD CORRECTLY INDENT...)
Given javascript (LITERAL WITH SINGLE NEWLINE);
{
html`
`;
}

Do:
=G

Expect javascript;
{
html`
`;
}

Given javascript (LITERAL WITH SINGLE HTML TAG);
{
html`
<div></div>
`;
}

Do:
=G

Expect javascript;
{
html`
<div></div>
`;
}


Given javascript (LITERAL WITH SINGLE SELF CLOSING TAG);
{
html`
<img />
`;
}

Do:
=G

Expect javascript;
{
html`
<img />
`;
}

Given javascript (LITERAL AT END OF LINE, NO SEMICOLON);
{
html`
<div>
</div>`
more()
}

Do:
=G

Expect javascript;
{
html`
<div>
</div>`
more()
}

Given javascript (LITERAL AT END OF LINE, WITH SEMICOLON);
{
html`
<div>
</div>`;
more()
}

Do:
=G

Expect javascript;
{
html`
<div>
</div>`;
more()
}

Given javascript (LITERAL AT END OF ONLY LINE);
{
html`
<div></div>`
more()
}

Do:
=G

Expect javascript;
{
html`
<div></div>`
more()
}

Given javascript (NEXT LINE AFTER LITERAL);
{
html`
${
html`
<div></div>` } `;
more()
}

Do:
=G

Expect javascript;
{
html`
${
html`
<div></div>` } `;
more()
}

After:
# Given javascript (IGNORED: LITERAL AFTER SELF-CLOSING TAG)
# {
# html`
# <div/>
# `;
# }
#
# Do:
# =G
#
# Expect javascript;
# {
# html`
# <div/>
# `;
# }
12 changes: 12 additions & 0 deletions test/indent/html-string-literal-start.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

" (IT SHOULD CORRECTLY INDENT...)
Given javascript (COMMENTED TEMPLATES):
// html`
// <div></div>`;

Do:
=G

Expect javascript:
// html`
// <div></div>`;
30 changes: 30 additions & 0 deletions test/indent/template-end.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Before:
set tabstop=2
set shiftwidth=2
set expandtab

" (IT SHOULD CORRECTLY INDENT...)
Given javascript (NEXT LINE OF HTML);
{
html`
${
html`${
2 + 2}`}
<div>
</div>
`;
}

Do:
=G

Expect javascript;
{
html`
${
html`${
2 + 2}`}
<div>
</div>
`;
}
7 changes: 7 additions & 0 deletions test/minimalvimrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ call plug#begin('~/.vim/plugged')
Plug 'pangloss/vim-javascript'
call plug#end()
syntax enable
let g:VHTL_debugging = 1
let g:html_indent_style1 = "inc"

nmap <F10> :echo map(synstack(line("."), col(".")), "synIDattr(v:val, 'name')")<cr>

set tabstop=2
set shiftwidth=2
set expandtab
91 changes: 0 additions & 91 deletions test/random-examples.vader

This file was deleted.

7 changes: 6 additions & 1 deletion test/runtests
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

cd "$(dirname "$0")"

vim -u <(cat minimalvimrc) +Vader*
if [[ "$CI" = true ]]; then
export VADER_OUTPUT_FILE='testresults.txt'
vim -u <(cat minimalvimrc) +'Vader! indent/*.vader'
else
vim -u <(cat minimalvimrc) +'Vader indent/*.vader'
fi

0 comments on commit 3499e07

Please sign in to comment.