diff --git a/tests/test_syntax.py b/tests/test_syntax.py index 8dc7c8f..5accd3e 100644 --- a/tests/test_syntax.py +++ b/tests/test_syntax.py @@ -42,21 +42,32 @@ return SyntaxLocation(line, column, filename) +# Test location getters +@given(integers(), integers(), text()) +def test_syntax_location_getters(line, column, filename): + test = SyntaxLocation(line, column, filename) + assert test.line == line + assert test.column == column + assert test.file == filename + + +# Test location equals +@given(draw_syntax_location(), draw_syntax_location()) +def test_syntax_location_equality(location1, location2): + equals = ( + location1.line == location2.line + and location1.column == location2.column + and location1.file == location2.file + ) + assert (location1 == location2) == equals + + # Draws a random syntax type @composite def draw_syntax_type(draw): return draw(sampled_from(list(SyntaxType))) -# Draws a token syntax value -@composite -def draw_syntax_token(draw): - value = draw(draw_token_classified()) - location = draw(draw_syntax_location()) - type = SyntaxType.TOKEN - return Syntax(value.value, location, type) - - # Draws a text syntax value @composite def draw_syntax_text(draw): @@ -66,37 +77,6 @@ return Syntax(value, location, type) -# Draws a random syntax -@composite -def draw_syntax_random(draw): - strategies = [ - draw_syntax_token(), - draw_syntax_text(), - ] - return draw(one_of(strategies)) - - -# Test syntax getters -@given(text(), draw_syntax_location(), draw_syntax_type()) -def test_syntax_syntax_getters(value, location, type): - # Use text as a somewhat random value - test = Syntax(value, location, type) - assert test.value == value - assert test.location == location - assert test.type == type - - -# Test syntax equals -@given(draw_syntax_random(), draw_syntax_random()) -def test_syntax_syntax_equality(syntax1, syntax2): - equals = ( - syntax1.type == syntax2.type - and syntax1.value == syntax2.value - and syntax1.location == syntax2.location - ) - assert (syntax1 == syntax2) == equals - - # Draws a random token @composite def draw_token_random(draw): @@ -177,39 +157,44 @@ return token -# Test location getters -@given(integers(), integers(), text()) -def test_syntax_location_getters(line, column, filename): - test = SyntaxLocation(line, column, filename) - assert test.line == line - assert test.column == column - assert test.file == filename +# Draws a token syntax value +@composite +def draw_syntax_token(draw): + value = draw(draw_token_classified()) + location = draw(draw_syntax_location()) + type = SyntaxType.TOKEN + return Syntax(value.value, location, type) -# Test location equals -@given(draw_syntax_location(), draw_syntax_location()) -def test_syntax_location_equality(location1, location2): - equals = ( - location1.line == location2.line - and location1.column == location2.column - and location1.file == location2.file - ) - assert (location1 == location2) == equals +# Draws a random syntax +@composite +def draw_syntax_random(draw): + strategies = [ + draw_syntax_token(), + draw_syntax_text(), + ] + return draw(one_of(strategies)) -# Test token getters -@given(text(), draw_syntax_location()) -def test_syntax_token_getters(value, location): - test = Syntax(value, location, SyntaxType.TOKEN) +# Test syntax getters +@given(text(), draw_syntax_location(), draw_syntax_type()) +def test_syntax_syntax_getters(value, location, type): + # Use text as a somewhat random value + test = Syntax(value, location, type) assert test.value == value assert test.location == location + assert test.type == type -# Test token equals -@given(draw_token_random(), draw_token_random()) -def test_syntax_token_equality(token1, token2): - equals = token1.value == token2.value and token1.location == token2.location - assert (token1 == token2) == equals +# Test syntax equals +@given(draw_syntax_random(), draw_syntax_random()) +def test_syntax_syntax_equality(syntax1, syntax2): + equals = ( + syntax1.type == syntax2.type + and syntax1.value == syntax2.value + and syntax1.location == syntax2.location + ) + assert (syntax1 == syntax2) == equals # Tests that a syntax stream reads items correctly