mirror of
https://github.com/google/blockly.git
synced 2026-01-05 08:00:09 +01:00
Adding tests for multiline block (#4317)
* Adding tests for multiline input
This commit is contained in:
@@ -937,6 +937,20 @@ void test_replace() {
|
||||
unittest_assertequals(''.replaceAll('a', 'chicken'), '', 'empty source');
|
||||
}
|
||||
|
||||
/// Tests the "multiline" block.
|
||||
void test_multiline() {
|
||||
unittest_assertequals('', '', 'no text');
|
||||
unittest_assertequals('Google', 'Google', 'simple');
|
||||
unittest_assertequals('paragraph' + '\n' +
|
||||
'with newlines' + '\n' +
|
||||
'yup', 'paragraph' + '\n' +
|
||||
'with newlines' + '\n' +
|
||||
'yup', 'no compile error with newlines');
|
||||
unittest_assertequals(text_count('bark bark' + '\n' +
|
||||
'bark bark bark' + '\n' +
|
||||
'bark bark bark bark', 'bark'), 9, 'count with newlines');
|
||||
}
|
||||
|
||||
/// Checks that the number of calls is one in order
|
||||
/// to confirm that a function was only called once.
|
||||
void check_number_of_calls2(test_name) {
|
||||
@@ -1624,6 +1638,7 @@ main() {
|
||||
test_count_text();
|
||||
test_text_reverse();
|
||||
test_replace();
|
||||
test_multiline();
|
||||
print(unittest_report());
|
||||
unittestResults = null;
|
||||
|
||||
|
||||
@@ -916,6 +916,20 @@ function test_replace() {
|
||||
assertEquals(textReplace('', 'a', 'chicken'), '', 'empty source');
|
||||
}
|
||||
|
||||
// Tests the "multiline" block.
|
||||
function test_multiline() {
|
||||
assertEquals('', '', 'no text');
|
||||
assertEquals('Google', 'Google', 'simple');
|
||||
assertEquals('paragraph' + '\n' +
|
||||
'with newlines' + '\n' +
|
||||
'yup', 'paragraph' + '\n' +
|
||||
'with newlines' + '\n' +
|
||||
'yup', 'no compile error with newlines');
|
||||
assertEquals(textCount('bark bark' + '\n' +
|
||||
'bark bark bark' + '\n' +
|
||||
'bark bark bark bark', 'bark'), 9, 'count with newlines');
|
||||
}
|
||||
|
||||
// Checks that the number of calls is one in order
|
||||
// to confirm that a function was only called once.
|
||||
function check_number_of_calls2(test_name) {
|
||||
@@ -1558,6 +1572,7 @@ test_trim();
|
||||
test_count_text();
|
||||
test_text_reverse();
|
||||
test_replace();
|
||||
test_multiline();
|
||||
console.log(unittest_report());
|
||||
unittestResults = null;
|
||||
|
||||
|
||||
@@ -1012,6 +1012,21 @@ function test_replace()
|
||||
end
|
||||
|
||||
|
||||
-- Tests the "multiline" block.
|
||||
function test_multiline()
|
||||
assertEquals('', '', 'no text')
|
||||
assertEquals('Google', 'Google', 'simple')
|
||||
assertEquals('paragraph' .. '\n' ..
|
||||
'with newlines' .. '\n' ..
|
||||
'yup', 'paragraph' .. '\n' ..
|
||||
'with newlines' .. '\n' ..
|
||||
'yup', 'no compile error with newlines')
|
||||
assertEquals(text_count('bark bark' .. '\n' ..
|
||||
'bark bark bark' .. '\n' ..
|
||||
'bark bark bark bark', 'bark'), 9, 'count with newlines')
|
||||
end
|
||||
|
||||
|
||||
-- Checks that the number of calls is one in order
|
||||
-- to confirm that a function was only called once.
|
||||
function check_number_of_calls2(test_name)
|
||||
@@ -1828,6 +1843,7 @@ test_trim()
|
||||
test_count_text()
|
||||
test_text_reverse()
|
||||
test_replace()
|
||||
test_multiline()
|
||||
print(unittest_report())
|
||||
unittestResults = nil
|
||||
|
||||
|
||||
@@ -925,6 +925,23 @@ function test_replace() {
|
||||
assertEquals(str_replace('a', 'chicken', ''), '', 'empty source');
|
||||
}
|
||||
|
||||
// Tests the "multiline" block.
|
||||
function test_multiline() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals('', '', 'no text');
|
||||
assertEquals('Google', 'Google', 'simple');
|
||||
assertEquals('paragraph' . "\n" .
|
||||
'with newlines' . "\n" .
|
||||
'yup', 'paragraph' . "\n" .
|
||||
'with newlines' . "\n" .
|
||||
'yup', 'no compile error with newlines');
|
||||
assertEquals(strlen('bark') === 0 ? strlen('bark bark' . "\n" .
|
||||
'bark bark bark' . "\n" .
|
||||
'bark bark bark bark') + 1 : substr_count('bark bark' . "\n" .
|
||||
'bark bark bark' . "\n" .
|
||||
'bark bark bark bark', 'bark'), 9, 'count with newlines');
|
||||
}
|
||||
|
||||
// Checks that the number of calls is one in order
|
||||
// to confirm that a function was only called once.
|
||||
function check_number_of_calls2($test_name) {
|
||||
@@ -1652,6 +1669,7 @@ test_trim();
|
||||
test_count_text();
|
||||
test_text_reverse();
|
||||
test_replace();
|
||||
test_multiline();
|
||||
print(unittest_report());
|
||||
$unittestResults = null;
|
||||
|
||||
|
||||
@@ -782,6 +782,20 @@ def test_replace():
|
||||
assertEquals('aaaaa'.replace('a', ''), '', 'empty replacement 3')
|
||||
assertEquals(''.replace('a', 'chicken'), '', 'empty source')
|
||||
|
||||
# Tests the "multiline" block.
|
||||
def test_multiline():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals('', '', 'no text')
|
||||
assertEquals('Google', 'Google', 'simple')
|
||||
assertEquals('paragraph' + '\n' +
|
||||
'with newlines' + '\n' +
|
||||
'yup', 'paragraph' + '\n' +
|
||||
'with newlines' + '\n' +
|
||||
'yup', 'no compile error with newlines')
|
||||
assertEquals(('bark bark' + '\n' +
|
||||
'bark bark bark' + '\n' +
|
||||
'bark bark bark bark').count('bark'), 9, 'count with newlines')
|
||||
|
||||
# Checks that the number of calls is one in order
|
||||
# to confirm that a function was only called once.
|
||||
def check_number_of_calls2(test_name):
|
||||
@@ -1396,6 +1410,7 @@ test_trim()
|
||||
test_count_text()
|
||||
test_text_reverse()
|
||||
test_replace()
|
||||
test_multiline()
|
||||
print(unittest_report())
|
||||
unittestResults = None
|
||||
|
||||
|
||||
@@ -362,6 +362,7 @@ h1 {
|
||||
<block type="text_count"></block>
|
||||
<block type="text_replace"></block>
|
||||
<block type="text_reverse"></block>
|
||||
<block type="text_multiline"></block>
|
||||
</category>
|
||||
<category name="Lists" colour="260">
|
||||
<block type="lists_create_empty"></block>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<xml xmlns="https://developers.google.com/blockly/xml">
|
||||
<block type="unittest_main" x="13" y="-63">
|
||||
<block type="unittest_main" x="13" y="13">
|
||||
<field name="SUITE_NAME">Text</field>
|
||||
<statement name="DO">
|
||||
<block type="procedures_callnoreturn">
|
||||
@@ -46,6 +46,11 @@
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test replace"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test multiline"></mutation>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
@@ -77,7 +82,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="388">
|
||||
<block type="procedures_defnoreturn" x="13" y="488">
|
||||
<mutation>
|
||||
<arg name="test name"></arg>
|
||||
</mutation>
|
||||
@@ -113,7 +118,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="563">
|
||||
<block type="procedures_defnoreturn" x="13" y="663">
|
||||
<field name="NAME">test create text</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "create text with" block with varying number of inputs.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -322,7 +327,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defreturn" x="13" y="1263">
|
||||
<block type="procedures_defreturn" x="13" y="1363">
|
||||
<mutation statements="false"></mutation>
|
||||
<field name="NAME">get empty</field>
|
||||
<comment pinned="false" h="80" w="160">Creates an empty string for use with the empty test.</comment>
|
||||
@@ -332,7 +337,7 @@
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="1338">
|
||||
<block type="procedures_defnoreturn" x="13" y="1438">
|
||||
<field name="NAME">test empty text</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "is empty" block".</comment>
|
||||
<statement name="STACK">
|
||||
@@ -424,7 +429,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="1663">
|
||||
<block type="procedures_defnoreturn" x="13" y="1763">
|
||||
<field name="NAME">test text length</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "length" block.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -509,7 +514,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="1963">
|
||||
<block type="procedures_defnoreturn" x="13" y="2063">
|
||||
<field name="NAME">test append</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "append text" block with different types of parameters.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -642,7 +647,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="2438">
|
||||
<block type="procedures_defnoreturn" x="13" y="2538">
|
||||
<field name="NAME">test find text simple</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "find" block with a variable.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -755,7 +760,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defreturn" x="13" y="2838">
|
||||
<block type="procedures_defreturn" x="13" y="2938">
|
||||
<field name="NAME">get fruit</field>
|
||||
<comment pinned="false" h="80" w="160">Creates a string for use with the find test.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -774,7 +779,7 @@
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="2938">
|
||||
<block type="procedures_defnoreturn" x="13" y="3038">
|
||||
<field name="NAME">test find text complex</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "find" block with a function call.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -1144,7 +1149,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="4013">
|
||||
<block type="procedures_defnoreturn" x="13" y="4113">
|
||||
<field name="NAME">test get text simple</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "get letter" block with a variable.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -1412,7 +1417,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defreturn" x="13" y="4838">
|
||||
<block type="procedures_defreturn" x="13" y="4938">
|
||||
<field name="NAME">get Blockly</field>
|
||||
<comment pinned="false" h="80" w="160">Creates a string for use with the get test.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -1431,7 +1436,7 @@
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="4938">
|
||||
<block type="procedures_defnoreturn" x="13" y="5038">
|
||||
<field name="NAME">test get text complex</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "get letter" block with a function call.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -2074,7 +2079,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defreturn" x="13" y="6738">
|
||||
<block type="procedures_defreturn" x="13" y="6863">
|
||||
<field name="NAME">get numbers</field>
|
||||
<comment pinned="false" h="80" w="160">Creates a string for use with the substring test.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -2093,7 +2098,7 @@
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="6838">
|
||||
<block type="procedures_defnoreturn" x="13" y="6963">
|
||||
<field name="NAME">test substring simple</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "get substring" block with a variable.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -2735,7 +2740,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="8388">
|
||||
<block type="procedures_defnoreturn" x="13" y="8513">
|
||||
<field name="NAME">test substring complex</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "get substring" block with a function call.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -3699,7 +3704,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="10838">
|
||||
<block type="procedures_defnoreturn" x="13" y="10963">
|
||||
<field name="NAME">test case</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "change casing" block.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -3913,7 +3918,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="11488">
|
||||
<block type="procedures_defnoreturn" x="13" y="11613">
|
||||
<field name="NAME">test trim</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "trim" block.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -4107,7 +4112,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="12088">
|
||||
<block type="procedures_defnoreturn" x="13" y="12213">
|
||||
<field name="NAME">test count text</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "trim" block.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -4317,7 +4322,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="12" y="12812">
|
||||
<block type="procedures_defnoreturn" x="13" y="12938">
|
||||
<field name="NAME">test text reverse</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "trim" block.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -4413,7 +4418,7 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="12" y="13237">
|
||||
<block type="procedures_defnoreturn" x="13" y="13363">
|
||||
<field name="NAME">test replace</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "trim" block.</comment>
|
||||
<statement name="STACK">
|
||||
@@ -4648,4 +4653,93 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</xml>
|
||||
<block type="procedures_defnoreturn" x="13" y="14063">
|
||||
<field name="NAME">test multiline</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "multiline" block.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">no text</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="text_multiline">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">simple</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="text_multiline">
|
||||
<field name="TEXT">Google</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">Google</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">no compile error with newlines</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="text_multiline">
|
||||
<field name="TEXT">paragraph with newlines yup</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text_multiline">
|
||||
<field name="TEXT">paragraph with newlines yup</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count with newlines</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="text_count">
|
||||
<value name="SUB">
|
||||
<block type="text">
|
||||
<field name="TEXT">bark</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TEXT">
|
||||
<block type="text_multiline">
|
||||
<field name="TEXT">bark bark bark bark bark bark bark bark bark</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">9</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</xml>
|
||||
150
tests/mocha/field_multilineinput_test.js
Normal file
150
tests/mocha/field_multilineinput_test.js
Normal file
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
suite('Multiline Input Fields', function() {
|
||||
/**
|
||||
* Configuration for field tests with invalid values.
|
||||
* @type {!Array<!FieldCreationTestCase>}
|
||||
*/
|
||||
var invalidValueTestCases = [
|
||||
{title: 'Undefined', value: undefined},
|
||||
{title: 'Null', value: null},
|
||||
];
|
||||
/**
|
||||
* Configuration for field tests with valid values.
|
||||
* @type {!Array<!FieldCreationTestCase>}
|
||||
*/
|
||||
var validValueTestCases = [
|
||||
{title: 'Empty string', value: '', expectedValue: ''},
|
||||
{title: 'String no newline', value: 'value', expectedValue: 'value'},
|
||||
{title: 'String with newline', value: 'bark bark\n bark bark bark\n bark bar bark bark\n', expectedValue: 'bark bark\n bark bark bark\n bark bar bark bark\n'},
|
||||
{title: 'Boolean true', value: true, expectedValue: 'true'},
|
||||
{title: 'Boolean false', value: false, expectedValue: 'false'},
|
||||
{title: 'Number (Truthy)', value: 1, expectedValue: '1'},
|
||||
{title: 'Number (Falsy)', value: 0, expectedValue: '0'},
|
||||
{title: 'NaN', value: NaN, expectedValue: 'NaN'},
|
||||
];
|
||||
var addArgsAndJson = function(testCase) {
|
||||
testCase.args = [testCase.value];
|
||||
testCase.json = {'text': testCase.value};
|
||||
};
|
||||
invalidValueTestCases.forEach(addArgsAndJson);
|
||||
validValueTestCases.forEach(addArgsAndJson);
|
||||
|
||||
/**
|
||||
* The expected default value for the field being tested.
|
||||
* @type {*}
|
||||
*/
|
||||
var defaultFieldValue = '';
|
||||
/**
|
||||
* Asserts that the field property values are set to default.
|
||||
* @param {!Blockly.FieldNumber} field The field to check.
|
||||
*/
|
||||
var assertFieldDefault = function(field) {
|
||||
testHelpers.assertFieldValue(field, defaultFieldValue);
|
||||
};
|
||||
/**
|
||||
* Asserts that the field properties are correct based on the test case.
|
||||
* @param {!Blockly.FieldNumber} field The field to check.
|
||||
* @param {!FieldValueTestCase} testCase The test case.
|
||||
*/
|
||||
var validTestCaseAssertField = function(field, testCase) {
|
||||
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
||||
};
|
||||
|
||||
testHelpers.runConstructorSuiteTests(
|
||||
Blockly.FieldMultilineInput, validValueTestCases, invalidValueTestCases,
|
||||
validTestCaseAssertField, assertFieldDefault);
|
||||
|
||||
testHelpers.runFromJsonSuiteTests(
|
||||
Blockly.FieldMultilineInput, validValueTestCases,invalidValueTestCases,
|
||||
validTestCaseAssertField, assertFieldDefault);
|
||||
|
||||
suite('setValue', function() {
|
||||
suite('Empty -> New Value', function() {
|
||||
setup(function() {
|
||||
this.field = new Blockly.FieldMultilineInput();
|
||||
});
|
||||
testHelpers.runSetValueTests(
|
||||
validValueTestCases, invalidValueTestCases, defaultFieldValue);
|
||||
test('With source block', function() {
|
||||
this.field.setSourceBlock(createTestBlock());
|
||||
this.field.setValue('value');
|
||||
testHelpers.assertFieldValue(this.field, 'value');
|
||||
});
|
||||
});
|
||||
suite('Value -> New Value', function() {
|
||||
var initialValue = 'oldValue';
|
||||
setup(function() {
|
||||
this.field = new Blockly.FieldMultilineInput(initialValue);
|
||||
});
|
||||
testHelpers.runSetValueTests(
|
||||
validValueTestCases, invalidValueTestCases, initialValue);
|
||||
test('With source block', function() {
|
||||
this.field.setSourceBlock(createTestBlock());
|
||||
this.field.setValue('value');
|
||||
testHelpers.assertFieldValue(this.field, 'value');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('blockToCode', function() {
|
||||
setup(function() {
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
const createBlockFn = (value) => {
|
||||
return (workspace) => {
|
||||
var block = workspace.newBlock('text_multiline');
|
||||
var textField = block.getField('TEXT');
|
||||
textField.setValue(value);
|
||||
return block;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Test suites for code generation tests.s
|
||||
* @type {Array<CodeGenerationTestSuite>}
|
||||
*/
|
||||
const testSuites = [
|
||||
{title: 'Dart', generator: Blockly.Dart,
|
||||
testCases: [
|
||||
{title: 'Empty string', expectedCode: '\'\'',
|
||||
createBlock: createBlockFn('')},
|
||||
{title: 'String with newline', expectedCode: '\'bark bark\' + \'\\n\' + \n\' bark bark bark\' + \'\\n\' + \n\' bark bar bark bark\' + \'\\n\' + \n\'\'',
|
||||
createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')},
|
||||
]},
|
||||
{title: 'JavaScript', generator: Blockly.JavaScript,
|
||||
testCases: [
|
||||
{title: 'Empty string', expectedCode: '\'\'',
|
||||
createBlock: createBlockFn('')},
|
||||
{title: 'String with newline', expectedCode: '\'bark bark\' + \'\\n\' +\n\' bark bark bark\' + \'\\n\' +\n\' bark bar bark bark\' + \'\\n\' +\n\'\'',
|
||||
createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')},
|
||||
]},
|
||||
{title: 'Lua', generator: Blockly.Lua,
|
||||
testCases: [
|
||||
{title: 'Empty string', expectedCode: '\'\'',
|
||||
createBlock: createBlockFn('')},
|
||||
{title: 'String with newline', expectedCode: '\'bark bark\' .. \'\\n\' ..\n\' bark bark bark\' .. \'\\n\' ..\n\' bark bar bark bark\' .. \'\\n\' ..\n\'\'',
|
||||
createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')},
|
||||
]},
|
||||
{title: 'PHP', generator: Blockly.PHP,
|
||||
testCases: [
|
||||
{title: 'Empty string', expectedCode: '\'\'',
|
||||
createBlock: createBlockFn('')},
|
||||
{title: 'String with newline', expectedCode: '\'bark bark\' . "\\n" .\n\' bark bark bark\' . "\\n" .\n\' bark bar bark bark\' . "\\n" .\n\'\'',
|
||||
createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')},
|
||||
]},
|
||||
{title: 'Python', generator: Blockly.Python,
|
||||
testCases: [
|
||||
{title: 'Empty string', expectedCode: '\'\'',
|
||||
createBlock: createBlockFn('')},
|
||||
{title: 'String with newline', expectedCode: '\'bark bark\' + \'\\n\' + \n\' bark bark bark\' + \'\\n\' + \n\' bark bar bark bark\' + \'\\n\' + \n\'\'',
|
||||
createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')},
|
||||
]},
|
||||
];
|
||||
testHelpers.runCodeGenerationTestSuites(testSuites);
|
||||
});
|
||||
});
|
||||
@@ -11,6 +11,13 @@
|
||||
<script src="../../generators/lua.js"></script>
|
||||
<script src="../../generators/php.js"></script>
|
||||
<script src="../../generators/python.js"></script>
|
||||
|
||||
<script src="../../generators/dart/text.js"></script>
|
||||
<script src="../../generators/javascript/text.js"></script>
|
||||
<script src="../../generators/lua/text.js"></script>
|
||||
<script src="../../generators/php/text.js"></script>
|
||||
<script src="../../generators/python/text.js"></script>
|
||||
|
||||
<script src="../../msg/messages.js"></script>
|
||||
<script src="../../blocks/loops.js"></script>
|
||||
<script src="../../blocks/lists.js"></script>
|
||||
@@ -63,6 +70,7 @@
|
||||
<script src="field_image_test.js"></script>
|
||||
<script src="field_label_test.js"></script>
|
||||
<script src="field_label_serializable_test.js"></script>
|
||||
<script src="field_multilineinput_test.js"></script>
|
||||
<script src="field_number_test.js"></script>
|
||||
<script src="field_registry_test.js"></script>
|
||||
<script src="field_textinput_test.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user