Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

print.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.printReceivedConstructorNameNot =
  6. exports.printReceivedConstructorName =
  7. exports.printExpectedConstructorNameNot =
  8. exports.printExpectedConstructorName =
  9. exports.printCloseTo =
  10. exports.printReceivedArrayContainExpectedItem =
  11. exports.printReceivedStringContainExpectedResult =
  12. exports.printReceivedStringContainExpectedSubstring =
  13. void 0;
  14. var _jestMatcherUtils = require('jest-matcher-utils');
  15. /**
  16. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  17. *
  18. * This source code is licensed under the MIT license found in the
  19. * LICENSE file in the root directory of this source tree.
  20. *
  21. */
  22. /* eslint-disable local/ban-types-eventually */
  23. // Format substring but do not enclose in double quote marks.
  24. // The replacement is compatible with pretty-format package.
  25. const printSubstring = val => val.replace(/"|\\/g, '\\$&');
  26. const printReceivedStringContainExpectedSubstring = (
  27. received,
  28. start,
  29. length // not end
  30. ) =>
  31. (0, _jestMatcherUtils.RECEIVED_COLOR)(
  32. '"' +
  33. printSubstring(received.slice(0, start)) +
  34. (0, _jestMatcherUtils.INVERTED_COLOR)(
  35. printSubstring(received.slice(start, start + length))
  36. ) +
  37. printSubstring(received.slice(start + length)) +
  38. '"'
  39. );
  40. exports.printReceivedStringContainExpectedSubstring =
  41. printReceivedStringContainExpectedSubstring;
  42. const printReceivedStringContainExpectedResult = (received, result) =>
  43. result === null
  44. ? (0, _jestMatcherUtils.printReceived)(received)
  45. : printReceivedStringContainExpectedSubstring(
  46. received,
  47. result.index,
  48. result[0].length
  49. ); // The serialized array is compatible with pretty-format package min option.
  50. // However, items have default stringify depth (instead of depth - 1)
  51. // so expected item looks consistent by itself and enclosed in the array.
  52. exports.printReceivedStringContainExpectedResult =
  53. printReceivedStringContainExpectedResult;
  54. const printReceivedArrayContainExpectedItem = (received, index) =>
  55. (0, _jestMatcherUtils.RECEIVED_COLOR)(
  56. '[' +
  57. received
  58. .map((item, i) => {
  59. const stringified = (0, _jestMatcherUtils.stringify)(item);
  60. return i === index
  61. ? (0, _jestMatcherUtils.INVERTED_COLOR)(stringified)
  62. : stringified;
  63. })
  64. .join(', ') +
  65. ']'
  66. );
  67. exports.printReceivedArrayContainExpectedItem =
  68. printReceivedArrayContainExpectedItem;
  69. const printCloseTo = (receivedDiff, expectedDiff, precision, isNot) => {
  70. const receivedDiffString = (0, _jestMatcherUtils.stringify)(receivedDiff);
  71. const expectedDiffString = receivedDiffString.includes('e') // toExponential arg is number of digits after the decimal point.
  72. ? expectedDiff.toExponential(0)
  73. : 0 <= precision && precision < 20 // toFixed arg is number of digits after the decimal point.
  74. ? // It may be a value between 0 and 20 inclusive.
  75. // Implementations may optionally support a larger range of values.
  76. expectedDiff.toFixed(precision + 1)
  77. : (0, _jestMatcherUtils.stringify)(expectedDiff);
  78. return (
  79. `Expected precision: ${isNot ? ' ' : ''} ${(0,
  80. _jestMatcherUtils.stringify)(precision)}\n` +
  81. `Expected difference: ${isNot ? 'not ' : ''}< ${(0,
  82. _jestMatcherUtils.EXPECTED_COLOR)(expectedDiffString)}\n` +
  83. `Received difference: ${isNot ? ' ' : ''} ${(0,
  84. _jestMatcherUtils.RECEIVED_COLOR)(receivedDiffString)}`
  85. );
  86. };
  87. exports.printCloseTo = printCloseTo;
  88. const printExpectedConstructorName = (label, expected) =>
  89. printConstructorName(label, expected, false, true) + '\n';
  90. exports.printExpectedConstructorName = printExpectedConstructorName;
  91. const printExpectedConstructorNameNot = (label, expected) =>
  92. printConstructorName(label, expected, true, true) + '\n';
  93. exports.printExpectedConstructorNameNot = printExpectedConstructorNameNot;
  94. const printReceivedConstructorName = (label, received) =>
  95. printConstructorName(label, received, false, false) + '\n'; // Do not call function if received is equal to expected.
  96. exports.printReceivedConstructorName = printReceivedConstructorName;
  97. const printReceivedConstructorNameNot = (label, received, expected) =>
  98. typeof expected.name === 'string' &&
  99. expected.name.length !== 0 &&
  100. typeof received.name === 'string' &&
  101. received.name.length !== 0
  102. ? printConstructorName(label, received, true, false) +
  103. ` ${
  104. Object.getPrototypeOf(received) === expected
  105. ? 'extends'
  106. : 'extends … extends'
  107. } ${(0, _jestMatcherUtils.EXPECTED_COLOR)(expected.name)}` +
  108. '\n'
  109. : printConstructorName(label, received, false, false) + '\n';
  110. exports.printReceivedConstructorNameNot = printReceivedConstructorNameNot;
  111. const printConstructorName = (label, constructor, isNot, isExpected) =>
  112. typeof constructor.name !== 'string'
  113. ? `${label} name is not a string`
  114. : constructor.name.length === 0
  115. ? `${label} name is an empty string`
  116. : `${label}: ${!isNot ? '' : isExpected ? 'not ' : ' '}${
  117. isExpected
  118. ? (0, _jestMatcherUtils.EXPECTED_COLOR)(constructor.name)
  119. : (0, _jestMatcherUtils.RECEIVED_COLOR)(constructor.name)
  120. }`;