Coverage for hdl_registers/generator/html/test/test_html_translator.py: 100%

49 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-19 20:51 +0000

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the hdl-registers project, an HDL register generator fast enough to run 

5# in real time. 

6# https://hdl-registers.com 

7# https://github.com/hdl-registers/hdl-registers 

8# -------------------------------------------------------------------------------------------------- 

9 

10# Third party libraries 

11import pytest 

12 

13# First party libraries 

14from hdl_registers.generator.html.html_translator import HtmlTranslator 

15 

16 

17@pytest.fixture 

18def html_translator(): 

19 return HtmlTranslator() 

20 

21 

22# False positive for pytest fixtures 

23# pylint: disable=redefined-outer-name 

24 

25 

26def test_markdown_parser_can_handle_annotating_sentences(html_translator): 

27 expected = "This sentence <strong>should have a large portion</strong> in bold face" 

28 text = r"This sentence **should have a large portion** in bold face" 

29 assert expected in html_translator.translate(text) 

30 

31 expected = "This sentence <em>should have a large portion</em> in italics" 

32 text = "This sentence *should have a large portion* in italics" 

33 assert expected in html_translator.translate(text) 

34 

35 

36def test_markdown_parser_can_handle_escaped_asterisks(html_translator): 

37 expected = "Part of this sentence **should be surrounded** by double asterisks" 

38 text = r"Part of this sentence \*\*should be surrounded\*\* by double asterisks" 

39 assert expected in html_translator.translate(text) 

40 

41 expected = "Part of this sentence *should be surrounded* by asterisks" 

42 text = r"Part of this sentence \*should be surrounded\* by asterisks" 

43 assert expected in html_translator.translate(text) 

44 

45 expected = "Part of this sentence <em>*should be in italics and surrounded*</em> by asterisks" 

46 text = r"Part of this sentence *\*should be in italics and surrounded\** by asterisks" 

47 assert expected in html_translator.translate(text) 

48 

49 expected = "Part of this sentence *<em>should be in italics and surrounded</em>* by asterisks" 

50 text = r"Part of this sentence \**should be in italics and surrounded*\* by asterisks" 

51 assert expected in html_translator.translate(text) 

52 

53 expected = "Part of this sentence should have an <em>*</em> in italics" 

54 text = r"Part of this sentence should have an *\** in italics" 

55 assert expected in html_translator.translate(text) 

56 

57 

58def test_line_breaks(html_translator): 

59 expected = "Two empty lines<br />\n<br />\nbetween paragraphs." 

60 text = "Two empty lines\n\nbetween paragraphs." 

61 assert expected in html_translator.translate(text) 

62 

63 expected = "Three empty lines<br />\n<br />\nbetween paragraphs." 

64 text = "Three empty lines\n\n\nbetween paragraphs." 

65 assert expected in html_translator.translate(text) 

66 

67 expected = r"Escaped \n\n\n should not result in paragraph break." 

68 text = r"Escaped \n\n\n should not result in paragraph break." 

69 assert expected in html_translator.translate(text) 

70 

71 expected = "One empty line means same paragraph." 

72 text = "One empty line\nmeans same paragraph." 

73 assert expected in html_translator.translate(text) 

74 

75 

76def test_literal_underscore_can_be_used(html_translator): 

77 # We do not translate underscores, unlike some markdown 

78 expected = "This sentence <strong>contains_underscores</strong> in some_places" 

79 text = r"This sentence **contains_underscores** in some_places" 

80 assert expected in html_translator.translate(text) 

81 

82 

83def test_angle_brackets_should_be_translated_to_html(html_translator): 

84 expected = "This string &lt;&lt; contains &gt; brackets &gt;&lt;" 

85 text = "This string << contains > brackets ><" 

86 assert expected in html_translator.translate(text)