summaryrefslogtreecommitdiff
path: root/src/tools/docwriter/tests/test_tomarkdown.py
blob: b19074fee69521f656d3f37c98552c0e0352d96d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
#  test_tomarkdown.py
#
#    Tests for markdown formatter (tomarkdown.py).
#
#  Copyright 2018 by
#  Nikhil Ramakrishnan.
#
#  This file is part of the FreeType project, and may only be used,
#  modified, and distributed under the terms of the FreeType project
#  license, LICENSE.TXT.  By continuing to use, modify, or distribute
#  this file you indicate that you have read the license and
#  understand and accept it fully.

"""Unit tests for `tomarkdown`.

This module contains tests for functions in `tomarkdown.py`.
"""

import content
import sources
import tomarkdown
import utils

# Create test objects
# create context and processor
source_processor  = sources.SourceProcessor()
content_processor = content.ContentProcessor()
# Names
project_title  = 'Test Docs'
project_prefix = 'test'
# retrieve the list of files to process
file_list = utils.make_file_list( ['./tests/assets/*.c'] )
for filename in file_list:
    source_processor.parse_file( filename )
    content_processor.parse_sources( source_processor )
# process sections
content_processor.finish()

formatter = tomarkdown.MdFormatter( content_processor,
                                    project_title,
                                    project_prefix )

def test_html_quote():
    test_string = '7 & 9 < 4 & 5 but 12 & 15 > 4 & 5'
    expt_string = '7 &amp; 9 &lt; 4 &amp; 5 but 12 &amp; 15 &gt; 4 &amp; 5'
    assert tomarkdown.html_quote(test_string) == expt_string

def test_normalize_url():
    global formatter
    url = 'protocol://test-url-with/[square-brackets]?and-query'
    expected_url = 'protocol://test-url-with/(square-brackets)?and-query'
    assert formatter.normalize_url( url ) == expected_url

def test_slugify():
    global formatter
    name     = 'FT_HAS_MULTIPLE_MASTERS'
    expected = 'ft_has_multiple_masters'
    assert formatter.slugify( name ) == expected

def test_slugify2():
    global formatter
    name     = 'FT_GetFilePath_From_Mac_ATS_Name'
    expected = 'ft_getfilepath_from_mac_ats_name'
    assert formatter.slugify( name ) == expected

def test_slugify3():
    global formatter
    name     = 'default-script'
    expected = 'default-script'
    assert formatter.slugify( name ) == expected

def test_make_section_url():
    global formatter
    expected_url = '../test-outline_processing/index.html'

    section = list(formatter.sections)[0]
    out_url = formatter.make_section_url( section, code = True )
    assert out_url == expected_url

def test_make_chapter_url():
    global formatter
    expected_text = '[Support API](test-toc.md#support-api)'

    section = list(formatter.sections)[0]
    out_text = formatter.make_chapter_url( section.chapter.title )

    assert out_text == expected_text

# eof