#!/bin/sh
# Load the installed module and run a few queries, so the test fails
# whenever the package does not actually work.
set -e

node -e '
var JSPath = require("jspath");

var cases = [
  [".a", {a: 42}, [42]],
  [".a{. > 1}", {a: 2}, [2]],
  [".a{. === null}", {a: null}, [null]],
  [".a.b", {a: {b: "x"}}, ["x"]]
];

cases.forEach(function (c) {
  var got = JSPath(c[0], c[1]);
  if (JSON.stringify(got) !== JSON.stringify(c[2])) {
    console.error("FAIL " + c[0] + ": expected " + JSON.stringify(c[2]) +
                  ", got " + JSON.stringify(got));
    process.exit(1);
  }
  console.log("ok " + c[0] + " -> " + JSON.stringify(got));
});
'
