Test TermRenderer with testdata/readme.markdown.in

This commit is contained in:
Christian Muehlhaeuser
2019-12-15 05:30:45 +01:00
parent 8a9d1795ff
commit 63c3acd5f9
3 changed files with 120 additions and 8 deletions
+36 -8
View File
@@ -1,35 +1,63 @@
package gold
import (
"bytes"
"io/ioutil"
"testing"
"github.com/charmbracelet/gold/ansi"
)
const (
generate = false
markdown = "testdata/readme.markdown.in"
testFile = "testdata/readme.test"
)
func TestTermRenderer(t *testing.T) {
r, err := NewTermRenderer("notty", ansi.Options{
r, err := NewTermRenderer("styles/dark.json", ansi.Options{
WordWrap: 80,
})
if err != nil {
t.Fatal(err)
}
expLen := 166
_, err = r.Write([]byte("# Test"))
in, err := ioutil.ReadFile(markdown)
if err != nil {
t.Error(err)
t.Fatal(err)
}
_, err = r.Write(in)
if err != nil {
t.Fatal(err)
}
err = r.Close()
if err != nil {
t.Error(err)
t.Fatal(err)
}
b, err := ioutil.ReadAll(r)
if err != nil {
t.Error(err)
t.Fatal(err)
}
if len(b) != expLen {
t.Errorf("Expected rendered content with a length of %d, got %d!", expLen, len(b))
// generate
if generate {
err := ioutil.WriteFile(testFile, b, 0644)
if err != nil {
t.Fatal(err)
}
return
}
// verify
td, err := ioutil.ReadFile(testFile)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(td, b) {
t.Errorf("Rendered output doesn't match!\nExpected: `\n%s`\nGot: `\n%s`\n",
string(td), b)
}
}
+36
View File
@@ -0,0 +1,36 @@
# Gold
Render markdown on the CLI, with _pizzazz_!
## What is it?
Gold is a Golang library that allows you to use JSON based stylesheets to
render Markdown files in the terminal. Just like CSS, you can define color and
style attributes on Markdown elements. The difference is that you use ANSI
color and terminal codes instead of CSS properties and hex colors.
## Usage
See [cmd/gold](cmd/gold/).
## Example Output
![Gold Dark Style](https://github.com/charmbracelet/gold/raw/master/styles/gallery/dark.png)
Check out the [Gold Style Gallery](https://github.com/charmbracelet/gold/blob/master/styles/gallery/README.md)!
## Colors
Currently `gold` uses the [Aurora ANSI colors](https://godoc.org/github.com/logrusorgru/aurora#Index).
## Development
Style definitions located in `styles/` can be embedded into the binary by
running [statik](https://github.com/rakyll/statik):
```console
statik -f -src styles -include "*.json"
```
You can re-generate screenshots of all available styles by running `gallery.sh`.
This requires `termshot` and `pngcrush` installed on your system!
+48
View File
@@ -0,0 +1,48 @@
  Gold                                                                       
                                                                             
                                                                             
 Render markdown on the CLI, with pizzazz!                                   
                                                                             
                                                                             
 ## What is it?                                                              
                                                                             
 Gold is a Golang library that allows you to use JSON based stylesheets to   
 render Markdown files in the terminal. Just like CSS, you can define color  
 and style attributes on Markdown elements. The difference is that you use   
 ANSI color and terminal codes instead of CSS properties and hex colors.     
                                                                             
                                                                             
 ## Usage                                                                    
                                                                             
 See cmd/gold /cmd/gold/.                                                    
                                                                             
                                                                             
 ## Example Output                                                           
                                                                             
 Image: Gold Dark Style 🡆                                                    
 https://github.com/charmbracelet/gold/raw/master/styles/gallery/dark.png    
                                                                             
 Check out the Gold Style Gallery                                            
 https://github.com/charmbracelet/gold/blob/master/styles/gallery/README.md! 
                                                                             
                                                                             
 ## Colors                                                                   
                                                                             
 Currently  gold  uses the Aurora ANSI colors                                
 https://godoc.org/github.com/logrusorgru/aurora#Index.                      
                                                                             
                                                                             
 ## Development                                                              
                                                                             
 Style definitions located in  styles/  can be embedded into the binary by   
 running statik https://github.com/rakyll/statik:                            
                                                                             
     statik -f -src styles -include "*.json"                                 
                                                                             
 You can re-generate screenshots of all available styles by running          
 gallery.sh . This requires  termshot  and  pngcrush  installed on your      
 system!