...
Run Format

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 c d"},
    22  	{"a  b\n\nc\r\rd\t\t  . BLA", 15, "a b c d ."},
    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  }
    39  
    40  func TestSynopsis(t *testing.T) {
    41  	for _, e := range tests {
    42  		fsl := firstSentenceLen(e.txt)
    43  		if fsl != e.fsl {
    44  			t.Errorf("got fsl = %d; want %d for %q\n", fsl, e.fsl, e.txt)
    45  		}
    46  		syn := Synopsis(e.txt)
    47  		if syn != e.syn {
    48  			t.Errorf("got syn = %q; want %q for %q\n", syn, e.syn, e.txt)
    49  		}
    50  	}
    51  }
    52  

View as plain text