github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/core/api/convert/excerpt/excerpt_test.go (about)

     1  // Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
     2  //
     3  // This software (Documize Community Edition) is licensed under
     4  // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
     5  //
     6  // You can operate outside the AGPL restrictions by purchasing
     7  // Documize Enterprise Edition and obtaining a commercial license
     8  // by contacting <sales@documize.com>.
     9  //
    10  // https://documize.com
    11  
    12  package excerpt_test
    13  
    14  import "testing"
    15  import "github.com/documize/community/core/api/convert/excerpt"
    16  import "strings"
    17  import "fmt"
    18  
    19  func TestExerpt(t *testing.T) {
    20  	if excerpt.Excerpt(nil, nil) != "" ||
    21  		excerpt.Excerpt([]string{}, []string{}) != "" {
    22  		t.Error("empty lists do not return empty string")
    23  	}
    24  	qbf := strings.Split("The quick brown fox jumps over the lazy dog .", " ")
    25  	qbf2 := qbf
    26  	for i := 0; i < 200; i++ {
    27  		qbf2 = append(qbf2, qbf...)
    28  	}
    29  	tst := excerpt.Excerpt(qbf, qbf2)
    30  	if tst !=
    31  		"The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog." {
    32  		t.Error("'quick brown fox' did not work:", tst)
    33  	}
    34  
    35  	tt123 := strings.Split("Testing , testing ; 1 2 3 is fun ! Bracket [ anyone ? .", " ")
    36  	tt123a := tt123
    37  	for i := 0; i < 200; i++ {
    38  		tt123a = append(tt123a, fmt.Sprintf("%d", i))
    39  		tt123a = append(tt123a, tt123...)
    40  	}
    41  	tst2 := excerpt.Excerpt(tt123, tt123a)
    42  	if tst2 !=
    43  		"Testing, testing; 123 is fun! … Testing, testing; 123 is fun! … 0 Testing, testing; 123 is fun!" {
    44  		t.Error("'Testing testing 123' did not work:", tst2)
    45  	}
    46  
    47  	s := strings.Split(strings.Replace(`
    48  It's supercalifragilisticexpialidocious
    49  Even though the sound of it is something quite atrocious
    50  If you say it loud enough, you'll always sound precocious
    51  Supercalifragilisticexpialidocious
    52  
    53  Um diddle, diddle diddle, um diddle ay
    54  Um diddle, diddle diddle, um diddle ay
    55  Um diddle, diddle diddle, um diddle ay
    56  Um diddle, diddle diddle, um diddle ay
    57  
    58  Because I was afraid to speak
    59  When I was just a lad
    60  My father gave me nose a tweak
    61  And told me I was bad
    62  
    63  But then one day I learned a word
    64  That saved me achin' nose
    65  The biggest word I ever heard
    66  And this is how it goes, oh
    67  
    68  Supercalifragilisticexpialidocious
    69  Even though the sound of it is something quite atrocious
    70  If you say it loud enough, you'll always sound precocious
    71  Supercalifragilisticexpialidocious
    72  
    73  Um diddle, diddle diddle, um diddle ay
    74  Um diddle, diddle diddle, um diddle ay
    75  Um diddle, diddle diddle, um diddle ay
    76  Um diddle, diddle diddle, um diddle ay
    77  
    78  He traveled all around the world
    79  And everywhere he went
    80  He'd use his word and all would say
    81  There goes a clever gent
    82  
    83  When Dukes and Maharajahs
    84  Pass the time of day with me
    85  I say me special word
    86  And then they ask me out to tea
    87  
    88  Oh, supercalifragilisticexpialidocious
    89  Even though the sound of it is something quite atrocious
    90  If you say it loud enough, you'll always sound precocious
    91  Supercalifragilisticexpialidocious
    92  
    93  Um diddle, diddle diddle, um diddle ay
    94  Um diddle, diddle diddle, um diddle ay
    95  
    96  No, you can say it backwards, which is dociousaliexpilisticfragicalirupus
    97  But that's going a bit too far, don't you think?
    98  
    99  So when the cat has got your tongue
   100  There's no need for dismay
   101  Just summon up this word
   102  And then you've got a lot to say
   103  
   104  But better use it carefully
   105  Or it could change your life
   106  For example, yes, one night I said it to me girl
   107  And now me girl's my wife, oh, and a lovely thing she's too
   108  
   109  She's, supercalifragilisticexpialidocious
   110  Supercalifragilisticexpialidocious
   111  Supercalifragilisticexpialidocious
   112  Supercalifragilisticexpialidocious
   113  .	`, "\n", " . ", -1), " ")
   114  	ts := []string{"Supercalifragilisticexpialidocious", "song", "lyrics"}
   115  	st := excerpt.Excerpt(ts, s)
   116  	if st != "Supercalifragilisticexpialidocious song lyrics. … Um diddle, diddle diddle, um diddle ay. Um diddle, diddle diddle, um diddle ay." {
   117  		t.Error("'Supercalifragilisticexpialidocious song lyrics' did not work:", st)
   118  	}
   119  
   120  	ss := []string{"Supercalifragilisticexpialidocious", "!"}
   121  	ssa := ss
   122  	for i := 0; i < 100; i++ {
   123  		ssa = append(ssa, ss...)
   124  	}
   125  	sst := excerpt.Excerpt(ss, ssa)
   126  	if sst !=
   127  		"Supercalifragilisticexpialidocious! Supercalifragilisticexpialidocious! Supercalifragilisticexpialidocious! Supercalifragilisticexpialidocious! Supercalifragilisticexpialidocious! Supercalifragilisticexpialidocious! Supercalifragilisticexpialidocious…" {
   128  		t.Error("'Supercalifragilisticexpialidocious' did not work:", sst)
   129  	}
   130  }