-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some unit tests on variableDeclarator
- Loading branch information
1 parent
274bdef
commit 22e5377
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
...ages/prettier-plugin-java/test/unit-test/snippets/classes/variableDeclarator/test.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
"use strict"; | ||
|
||
const { expect } = require("chai"); | ||
const { formatJavaSnippet } = require("../../../../test-utils"); | ||
|
||
describe("VariableDeclarator", () => { | ||
it("should format a variable declaration", () => { | ||
const snippet = "i=1"; | ||
const entryPoint = "variableDeclarator"; | ||
|
||
const formattedText = formatJavaSnippet(snippet, entryPoint); | ||
const expectedContents = "i = 1"; | ||
expect(formattedText).to.equal(expectedContents); | ||
}); | ||
|
||
it("should format a variable declaration with an array initialisation", () => { | ||
const snippet = "i={alpha}"; | ||
const entryPoint = "variableDeclarator"; | ||
|
||
const formattedText = formatJavaSnippet(snippet, entryPoint); | ||
const expectedContents = "i = { alpha }"; | ||
expect(formattedText).to.equal(expectedContents); | ||
}); | ||
|
||
it("should not add a blank line with an array initialisation that break", () => { | ||
const snippet = | ||
"i={alpha, beta, gamma, delta, epsilon, zeta, eta, theta, iota, kappa, lambda, mu, nu, xi}"; | ||
const entryPoint = "variableDeclarator"; | ||
|
||
const formattedText = formatJavaSnippet(snippet, entryPoint); | ||
const expectedContents = | ||
"i = {\n alpha,\n beta,\n gamma,\n delta,\n epsilon,\n zeta,\n eta,\n theta,\n iota,\n kappa,\n lambda,\n mu,\n nu,\n xi\n}"; | ||
expect(formattedText).to.equal(expectedContents); | ||
}); | ||
|
||
it("should format a variable declaration with a lambda", () => { | ||
const snippet = "lambda= test -> {}"; | ||
const entryPoint = "variableDeclarator"; | ||
|
||
const formattedText = formatJavaSnippet(snippet, entryPoint); | ||
const expectedContents = "lambda = test -> {}"; | ||
expect(formattedText).to.equal(expectedContents); | ||
}); | ||
|
||
it("should not add a blank line with a lambda that break", () => { | ||
const snippet = "lambda= test -> {int i;}"; | ||
const entryPoint = "variableDeclarator"; | ||
|
||
const formattedText = formatJavaSnippet(snippet, entryPoint); | ||
const expectedContents = "lambda = test -> {\n int i;\n}"; | ||
expect(formattedText).to.equal(expectedContents); | ||
}); | ||
|
||
it("should format a variable declaration with a ternary expression", () => { | ||
const snippet = "value= bool ? one : two"; | ||
const entryPoint = "variableDeclarator"; | ||
|
||
const formattedText = formatJavaSnippet(snippet, entryPoint); | ||
const expectedContents = "value = bool ? one : two"; | ||
expect(formattedText).to.equal(expectedContents); | ||
}); | ||
|
||
it("should not add a blank line with a ternary expression that break", () => { | ||
const snippet = | ||
"value = thisIsAnotherVeryLongIntegerThatIsEvenLongerThanFirstOne ? thisIsAnotherVeryLongIntegerThatIsEvenLongerThanFirstOne : thisIsAShortInteger"; | ||
const entryPoint = "variableDeclarator"; | ||
|
||
const formattedText = formatJavaSnippet(snippet, entryPoint); | ||
const expectedContents = | ||
"value = thisIsAnotherVeryLongIntegerThatIsEvenLongerThanFirstOne\n ? thisIsAnotherVeryLongIntegerThatIsEvenLongerThanFirstOne\n : thisIsAShortInteger"; | ||
expect(formattedText).to.equal(expectedContents); | ||
}); | ||
}); |