Spaces:
Sleeping
Sleeping
File size: 1,832 Bytes
4cadbaf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
<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>
|