Skip to content

Commit 2104335

Browse files
committed
test: add tests for Index.__hash__ with single and multiple indices
1 parent 3559782 commit 2104335

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

tests/test_jsonpath.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
from typing import Callable
55
from jsonpath_ng.ext.parser import parse as ext_parse
6-
from jsonpath_ng.jsonpath import DatumInContext, Fields, Root, This
6+
from jsonpath_ng.jsonpath import DatumInContext, Fields, Index, Root, This
77
from jsonpath_ng.lexer import JsonPathLexerError
88
from jsonpath_ng.parser import parse as base_parse
99
from jsonpath_ng import JSONPath
@@ -435,3 +435,15 @@ def test_nested_index_auto_id(auto_id_field, parse, string, target):
435435
def test_invalid_hyphenation_in_key():
436436
with pytest.raises(JsonPathLexerError):
437437
base_parse("foo.-baz")
438+
439+
440+
def test_index_hashable():
441+
idx = Index(0)
442+
assert hash(idx) == hash((0,))
443+
assert {idx: "value"}[idx] == "value"
444+
445+
446+
def test_index_multi_indices_hashable():
447+
idx = Index(0, 1, 2)
448+
assert hash(idx) == hash((0, 1, 2))
449+
assert {idx: "value"}[idx] == "value"

0 commit comments

Comments
 (0)