blob: 0fc784f1b9ddb8e8ab40ff33cb5c694daef5322e [file] [log] [blame]
<html>
<head>
<title>JSONSelect JS matching tests</title>
<link rel="stylesheet" type="text/css" href="js/doctest.css" />
<script src="js/doctest.js"></script>
<script src="../jsonselect.js"></script>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
</head>
<body>
<div>
<button onclick="doctest()" type="button">run tests</button>
<pre id="doctestOutput"></pre>
</div>
<h2> Tests of the JSONSelect matcher </h2>
<div class="test">
Types
<pre class="doctest">
$ JSONSelect.match("null", null);
[null]
$ JSONSelect.match("array", { 1: [], 2: [] });
[[], []]
$ JSONSelect.match("object", [ {}, {} ]);
[{}, {}]
$ JSONSelect.match("string", [ "a", 1, true, null, false, "b", 3.1415, "c" ] );
["a", "b", "c"]
$ JSONSelect.match("boolean", [ "a", 1, true, null, false, "b", 3.1415, "c" ] );
[true, false]
$ JSONSelect.match("number", [ "a", 1, true, null, false, "b", 3.1415, "c" ] );
[1, 3.1415]
</pre>
</div>
<div class="test">
IDs
<pre class="doctest">
$ JSONSelect.match(".foo", {foo: "aMatch", bar: [ { foo: "anotherMatch" } ] });
["aMatch", "anotherMatch"]
</pre>
</div>
<div class="test">
Descendants
<pre class="doctest">
$ JSONSelect.match(".foo .bar", {foo: { baz: 1, bar: 2 }, bar: 3});
[2]
$ JSONSelect.match(".foo > .bar", {foo: { baz: 1, bar: 2 }, bar: 3});
[2]
$ JSONSelect.match(".foo > .bar", {foo: { baz: { bar: 4 }, bar: 2 }, bar: 3});
[2]
$ JSONSelect.match(".foo .bar", {foo: { baz: { bar: 4 }, bar: 2 }, bar: 3});
[4, 2]
</pre>
</div>
<div class="test">
Grouping
<pre class="doctest">
$ JSONSelect.match("number,boolean", [ "a", 1, true, null, false, "b", 3.1415, "c" ] );
[1, true, false, 3.1415]
$ JSONSelect.match("number,boolean,null", [ "a", 1, true, null, false, "b", 3.1415, "c" ] );
[1, true, null, false, 3.1415]
</pre>
</div>
</body>
</html>