summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/IndexedDB/idbkeyrange-includes.htm
blob: 6a05627463e086cc65c3b724546f3aef32ae31f6 (plain)
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
<!doctype html>
<meta charset=utf-8>
<title></title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>

  test(function() {
    var closedRange = IDBKeyRange.bound(5, 20);
    assert_true(!!closedRange.includes, "IDBKeyRange has a .includes");
    assert_true(closedRange.includes(7), "in range");
    assert_false(closedRange.includes(1), "below range");
    assert_false(closedRange.includes(42), "above range");
    assert_true(closedRange.includes(5) && closedRange.includes(20),
                 "boundary points");
    assert_throws("DataError", function() { closedRange.includes({}) },
                  "invalid key");
  }, "IDBKeyRange.includes() with a closed range");

  test(function() {
    var openRange = IDBKeyRange.bound(5, 20, true, true);
    assert_false(openRange.includes(5) || openRange.includes(20),
                 "boundary points");
  }, "IDBKeyRange.includes() with an open range");

  test(function() {
    var range = IDBKeyRange.only(42);
    assert_true(range.includes(42), "in range");
    assert_false(range.includes(1), "below range");
    assert_false(range.includes(9000), "above range");
  }, "IDBKeyRange.includes() with an only range");

  test(function() {
    var range = IDBKeyRange.lowerBound(5);
    assert_false(range.includes(4), 'value before closed lower bound');
    assert_true(range.includes(5), 'value at closed lower bound');
    assert_true(range.includes(6), 'value after closed lower bound');
  }, "IDBKeyRange.includes() with an closed lower-bounded range");

  test(function() {
    var range = IDBKeyRange.lowerBound(5, true);
    assert_false(range.includes(4), 'value before open lower bound');
    assert_false(range.includes(5), 'value at open lower bound');
    assert_true(range.includes(6), 'value after open lower bound');
  }, "IDBKeyRange.includes() with an open lower-bounded range");

  test(function() {
    var range = IDBKeyRange.upperBound(5);
    assert_true(range.includes(4), 'value before closed upper bound');
    assert_true(range.includes(5), 'value at closed upper bound');
    assert_false(range.includes(6), 'value after closed upper bound');
  }, "IDBKeyRange.includes() with an closed upper-bounded range");

  test(function() {
    var range = IDBKeyRange.upperBound(5, true);
    assert_true(range.includes(4), 'value before open upper bound');
    assert_false(range.includes(5), 'value at open upper bound');
    assert_false(range.includes(6), 'value after open upper bound');
  }, "IDBKeyRange.includes() with an open upper-bounded range");

</script>