Skip to content

Commit

Permalink
add some unit tests on variableDeclarator
Browse files Browse the repository at this point in the history
  • Loading branch information
clementdessoude committed Dec 23, 2019
1 parent 274bdef commit 22e5377
Showing 1 changed file with 73 additions and 0 deletions.
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);
});
});

0 comments on commit 22e5377

Please sign in to comment.