mirror of
https://github.com/drewcassidy/yaclog.git
synced 2024-09-01 14:58:58 +00:00
Add unit tests for parser
This commit is contained in:
parent
358942c858
commit
be78167b4b
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file
|
All notable changes to this project will be documented in this file
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Unit tests in the `tests` folder
|
||||||
|
|
||||||
## 0.3.2 - 2021-04-24
|
## 0.3.2 - 2021-04-24
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -37,3 +37,6 @@ packages = find:
|
|||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
yaclog = yaclog.cli.__main__:cli
|
yaclog = yaclog.cli.__main__:cli
|
||||||
|
|
||||||
|
[options.packages.find]
|
||||||
|
exclude = tests.*
|
64
tests/Test-Changelog.md
Normal file
64
tests/Test-Changelog.md
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
This changelog is for testing the parser, and has many things in it that might trip it up.
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
- bullet point with no section
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- bullet point dash
|
||||||
|
* bullet point star
|
||||||
|
+ bullet point plus
|
||||||
|
- sub point 1
|
||||||
|
- sub point 2
|
||||||
|
- sub point 3
|
||||||
|
|
||||||
|
### Fixed ##
|
||||||
|
|
||||||
|
- this is a bullet point
|
||||||
|
it spans many lines
|
||||||
|
|
||||||
|
This is
|
||||||
|
a paragraph
|
||||||
|
it spans many lines
|
||||||
|
|
||||||
|
this line has an [id] link
|
||||||
|
|
||||||
|
#### This is an H4
|
||||||
|
|
||||||
|
##### This is an H5
|
||||||
|
|
||||||
|
###### This is an H6
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
this is some example code
|
||||||
|
it spans many lines
|
||||||
|
```
|
||||||
|
|
||||||
|
> this is a block quote
|
||||||
|
it spans many lines
|
||||||
|
|
||||||
|
[1.1.0] - 1969-07-20 [PRERELEASE]
|
||||||
|
---
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Nyan Cat now has correct music
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Multiplayer
|
||||||
|
|
||||||
|
## Not a version number
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- Herobrine
|
||||||
|
|
||||||
|
[unreleased]: http://beesbeesbees.com
|
||||||
|
|
||||||
|
[1.1.0]: http://endless.horse
|
||||||
|
|
||||||
|
[id]: http://www.koalastothemax.com
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
62
tests/test_changelog.py
Normal file
62
tests/test_changelog.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import unittest
|
||||||
|
import yaclog
|
||||||
|
import os.path
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
test_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
class TestParser(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.log = yaclog.read(os.path.join(test_dir, 'Test-Changelog.md'))
|
||||||
|
|
||||||
|
def test_header(self):
|
||||||
|
self.assertEqual(self.log.header,
|
||||||
|
'# Changelog\n\n'
|
||||||
|
'This changelog is for testing the parser, and has many things in it that might trip it up.')
|
||||||
|
|
||||||
|
def test_path(self):
|
||||||
|
self.assertEqual(self.log.path, os.path.join(test_dir, 'Test-Changelog.md'))
|
||||||
|
|
||||||
|
def test_links(self):
|
||||||
|
self.assertEqual(self.log.links, {'unreleased': 'http://beesbeesbees.com',
|
||||||
|
'1.1.0': 'http://endless.horse',
|
||||||
|
'id': 'http://www.koalastothemax.com'})
|
||||||
|
|
||||||
|
def test_versions(self):
|
||||||
|
v = self.log.versions
|
||||||
|
self.assertEqual(v[0].name, 'Unreleased')
|
||||||
|
self.assertEqual(v[0].link, 'http://beesbeesbees.com')
|
||||||
|
self.assertEqual(v[0].date, None)
|
||||||
|
self.assertEqual(v[0].tags, [])
|
||||||
|
|
||||||
|
self.assertEqual(v[1].name, '1.1.0')
|
||||||
|
self.assertEqual(v[1].link, 'http://endless.horse')
|
||||||
|
self.assertEqual(v[1].date, datetime.date.fromisoformat('1969-07-20'))
|
||||||
|
self.assertEqual(v[1].tags, ['PRERELEASE'])
|
||||||
|
|
||||||
|
self.assertEqual(v[2].name, 'Not a version number')
|
||||||
|
self.assertEqual(v[2].link, None)
|
||||||
|
self.assertEqual(v[2].date, None)
|
||||||
|
self.assertEqual(v[2].tags, [])
|
||||||
|
|
||||||
|
def test_unreleased(self):
|
||||||
|
v = self.log.versions[0]
|
||||||
|
|
||||||
|
self.assertEqual(v.sections[''], ['- bullet point with no section'])
|
||||||
|
self.assertEqual(v.sections['Added'],
|
||||||
|
['- bullet point dash', '* bullet point star',
|
||||||
|
'+ bullet point plus\n - sub point 1\n - sub point 2\n - sub point 3'])
|
||||||
|
self.assertEqual(v.sections['Fixed'],
|
||||||
|
['- this is a bullet point\n it spans many lines',
|
||||||
|
'This is\na paragraph\nit spans many lines',
|
||||||
|
'this line has an [id] link',
|
||||||
|
'#### This is an H4',
|
||||||
|
'##### This is an H5',
|
||||||
|
'###### This is an H6',
|
||||||
|
'```markdown\nthis is some example code\nit spans many lines\n```',
|
||||||
|
'> this is a block quote\nit spans many lines'])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
@ -66,8 +66,8 @@ class VersionEntry:
|
|||||||
self.name: str = 'Unreleased'
|
self.name: str = 'Unreleased'
|
||||||
self.date: Optional[datetime.date] = None
|
self.date: Optional[datetime.date] = None
|
||||||
self.tags: List[str] = []
|
self.tags: List[str] = []
|
||||||
self.link: str = ''
|
self.link: Optional[str] = None
|
||||||
self.link_id: str = ''
|
self.link_id: Optional[str] = None
|
||||||
self.line_no: int = -1
|
self.line_no: int = -1
|
||||||
|
|
||||||
def body(self, md: bool = True) -> str:
|
def body(self, md: bool = True) -> str:
|
||||||
@ -203,7 +203,7 @@ class Changelog:
|
|||||||
version.name = slug
|
version.name = slug
|
||||||
version.line_no = segment[0]
|
version.line_no = segment[0]
|
||||||
tags = []
|
tags = []
|
||||||
date = []
|
date = None
|
||||||
|
|
||||||
for word in split[1:]:
|
for word in split[1:]:
|
||||||
if match := re.match(r'\d{4}-\d{2}-\d{2}', word):
|
if match := re.match(r'\d{4}-\d{2}-\d{2}', word):
|
||||||
@ -246,13 +246,13 @@ class Changelog:
|
|||||||
# ref-matched link
|
# ref-matched link
|
||||||
link_id = match[1].lower()
|
link_id = match[1].lower()
|
||||||
if link_id in self.links:
|
if link_id in self.links:
|
||||||
version.link = self.links.pop(link_id)
|
version.link = self.links[link_id]
|
||||||
version.link_id = None
|
version.link_id = None
|
||||||
version.name = match[1]
|
version.name = match[1]
|
||||||
|
|
||||||
elif version.link_id in self.links:
|
elif version.link_id in self.links:
|
||||||
# id-matched link
|
# id-matched link
|
||||||
version.link = self.links.pop(version.link_id)
|
version.link = self.links[version.link_id]
|
||||||
|
|
||||||
# strip whitespace from header
|
# strip whitespace from header
|
||||||
self.header = _join_markdown(header_segments)
|
self.header = _join_markdown(header_segments)
|
||||||
@ -261,10 +261,8 @@ class Changelog:
|
|||||||
if path is None:
|
if path is None:
|
||||||
path = self.path
|
path = self.path
|
||||||
|
|
||||||
v_links = {}
|
|
||||||
v_links.update(self.links)
|
|
||||||
|
|
||||||
segments = [self.header]
|
segments = [self.header]
|
||||||
|
v_links = {**self.links}
|
||||||
|
|
||||||
for version in self.versions:
|
for version in self.versions:
|
||||||
if version.link:
|
if version.link:
|
||||||
@ -272,8 +270,7 @@ class Changelog:
|
|||||||
|
|
||||||
segments.append(version.text())
|
segments.append(version.text())
|
||||||
|
|
||||||
for link_id, link in v_links.items():
|
segments += [f'[{link_id.lower()}]: {link}' for link_id, link in v_links.items()]
|
||||||
segments.append(f'[{link_id.lower()}]: {link}')
|
|
||||||
|
|
||||||
text = _join_markdown(segments)
|
text = _join_markdown(segments)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user