summaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/tools/present
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/tools/present')
-rw-r--r--vendor/golang.org/x/tools/present/code_test.go225
-rw-r--r--vendor/golang.org/x/tools/present/doc.go2
-rw-r--r--vendor/golang.org/x/tools/present/link_test.go40
-rw-r--r--vendor/golang.org/x/tools/present/style_test.go124
4 files changed, 1 insertions, 390 deletions
diff --git a/vendor/golang.org/x/tools/present/code_test.go b/vendor/golang.org/x/tools/present/code_test.go
deleted file mode 100644
index b01a4e3..0000000
--- a/vendor/golang.org/x/tools/present/code_test.go
+++ /dev/null
@@ -1,225 +0,0 @@
-// Copyright 2012 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package present
-
-import (
- "fmt"
- "html/template"
- "strings"
- "testing"
-)
-
-func TestParseCode(t *testing.T) {
- // Enable play but revert the change at the end.
- defer func(play bool) { PlayEnabled = play }(PlayEnabled)
- PlayEnabled = true
-
- helloTest := []byte(`
-package main
-
-import "fmt"
-
-func main() {
- fmt.Println("hello, test")
-}
-`)
- helloTestHTML := template.HTML(`
-<pre><span num="2">package main</span>
-<span num="3"></span>
-<span num="4">import &#34;fmt&#34;</span>
-<span num="5"></span>
-<span num="6">func main() {</span>
-<span num="7"> fmt.Println(&#34;hello, test&#34;)</span>
-<span num="8">}</span>
-</pre>
-`)
- helloTestHL := []byte(`
-package main
-
-import "fmt" // HLimport
-
-func main() { // HLfunc
- fmt.Println("hello, test") // HL
-}
-`)
- highlight := func(h template.HTML, s string) template.HTML {
- return template.HTML(strings.Replace(string(h), s, "<b>"+s+"</b>", -1))
- }
- read := func(b []byte, err error) func(string) ([]byte, error) {
- return func(string) ([]byte, error) { return b, err }
- }
-
- tests := []struct {
- name string
- readFile func(string) ([]byte, error)
- sourceFile string
- cmd string
- err string
- Code
- }{
- {
- name: "all code, no play",
- readFile: read(helloTest, nil),
- sourceFile: "main.go",
- cmd: ".code main.go",
- Code: Code{
- Ext: ".go",
- FileName: "main.go",
- Raw: helloTest,
- Text: helloTestHTML,
- },
- },
- {
- name: "all code, play",
- readFile: read(helloTest, nil),
- sourceFile: "main.go",
- cmd: ".play main.go",
- Code: Code{
- Ext: ".go",
- FileName: "main.go",
- Play: true,
- Raw: helloTest,
- Text: helloTestHTML,
- },
- },
- {
- name: "all code, highlighted",
- readFile: read(helloTestHL, nil),
- sourceFile: "main.go",
- cmd: ".code main.go",
- Code: Code{
- Ext: ".go",
- FileName: "main.go",
- Raw: helloTestHL,
- Text: highlight(helloTestHTML, "fmt.Println(&#34;hello, test&#34;)"),
- },
- },
- {
- name: "highlight only func",
- readFile: read(helloTestHL, nil),
- sourceFile: "main.go",
- cmd: ".code main.go HLfunc",
- Code: Code{
- Ext: ".go",
- FileName: "main.go",
- Play: false,
- Raw: []byte("package main\n\nimport \"fmt\" // HLimport\n\nfunc main() { // HLfunc\n\tfmt.Println(\"hello, test\") // HL\n}"),
- Text: highlight(helloTestHTML, "func main() {"),
- },
- },
- {
- name: "bad highlight syntax",
- readFile: read(helloTest, nil),
- sourceFile: "main.go",
- cmd: ".code main.go HL",
- err: "invalid highlight syntax",
- },
- {
- name: "error reading file",
- readFile: read(nil, fmt.Errorf("nope")),
- sourceFile: "main.go",
- cmd: ".code main.go",
- err: "main.go:0: nope",
- },
- {
- name: "from func main to the end",
- readFile: read(helloTest, nil),
- sourceFile: "main.go",
- cmd: ".code main.go /func main/,",
- Code: Code{
- Ext: ".go",
- FileName: "main.go",
- Play: false,
- Raw: []byte("func main() {\n\tfmt.Println(\"hello, test\")\n}"),
- Text: "<pre><span num=\"6\">func main() {</span>\n<span num=\"7\"> fmt.Println(&#34;hello, test&#34;)</span>\n<span num=\"8\">}</span>\n</pre>",
- },
- },
- {
- name: "just func main",
- readFile: read(helloTest, nil),
- sourceFile: "main.go",
- cmd: ".code main.go /func main/",
- Code: Code{
- Ext: ".go",
- FileName: "main.go",
- Play: false,
- Raw: []byte("func main() {"),
- Text: "<pre><span num=\"6\">func main() {</span>\n</pre>",
- },
- },
- {
- name: "bad address",
- readFile: read(helloTest, nil),
- sourceFile: "main.go",
- cmd: ".code main.go /function main/",
- err: "main.go:0: no match for function main",
- },
- {
- name: "all code with numbers",
- readFile: read(helloTest, nil),
- sourceFile: "main.go",
- cmd: ".code -numbers main.go",
- Code: Code{
- Ext: ".go",
- FileName: "main.go",
- Raw: helloTest,
- // Replacing the first "<pre>"
- Text: "<pre class=\"numbers\">" + helloTestHTML[6:],
- },
- },
- {
- name: "all code editable",
- readFile: read(helloTest, nil),
- sourceFile: "main.go",
- cmd: ".code -edit main.go",
- Code: Code{
- Ext: ".go",
- FileName: "main.go",
- Raw: helloTest,
- Text: "<pre contenteditable=\"true\" spellcheck=\"false\">" + helloTestHTML[6:],
- },
- },
- }
-
- trimHTML := func(t template.HTML) string { return strings.TrimSpace(string(t)) }
- trimBytes := func(b []byte) string { return strings.TrimSpace(string(b)) }
-
- for _, tt := range tests {
- ctx := &Context{tt.readFile}
- e, err := parseCode(ctx, tt.sourceFile, 0, tt.cmd)
- if err != nil {
- if tt.err == "" {
- t.Errorf("%s: unexpected error %v", tt.name, err)
- } else if !strings.Contains(err.Error(), tt.err) {
- t.Errorf("%s: expected error %s; got %v", tt.name, tt.err, err)
- }
- continue
- }
- if tt.err != "" {
- t.Errorf("%s: expected error %s; but got none", tt.name, tt.err)
- continue
- }
- c, ok := e.(Code)
- if !ok {
- t.Errorf("%s: expected a Code value; got %T", tt.name, e)
- continue
- }
- if c.FileName != tt.FileName {
- t.Errorf("%s: expected FileName %s; got %s", tt.name, tt.FileName, c.FileName)
- }
- if c.Ext != tt.Ext {
- t.Errorf("%s: expected Ext %s; got %s", tt.name, tt.Ext, c.Ext)
- }
- if c.Play != tt.Play {
- t.Errorf("%s: expected Play %v; got %v", tt.name, tt.Play, c.Play)
- }
- if got, wants := trimBytes(c.Raw), trimBytes(tt.Raw); got != wants {
- t.Errorf("%s: expected Raw \n%q\n; got \n%q\n", tt.name, wants, got)
- }
- if got, wants := trimHTML(c.Text), trimHTML(tt.Text); got != wants {
- t.Errorf("%s: expected Text \n%q\n; got \n%q\n", tt.name, wants, got)
- }
- }
-}
diff --git a/vendor/golang.org/x/tools/present/doc.go b/vendor/golang.org/x/tools/present/doc.go
index 1eae9c8..45039b6 100644
--- a/vendor/golang.org/x/tools/present/doc.go
+++ b/vendor/golang.org/x/tools/present/doc.go
@@ -117,7 +117,7 @@ a file name followed by an optional address that specifies what
section of the file to display. The address syntax is similar in
its simplest form to that of ed, but comes from sam and is more
general. See
- http://plan9.bell-labs.com/sys/doc/sam/sam.html Table II
+ https://plan9.io/sys/doc/sam/sam.html Table II
for full details. The displayed block is always rounded out to a
full line at both ends.
diff --git a/vendor/golang.org/x/tools/present/link_test.go b/vendor/golang.org/x/tools/present/link_test.go
deleted file mode 100644
index 334e72b..0000000
--- a/vendor/golang.org/x/tools/present/link_test.go
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2012 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package present
-
-import "testing"
-
-func TestInlineParsing(t *testing.T) {
- var tests = []struct {
- in string
- link string
- text string
- length int
- }{
- {"[[http://golang.org]]", "http://golang.org", "golang.org", 21},
- {"[[http://golang.org][]]", "http://golang.org", "http://golang.org", 23},
- {"[[http://golang.org]] this is ignored", "http://golang.org", "golang.org", 21},
- {"[[http://golang.org][link]]", "http://golang.org", "link", 27},
- {"[[http://golang.org][two words]]", "http://golang.org", "two words", 32},
- {"[[http://golang.org][*link*]]", "http://golang.org", "<b>link</b>", 29},
- {"[[http://bad[url]]", "", "", 0},
- {"[[http://golang.org][a [[link]] ]]", "http://golang.org", "a [[link", 31},
- {"[[http:// *spaces* .com]]", "", "", 0},
- {"[[http://bad`char.com]]", "", "", 0},
- {" [[http://google.com]]", "", "", 0},
- {"[[mailto:gopher@golang.org][Gopher]]", "mailto:gopher@golang.org", "Gopher", 36},
- {"[[mailto:gopher@golang.org]]", "mailto:gopher@golang.org", "gopher@golang.org", 28},
- }
-
- for i, test := range tests {
- link, length := parseInlineLink(test.in)
- if length == 0 && test.length == 0 {
- continue
- }
- if a := renderLink(test.link, test.text); length != test.length || link != a {
- t.Errorf("#%d: parseInlineLink(%q):\ngot\t%q, %d\nwant\t%q, %d", i, test.in, link, length, a, test.length)
- }
- }
-}
diff --git a/vendor/golang.org/x/tools/present/style_test.go b/vendor/golang.org/x/tools/present/style_test.go
deleted file mode 100644
index cef5a62..0000000
--- a/vendor/golang.org/x/tools/present/style_test.go
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2012 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package present
-
-import (
- "fmt"
- "reflect"
- "testing"
-)
-
-func TestSplit(t *testing.T) {
- var tests = []struct {
- in string
- out []string
- }{
- {"", []string{}},
- {" ", []string{" "}},
- {"abc", []string{"abc"}},
- {"abc def", []string{"abc", " ", "def"}},
- {"abc def ", []string{"abc", " ", "def", " "}},
- {"hey [[http://golang.org][Gophers]] around",
- []string{"hey", " ", "[[http://golang.org][Gophers]]", " ", "around"}},
- {"A [[http://golang.org/doc][two words]] link",
- []string{"A", " ", "[[http://golang.org/doc][two words]]", " ", "link"}},
- {"Visit [[http://golang.org/doc]] now",
- []string{"Visit", " ", "[[http://golang.org/doc]]", " ", "now"}},
- {"not [[http://golang.org/doc][a [[link]] ]] around",
- []string{"not", " ", "[[http://golang.org/doc][a [[link]]", " ", "]]", " ", "around"}},
- {"[[http://golang.org][foo bar]]",
- []string{"[[http://golang.org][foo bar]]"}},
- {"ends with [[http://golang.org][link]]",
- []string{"ends", " ", "with", " ", "[[http://golang.org][link]]"}},
- {"my talk ([[http://talks.golang.org/][slides here]])",
- []string{"my", " ", "talk", " ", "(", "[[http://talks.golang.org/][slides here]]", ")"}},
- }
- for _, test := range tests {
- out := split(test.in)
- if !reflect.DeepEqual(out, test.out) {
- t.Errorf("split(%q):\ngot\t%q\nwant\t%q", test.in, out, test.out)
- }
- }
-}
-
-func TestFont(t *testing.T) {
- var tests = []struct {
- in string
- out string
- }{
- {"", ""},
- {" ", " "},
- {"\tx", "\tx"},
- {"_a_", "<i>a</i>"},
- {"*a*", "<b>a</b>"},
- {"`a`", "<code>a</code>"},
- {"_a_b_", "<i>a b</i>"},
- {"_a__b_", "<i>a_b</i>"},
- {"_a___b_", "<i>a_ b</i>"},
- {"*a**b*?", "<b>a*b</b>?"},
- {"_a_<>_b_.", "<i>a <> b</i>."},
- {"(_a_)", "(<i>a</i>)"},
- {"((_a_), _b_, _c_).", "((<i>a</i>), <i>b</i>, <i>c</i>)."},
- {"(_a)", "(_a)"},
- {"(_a)", "(_a)"},
- {"_Why_use_scoped__ptr_? Use plain ***ptr* instead.", "<i>Why use scoped_ptr</i>? Use plain <b>*ptr</b> instead."},
- {"_hey_ [[http://golang.org][*Gophers*]] *around*",
- `<i>hey</i> <a href="http://golang.org" target="_blank"><b>Gophers</b></a> <b>around</b>`},
- {"_hey_ [[http://golang.org][so _many_ *Gophers*]] *around*",
- `<i>hey</i> <a href="http://golang.org" target="_blank">so <i>many</i> <b>Gophers</b></a> <b>around</b>`},
- {"Visit [[http://golang.org]] now",
- `Visit <a href="http://golang.org" target="_blank">golang.org</a> now`},
- {"my talk ([[http://talks.golang.org/][slides here]])",
- `my talk (<a href="http://talks.golang.org/" target="_blank">slides here</a>)`},
- {"Markup—_especially_italic_text_—can easily be overused.",
- `Markup—<i>especially italic text</i>—can easily be overused.`},
- {"`go`get`'s codebase", // ascii U+0027 ' before s
- `<code>go get</code>'s codebase`},
- {"`go`get`’s codebase", // unicode right single quote U+2019 ’ before s
- `<code>go get</code>’s codebase`},
- {"a_variable_name",
- `a_variable_name`},
- }
- for _, test := range tests {
- out := font(test.in)
- if out != test.out {
- t.Errorf("font(%q):\ngot\t%q\nwant\t%q", test.in, out, test.out)
- }
- }
-}
-
-func TestStyle(t *testing.T) {
- var tests = []struct {
- in string
- out string
- }{
- {"", ""},
- {" ", " "},
- {"\tx", "\tx"},
- {"_a_", "<i>a</i>"},
- {"*a*", "<b>a</b>"},
- {"`a`", "<code>a</code>"},
- {"_a_b_", "<i>a b</i>"},
- {"_a__b_", "<i>a_b</i>"},
- {"_a___b_", "<i>a_ b</i>"},
- {"*a**b*?", "<b>a*b</b>?"},
- {"_a_<>_b_.", "<i>a &lt;&gt; b</i>."},
- {"(_a_<>_b_)", "(<i>a &lt;&gt; b</i>)"},
- {"((_a_), _b_, _c_).", "((<i>a</i>), <i>b</i>, <i>c</i>)."},
- {"(_a)", "(_a)"},
- }
- for _, test := range tests {
- out := string(Style(test.in))
- if out != test.out {
- t.Errorf("style(%q):\ngot\t%q\nwant\t%q", test.in, out, test.out)
- }
- }
-}
-
-func ExampleStyle() {
- const s = "*Gophers* are _clearly_ > *cats*!"
- fmt.Println(Style(s))
- // Output: <b>Gophers</b> are <i>clearly</i> &gt; <b>cats</b>!
-}