github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/src/pkg/go/doc/synopsis_test.go (about) 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 foo does bar.", 21, "Package foo does bar."}, 32 {"Copyright 2012 Google, Inc. Package foo does bar.", 27, ""}, 33 {"All Rights reserved. Package foo does bar.", 20, ""}, 34 {"All rights reserved. Package foo does bar.", 20, ""}, 35 {"Authors: foo@bar.com. Package foo does bar.", 21, ""}, 36 } 37 38 func TestSynopsis(t *testing.T) { 39 for _, e := range tests { 40 fsl := firstSentenceLen(e.txt) 41 if fsl != e.fsl { 42 t.Errorf("got fsl = %d; want %d for %q\n", fsl, e.fsl, e.txt) 43 } 44 syn := Synopsis(e.txt) 45 if syn != e.syn { 46 t.Errorf("got syn = %q; want %q for %q\n", syn, e.syn, e.txt) 47 } 48 } 49 }