github.com/jd-ly/tools@v0.5.7/present/link_test.go (about)

     1  // Copyright 2012 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package present
     6  
     7  import "testing"
     8  
     9  func TestInlineParsing(t *testing.T) {
    10  	var tests = []struct {
    11  		in     string
    12  		link   string
    13  		text   string
    14  		length int
    15  	}{
    16  		{"[[http://golang.org]]", "http://golang.org", "golang.org", 21},
    17  		{"[[http://golang.org][]]", "http://golang.org", "http://golang.org", 23},
    18  		{"[[http://golang.org]] this is ignored", "http://golang.org", "golang.org", 21},
    19  		{"[[http://golang.org][link]]", "http://golang.org", "link", 27},
    20  		{"[[http://golang.org][two words]]", "http://golang.org", "two words", 32},
    21  		{"[[http://golang.org][*link*]]", "http://golang.org", "<b>link</b>", 29},
    22  		{"[[http://bad[url]]", "", "", 0},
    23  		{"[[http://golang.org][a [[link]] ]]", "http://golang.org", "a [[link", 31},
    24  		{"[[http:// *spaces* .com]]", "", "", 0},
    25  		{"[[http://bad`char.com]]", "", "", 0},
    26  		{" [[http://google.com]]", "", "", 0},
    27  		{"[[mailto:gopher@golang.org][Gopher]]", "mailto:gopher@golang.org", "Gopher", 36},
    28  		{"[[mailto:gopher@golang.org]]", "mailto:gopher@golang.org", "gopher@golang.org", 28},
    29  	}
    30  
    31  	for i, test := range tests {
    32  		link, length := parseInlineLink(test.in)
    33  		if length == 0 && test.length == 0 {
    34  			continue
    35  		}
    36  		if a := renderLink(test.link, test.text); length != test.length || link != a {
    37  			t.Errorf("#%d: parseInlineLink(%q):\ngot\t%q, %d\nwant\t%q, %d", i, test.in, link, length, a, test.length)
    38  		}
    39  	}
    40  }