diff --git a/tests/unit/reader/files/invalid8.manifest b/tests/unit/reader/files/invalid8.manifest new file mode 100644 index 0000000..630ef4f --- /dev/null +++ b/tests/unit/reader/files/invalid8.manifest @@ -0,0 +1,3 @@ +# bare identifier fails + +directory diff --git a/tests/unit/reader/files/valid4.manifest b/tests/unit/reader/files/valid4.manifest new file mode 100644 index 0000000..24eb83f --- /dev/null +++ b/tests/unit/reader/files/valid4.manifest @@ -0,0 +1,5 @@ +# a single file block with a primary attr + +file "/d/e/f/g" { + source /a/b/c +} diff --git a/tests/unit/reader/files/valid5.manifest b/tests/unit/reader/files/valid5.manifest new file mode 100644 index 0000000..50795de --- /dev/null +++ b/tests/unit/reader/files/valid5.manifest @@ -0,0 +1,8 @@ +# primary_attr block, followed by non-primary_attr block + +manifest "man man" + +file { + source "potato" + target "mango" +} diff --git a/tests/unit/reader/files/valid6.manifest b/tests/unit/reader/files/valid6.manifest new file mode 100644 index 0000000..61e4571 --- /dev/null +++ b/tests/unit/reader/files/valid6.manifest @@ -0,0 +1,9 @@ +# multiple Primary Attribute style blocks + +manifest "man man" + +file "bat man" + +directory "super man" + +manifest "wo man" diff --git a/tests/unit/reader/files/valid7.manifest b/tests/unit/reader/files/valid7.manifest new file mode 100644 index 0000000..f1fd5fc --- /dev/null +++ b/tests/unit/reader/files/valid7.manifest @@ -0,0 +1,3 @@ +# primary attr block with empty body + +manifest "man man" {} diff --git a/tests/unit/reader/files/valid8.manifest b/tests/unit/reader/files/valid8.manifest new file mode 100644 index 0000000..509d3f8 --- /dev/null +++ b/tests/unit/reader/files/valid8.manifest @@ -0,0 +1,5 @@ +# primary_attr block with other attrs + +file "lobster" { + source "salad" +} diff --git a/tests/unit/reader/parse_test.py b/tests/unit/reader/parse_test.py index 1cba82a..32cc28d 100644 --- a/tests/unit/reader/parse_test.py +++ b/tests/unit/reader/parse_test.py @@ -3,7 +3,6 @@ from nose.tools import istest from os.path import dirname, join as pjoin -import salve.block.file_block from salve.reader import parse from salve.reader.tokenize import Token from salve.util.context import FileContext @@ -11,6 +10,9 @@ from tests.utils.exceptions import ensure_except +import salve.block.file_block +import salve.block.manifest_block + _testfile_dir = pjoin(dirname(__file__), 'files') dummy_context = FileContext('no such file') @@ -217,11 +219,44 @@ def attribute_with_spaces(): def file_primary_attr_assigned(): """ Unit: Parser File Block Primary Attr - Checks that parsing an attribute that contains spaces in quotes - does not raise an error and correctly assigns to the attribute. + Checks that parsing a Primary Attribute style file block does not raise any + errors. """ blocks = parse_filename(get_full_path('valid4.manifest')) assert len(blocks) == 1 assert isinstance(blocks[0], salve.block.file_block.FileBlock) assert len(blocks[0].attrs) == 2 assert blocks[0].get(blocks[0].primary_attr) == "/d/e/f/g" + + +@istest +def primary_attr_followed_by_block(): + """ + Unit: Parser Primary Attribute Block Followed By Normal Block + Checks that there are no errors parsing a Primary Attribute style block + followed by an ordinary block. + """ + blocks = parse_filename(get_full_path('valid5.manifest')) + assert len(blocks) == 2 + assert isinstance(blocks[0], salve.block.manifest_block.ManifestBlock) + assert len(blocks[0].attrs) == 1 + assert blocks[0].get(blocks[0].primary_attr) == "man man" + assert isinstance(blocks[1], salve.block.file_block.FileBlock) + assert len(blocks[1].attrs) == 2 + assert blocks[1].get('source') == "potato" + assert blocks[1].get('target') == "mango" + + +@istest +def file_primary_attr_with_body(): + """ + Unit: Parser File Block Primary Attr And Block Body + Checks that parsing is successful on a primary attr block with a nonempty + body. + """ + blocks = parse_filename(get_full_path('valid8.manifest')) + assert len(blocks) == 1 + assert isinstance(blocks[0], salve.block.file_block.FileBlock) + assert len(blocks[0].attrs) == 2 + assert blocks[0].get(blocks[0].primary_attr) == "lobster" + assert blocks[0].get('source') == "salad" diff --git a/tests/unit/reader/tokenize_test.py b/tests/unit/reader/tokenize_test.py index fb3ad29..73b7674 100644 --- a/tests/unit/reader/tokenize_test.py +++ b/tests/unit/reader/tokenize_test.py @@ -50,10 +50,11 @@ def missing_open(): @istest -def double_identifier(): +def missing_open_primary_attr(): """ - Unit: Tokenizer Double Identifier Fails - Ensures that two successive block ids raise a TokenizationException. + Unit: Tokenizer Missing Block Open (Primary Attribute Block) Fails + Ensures that a missing { raises a TokenizationException even on block's + with a Primary Attribute setting. """ ensure_TokenizationException('invalid3.manifest') @@ -77,6 +78,16 @@ def missing_attribute_value(): ensure_TokenizationException('invalid5.manifest') +@istest +def bare_identifier(): + """ + Unit: Tokenizer Bare Identifier Fails + Ensures that a block without body or primary attr value raises a + TokenizationException. + """ + ensure_TokenizationException('invalid8.manifest') + + @istest def double_open(): """ @@ -188,6 +199,21 @@ def primary_attr_block_series(): assert tokens[7].ty == tokenize.Token.types.TEMPLATE +@istest +def primary_attr_block_empty_body(): + """ + Unit: Tokenizer Primary Attribute Block Empty Body + Verifies that tokenization proceeds correctly when a "Primary Attribute" + style block is given a "{}" body + """ + tokens = tokenize_filename(get_full_path('valid7.manifest')) + assert len(tokens) == 4 + assert tokens[0].ty == tokenize.Token.types.IDENTIFIER + assert tokens[1].ty == tokenize.Token.types.TEMPLATE + assert tokens[2].ty == tokenize.Token.types.BLOCK_START + assert tokens[3].ty == tokenize.Token.types.BLOCK_END + + @istest def token_to_string(): """