...

Source file src/github.com/yuin/goldmark/commonmark_test.go

Documentation: github.com/yuin/goldmark

     1  package goldmark_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"io/ioutil"
     6  	"testing"
     7  
     8  	. "github.com/yuin/goldmark"
     9  	"github.com/yuin/goldmark/renderer/html"
    10  	"github.com/yuin/goldmark/testutil"
    11  )
    12  
    13  type commonmarkSpecTestCase struct {
    14  	Markdown  string `json:"markdown"`
    15  	HTML      string `json:"html"`
    16  	Example   int    `json:"example"`
    17  	StartLine int    `json:"start_line"`
    18  	EndLine   int    `json:"end_line"`
    19  	Section   string `json:"section"`
    20  }
    21  
    22  func TestSpec(t *testing.T) {
    23  	bs, err := ioutil.ReadFile("_test/spec.json")
    24  	if err != nil {
    25  		panic(err)
    26  	}
    27  	var testCases []commonmarkSpecTestCase
    28  	if err := json.Unmarshal(bs, &testCases); err != nil {
    29  		panic(err)
    30  	}
    31  	cases := []testutil.MarkdownTestCase{}
    32  	nos := testutil.ParseCliCaseArg()
    33  	for _, c := range testCases {
    34  		shouldAdd := len(nos) == 0
    35  		if !shouldAdd {
    36  			for _, no := range nos {
    37  				if c.Example == no {
    38  					shouldAdd = true
    39  					break
    40  				}
    41  			}
    42  		}
    43  
    44  		if shouldAdd {
    45  			cases = append(cases, testutil.MarkdownTestCase{
    46  				No:       c.Example,
    47  				Markdown: c.Markdown,
    48  				Expected: c.HTML,
    49  			})
    50  		}
    51  	}
    52  	markdown := New(WithRendererOptions(
    53  		html.WithXHTML(),
    54  		html.WithUnsafe(),
    55  	))
    56  	testutil.DoTestCases(markdown, cases, t)
    57  }
    58  

View as plain text