Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

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

3# 

4# This file is part of the tsfpga project. 

5# https://tsfpga.com 

6# https://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9import unittest 

10 

11from tsfpga.registers.html_translator import HtmlTranslator 

12 

13 

14class TestTranslator(unittest.TestCase): 

15 def setUp(self): 

16 self.html_translator = HtmlTranslator() 

17 

18 def test_markdown_parser_can_handle_annotating_sentences(self): 

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

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

21 assert expected in self.html_translator.translate(text) 

22 

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

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

25 assert expected in self.html_translator.translate(text) 

26 

27 def test_markdown_parser_can_handle_escaped_asterisks(self): 

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

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

30 assert expected in self.html_translator.translate(text) 

31 

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

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

34 assert expected in self.html_translator.translate(text) 

35 

36 expected = ( 

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

38 ) 

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

40 assert expected in self.html_translator.translate(text) 

41 

42 expected = ( 

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

44 ) 

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

46 assert expected in self.html_translator.translate(text) 

47 

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

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

50 assert expected in self.html_translator.translate(text) 

51 

52 def test_line_breaks(self): 

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

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

55 assert expected in self.html_translator.translate(text) 

56 

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

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

59 assert expected in self.html_translator.translate(text) 

60 

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

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

63 assert expected in self.html_translator.translate(text) 

64 

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

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

67 assert expected in self.html_translator.translate(text) 

68 

69 def test_literal_underscore_can_be_used(self): 

70 # We do not translate underscores, unlike some markdown 

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

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

73 assert expected in self.html_translator.translate(text) 

74 

75 def test_angle_brackets_should_be_translated_to_html(self): 

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

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

78 assert expected in self.html_translator.translate(text)