/** * @license * Copyright 2021 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import * as Blockly from '../../build/src/core/blockly.js'; import {assert} from '../../node_modules/chai/index.js'; import { TestCase, TestSuite, runTestCases, runTestSuites, } from './test_helpers/common.js'; import { sharedTestSetup, sharedTestTeardown, workspaceTeardown, } from './test_helpers/setup_teardown.js'; // TODO: Move this into samples as part of the dev-tools package. // TODO: Fix up typing of SerializerTestCase & SerializerTestSuite to match // decision in google/blockly-samples#819. /** * Constructs a serializer test. * @param {string} title The title of this testcase. * @param {string} xml The XML to use for the round-trip test. * @constructor * @implements {TestCase} */ function SerializerTestCase(title, xml) { this.title = title; this.xml = xml; } SerializerTestCase.prototype = new TestCase(); /** * The XML we want to ensure round-trips through the serializer. */ SerializerTestCase.prototype.xml = ''; /** * Constructs a serializer test suite. * @param {string} title The title of this test suite. * @extends {TestSuite} */ function SerializerTestSuite(title) { this.title = title; } SerializerTestSuite.prototype = new TestSuite(); const Serializer = new SerializerTestSuite('Serializer'); // TODO: Make sure all of these properties are documented ad exported properly. Serializer.Empty = new SerializerTestCase( 'Empty', '', ); Serializer.Data = new SerializerTestCase( 'Data', '' + '' + 'test data' + '' + '', ); Serializer.testCases = [Serializer.Empty, Serializer.Data]; Serializer.Attributes = new SerializerTestSuite('Attributes'); Serializer.Attributes.Basic = new SerializerTestCase( 'Basic', '' + '' + '', ); Serializer.Attributes.Collapsed = new SerializerTestCase( 'Collapsed', '' + '' + '', ); Serializer.Attributes.Disabled = new SerializerTestCase( 'Disabled', '' + '' + '', ); Serializer.Attributes.DisabledWithEncodedComma = new SerializerTestCase( 'DisabledWithEncodedComma', '' + '' + '', ); Serializer.Attributes.NotDeletable = new SerializerTestCase( 'Deletable', '' + '' + '', ); Serializer.Attributes.NotMovable = new SerializerTestCase( 'Movable', '' + '' + '', ); Serializer.Attributes.NotEditable = new SerializerTestCase( 'Editable', '' + '' + '', ); Serializer.Attributes.testCases = [ Serializer.Attributes.Basic, Serializer.Attributes.Collapsed, Serializer.Attributes.Disabled, Serializer.Attributes.DisabledWithEncodedComma, Serializer.Attributes.NotDeletable, Serializer.Attributes.NotMovable, Serializer.Attributes.NotEditable, ]; Serializer.Attributes.Inline = new SerializerTestSuite('Inline'); Serializer.Attributes.Inline.True = new SerializerTestCase( 'True', '' + '' + '', ); Serializer.Attributes.Inline.False = new SerializerTestCase( 'False', '' + '' + '', ); Serializer.Attributes.Inline.testCases = [ Serializer.Attributes.Inline.True, Serializer.Attributes.Inline.False, ]; Serializer.Attributes.Coordinates = new SerializerTestSuite('Coordinates'); Serializer.Attributes.Coordinates.Simple = new SerializerTestCase( 'Simple', '' + '' + '', ); Serializer.Attributes.Coordinates.Negative = new SerializerTestCase( 'Negative', '' + '' + '', ); Serializer.Attributes.Coordinates.Zero = new SerializerTestCase( 'Zero', '' + '' + '', ); Serializer.Attributes.Coordinates.testCases = [ Serializer.Attributes.Coordinates.Simple, Serializer.Attributes.Coordinates.Negative, Serializer.Attributes.Coordinates.Zero, ]; Serializer.Attributes.Id = new SerializerTestSuite('Ids'); Serializer.Attributes.Id.Length = new SerializerTestSuite('Length'); Serializer.Attributes.Id.Length.Short = new SerializerTestCase( 'Short', '' + '' + '', ); Serializer.Attributes.Id.Length.Long = new SerializerTestCase( 'Long', '' + '' + '' + '', ); Serializer.Attributes.Id.Length.testCases = [ Serializer.Attributes.Id.Length.Short, Serializer.Attributes.Id.Length.Long, ]; Serializer.Attributes.Id.Chars = new SerializerTestSuite('Chars'); Serializer.Attributes.Id.Chars.Symbols = new SerializerTestCase( 'Symbols', '' + '' + '' + '', ); Serializer.Attributes.Id.Chars.Uppercase = new SerializerTestCase( 'Uppercase', '' + '' + '' + '', ); Serializer.Attributes.Id.Chars.Lowercase = new SerializerTestCase( 'Lowercase', '' + '' + '' + '', ); Serializer.Attributes.Id.Chars.Numbers = new SerializerTestCase( 'Numbers', '' + '' + '', ); Serializer.Attributes.Id.Chars.testCases = [ Serializer.Attributes.Id.Chars.Symbols, Serializer.Attributes.Id.Chars.Uppercase, Serializer.Attributes.Id.Chars.Lowercase, Serializer.Attributes.Id.Chars.Numbers, ]; Serializer.Attributes.Id.testSuites = [ Serializer.Attributes.Id.Length, Serializer.Attributes.Id.Chars, ]; Serializer.Attributes.testSuites = [ Serializer.Attributes.Inline, Serializer.Attributes.Coordinates, Serializer.Attributes.Id, ]; Serializer.Fields = new SerializerTestSuite('Fields'); Serializer.Fields.Checkbox = new SerializerTestSuite('Checkbox'); Serializer.Fields.Checkbox.True = new SerializerTestCase( 'True', '' + '' + 'TRUE' + '' + '', ); Serializer.Fields.Checkbox.False = new SerializerTestCase( 'False', '' + '' + 'FALSE' + '' + '', ); Serializer.Fields.Checkbox.testCases = [ Serializer.Fields.Checkbox.True, Serializer.Fields.Checkbox.False, ]; Serializer.Fields.Dropdown = new SerializerTestSuite('Dropdown'); Serializer.Fields.Dropdown.Default = new SerializerTestCase( 'Default', '' + '' + 'ITEM1' + '' + '', ); Serializer.Fields.Dropdown.NotDefault = new SerializerTestCase( 'NotDefault', '' + '' + 'ITEM32' + '' + '', ); Serializer.Fields.Dropdown.Dynamic = new SerializerTestCase( 'Dynamic', '' + '' + '0' + '' + '', ); Serializer.Fields.Dropdown.testCases = [ Serializer.Fields.Dropdown.Default, Serializer.Fields.Dropdown.NotDefault, Serializer.Fields.Dropdown.Dynamic, ]; Serializer.Fields.LabelSerializable = new SerializerTestSuite( 'LabelSerializable', ); Serializer.Fields.LabelSerializable.Simple = new SerializerTestCase( 'Simple', '' + '' + 'test' + '' + '', ); Serializer.Fields.LabelSerializable.Symbols = new SerializerTestCase( 'Symbols', '' + '' + '~`!@#$%^*()_+-={[}]|\\:;,.?/' + '' + '', ); Serializer.Fields.LabelSerializable.EscapedSymbols = new SerializerTestCase( 'EscapedSymbols', '' + '' + '&<>' + '' + '', ); Serializer.Fields.LabelSerializable.SingleQuotes = new SerializerTestCase( 'SingleQuotes', '' + '' + '\'test\'' + '' + '', ); Serializer.Fields.LabelSerializable.DoubleQuotes = new SerializerTestCase( 'DoubleQuotes', '' + '' + '"test"' + '' + '', ); Serializer.Fields.LabelSerializable.Numbers = new SerializerTestCase( 'Numbers', '' + '' + '1234567890a123a123a' + '' + '', ); Serializer.Fields.LabelSerializable.Emoji = new SerializerTestCase( 'Emoji', '' + '' + '😀👋🏿👋🏾👋🏽👋🏼👋🏻😀❤❤❤' + '' + '', ); Serializer.Fields.LabelSerializable.Russian = new SerializerTestCase( 'Russian', '' + '' + 'ты любопытный кот' + '' + '', ); Serializer.Fields.LabelSerializable.Japanese = new SerializerTestCase( 'Japanese', '' + '' + 'あなたは好奇心旺盛な猫です' + '' + '', ); Serializer.Fields.LabelSerializable.Zalgo = new SerializerTestCase( 'Zalgo', '' + '' + 'z̴̪͈̲̜͕̽̈̀͒͂̓̋̉̍a̸̧̧̜̻̘̤̫̱̲͎̞̻͆̋ļ̸̛̖̜̳͚̖͔̟̈́͂̉̀͑̑͑̎ǵ̸̫̳̽̐̃̑̚̕o̶͇̫͔̮̼̭͕̹̘̬͋̀͆̂̇̋͊̒̽' + '' + '', ); Serializer.Fields.LabelSerializable.ControlChars = new SerializerTestCase( 'ControlChars', '' + '' + '&#a1;' + '' + '', ); Serializer.Fields.LabelSerializable.testCases = [ Serializer.Fields.LabelSerializable.Simple, Serializer.Fields.LabelSerializable.Symbols, Serializer.Fields.LabelSerializable.EscapedSymbols, Serializer.Fields.LabelSerializable.SingleQuotes, Serializer.Fields.LabelSerializable.DoubleQuotes, Serializer.Fields.LabelSerializable.Numbers, Serializer.Fields.LabelSerializable.Emoji, Serializer.Fields.LabelSerializable.Russian, Serializer.Fields.LabelSerializable.Japanese, Serializer.Fields.LabelSerializable.Zalgo, // TODO: Uncoment once #4945 is merged. // Serializer.Fields.LabelSerializable.ControlChars, ]; Serializer.Fields.Number = new SerializerTestSuite('Number'); Serializer.Fields.Number.Simple = new SerializerTestCase( 'Simple', '' + '' + '123' + '' + '', ); Serializer.Fields.Number.Negative = new SerializerTestCase( 'Negative', '' + '' + '-123' + '' + '', ); Serializer.Fields.Number.PosInfinity = new SerializerTestCase( 'PosInfinity', '' + '' + 'Infinity' + '' + '', ); Serializer.Fields.Number.NegInfinity = new SerializerTestCase( 'NegInfinity', '' + '' + '-Infinity' + '' + '', ); Serializer.Fields.Number.Decimals = new SerializerTestCase( 'Decimals', '' + '' + '1.5' + '' + '', ); Serializer.Fields.Number.Smallest = new SerializerTestCase( 'Smallest', '' + '' + '5e-324' + '' + '', ); Serializer.Fields.Number.Largest = new SerializerTestCase( 'Largest', '' + '' + '1.7976931348623157e+308' + '' + '', ); Serializer.Fields.Number.MaxPrecisionSmall = new SerializerTestCase( 'MaxPrecisionSmall', '' + '' + '1.000000000000001' + '' + '', ); Serializer.Fields.Number.MaxPrecisionLarge = new SerializerTestCase( 'MaxPrecisionLarge', '' + '' + '1000000000000001' + '' + '', ); Serializer.Fields.Number.testCases = [ Serializer.Fields.Number.Simple, Serializer.Fields.Number.Negative, Serializer.Fields.Number.PosInfinity, Serializer.Fields.Number.NegInfinity, Serializer.Fields.Number.Decimals, Serializer.Fields.Number.Smallest, Serializer.Fields.Number.Largest, Serializer.Fields.Number.MaxPrecisionSmall, Serializer.Fields.Number.MaxPrecisionLarge, ]; Serializer.Fields.TextInput = new SerializerTestSuite('TextInput'); Serializer.Fields.TextInput.Simple = new SerializerTestCase( 'Simple', '' + '' + 'test' + '' + '', ); Serializer.Fields.TextInput.Tabs = new SerializerTestCase( 'Tabs', '' + '' + 'line1&#x9line2&#x9line3' + '' + '', ); Serializer.Fields.TextInput.Symbols = new SerializerTestCase( 'Symbols', '' + '' + '~`!@#$%^*()_+-={[}]|\\:;,.?/' + '' + '', ); Serializer.Fields.TextInput.EscapedSymbols = new SerializerTestCase( 'EscapedSymbols', '' + '' + '&<>' + '' + '', ); Serializer.Fields.TextInput.SingleQuotes = new SerializerTestCase( 'SingleQuotes', '' + '' + '\'test\'' + '' + '', ); Serializer.Fields.TextInput.DoubleQuotes = new SerializerTestCase( 'DoubleQuotes', '' + '' + '"test"' + '' + '', ); Serializer.Fields.TextInput.Numbers = new SerializerTestCase( 'Numbers', '' + '' + '1234567890a123a123a' + '' + '', ); Serializer.Fields.TextInput.Emoji = new SerializerTestCase( 'Emoji', '' + '' + '😀👋🏿👋🏾👋🏽👋🏼👋🏻😀❤❤❤' + '' + '', ); Serializer.Fields.TextInput.Russian = new SerializerTestCase( 'Russian', '' + '' + 'ты любопытный кот' + '' + '', ); Serializer.Fields.TextInput.Japanese = new SerializerTestCase( 'Japanese', '' + '' + 'あなたは好奇心旺盛な猫です' + '' + '', ); Serializer.Fields.TextInput.Zalgo = new SerializerTestCase( 'Zalgo', '' + '' + 'z̴̪͈̲̜͕̽̈̀͒͂̓̋̉̍a̸̧̧̜̻̘̤̫̱̲͎̞̻͆̋ļ̸̛̖̜̳͚̖͔̟̈́͂̉̀͑̑͑̎ǵ̸̫̳̽̐̃̑̚̕o̶͇̫͔̮̼̭͕̹̘̬͋̀͆̂̇̋͊̒̽' + '' + '', ); Serializer.Fields.TextInput.ControlChars = new SerializerTestCase( 'ControlChars', '' + '' + '&#a1;' + '' + '', ); Serializer.Fields.TextInput.testCases = [ Serializer.Fields.TextInput.Simple, Serializer.Fields.TextInput.Tabs, Serializer.Fields.TextInput.Symbols, Serializer.Fields.TextInput.EscapedSymbols, Serializer.Fields.TextInput.SingleQuotes, Serializer.Fields.TextInput.DoubleQuotes, Serializer.Fields.TextInput.Numbers, Serializer.Fields.TextInput.Emoji, Serializer.Fields.TextInput.Russian, Serializer.Fields.TextInput.Japanese, Serializer.Fields.TextInput.Zalgo, // TODO: Uncoment once #4945 is merged. // Serializer.Fields.TextInput.ControlChars, ]; Serializer.Fields.Variable = new SerializerTestSuite('Variable'); Serializer.Fields.Variable.Simple = new SerializerTestCase( 'Simple', '' + '' + 'test' + '' + '' + 'test' + '' + '', ); Serializer.Fields.Variable.Types = new SerializerTestCase( 'Types', '' + '' + 'test' + 'test2' + 'test3' + '' + '' + 'test' + '' + '' + 'test2' + '' + '' + 'test3' + '' + '', ); Serializer.Fields.Variable.Tabs = new SerializerTestCase( 'Tabs', '' + '' + 'line1&#x9line2&#x9line3' + '' + '' + 'line1&#x9line2&#x9line3' + '' + '', ); Serializer.Fields.Variable.Symbols = new SerializerTestCase( 'Symbols', '' + '' + '~`!@#$%^*()_+-={[}]|\\:;,.?/' + '' + '' + '~`!@#$%^*()_+-={[}]|\\:;,.?/' + '' + '', ); Serializer.Fields.Variable.EscapedSymbols = new SerializerTestCase( 'EscapedSymbols', '' + '' + '&<>' + '' + '' + '&<>' + '' + '', ); Serializer.Fields.Variable.SingleQuotes = new SerializerTestCase( 'SingleQuotes', '' + '' + '\'test\'' + '' + '' + '\'test\'' + '' + '', ); Serializer.Fields.Variable.DoubleQuotes = new SerializerTestCase( 'DoubleQuotes', '' + '' + '"test"' + '' + '' + '"test"' + '' + '', ); Serializer.Fields.Variable.Numbers = new SerializerTestCase( 'Numbers', '' + '' + '1234567890a123a123a' + '' + '' + '1234567890a123a123a' + '' + '', ); Serializer.Fields.Variable.Emoji = new SerializerTestCase( 'Emoji', '' + '' + '😀👋🏿👋🏾👋🏽👋🏼👋🏻😀❤❤❤' + '' + '' + '😀👋🏿👋🏾👋🏽👋🏼👋🏻😀❤❤❤' + '' + '', ); Serializer.Fields.Variable.Russian = new SerializerTestCase( 'Russian', '' + '' + 'ты любопытный кот' + '' + '' + 'ты любопытный кот' + '' + '', ); Serializer.Fields.Variable.Japanese = new SerializerTestCase( 'Japanese', '' + '' + 'あなたは好奇心旺盛な猫です' + '' + '' + 'あなたは好奇心旺盛な猫です' + '' + '', ); Serializer.Fields.Variable.Zalgo = new SerializerTestCase( 'Zalgo', '' + '' + 'z̴̪͈̲̜͕̽̈̀͒͂̓̋̉̍a̸̧̧̜̻̘̤̫̱̲͎̞̻͆̋ļ̸̛̖̜̳͚̖͔̟̈́͂̉̀͑̑͑̎ǵ̸̫̳̽̐̃̑̚̕o̶͇̫͔̮̼̭͕̹̘̬͋̀͆̂̇̋͊̒̽' + '' + '' + 'z̴̪͈̲̜͕̽̈̀͒͂̓̋̉̍a̸̧̧̜̻̘̤̫̱̲͎̞̻͆̋ļ̸̛̖̜̳͚̖͔̟̈́͂̉̀͑̑͑̎ǵ̸̫̳̽̐̃̑̚̕o̶͇̫͔̮̼̭͕̹̘̬͋̀͆̂̇̋͊̒̽' + '' + '', ); Serializer.Fields.Variable.ControlChars = new SerializerTestCase( 'ControlChars', '' + '' + '&#a1;' + '' + '' + '&#a1;' + '' + '', ); Serializer.Fields.Variable.testCases = [ Serializer.Fields.Variable.Simple, Serializer.Fields.Variable.Types, Serializer.Fields.Variable.Tabs, Serializer.Fields.Variable.Symbols, Serializer.Fields.Variable.EscapedSymbols, Serializer.Fields.Variable.SingleQuotes, Serializer.Fields.Variable.DoubleQuotes, Serializer.Fields.Variable.Numbers, Serializer.Fields.Variable.Emoji, Serializer.Fields.Variable.Russian, Serializer.Fields.Variable.Japanese, Serializer.Fields.Variable.Zalgo, // TODO: Uncoment once #4945 is merged. // Serializer.Fields.Variable.ControlChars, ]; Serializer.Fields.Variable.Id = new SerializerTestSuite('Id'); Serializer.Fields.Variable.Id.Length = new SerializerTestSuite('Length'); Serializer.Fields.Variable.Id.Length.Short = new SerializerTestCase( 'Short', '' + '' + 'test' + '' + '' + 'test' + '' + '', ); Serializer.Fields.Variable.Id.Length.Long = new SerializerTestCase( 'Long', '' + '' + 'test' + '' + '' + 'test' + '' + '', ); Serializer.Fields.Variable.Id.Length.testCases = [ Serializer.Fields.Variable.Id.Length.Short, Serializer.Fields.Variable.Id.Length.Long, ]; Serializer.Fields.Variable.Id.Chars = new SerializerTestSuite('Chars'); Serializer.Fields.Variable.Id.Chars.Symbols = new SerializerTestCase( 'Symbols', '' + '' + 'test' + 'test2' + '' + '' + 'test' + '' + '' + 'test2' + '' + '', ); Serializer.Fields.Variable.Id.Chars.Uppercase = new SerializerTestCase( 'Uppercase', '' + '' + 'test' + 'test2' + '' + '' + 'test' + '' + '' + 'test2' + '' + '', ); Serializer.Fields.Variable.Id.Chars.Lowercase = new SerializerTestCase( 'Lowercase', '' + '' + 'test' + 'test2' + '' + '' + 'test' + '' + '' + 'test2' + '' + '', ); Serializer.Fields.Variable.Id.Chars.Numbers = new SerializerTestCase( 'Numbers', '' + '' + 'test' + '' + '' + 'test' + '' + '', ); Serializer.Fields.Variable.Id.Chars.testCases = [ Serializer.Fields.Variable.Id.Chars.Symbols, Serializer.Fields.Variable.Id.Chars.Uppercase, Serializer.Fields.Variable.Id.Chars.Lowercase, Serializer.Fields.Variable.Id.Chars.Numbers, ]; Serializer.Fields.Variable.Id.testSuites = [ Serializer.Fields.Variable.Id.Length, Serializer.Fields.Variable.Id.Chars, ]; Serializer.Fields.Variable.testSuites = [Serializer.Fields.Variable.Id]; Serializer.Fields.testSuites = [ Serializer.Fields.Checkbox, Serializer.Fields.Dropdown, Serializer.Fields.LabelSerializable, Serializer.Fields.Number, Serializer.Fields.TextInput, Serializer.Fields.Variable, ]; Serializer.Icons = new SerializerTestSuite('Icons'); Serializer.Icons.Comment = new SerializerTestSuite('Comment'); Serializer.Icons.Comment.Basic = new SerializerTestCase( 'Basic', '' + '' + 'test' + '' + '', ); Serializer.Icons.Comment.Size = new SerializerTestSuite('Size'); Serializer.Icons.Comment.Size.Different = new SerializerTestCase( 'Different', '' + '' + 'test' + '' + '', ); Serializer.Icons.Comment.Size.Large = new SerializerTestCase( 'Large', '' + '' + 'test' + '' + '', ); Serializer.Icons.Comment.Size.testCases = [ Serializer.Icons.Comment.Size.Different, Serializer.Icons.Comment.Size.Large, ]; Serializer.Icons.Comment.Pinned = new SerializerTestSuite('Pinned'); Serializer.Icons.Comment.Pinned.True = new SerializerTestCase( 'True', '' + '' + 'test' + '' + '', ); Serializer.Icons.Comment.Pinned.False = new SerializerTestCase( 'False', '' + '' + 'test' + '' + '', ); Serializer.Icons.Comment.Pinned.testCases = [ Serializer.Icons.Comment.Pinned.True, Serializer.Icons.Comment.Pinned.False, ]; Serializer.Icons.Comment.Text = new SerializerTestSuite('Text'); Serializer.Icons.Comment.Text.Symbols = new SerializerTestCase( 'Symbols', '' + '' + '~`!@#$%^*()_+-={[}]|\\:;,.?/' + '' + '', ); Serializer.Icons.Comment.Text.EscapedSymbols = new SerializerTestCase( 'EscapedSymbols', '' + '' + '&<>' + '' + '', ); Serializer.Icons.Comment.Text.SingleQuotes = new SerializerTestCase( 'SingleQuotes', '' + '' + '\'test\'' + '' + '', ); Serializer.Icons.Comment.Text.DoubleQuotes = new SerializerTestCase( 'DoubleQuotes', '' + '' + '"test"' + '' + '', ); Serializer.Icons.Comment.Text.Numbers = new SerializerTestCase( 'Numbers', '' + '' + '1234567890a123a123a' + '' + '', ); Serializer.Icons.Comment.Text.Emoji = new SerializerTestCase( 'Emoji', '' + '' + '😀👋🏿👋🏾👋🏽👋🏼👋🏻😀❤❤❤' + '' + '', ); Serializer.Icons.Comment.Text.Russian = new SerializerTestCase( 'Russian', '' + '' + 'ты любопытный кот' + '' + '', ); Serializer.Icons.Comment.Text.Japanese = new SerializerTestCase( 'Japanese', '' + '' + 'あなたは好奇心旺盛な猫です' + '' + '', ); Serializer.Icons.Comment.Text.Zalgo = new SerializerTestCase( 'Zalgo', '' + '' + 'z̴̪͈̲̜͕̽̈̀͒͂̓̋̉̍a̸̧̧̜̻̘̤̫̱̲͎̞̻͆̋ļ̸̛̖̜̳͚̖͔̟̈́͂̉̀͑̑͑̎ǵ̸̫̳̽̐̃̑̚̕o̶͇̫͔̮̼̭͕̹̘̬͋̀͆̂̇̋͊̒̽' + '' + '', ); Serializer.Icons.Comment.Text.ControlChars = new SerializerTestCase( 'ControlChars', '' + '' + '&#a1;' + '' + '', ); Serializer.Icons.Comment.Text.testCases = [ Serializer.Icons.Comment.Text.Symbols, Serializer.Icons.Comment.Text.EscapedSymbols, Serializer.Icons.Comment.Text.SingleQuotes, Serializer.Icons.Comment.Text.DoubleQuotes, Serializer.Icons.Comment.Text.Numbers, Serializer.Icons.Comment.Text.Emoji, Serializer.Icons.Comment.Text.Russian, Serializer.Icons.Comment.Text.Japanese, Serializer.Icons.Comment.Text.Zalgo, // TODO: Uncoment once #4945 is merged. // Serializer.Icons.Comment.Text.ControlChars, ]; Serializer.Icons.Comment.testSuites = [ Serializer.Icons.Comment.Size, Serializer.Icons.Comment.Pinned, Serializer.Icons.Comment.Text, ]; Serializer.Icons.Comment.testCases = [Serializer.Icons.Comment.Basic]; Serializer.Icons.testSuites = [Serializer.Icons.Comment]; Serializer.Connections = new SerializerTestSuite('Connections'); Serializer.Connections.Child = new SerializerTestSuite('Child'); Serializer.Connections.Child.Value = new SerializerTestCase( 'Value', '' + '' + '' + '' + 'TRUE' + '' + '' + '' + '', ); Serializer.Connections.Child.Statement = new SerializerTestCase( 'Statement', '' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.Child.Next = new SerializerTestCase( 'Next', '' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.Child.Row = new SerializerTestCase( 'Row', '' + '' + '' + '' + '' + '' + 'TRUE' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.Child.Nested = new SerializerTestCase( 'Nested', '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.Child.Stack = new SerializerTestCase( 'Stack', '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.Child.testCases = [ Serializer.Connections.Child.Value, Serializer.Connections.Child.Statement, Serializer.Connections.Child.Next, Serializer.Connections.Child.Row, Serializer.Connections.Child.Nested, Serializer.Connections.Child.Stack, ]; Serializer.Connections.Shadow = new SerializerTestSuite('Shadow'); Serializer.Connections.Shadow.Value = new SerializerTestCase( 'Value', '' + '' + '' + '' + 'TRUE' + '' + '' + '' + '', ); Serializer.Connections.Shadow.Statement = new SerializerTestCase( 'Statement', '' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.Shadow.Next = new SerializerTestCase( 'Next', '' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.Shadow.Row = new SerializerTestCase( 'Row', '' + '' + '' + '' + '' + '' + 'TRUE' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.Shadow.Nested = new SerializerTestCase( 'Nested', '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.Shadow.Stack = new SerializerTestCase( 'Stack', '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.Shadow.testCases = [ Serializer.Connections.Shadow.Value, Serializer.Connections.Shadow.Statement, Serializer.Connections.Shadow.Next, Serializer.Connections.Shadow.Row, Serializer.Connections.Shadow.Nested, Serializer.Connections.Shadow.Stack, ]; Serializer.Connections.OverwrittenShadow = new SerializerTestSuite( 'OverwrittenShadow', ); Serializer.Connections.OverwrittenShadow.Value = new SerializerTestCase( 'Value', '' + '' + '' + '' + 'TRUE' + '' + '' + 'TRUE' + '' + '' + '' + '', ); Serializer.Connections.OverwrittenShadow.Statement = new SerializerTestCase( 'Statement', '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.OverwrittenShadow.Next = new SerializerTestCase( 'Next', '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.OverwrittenShadow.Row = new SerializerTestCase( 'Row', '' + '' + '' + '' + '' + '' + 'TRUE' + '' + '' + '' + '' + 'TRUE' + '' + '' + '' + '', ); Serializer.Connections.OverwrittenShadow.Nested = new SerializerTestCase( 'Nested', '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.OverwrittenShadow.Stack = new SerializerTestCase( 'Stack', '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Connections.OverwrittenShadow.testCases = [ Serializer.Connections.OverwrittenShadow.Value, Serializer.Connections.OverwrittenShadow.Statement, Serializer.Connections.OverwrittenShadow.Next, Serializer.Connections.OverwrittenShadow.Row, Serializer.Connections.OverwrittenShadow.Nested, Serializer.Connections.OverwrittenShadow.Stack, ]; Serializer.Connections.testSuites = [ Serializer.Connections.Child, Serializer.Connections.Shadow, Serializer.Connections.OverwrittenShadow, ]; Serializer.Mutations = new SerializerTestSuite('Mutations'); Serializer.Mutations.ListGetIndex = new SerializerTestCase( 'ListGetIndex', '' + '' + '' + 'REMOVE' + 'LAST' + '' + '', ); Serializer.Mutations.ListSetIndex = new SerializerTestCase( 'ListSetIndex', '' + '' + '' + 'SET' + 'LAST' + '' + '', ); Serializer.Mutations.ListGetSublist = new SerializerTestCase( 'ListGetSublist', '' + '' + '' + 'FIRST' + 'LAST' + '' + '', ); Serializer.Mutations.MathNumberProperty = new SerializerTestCase( 'MathNumberProperty', '' + '' + '' + 'DIVISIBLE_BY' + '' + '', ); Serializer.Mutations.MathOnList = new SerializerTestCase( 'MathOnList', '' + '' + '' + 'MODE' + '' + '', ); Serializer.Mutations.TextJoin = new SerializerTestCase( 'TextJoin', '' + '' + '' + '' + '', ); Serializer.Mutations.TextCharAt = new SerializerTestCase( 'TextCharAt', '' + '' + '' + 'FIRST' + '' + '', ); Serializer.Mutations.TextGetSubstring = new SerializerTestCase( 'TextGetSubstring', '' + '' + '' + 'FROM_START' + 'LAST' + '' + '', ); Serializer.Mutations.TextPromptExt = new SerializerTestCase( 'TextPromptExt', '' + '' + '' + 'NUMBER' + '' + '', ); Serializer.Mutations.TextPrompt = new SerializerTestCase( 'TextPrompt', '' + '' + '' + 'NUMBER' + '' + '' + '', ); Serializer.Mutations.testCases = [ Serializer.Mutations.ListGetIndex, Serializer.Mutations.ListSetIndex, Serializer.Mutations.ListGetSublist, Serializer.Mutations.MathNumberProperty, Serializer.Mutations.MathOnList, Serializer.Mutations.TextJoin, Serializer.Mutations.TextCharAt, Serializer.Mutations.TextGetSubstring, Serializer.Mutations.TextPromptExt, Serializer.Mutations.TextPrompt, ]; Serializer.Mutations.ControlsIf = new SerializerTestSuite('ControlsIf'); Serializer.Mutations.ControlsIf.NoMutation = new SerializerTestCase( 'NoMutation', '' + '' + '', ); Serializer.Mutations.ControlsIf.ElseIfAndElse = new SerializerTestCase( 'ElseIfAndElse', '' + '' + '' + '' + '', ); Serializer.Mutations.ControlsIf.MultipleElseIfs = new SerializerTestCase( 'MultipleElseIfs', '' + '' + '' + '' + '', ); Serializer.Mutations.ControlsIf.MutlipleElseIfsAndElse = new SerializerTestCase( 'MutlipleElseIfsAndElse', '' + '' + '' + '' + '', ); Serializer.Mutations.ControlsIf.testCases = [ Serializer.Mutations.ControlsIf.NoMutation, Serializer.Mutations.ControlsIf.ElseIfAndElse, Serializer.Mutations.ControlsIf.MultipleElseIfs, Serializer.Mutations.ControlsIf.MutlipleElseIfsAndElse, ]; Serializer.Mutations.ControlsIf.ElseIf = new SerializerTestSuite('ElseIf'); Serializer.Mutations.ControlsIf.ElseIf.NoChild = new SerializerTestCase( 'NoChild', '' + '' + '' + '' + '', ); Serializer.Mutations.ControlsIf.ElseIf.Child = new SerializerTestCase( 'Child', '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.ControlsIf.ElseIf.Shadow = new SerializerTestCase( 'Shadow', '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.ControlsIf.ElseIf.OverwrittenShadow = new SerializerTestCase( 'OverwrittenShadow', '' + '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.ControlsIf.ElseIf.testCases = [ Serializer.Mutations.ControlsIf.ElseIf.NoChild, Serializer.Mutations.ControlsIf.ElseIf.Child, Serializer.Mutations.ControlsIf.ElseIf.Shadow, Serializer.Mutations.ControlsIf.ElseIf.OverwrittenShadow, ]; Serializer.Mutations.ControlsIf.Else = new SerializerTestSuite('Else'); Serializer.Mutations.ControlsIf.Else.NoChild = new SerializerTestCase( 'NoChild', '' + '' + '' + '' + '', ); Serializer.Mutations.ControlsIf.Else.Child = new SerializerTestCase( 'Child', '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.ControlsIf.Else.Shadow = new SerializerTestCase( 'Shadow', '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.ControlsIf.Else.OverwrittenShadow = new SerializerTestCase( 'OverwrittenShadow', '' + '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.ControlsIf.Else.testCases = [ Serializer.Mutations.ControlsIf.Else.NoChild, Serializer.Mutations.ControlsIf.Else.Child, Serializer.Mutations.ControlsIf.Else.Shadow, Serializer.Mutations.ControlsIf.Else.OverwrittenShadow, ]; Serializer.Mutations.ControlsIf.testSuites = [ Serializer.Mutations.ControlsIf.ElseIf, Serializer.Mutations.ControlsIf.Else, ]; Serializer.Mutations.ListCreate = new SerializerTestSuite('ListCreate'); Serializer.Mutations.ListCreate.Default = new SerializerTestCase( 'Default', '' + '' + '' + '' + '', ); Serializer.Mutations.ListCreate.ZeroInputs = new SerializerTestCase( 'ZeroInputs', '' + '' + '' + '' + '', ); Serializer.Mutations.ListCreate.MultipleInputs = new SerializerTestCase( 'MultipleInputs', '' + '' + '' + '' + '', ); Serializer.Mutations.ListCreate.testCases = [ Serializer.Mutations.ListCreate.Default, Serializer.Mutations.ListCreate.ZeroInputs, Serializer.Mutations.ListCreate.MultipleInputs, ]; Serializer.Mutations.ListCreate.OneInput = new SerializerTestSuite('OneIput'); Serializer.Mutations.ListCreate.OneInput.NoChild = new SerializerTestCase( 'NoChild', '' + '' + '' + '' + '', ); Serializer.Mutations.ListCreate.OneInput.Child = new SerializerTestCase( 'Child', '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.ListCreate.OneInput.Shadow = new SerializerTestCase( 'Shadow', '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.ListCreate.OneInput.OverwrittenShadow = new SerializerTestCase( 'OverwrittenShadow', '' + '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.ListCreate.OneInput.testCases = [ Serializer.Mutations.ListCreate.OneInput.NoChild, Serializer.Mutations.ListCreate.OneInput.Child, Serializer.Mutations.ListCreate.OneInput.Shadow, Serializer.Mutations.ListCreate.OneInput.OverwrittenShadow, ]; Serializer.Mutations.ListCreate.testSuites = [ Serializer.Mutations.ListCreate.OneInput, ]; Serializer.Mutations.Procedure = new SerializerTestSuite('Procedure'); Serializer.Mutations.Procedure.NoMutation = new SerializerTestCase( 'NoMutation', '' + '' + 'do something' + '' + '', ); Serializer.Mutations.Procedure.Variables = new SerializerTestCase( 'Variables', '' + '' + 'x' + 'y' + 'z' + '' + '' + '' + '' + '' + '' + '' + 'do something' + '' + '', ); Serializer.Mutations.Procedure.NoStatements = new SerializerTestCase( 'NoStatements', '' + '' + '' + 'do something' + '' + '', ); Serializer.Mutations.Procedure.IfReturn = new SerializerTestCase( 'IfReturn', '' + '' + 'do something' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.Procedure.Caller = new SerializerTestCase( 'Caller', '' + '' + 'x' + 'y' + '' + '' + '' + '' + '' + '' + 'do something' + '' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.Procedure.CollapsedProceduresCallreturn = new SerializerTestCase( 'CollapsedProceduresCallreturn', '' + '' + 'x' + '' + '' + '' + '' + '' + 'do something' + 'Describe this function...' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.Procedure.CollapsedProceduresCallnoreturn = new SerializerTestCase( 'CollapsedProceduresCallnoreturn', '' + '' + 'x' + '' + '' + '' + '' + '' + 'do something' + 'Describe this function...' + '' + '' + '' + '' + '' + '' + '', ); Serializer.Mutations.Procedure.testCases = [ Serializer.Mutations.Procedure.NoMutation, Serializer.Mutations.Procedure.Variables, Serializer.Mutations.Procedure.NoStatements, Serializer.Mutations.Procedure.IfReturn, Serializer.Mutations.Procedure.Caller, Serializer.Mutations.Procedure.CollapsedProceduresCallreturn, Serializer.Mutations.Procedure.CollapsedProceduresCallnoreturn, ]; Serializer.Mutations.Procedure.Names = new SerializerTestSuite('Names'); Serializer.Mutations.Procedure.Names.Symbols = new SerializerTestCase( 'Symbols', '' + '' + '~`!@#$%^*()_+-={[}]|\\:;,.?/' + '' + '', ); Serializer.Mutations.Procedure.Names.EscapedSymbols = new SerializerTestCase( 'EscapedSymbols', '' + '' + '&<>' + '' + '', ); Serializer.Mutations.Procedure.Names.SingleQuotes = new SerializerTestCase( 'SingleQuotes', '' + '' + '\'test\'' + '' + '', ); Serializer.Mutations.Procedure.Names.DoubleQuotes = new SerializerTestCase( 'DoubleQuotes', '' + '' + '"test"' + '' + '', ); Serializer.Mutations.Procedure.Names.Numbers = new SerializerTestCase( 'Numbers', '' + '' + '1234567890a123a123a' + '' + '', ); Serializer.Mutations.Procedure.Names.Emoji = new SerializerTestCase( 'Emoji', '' + '' + '😀👋🏿👋🏾👋🏽👋🏼👋🏻😀❤❤❤' + '' + '', ); Serializer.Mutations.Procedure.Names.Russian = new SerializerTestCase( 'Russian', '' + '' + 'ты любопытный кот' + '' + '', ); Serializer.Mutations.Procedure.Names.Japanese = new SerializerTestCase( 'Japanese', '' + '' + 'あなたは好奇心旺盛な猫です' + '' + '', ); Serializer.Mutations.Procedure.Names.Zalgo = new SerializerTestCase( 'Zalgo', '' + '' + 'z̴̪͈̲̜͕̽̈̀͒͂̓̋̉̍a̸̧̧̜̻̘̤̫̱̲͎̞̻͆̋ļ̸̛̖̜̳͚̖͔̟̈́͂̉̀͑̑͑̎ǵ̸̫̳̽̐̃̑̚̕o̶͇̫͔̮̼̭͕̹̘̬͋̀͆̂̇̋͊̒̽' + '' + '', ); Serializer.Mutations.Procedure.Names.ControlChars = new SerializerTestCase( 'ControlChars', '' + '' + '&#a1;' + '' + '', ); Serializer.Mutations.Procedure.Names.testCases = [ Serializer.Mutations.Procedure.Names.Symbols, Serializer.Mutations.Procedure.Names.EscapedSymbols, Serializer.Mutations.Procedure.Names.SingleQuotes, Serializer.Mutations.Procedure.Names.DoubleQuotes, Serializer.Mutations.Procedure.Names.Numbers, Serializer.Mutations.Procedure.Names.Emoji, Serializer.Mutations.Procedure.Names.Russian, Serializer.Mutations.Procedure.Names.Japanese, Serializer.Mutations.Procedure.Names.Zalgo, // TODO: Uncoment once #4945 is merged. // Serializer.Mutations.Procedure.Names.ControlChars, ]; Serializer.Mutations.Procedure.testSuites = [ Serializer.Mutations.Procedure.Names, ]; Serializer.Mutations.testSuites = [ Serializer.Mutations.ControlsIf, Serializer.Mutations.ListCreate, Serializer.Mutations.Procedure, ]; Serializer.Comments = new SerializerTestSuite('Comments'); Serializer.Comments.Coordinates = new SerializerTestSuite('Coordinates'); Serializer.Comments.Coordinates.Basic = new SerializerTestCase( 'Basic', '' + '' + '' + '', ); Serializer.Comments.Coordinates.Negative = new SerializerTestCase( 'Negative', '' + '' + '' + '', ); Serializer.Comments.Coordinates.Zero = new SerializerTestCase( 'Zero', '' + '' + '' + '', ); Serializer.Comments.Coordinates.testCases = [ Serializer.Comments.Coordinates.Basic, Serializer.Comments.Coordinates.Negative, Serializer.Comments.Coordinates.Zero, ]; Serializer.Comments.Size = new SerializerTestSuite('Size'); Serializer.Comments.Size.Basic = new SerializerTestCase( 'Basic', '' + '' + '' + '', ); Serializer.Comments.Size.testCases = [Serializer.Comments.Size.Basic]; Serializer.Comments.Text = new SerializerTestSuite('Text'); Serializer.Comments.Text.Symbols = new SerializerTestCase( 'Symbols', '' + '' + '~`!@#$%^*()_+-={[}]|\\:;,.?/' + '' + '', ); Serializer.Comments.Text.EscapedSymbols = new SerializerTestCase( 'EscapedSymbols', '' + '' + '&<>' + '' + '', ); Serializer.Comments.Text.SingleQuotes = new SerializerTestCase( 'SingleQuotes', '' + '' + "'test'" + '' + '', ); Serializer.Comments.Text.DoubleQuotes = new SerializerTestCase( 'DoubleQuotes', '' + '' + '"test"' + '' + '', ); Serializer.Comments.Text.Numbers = new SerializerTestCase( 'Numbers', '' + '' + '1234567890a123a123a' + '' + '', ); Serializer.Comments.Text.Emoji = new SerializerTestCase( 'Emoji', '' + '' + '😀👋🏿👋🏾👋🏽👋🏼👋🏻😀❤❤❤' + '' + '', ); Serializer.Comments.Text.Russian = new SerializerTestCase( 'Russian', '' + '' + 'ты любопытный кот' + '' + '', ); Serializer.Comments.Text.Japanese = new SerializerTestCase( 'Japanese', '' + '' + 'あなたは好奇心旺盛な猫です' + '' + '', ); Serializer.Comments.Text.Zalgo = new SerializerTestCase( 'Zalgo', '' + '' + 'z̴̪͈̲̜͕̽̈̀͒͂̓̋̉̍a̸̧̧̜̻̘̤̫̱̲͎̞̻͆̋ļ̸̛̖̜̳͚̖͔̟̈́͂̉̀͑̑͑̎ǵ̸̫̳̽̐̃̑̚̕o̶͇̫͔̮̼̭͕̹̘̬͋̀͆̂̇̋͊̒̽' + '' + '', ); Serializer.Comments.Text.testCases = [ Serializer.Comments.Text.Symbols, Serializer.Comments.Text.EscapedSymbols, Serializer.Comments.Text.SingleQuotes, Serializer.Comments.Text.DoubleQuotes, Serializer.Comments.Text.Numbers, Serializer.Comments.Text.Emoji, Serializer.Comments.Text.Russian, Serializer.Comments.Text.Japanese, Serializer.Comments.Text.Zalgo, ]; Serializer.Comments.Attributes = new SerializerTestSuite('Attributes'); Serializer.Comments.Attributes.Collapsed = new SerializerTestCase( 'Collapsed', '' + '' + '' + '', ); Serializer.Comments.Attributes.NotEditable = new SerializerTestCase( 'NotEditable', '' + '' + '' + '', ); Serializer.Comments.Attributes.NotMovable = new SerializerTestCase( 'NotMovable', '' + '' + '' + '', ); Serializer.Comments.Attributes.NotDeletable = new SerializerTestCase( 'NotDeletable', '' + '' + '' + '', ); Serializer.Comments.Attributes.testCases = [ Serializer.Comments.Attributes.Collapsed, Serializer.Comments.Attributes.NotEditable, Serializer.Comments.Attributes.NotMovable, Serializer.Comments.Attributes.NotDeletable, ]; Serializer.Comments.testSuites = [ Serializer.Comments.Coordinates, Serializer.Comments.Size, Serializer.Comments.Text, Serializer.Comments.Attributes, ]; Serializer.testSuites = [ Serializer.Attributes, Serializer.Fields, Serializer.Icons, Serializer.Connections, Serializer.Mutations, Serializer.Comments, ]; const runSerializerTestSuite = (serializer, deserializer, testSuite) => { const workspaces = Blockly.serialization.workspaces; const createTestFunction = function (test) { return function () { Blockly.Xml.domToWorkspace( Blockly.utils.xml.textToDom(test.xml), this.workspace, ); if (serializer && deserializer) { const save = serializer(workspaces.save(this.workspace)); this.workspace.clear(); workspaces.load(deserializer(save), this.workspace); } const newXml = Blockly.Xml.workspaceToDom(this.workspace); assert.equal(Blockly.Xml.domToText(newXml), test.xml); }; }; // This takes in a suite, but we don't care. const createTestCaseFunction = function (_) { return createTestFunction; }; let suiteCall = testSuite.skip ? suite.skip : suite; suiteCall = testSuite.only ? suite.only : suiteCall; suiteCall(testSuite.title, function () { setup(function () { sharedTestSetup.call(this, {fireEventsNow: false}); this.workspace = new Blockly.Workspace(); }); teardown(function () { workspaceTeardown.call(this, this.workspace); sharedTestTeardown.call(this); }); runTestSuites(testSuite.testSuites, createTestCaseFunction); runTestCases(testSuite.testCases, createTestFunction); }); }; runSerializerTestSuite(null, null, Serializer); runSerializerTestSuite( (state) => state, (state) => state, Serializer, );