Codebase list node-d3-shape / bc2ef0ac-85f6-49b4-8af2-c74450b0e640/main test / pathEqual.js
bc2ef0ac-85f6-49b4-8af2-c74450b0e640/main

Tree @bc2ef0ac-85f6-49b4-8af2-c74450b0e640/main (Download .tar.gz)

pathEqual.js @bc2ef0ac-85f6-49b4-8af2-c74450b0e640/mainraw · history · blame

var tape = require("tape");

var reNumber = /[-+]?(?:\d+\.\d+|\d+\.|\.\d+|\d+)(?:[eE][-]?\d+)?/g;

tape.Test.prototype.pathEqual = function(actual, expected) {
  actual = normalizePath(actual + "");
  // expected = normalizePath(expected + "");
  this._assert(actual === expected, {
    message: "should be equal",
    operator: "pathEqual",
    actual: actual,
    expected: expected
  });
};

function normalizePath(path) {
  return path.replace(reNumber, formatNumber);
}

function formatNumber(s) {
  return Math.abs((s = +s) - Math.round(s)) < 1e-6 ? Math.round(s) : s.toFixed(6);
}