Exemple #1
0
 def can_check_equality():
     loc1 = Location(1, 2, token1, token2, source)
     loc2 = Location(1, 2, token1, token2, source)
     assert loc2 == loc1
     loc3 = Location(3, 2, token1, token2, source)
     assert loc3 != loc1
     loc4 = Location(1, 4, token1, token2, source)
     assert loc4 != loc1
Exemple #2
0
 def can_hash():
     loc1 = Location(1, 2, token1, token2, source)
     loc2 = Location(1, 2, token1, token2, source)
     assert loc2 == loc1
     assert hash(loc2) == hash(loc1)
     loc3 = Location(1, 3, token1, token2, source)
     assert loc3 != loc1
     assert hash(loc3) != hash(loc1)
Exemple #3
0
 def initializes():
     loc = Location(token1, token2, source)
     assert loc.start == token1.start
     assert loc.end == token2.end
     assert loc.start_token is token1
     assert loc.end_token is token2
     assert loc.source is source
Exemple #4
0
 def initializes():
     loc = Location(1, 2, token1, token2, source)
     assert loc.start == 1
     assert loc.end == 2
     assert loc.start_token is token1
     assert loc.end_token is token2
     assert loc.source is source
Exemple #5
0
 def can_check_equality_with_tuple_or_list():
     loc = Location(token1, token2, source)
     assert loc == (1, 3)
     assert loc == [1, 3]
     assert not loc != (1, 3)
     assert not loc != [1, 3]
     assert loc != (1, 2)
     assert loc != [2, 3]
Exemple #6
0
 def can_can_convert_to_dict_with_locations():
     token = Token(
         kind=TokenKind.NAME,
         start=1,
         end=3,
         line=1,
         column=1,
         value="foo",
     )
     loc = Location(token, token, Source("foo"))
     node = SampleTestNode(alpha=1, beta=2, loc=loc)
     res = node.to_dict(locations=True)
     assert res == {
         "kind": "sample_test",
         "alpha": 1,
         "beta": 2,
         "loc": {
             "start": 1,
             "end": 3
         },
     }
     assert list(res) == ["kind", "alpha", "beta", "loc"]
     assert list(res["loc"]) == ["start", "end"]
Exemple #7
0
 def can_stringify_with_start_and_end():
     loc = Location(token1, token2, source)
     assert str(loc) == "1:3"
Exemple #8
0
 def does_not_equal_incompatible_object():
     loc = Location(token1, token2, source)
     assert not loc == (1, 2, 3)
     assert loc != (1, 2, 3)
     assert not loc == {1: 2}
     assert loc != {1: 2}
Exemple #9
0
 def has_representation_with_start_and_end():
     loc = Location(token1, token2, source)
     assert repr(loc) == "<Location 1:3>"
     assert inspect(loc) == repr(loc)