Skip to content

Commit

Permalink
npm run format
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnesky committed Aug 4, 2023
1 parent d6dc413 commit e3a78c8
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 85 deletions.
10 changes: 9 additions & 1 deletion core/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ import {StatementInput} from './inputs/statement_input.js';
import {ValueInput} from './inputs/value_input.js';
import {inputTypes} from './inputs/input_types.js';

export {Align, Input, DummyInput, EndRowInput, StatementInput, ValueInput, inputTypes};
export {
Align,
Input,
DummyInput,
EndRowInput,
StatementInput,
ValueInput,
inputTypes,
};
19 changes: 12 additions & 7 deletions core/utils/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ function tokenizeInterpolationInternal(
Array.prototype.push.apply(
tokens,
tokenizeInterpolationInternal(
rawValue,
parseInterpolationTokens,
tokenizeNewlines,
rawValue,
parseInterpolationTokens,
tokenizeNewlines,
),
);
} else if (parseInterpolationTokens) {
Expand Down Expand Up @@ -155,8 +155,10 @@ function tokenizeInterpolationInternal(
const mergedTokens = [];
buffer.length = 0;
for (let i = 0; i < tokens.length; i++) {
if (typeof tokens[i] === 'string' &&
!(tokenizeNewlines && tokens[i] === '\n')) {
if (
typeof tokens[i] === 'string' &&
!(tokenizeNewlines && tokens[i] === '\n')
) {
buffer.push(tokens[i] as string);
} else {
text = buffer.join('');
Expand Down Expand Up @@ -205,8 +207,11 @@ export function replaceMessageReferences(message: string | any): string {
if (typeof message !== 'string') {
return message;
}
const interpolatedResult =
tokenizeInterpolationInternal(message, false, false);
const interpolatedResult = tokenizeInterpolationInternal(
message,
false,
false,
);
// When parseInterpolationTokens and tokenizeNewlines are false,
// interpolatedResult should be at most length 1.
return interpolatedResult.length ? String(interpolatedResult[0]) : '';
Expand Down
123 changes: 58 additions & 65 deletions tests/mocha/block_json_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ suite('Block JSON initialization', function () {
);
});

test('Newline tokens are valid', function() {
test('Newline tokens are valid', function () {
this.assertNoError(['test', '\n', 'test'], 0);
});
});
Expand Down Expand Up @@ -317,75 +317,68 @@ suite('Block JSON initialization', function () {
]);
});

test('interpolation output includes end-row inputs', function() {
test('interpolation output includes end-row inputs', function () {
this.assertInterpolation(
['test1', {'type': 'input_end_row'}, 'test2'],
[],
undefined,
[
{
'type': 'field_label',
'text': 'test1',
},
{
'type': 'input_end_row',
},
{
'type': 'field_label',
'text': 'test2',
},
{
'type': 'input_dummy',
},
]);
['test1', {'type': 'input_end_row'}, 'test2'],
[],
undefined,
[
{
'type': 'field_label',
'text': 'test1',
},
{
'type': 'input_end_row',
},
{
'type': 'field_label',
'text': 'test2',
},
{
'type': 'input_dummy',
},
],
);
});

test('Newline is converted to end-row input', function() {
this.assertInterpolation(
['test1', '\n', 'test2'],
[],
undefined,
[
{
'type': 'field_label',
'text': 'test1',
},
{
'type': 'input_end_row',
},
{
'type': 'field_label',
'text': 'test2',
},
{
'type': 'input_dummy',
},
]);
test('Newline is converted to end-row input', function () {
this.assertInterpolation(['test1', '\n', 'test2'], [], undefined, [
{
'type': 'field_label',
'text': 'test1',
},
{
'type': 'input_end_row',
},
{
'type': 'field_label',
'text': 'test2',
},
{
'type': 'input_dummy',
},
]);
});

test('Newline converted to end-row aligned like last dummy', function() {
this.assertInterpolation(
['test1', '\n', 'test2'],
[],
'CENTER',
[
{
'type': 'field_label',
'text': 'test1',
},
{
'type': 'input_end_row',
'align': 'CENTER',
},
{
'type': 'field_label',
'text': 'test2',
},
{
'type': 'input_dummy',
'align': 'CENTER',
},
]);
test('Newline converted to end-row aligned like last dummy', function () {
this.assertInterpolation(['test1', '\n', 'test2'], [], 'CENTER', [
{
'type': 'field_label',
'text': 'test1',
},
{
'type': 'input_end_row',
'align': 'CENTER',
},
{
'type': 'field_label',
'text': 'test2',
},
{
'type': 'input_dummy',
'align': 'CENTER',
},
]);
});
});

Expand Down
16 changes: 9 additions & 7 deletions tests/mocha/block_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2404,21 +2404,23 @@ suite('Blocks', function () {
});
});

suite('EndOfRow', function() {
setup(function() {
suite('EndOfRow', function () {
setup(function () {
Blockly.defineBlocksWithJsonArray([
{
"type": "end_row_test_block",
"message0": "Row1\nRow2",
'type': 'end_row_test_block',
'message0': 'Row1\nRow2',
'inputsInline': true,
},
]);
});
test('Newline is converted to an end-row input', function() {
test('Newline is converted to an end-row input', function () {
const block = this.workspace.newBlock('end_row_test_block');
chai.assert.equal(block.inputList[0].fieldRow[0].getValue(), 'Row1');
chai.assert.isTrue(block.inputList[0] instanceof EndRowInput,
'newline should be converted to an end-row input');
chai.assert.isTrue(
block.inputList[0] instanceof EndRowInput,
'newline should be converted to an end-row input',
);
chai.assert.equal(block.inputList[1].fieldRow[0].getValue(), 'Row2');
});
});
Expand Down
16 changes: 11 additions & 5 deletions tests/mocha/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ suite('Utils', function () {
);
});

test('Newlines are tokenized', function() {
test('Newlines are tokenized', function () {
chai.assert.deepEqual(
Blockly.utils.parsing.tokenizeInterpolation('Hello\nWorld'),
['Hello', '\n', 'World']);
Blockly.utils.parsing.tokenizeInterpolation('Hello\nWorld'),
['Hello', '\n', 'World'],
);
});
});

Expand Down Expand Up @@ -237,8 +238,13 @@ suite('Utils', function () {
'Unrecognized % escape code treated as literal',
);

resultString = Blockly.utils.parsing.replaceMessageReferences('Hello\nWorld');
chai.assert.equal(resultString, 'Hello\nWorld', 'Newlines are not tokenized');
resultString =
Blockly.utils.parsing.replaceMessageReferences('Hello\nWorld');
chai.assert.equal(
resultString,
'Hello\nWorld',
'Newlines are not tokenized',
);

resultString = Blockly.utils.parsing.replaceMessageReferences('%1');
chai.assert.equal(resultString, '%1', 'Interpolation tokens ignored.');
Expand Down

0 comments on commit e3a78c8

Please sign in to comment.