errors.test.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. var errors = require("../lib/errors");
  2. var StringSource = require("../lib/StringSource");
  3. exports.errorDescriptionIncludesLocationAndActualValueAndExpectedValue = function(test) {
  4. var error = errors.error({
  5. expected: "Nothing",
  6. actual: "Something",
  7. location: {
  8. describe: function() {
  9. return "Here"
  10. }
  11. }
  12. });
  13. test.equal("Here:\nExpected Nothing\nbut got Something", error.describe());
  14. test.done();
  15. };
  16. exports.canDescribeErrorWithoutLocation = function(test) {
  17. var error = errors.error({
  18. expected: "Nothing",
  19. actual: "Something"
  20. });
  21. test.equal("Expected Nothing\nbut got Something", error.describe());
  22. test.done();
  23. };
  24. exports.canGetPositionFromError = function(test) {
  25. var error = errors.error({
  26. expected: "Nothing",
  27. actual: "Something",
  28. location: new StringSource("abc\ndef\nghi\n", "").range(6, 8)
  29. });
  30. test.equal(2, error.lineNumber());
  31. test.equal(3, error.characterNumber());
  32. test.done();
  33. };