* gcc.dg/guality/guality.exp: Skip on AIX.
[official-gcc.git] / libgo / go / go / doc / comment_test.go
blobaa21b8d1b30765e8699445f97f8f105f1ee19721
1 // Copyright 2011 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.
5 package doc
7 import (
8 "bytes"
9 "reflect"
10 "testing"
13 var headingTests = []struct {
14 line string
15 ok bool
17 {"Section", true},
18 {"A typical usage", true},
19 {"ΔΛΞ is Greek", true},
20 {"Foo 42", true},
21 {"", false},
22 {"section", false},
23 {"A typical usage:", false},
24 {"This code:", false},
25 {"δ is Greek", false},
26 {"Foo §", false},
27 {"Fermat's Last Sentence", true},
28 {"Fermat's", true},
29 {"'sX", false},
30 {"Ted 'Too' Bar", false},
31 {"Use n+m", false},
32 {"Scanning:", false},
33 {"N:M", false},
36 func TestIsHeading(t *testing.T) {
37 for _, tt := range headingTests {
38 if h := heading(tt.line); (len(h) > 0) != tt.ok {
39 t.Errorf("isHeading(%q) = %v, want %v", tt.line, h, tt.ok)
44 var blocksTests = []struct {
45 in string
46 out []block
49 in: `Para 1.
50 Para 1 line 2.
52 Para 2.
54 Section
56 Para 3.
58 pre
59 pre1
61 Para 4.
62 pre
63 pre2
65 out: []block{
66 {opPara, []string{"Para 1.\n", "Para 1 line 2.\n"}},
67 {opPara, []string{"Para 2.\n"}},
68 {opHead, []string{"Section"}},
69 {opPara, []string{"Para 3.\n"}},
70 {opPre, []string{"pre\n", "pre1\n"}},
71 {opPara, []string{"Para 4.\n"}},
72 {opPre, []string{"pre\n", "pre2\n"}},
77 func TestBlocks(t *testing.T) {
78 for i, tt := range blocksTests {
79 b := blocks(tt.in)
80 if !reflect.DeepEqual(b, tt.out) {
81 t.Errorf("#%d: mismatch\nhave: %v\nwant: %v", i, b, tt.out)
86 var emphasizeTests = []struct {
87 in string
88 out string
90 {"http://www.google.com/", `<a href="http://www.google.com/">http://www.google.com/</a>`},
91 {"https://www.google.com/", `<a href="https://www.google.com/">https://www.google.com/</a>`},
92 {"http://www.google.com/path.", `<a href="http://www.google.com/path">http://www.google.com/path</a>.`},
93 {"(http://www.google.com/)", `(<a href="http://www.google.com/">http://www.google.com/</a>)`},
94 {"Foo bar http://example.com/ quux!", `Foo bar <a href="http://example.com/">http://example.com/</a> quux!`},
95 {"Hello http://example.com/%2f/ /world.", `Hello <a href="http://example.com/%2f/">http://example.com/%2f/</a> /world.`},
96 {"Lorem http: ipsum //host/path", "Lorem http: ipsum //host/path"},
97 {"javascript://is/not/linked", "javascript://is/not/linked"},
100 func TestEmphasize(t *testing.T) {
101 for i, tt := range emphasizeTests {
102 var buf bytes.Buffer
103 emphasize(&buf, tt.in, nil, true)
104 out := buf.String()
105 if out != tt.out {
106 t.Errorf("#%d: mismatch\nhave: %v\nwant: %v", i, out, tt.out)