unittest.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * @license
  3. * Visual Blocks Language
  4. *
  5. * Copyright 2012 Google Inc.
  6. * https://developers.google.com/blockly/
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. /**
  21. * @fileoverview Unit test blocks for Blockly.
  22. * @author fraser@google.com (Neil Fraser)
  23. */
  24. 'use strict';
  25. Blockly.Blocks['unittest_main'] = {
  26. // Container for unit tests.
  27. init: function() {
  28. this.setColour(65);
  29. this.appendDummyInput()
  30. .appendField('run tests');
  31. this.appendStatementInput('DO');
  32. this.setTooltip('Executes the enclosed unit tests,\n' +
  33. 'then prints a summary.');
  34. },
  35. getVars: function() {
  36. return ['unittestResults'];
  37. }
  38. };
  39. Blockly.Blocks['unittest_assertequals'] = {
  40. // Asserts that a value equals another value.
  41. init: function() {
  42. this.setColour(65);
  43. this.setPreviousStatement(true);
  44. this.setNextStatement(true);
  45. this.appendValueInput('MESSAGE')
  46. .appendField('name')
  47. .setCheck('String');
  48. this.appendValueInput('ACTUAL')
  49. .appendField('actual');
  50. this.appendValueInput('EXPECTED')
  51. .appendField('expected');
  52. this.setTooltip('Tests that "actual == expected".');
  53. },
  54. getVars: function() {
  55. return ['unittestResults'];
  56. }
  57. };
  58. Blockly.Blocks['unittest_assertvalue'] = {
  59. // Asserts that a value is true, false, or null.
  60. init: function() {
  61. this.setColour(65);
  62. this.setPreviousStatement(true);
  63. this.setNextStatement(true);
  64. this.appendValueInput('MESSAGE', 'test name')
  65. .appendField('name')
  66. .setCheck('String');
  67. this.appendValueInput('ACTUAL')
  68. .appendField('assert')
  69. .appendField(new Blockly.FieldDropdown(
  70. [['true', 'TRUE'], ['false', 'FALSE'], ['null', 'NULL']]), 'EXPECTED');
  71. this.setTooltip('Tests that the value is true, false, or null.');
  72. },
  73. getVars: function() {
  74. return ['unittestResults'];
  75. }
  76. };
  77. Blockly.Blocks['unittest_fail'] = {
  78. // Always assert an error.
  79. init: function() {
  80. this.setColour(65);
  81. this.setPreviousStatement(true);
  82. this.setNextStatement(true);
  83. this.appendDummyInput()
  84. .appendField(new Blockly.FieldTextInput('test name'), 'MESSAGE')
  85. .appendField('fail');
  86. this.setTooltip('Records an error.');
  87. },
  88. getVars: function() {
  89. return ['unittestResults'];
  90. }
  91. };
  92. Blockly.Blocks['unittest_adjustindex'] = {
  93. // Adjusts the indexing based on current setting.
  94. init: function() {
  95. this.jsonInit({
  96. "message0": "adjusted %1",
  97. "args0": [
  98. {
  99. "type": "input_value",
  100. "name": "INDEX",
  101. "check": "Number"
  102. }
  103. ],
  104. "inputsInline": true,
  105. "output": "Number",
  106. "colour": 65,
  107. "tooltip": "Adjusts the value based on whether generated code is using " +
  108. "zero or one based indexing."
  109. });
  110. }
  111. };