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.

26 lines
1012 B

  1. export function assert(testName: string, expected: string, actual: string, message?: undefined) {
  2. var result = CompareString(actual, expected);
  3. if (result != true) {
  4. console.log('"' + testName + "\" failed: \n" + result);
  5. }
  6. else {
  7. //console.log(testName + " pass");
  8. }
  9. }
  10. export function CompareString(actual: string, expected: string) {
  11. var l = Math.min(actual.length, expected.length);
  12. for (var i = 0; i < l; i++) {
  13. if (actual[i] != expected[i]) {
  14. var toEnd = Math.min(i + 50, l);
  15. return '\ndifferent at ' + i.toString() +
  16. '\nactual: "\n' + actual.substring(i, toEnd) +
  17. '\nexpected: "\n' + expected.substring(i, toEnd) + '"\n---' +
  18. "\nactual (full): \n" + actual + "\n---" +
  19. "\nexpected (full): \n" + expected + "\n====\n";
  20. }
  21. }
  22. if (actual != expected) {
  23. return 'actual: \n"' + actual + '"\nexpected: \n"' + expected + '"';
  24. }
  25. return true;
  26. }