From 1de9198f0c69152fe6f474185ac351e9500a4ce8 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 24 Nov 2016 21:38:10 +0000 Subject: Implement document matcher parser --- .../styles/parser/document_matcher_parser_tests.py | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 tests/styles/parser/document_matcher_parser_tests.py (limited to 'tests/styles/parser/document_matcher_parser_tests.py') diff --git a/tests/styles/parser/document_matcher_parser_tests.py b/tests/styles/parser/document_matcher_parser_tests.py new file mode 100644 index 0000000..18109ca --- /dev/null +++ b/tests/styles/parser/document_matcher_parser_tests.py @@ -0,0 +1,109 @@ +from nose.tools import istest, assert_equal + +from mammoth import documents, document_matchers +from mammoth.styles.parser.document_matcher_parser import parse_document_matcher +from mammoth.styles.parser.tokeniser import tokenise +from mammoth.styles.parser.token_iterator import TokenIterator + + +@istest +def reads_plain_paragraph(): + assert_equal( + document_matchers.paragraph(), + read_document_matcher("p") + ) + + +@istest +def reads_paragraph_with_style_id(): + assert_equal( + document_matchers.paragraph(style_id="Heading1"), + read_document_matcher("p.Heading1") + ) + + +@istest +def reads_paragraph_with_exact_style_name(): + assert_equal( + document_matchers.paragraph(style_name="Heading 1"), + read_document_matcher("p[style-name='Heading 1']") + ) + + +@istest +def reads_paragraph_ordered_list(): + assert_equal( + document_matchers.paragraph(numbering=documents.numbering_level(1, is_ordered=True)), + read_document_matcher("p:ordered-list(2)") + ) + + +@istest +def reads_paragraph_unordered_list(): + assert_equal( + document_matchers.paragraph(numbering=documents.numbering_level(1, is_ordered=False)), + read_document_matcher("p:unordered-list(2)") + ) + + +@istest +def reads_plain_run(): + assert_equal( + document_matchers.run(), + read_document_matcher("r") + ) + + +@istest +def reads_run_with_style_id(): + assert_equal( + document_matchers.run(style_id="Emphasis"), + read_document_matcher("r.Emphasis") + ) + + +@istest +def reads_run_with_style_name(): + assert_equal( + document_matchers.run(style_name="Emphasis"), + read_document_matcher("r[style-name='Emphasis']") + ) + +@istest +def reads_bold(): + assert_equal( + document_matchers.bold, + read_document_matcher("b") + ) + +@istest +def reads_italic(): + assert_equal( + document_matchers.italic, + read_document_matcher("i") + ) + +@istest +def reads_underline(): + assert_equal( + document_matchers.underline, + read_document_matcher("u") + ) + +@istest +def reads_strikethrough(): + assert_equal( + document_matchers.strikethrough, + read_document_matcher("strike") + ) + +@istest +def reads_comment_reference(): + assert_equal( + document_matchers.comment_reference, + read_document_matcher("comment-reference") + ) + + +def read_document_matcher(string): + return parse_document_matcher(TokenIterator(tokenise(string))) -- cgit v1.2.3