...

Source file src/go/doc/synopsis_test.go

Documentation: go/doc

     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 doc
     6  
     7  import "testing"
     8  
     9  var tests = []struct {
    10  	txt string
    11  	fsl int
    12  	syn string
    13  }{
    14  	{"", 0, ""},
    15  	{"foo", 3, "foo"},
    16  	{"foo.", 4, "foo."},
    17  	{"foo.bar", 7, "foo.bar"},
    18  	{"  foo.  ", 6, "foo."},
    19  	{"  foo\t  bar.\n", 12, "foo bar."},
    20  	{"  foo\t  bar.\n", 12, "foo bar."},
    21  	{"a  b\n\nc\r\rd\t\t", 12, "a b"},
    22  	{"a  b\n\nc\r\rd\t\t  . BLA", 15, "a b"},
    23  	{"Package poems by T.S.Eliot. To rhyme...", 27, "Package poems by T.S.Eliot."},
    24  	{"Package poems by T. S. Eliot. To rhyme...", 29, "Package poems by T. S. Eliot."},
    25  	{"foo implements the foo ABI. The foo ABI is...", 27, "foo implements the foo ABI."},
    26  	{"Package\nfoo. ..", 12, "Package foo."},
    27  	{"P . Q.", 3, "P ."},
    28  	{"P. Q.   ", 8, "P. Q."},
    29  	{"Package Καλημέρα κόσμε.", 36, "Package Καλημέρα κόσμε."},
    30  	{"Package こんにちは 世界\n", 31, "Package こんにちは 世界"},
    31  	{"Package こんにちは。世界", 26, "Package こんにちは。"},
    32  	{"Package 안녕.世界", 17, "Package 안녕."},
    33  	{"Package foo does bar.", 21, "Package foo does bar."},
    34  	{"Copyright 2012 Google, Inc. Package foo does bar.", 27, ""},
    35  	{"All Rights reserved. Package foo does bar.", 20, ""},
    36  	{"All rights reserved. Package foo does bar.", 20, ""},
    37  	{"Authors: foo@bar.com. Package foo does bar.", 21, ""},
    38  	{"typically invoked as ``go tool asm'',", 37, "typically invoked as “go tool asm”,"},
    39  }
    40  
    41  func TestSynopsis(t *testing.T) {
    42  	for _, e := range tests {
    43  		fs := firstSentence(e.txt)
    44  		if fs != e.txt[:e.fsl] {
    45  			t.Errorf("firstSentence(%q) = %q, want %q", e.txt, fs, e.txt[:e.fsl])
    46  		}
    47  		syn := Synopsis(e.txt)
    48  		if syn != e.syn {
    49  			t.Errorf("Synopsis(%q) = %q, want %q", e.txt, syn, e.syn)
    50  		}
    51  	}
    52  }
    53  

View as plain text