Add some very, very basic tests to the parser package
This commit is contained in:
72
example/complexDoc.rst
Normal file
72
example/complexDoc.rst
Normal file
@ -0,0 +1,72 @@
|
||||
Title
|
||||
=====
|
||||
|
||||
Subtitle
|
||||
--------
|
||||
|
||||
Paragraphs are separated by a blank line.
|
||||
|
||||
Two lines of text should be enough to make up an entire
|
||||
paragraph.
|
||||
|
||||
In some formats, this is represented using a blank line.
|
||||
|
||||
*emphasis*
|
||||
|
||||
**strong emphasis**
|
||||
|
||||
`*literal text*`
|
||||
|
||||
* item 1
|
||||
* item 2
|
||||
|
||||
1. Item 1
|
||||
2. Item 2
|
||||
|
||||
#. Item 1
|
||||
#. Item 2
|
||||
|
||||
`inline code`
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
def hello_world():
|
||||
print("Hello, world!")
|
||||
|
||||
.. image:: /path/to/image.png
|
||||
:alt: Alternative text
|
||||
:width: 200px
|
||||
:height: 100px
|
||||
|
||||
.. _label:
|
||||
|
||||
This is a reference to a label.
|
||||
|
||||
.. [1] Citation 1
|
||||
|
||||
.. [2] Citation 2
|
||||
.. note::
|
||||
This is a note.
|
||||
|
||||
.. warning::
|
||||
This is a warning.
|
||||
|
||||
.. versionadded:: 1.0
|
||||
This feature was added in version 1.0.
|
||||
|
||||
.. versionchanged:: 1.0
|
||||
This feature was changed in version 1.0.
|
||||
|
||||
.. deprecated:: 1.0
|
||||
This feature is deprecated since version 1.0.
|
||||
|
||||
.. seealso::
|
||||
See also this other thing.
|
||||
|
||||
.. todo::
|
||||
This is a todo item.
|
||||
|
||||
.. math::
|
||||
E = mc^2
|
||||
|
||||
.. raw:: html
|
48
pkg/parser/parser_test.go
Normal file
48
pkg/parser/parser_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package parser
|
||||
|
||||
// test the functionality of the parser package using the test package
|
||||
// Use example restructuredText files embedded in the test functions
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"i2pgit.org/idk/go-rst/pkg/translator"
|
||||
)
|
||||
|
||||
const simpleDoc = "example/doc.rst"
|
||||
const complexDoc = "example/complexDoc.rst"
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
noopTranslator := translator.NewNoopTranslator()
|
||||
parser := NewParser(noopTranslator)
|
||||
doc := parser.Parse(simpleDoc)
|
||||
if doc == nil {
|
||||
t.Errorf("Expected a document, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTwo(t *testing.T) {
|
||||
noopTranslator := translator.NewNoopTranslator()
|
||||
parser := NewParser(noopTranslator)
|
||||
doc := parser.Parse(complexDoc)
|
||||
if doc == nil {
|
||||
t.Errorf("Expected a document, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseEmpty(t *testing.T) {
|
||||
noopTranslator := translator.NewNoopTranslator()
|
||||
parser := NewParser(noopTranslator)
|
||||
doc := parser.Parse("")
|
||||
if len(doc) > 0 {
|
||||
t.Errorf("Expected empty, got a document")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseNilTranslatorEmptyInput(t *testing.T) {
|
||||
parser := NewParser(nil)
|
||||
doc := parser.Parse("")
|
||||
if len(doc) > 0 {
|
||||
t.Errorf("Expected empty, got a document")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user