|
| 1 | +require 'test_helper' |
| 2 | +require 'docs' |
| 3 | + |
| 4 | +class UsagesFilterTest < MiniTest::Spec |
| 5 | + include FilterTestHelper |
| 6 | + self.filter_class = Docs::Go::UsagesFilter |
| 7 | + |
| 8 | + before do |
| 9 | + context[:base_url] = 'http://example.com/path/' |
| 10 | + context[:url] = 'http://example.com/path/bytes/' |
| 11 | + end |
| 12 | + |
| 13 | + it "adds examples link for functions" do |
| 14 | + @body = '<div><h2 id="Contains">func Contains </h2></div>' |
| 15 | + assert_equal "<div>\n"\ |
| 16 | + "<h2 id=\"Contains\">func Contains </h2>\n"\ |
| 17 | + "<a href=\"https://sourcegraph.com/github.com/golang/go/-/land/GoPackage/bytes/-/Contains?utm_source=devdocs.io&utm_medium=web&utm_campaign=docs\">Examples</a>\n"\ |
| 18 | + "</div>", filter_output_string |
| 19 | + end |
| 20 | + |
| 21 | + it "adds examples link for methods" do |
| 22 | + @body = |
| 23 | + '<div><h3 id="Buffer.WriteString">func (*Buffer) <a href="https://golang.org/src/bytes/buffer.go?s=4916:4973#L131">WriteString</a> </h3></div>' |
| 24 | + assert_equal "<div>\n"\ |
| 25 | + "<h3 id=\"Buffer.WriteString\">func (*Buffer) <a href=\"https://golang.org/src/bytes/buffer.go?s=4916:4973#L131\">WriteString</a> </h3>\n"\ |
| 26 | + "<a href=\"https://sourcegraph.com/github.com/golang/go/-/land/GoPackage/bytes/-/Buffer/WriteString?utm_source=devdocs.io&utm_medium=web&utm_campaign=docs\">Examples</a>\n"\ |
| 27 | + "</div>", filter_output_string |
| 28 | + end |
| 29 | + |
| 30 | + it "adds examples link for variables" do |
| 31 | + @body = |
| 32 | + "<div>\n"\ |
| 33 | + "<h2 id=\"pkg-variables\">Variables</h2>\n"\ |
| 34 | + "<pre data-language=\"go\" class=\" language-go\"><span class=\"token keyword\">var</span> ErrTooLarge <span class=\"token operator\">=</span> errors<span class=\"token punctuation\">.</span><span class=\"token function\">New</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"bytes.Buffer: too large\"</span><span class=\"token punctuation\">)</span></pre>\n"\ |
| 35 | + "</div>" |
| 36 | + |
| 37 | + assert_equal "<div>\n"\ |
| 38 | + "<h2 id=\"pkg-variables\">Variables</h2>\n"\ |
| 39 | + "<pre data-language=\"go\" class=\" language-go\"><span class=\"token keyword\">var</span> ErrTooLarge <span class=\"token operator\">=</span> errors<span class=\"token punctuation\">.</span><span class=\"token function\">New</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"bytes.Buffer: too large\"</span><span class=\"token punctuation\">)</span></pre>\n"\ |
| 40 | + "<div><a href=\"https://sourcegraph.com/github.com/golang/go/-/land/GoPackage/bytes/-/ErrTooLarge?utm_source=devdocs.io&utm_medium=web&utm_campaign=docs\">ErrTooLarge examples</a></div>\n"\ |
| 41 | + "</div>", filter_output_string |
| 42 | + end |
| 43 | + |
| 44 | + it "adds examples link for constants" do |
| 45 | + @body = |
| 46 | + "<div>\n"\ |
| 47 | + "<h2 id=\"pkg-constants\">Constants</h2>\n"\ |
| 48 | + "<pre data-language=\"go\" class=\" language-go\"><span class=\"token keyword\">const</span> Size <span class=\"token operator\">=</span> <span class=\"token number\">4</span></pre>\n"\ |
| 49 | + "</div>" |
| 50 | + |
| 51 | + assert_equal "<div>\n"\ |
| 52 | + "<h2 id=\"pkg-constants\">Constants</h2>\n"\ |
| 53 | + "<pre data-language=\"go\" class=\" language-go\"><span class=\"token keyword\">const</span> Size <span class=\"token operator\">=</span> <span class=\"token number\">4</span></pre>\n"\ |
| 54 | + "<div><a href=\"https://sourcegraph.com/github.com/golang/go/-/land/GoPackage/bytes/-/Size?utm_source=devdocs.io&utm_medium=web&utm_campaign=docs\">Size examples</a></div>\n"\ |
| 55 | + "</div>", filter_output_string |
| 56 | + end |
| 57 | + |
| 58 | +end |
0 commit comments