func Test_prefixWithArticleUrlBase(t *testing.T) { slateUrl, _ := url.Parse("http://www.slate.com/articles/technology/bitwise/2015/08/windows_10_privacy_problems_here_s_how_bad_they_are_and_how_to_plug_them.html") type inputs struct { link string articleUrl url.URL } tests := []struct { in inputs want string }{ { in: inputs{ link: "/content/dam/slate/articles/technology/bitwise/2015/08/150803_BIT_Windows10-10.png.CROP.original-original.png", articleUrl: *slateUrl, }, want: "http://www.slate.com/content/dam/slate/articles/technology/bitwise/2015/08/150803_BIT_Windows10-10.png.CROP.original-original.png", }, } for _, test := range tests { got := prefixWithArticleUrlBase(test.in.link, test.in.articleUrl) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall prefixWithArticleUrlBase(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_SpaceBeforeClosingBrackets_hasNoSpaceBeforeAndAfterBrackets_NoNewSpaceShouldBeAdded(t *testing.T) { tests := testutils.ConversionTests{ { In: `Test. Test. \emph{Test}Test Test`, Want: `Test. Test. \emph{Test}Test Test`, }, } for _, test := range tests { got := SpaceBeforeClosingBrackets(test.In) if !reflect.DeepEqual(test.Want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall SpaceBeforeClosingBrackets(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.In, test.Want, got) t.FailNow() } } testutils.Cleanup() }
func Test_isMultiLined(t *testing.T) { tests := []struct { in string want bool }{ { in: `1234567890`, want: false, }, { // test regular ASCII in: "it is\nmulti-lined", want: true, }, { // test regular ASCII in: `it is multi-lined, too`, want: true, }, } for _, test := range tests { got := IsMultiLined(test.in) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall isMultiLined(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_BrHtmlTag(t *testing.T) { tests := testutils.ConversionTests{ { In: `a<br/> b<br/> c`, Want: `a \\ b \\ c`, }, { In: `a<br> b<br> c`, Want: `a \\ b \\ c`, }, } for _, test := range tests { got := BrHtmlTagToLatexLinebreak(test.In) if !reflect.DeepEqual(test.Want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall BrHtmlTag(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.In, test.Want, got) t.FailNow() } } testutils.Cleanup() }
func Test_codeShouldHaveFullPageWidth(t *testing.T) { tests := []struct { in string want bool }{ { in: `test`, want: false, }, { // has only 2 line but all are overlength so show as full width in: ` test adfas asj sadf jsadf jasdfj asdf jsad f test asdf sdf sadf sdf sdf sadffdf ksadf sdsss`, want: false, }, { // has more 25% over line but only two lines in: `test test sd dddddddddddd`, want: false, }, { in: `test1 test2 test3 test4`, want: false, }, { in: "", want: false, }, { // more than 25% overline, but only 4 lines and not 100% are overline in: `Set<Box> hasBlueShape = shapes.stream() .filter(s -> s.getColor() == BLUE) .map(s -> s.getContainingBox()) .collect(Collectors.toSet());`, want: false, }, { // long single line is broken only once in: `1 test adfas asj sadf jsadf jasdfj asdf jsad 3 test adfas asj sadf jsadf jasdfj asdf jsad`, want: false, }, { // long single line counts as multiple overline as it is broken mult times in: `1 test adfas asj sadf jsadf jasdfj asdf jsad 2 test adfas asj sadf jsadf jasdfj asdf jsad 3 test asdf sdf sadf sdf sdf sadffdf ksadf sdsss 4`, want: true, }, } for _, test := range tests { got := codeShouldHaveFullPageWidth(test.in) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall codeShouldHaveFullPageWidth(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_LeadingSpaces_haveSpacesBeforeFireChar_spaceAreRemoved(t *testing.T) { tests := testutils.ConversionTests{ { // simple spaces In: ` a `, Want: `a `, }, { // tabs In: ` a `, Want: `a `, }, { // newline spaces In: ` <li>Services\EntityService.cs</li> <li>Services\GameService.cs</li> <li>Services\IEntityService.cs</li> <li>Services\PlayerService.cs</li> `, Want: ` <li>Services\EntityService.cs</li> <li>Services\GameService.cs</li> <li>Services\IEntityService.cs</li> <li>Services\PlayerService.cs</li> `, }, { // newline tabs In: ` <li>Services\EntityService.cs</li> <li>Services\GameService.cs</li> <li>Services\IEntityService.cs</li> <li>Services\PlayerService.cs</li> `, Want: ` <li>Services\EntityService.cs</li> <li>Services\GameService.cs</li> <li>Services\IEntityService.cs</li> <li>Services\PlayerService.cs</li> `, }, } for _, test := range tests { got := LeadingSpaces(test.In) if !reflect.DeepEqual(test.Want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall LeadingSpaces(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.In, test.Want, got) t.FailNow() } } testutils.Cleanup() }
func runIntegrationTestsAndCleanup(tests IntegrationTests, shouldCleanup bool) error { err := runIntegrationTests(tests) if err != nil { return err } if shouldCleanup && err == nil { testutils.Cleanup() } return nil }
func Test_LinesAboveTextWidthLimit(t *testing.T) { tests := []struct { in string want int }{ { in: `test`, want: 0, }, { in: ` test adfas asj sadf jsadf jasdfj asdf jsad f test asdf sdf sadf sdf sdf sadffdf ksadf sdsss`, want: 1, }, { in: `test test sd dddddddddddd`, want: 1, }, { in: `test1 test2 test3 test4`, want: 0, }, { in: "", want: 0, }, { in: `Set<Box> hasBlueShape = shapes.stream() .filter(s -> s.getColor() == BLUE) .map(s -> s.getContainingBox()) .collect(Collectors.toSet());`, want: 3, }, { // long line counts as multiple overline as it is broken mult times in: `1 2 test adfas asj sadf jsadf jasdfj asdf jsad 3 test adfas asj sadf jsadf jasdfj asdf jsad 4 test asdf sdf sadf sdf sdf sadffdf ksadf sdsss 5 test asdf sdf sadf sdf sdf sadffdf ksadf sdsss 6 test asdf sdf sadf sdf sdf sadffdf ksadf sdsss`, want: 5, }, } for _, test := range tests { got := LinesAboveTextWidthLimit(test.in) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall LinesAboveTextWidthLimit(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_createValidImgUrl(t *testing.T) { bbgUrl, _ := url.Parse("http://www.bloomberg.com/graphics/2015-paul-ford-what-is-code/") slateUrl, _ := url.Parse("http://www.slate.com/articles/technology/bitwise/2015/08/windows_10_privacy_problems_here_s_how_bad_they_are_and_how_to_plug_them.html") fowlerUrl, _ := url.Parse("http://martinfowler.com/eaaDev/uiArchs.html") type inputs struct { link string articleUrl *url.URL } tests := []struct { in inputs want string }{ { in: inputs{ link: "images/sec1_conference04.jpg", articleUrl: bbgUrl, }, want: "http://www.bloomberg.com/graphics/2015-paul-ford-what-is-code/images/sec1_conference04.jpg", }, { in: inputs{ link: "uiArchs/formsAndControls-cd.gif", articleUrl: fowlerUrl, }, want: "http://martinfowler.com/eaaDev/uiArchs/formsAndControls-cd.gif", }, { in: inputs{ link: "uiArchs/assessmentUI.gif", articleUrl: fowlerUrl, }, want: "http://martinfowler.com/eaaDev/uiArchs/assessmentUI.gif", }, { in: inputs{ link: "/content/dam/slate/articles/technology/bitwise/2015/08/150803_BIT_Windows10-10.png.CROP.original-original.png", articleUrl: slateUrl, }, want: "http://www.slate.com/content/dam/slate/articles/technology/bitwise/2015/08/150803_BIT_Windows10-10.png.CROP.original-original.png", }, } for _, test := range tests { got := createValidImgUrl(test.in.link, test.in.articleUrl) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall createValidImgUrl(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_TrailingSpaces_haveSpacesBeforeLinebreaks_spaceAreRemoved(t *testing.T) { tests := testutils.ConversionTests{ { In: `a b c d e `, Want: `a b c d e `, }, } for _, test := range tests { got := TrailingSpaces(test.In) if !reflect.DeepEqual(test.Want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall TrailingSpaces(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.In, test.Want, got) t.FailNow() } } testutils.Cleanup() }
func Test_PercentOfLinesOverLimit(t *testing.T) { tests := []struct { in string want float64 }{ { in: `test`, want: 0, }, { in: `1 2 test adfas asj sadf jsadf jasdfj asdf jsad 3 test adfas asj sadf jsadf jasdfj asdf jsad 4 test asdf sdf sadf sdf sdf sadffdf ksadf sdsss 5 test asdf sdf sadf sdf sdf sadffdf ksadf sdsss 6 test asdf sdf sadf sdf sdf sadffdf ksadf sdsss`, want: 0.5, }, { in: `test test sd dddddddddddd`, want: 0.5, }, { in: `test1 test2 test3 test4`, want: 0., }, { in: "", want: 0., }, } for _, test := range tests { got := PercentOfLinesOverLimit(test.in) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall PercenttOfLinesAreOverLimit(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_prefixWithFullArticleUrl(t *testing.T) { bbgUrl, _ := url.Parse("http://www.bloomberg.com/graphics/2015-paul-ford-what-is-code/") type inputs struct { link string articleUrl url.URL } tests := []struct { in inputs want string }{ { in: inputs{ link: "images/sec1_conference04.jpg", articleUrl: *bbgUrl, }, want: "http://www.bloomberg.com/graphics/2015-paul-ford-what-is-code/images/sec1_conference04.jpg", }, //{ // in: inputs{ // link: "images/sec1_conference04.jpg", // articleUrl: nil, // }, // want: "", //}, //{ // in: inputs{ // link: "", // articleUrl: bbgUrl2, // }, // want: "", //}, } for _, test := range tests { got := prefixWithFullArticleUrl(test.in.link, test.in.articleUrl) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall prefixWithfullArticleUrl(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_LinebreaksToTwoLinebreaks_haveMultipleLinebreaks_reducedToTwoLinebreaks(t *testing.T) { tests := testutils.ConversionTests{ { In: `a b c d e `, Want: `a b c d e `, }, } for _, test := range tests { got := LinebreaksToTwoLinebreaks(test.In) if !reflect.DeepEqual(test.Want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall LineBreaks(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.In, test.Want, got) t.FailNow() } } testutils.Cleanup() }
func Test_imageURLisValid(t *testing.T) { tests := []struct { in string want bool }{ { in: "https://cdn3.vox-cdn.com", want: false, }, { in: "http://www.spiegel.de", want: false, }, { in: "images/sec1_conference04.jpg", want: false, }, { in: "http://www.slate.com/articles/technology/bitwise/2015/08/windows_10_privacy_problems_here_s_how_bad_they_are_and_how_to_plug_them.html/content/dam/slate/articles/technology/bitwise/2015/08/150803_BIT_Windows10-10.png.CROP.original-original.png", want: false, }, { in: "http://www.slate.com/content/dam/slate/articles/technology/bitwise/2015/08/150803_BIT_Windows10-10.png.CROP.original-original.png", want: true, }, { in: "http://martinfowler.com/eaaDev/uiArchs/formsAndControls-cd.gif", want: true, }, } for _, test := range tests { got := imageURLisValid(test.in) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall imageURLisValid (%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_splitStringIntoLines(t *testing.T) { tests := []struct { in string want []string }{ { in: `test`, want: []string{"test"}, }, { in: "test\ntest", want: []string{"test", "test"}, }, { in: `test test`, want: []string{"test", "test"}, }, { in: `test1 test2 test3 test4`, want: []string{"test1", "test2 test3", "test4"}, }, { in: "", want: []string{}, }, } for _, test := range tests { got := SplitStringIntoLines(test.in) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall splitStringIntoLines(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_removeInvalidURLs(t *testing.T) { bbgUrl, _ := url.Parse("http://www.bloomberg.com/graphics/2015-paul-ford-what-is-code/") slateUrl, _ := url.Parse("http://www.slate.com/articles/technology/bitwise/2015/08/windows_10_privacy_problems_here_s_how_bad_they_are_and_how_to_plug_them.html") type inputs struct { links []string articleUrl *url.URL } tests := []struct { in inputs want []string }{ { in: inputs{ links: []string{"images/sec1_conference04.jpg"}, articleUrl: bbgUrl, }, want: []string{"http://www.bloomberg.com/graphics/2015-paul-ford-what-is-code/images/sec1_conference04.jpg"}, }, { in: inputs{ links: []string{"/content/dam/slate/articles/technology/bitwise/2015/08/150803_BIT_Windows10-10.png.CROP.original-original.png"}, articleUrl: slateUrl, }, want: []string{"http://www.slate.com/content/dam/slate/articles/technology/bitwise/2015/08/150803_BIT_Windows10-10.png.CROP.original-original.png"}, }, } for _, test := range tests { got := removeInvalidURLs(test.in.links, test.in.articleUrl) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall removeInvalidURLs(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_getHeight(t *testing.T) { tests := []struct { in string want string }{ { in: `<html><head></head><body> <p align="center"><img border="0" alt="" src="/pictures/unicode/rose.jpg" width="300" height="225" /></p> </body></html>`, want: "225", }, { in: `<html><head></head><body> <p align="center"><img border="0" alt="" src="/pictures/unicode/rose.jpg" width="300" height="9" /></p> </body></html>`, want: "9", }, { in: `<html><head></head><body> <p align="center"><img border="0" alt="" src="/pictures/unicode/rose.jpg" width="300" /></p> </body></html>`, want: "", }, } for _, test := range tests { doc := newDocFromString(test.in) s := doc.Find("img") got := getHeight(s) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall getHeigth(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_heightIsBelowLimit(t *testing.T) { tests := []struct { in string want bool }{ { in: "225", want: false, }, { in: "9", want: true, }, { in: "-1", want: true, }, { in: "", want: false, }, { in: "a", want: false, }, } for _, test := range tests { got := heightIsBelowLimit(test.in) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall heigthIsBelowLimit(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_imageFile_testReturnedError(t *testing.T) { tisj := testutils.TestImgServer("jpg") defer tisj.Close() tisg := testutils.TestImgServer("gif") defer tisg.Close() type inputs struct { url string nr string } tests := []struct { in inputs want error }{ //{in: inputs{tisg.URL, "1"}, want: fmt.Errorf("unsupported format: gif")}, // test gif -> fail {in: inputs{tisg.URL, "1"}, want: nil}, // test gif -> true (gif is supported now) { // wrong MIME type --> fail // cannot test against testServer as its port in the url is random in: inputs{"https://www.cs.cmu.edu/~chuck/jokepg/joke_19970213_01.txt#", "1"}, want: fmt.Errorf("has NOT mime content-type image")}, // test txt -> fail { // invalid url, get error from fetch(url) // cannot test against testServer as its port in the url is random in: inputs{"invalidURL", "1"}, want: fmt.Errorf("fetch: Get invalidURL: unsupported protocol scheme \"\""), }, {in: inputs{tisj.URL, "1"}, want: nil}, // test jpeg -> ok } for _, test := range tests { _, got := imageFile(test.in.url) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall imageFile(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got.Error()) t.FailNow() } } testutils.Cleanup() }
func Test_EmptyBrackets_haveMultilinedEmptyBrackets_spaceAndNewlinesAreRemoved(t *testing.T) { tests := testutils.ConversionTests{ { In: `\emph{ }`, Want: `\emph{}`, }, } for _, test := range tests { got := EmptyBrackets(test.In) if !reflect.DeepEqual(test.Want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall EmptyBrackets(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.In, test.Want, got) t.FailNow() } } testutils.Cleanup() }
func Test_base(t *testing.T) { tests := []struct { in string want string }{ { in: "/home/frank/rol/970160665.jpeg", want: "970160665", }, } for _, test := range tests { got := base(test.in) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall base (%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_guessSourceURL(t *testing.T) { tests := []struct { in string want string }{ { in: `<html><head></head><body> <p><figure class="e-image"> <span style="'position:relative;'"> <img alt="operationslog" class="vox-lazy-load m-chorus-asset__in-entry-body" data-chorus-asset-id="671860" data-full-size="https://cdn2.vox-cdn.com/thumbor/kA3aLNmpDy8TZ2IOMGh1ysvmi-4=/cdn0.vox-cdn.com/uploads/chorus_asset/file/671860/Hello_lovely_sloggers_watermarked.0.jpg" data-original="https://cdn3.vox-cdn.com/uploads/chorus_asset/file/671860/Hello_lovely_sloggers_watermarked.0.jpg" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="> <noscript> <img alt="operationslog" src="https://cdn2.vox-cdn.com/thumbor/kA3aLNmpDy8TZ2IOMGh1ysvmi-4=/cdn0.vox-cdn.com/uploads/chorus_asset/file/671860/Hello_lovely_sloggers_watermarked.0.jpg"> </noscript> </span> </figure> </p> </body></html>`, want: "https://cdn2.vox-cdn.com/thumbor/kA3aLNmpDy8TZ2IOMGh1ysvmi-4=/cdn0.vox-cdn.com/uploads/chorus_asset/file/671860/Hello_lovely_sloggers_watermarked.0.jpg", }, } for _, test := range tests { node, _ := html.Parse(strings.NewReader(test.in)) doc := goquery.NewDocumentFromNode(node) s := doc.Find("img") got := guessSourceURL(s, nil) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall guessSourceURL(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, s, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_extractCodeLang(t *testing.T) { tests := []struct { in string want string }{ {in: "C", want: "c"}, {in: "brush: csharp; html: collapse;", want: "[Sharp]c"}, {in: "cpp", want: "c++"}, {in: "Pyhton", want: ""}, // wrong spelling {in: "smalltalk", want: ""}, // not supported } for _, test := range tests { got := extractCodeLang(test.in) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall guessCodeLang(%#v):\n\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }
func Test_moreThanXPercentPercentOfLinesOverLimit(t *testing.T) { type inputs struct { percent float64 code string } tests := []struct { in inputs want bool }{ { in: inputs{ percent: 0.50, code: `test`, }, want: false, }, { in: inputs{ percent: 0.5, code: `1 2 test adfas asj sadf jsadf jasdfj asdf jsad 3 test adfas asj sadf jsadf jasdfj asdf jsad 4 test asdf sdf sadf sdf sdf sadffdf ksadf sdsss 5 test asdf sdf sadf sdf sdf sadffdf ksadf sdsss 6 test asdf sdf sadf sdf sdf sadffdf ksadf sdsss 7 test asdf sdf sadf sdf sdf sadffdf ksadf sdsss`, }, want: true, }, { in: inputs{ percent: 0.25, code: `test test test test sd dddddddddddd`, }, want: true, }, { in: inputs{ percent: 1.0, code: `test1 test2 test3 test4`, }, want: false, }, { in: inputs{ percent: 0.01, code: "", }, want: false, }, { in: inputs{ percent: 0.0, code: "", }, want: true, }, { in: inputs{ percent: 0.25, code: `Set<Box> hasBlueShape = shapes.stream() .filter(s -> s.getColor() == BLUE) .map(s -> s.getContainingBox()) .collect(Collectors.toSet());`, }, want: true, }, { in: inputs{ percent: 0.25, code: `interface User { String name(); Address address(); BankAccount account(); }`, }, want: false, }, } for _, test := range tests { got := moreThanXPercentOfLinesOverLimit(test.in.percent, test.in.code) if !reflect.DeepEqual(test.want, got) { _, file, line, _ := runtime.Caller(0) fmt.Printf("%s:%d:\n\ncall moreThanXPercentOfLinesOverLimit (%#v)\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, test.in, test.want, got) t.FailNow() } } testutils.Cleanup() }