8000 color/color_test.go at master · slrem/color · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
{"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"vendor","path":"vendor","contentType":"directory"},{"name":".travis.yml","path":".travis.yml","contentType":"file"},{"name":"LICENSE.md","path":"LICENSE.md","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"color.go","path":"color.go","contentType":"file"},{"name":"color_test.go","path":"color_test.go","contentType":"file"},{"name":"doc.go","path":"doc.go","contentType":"file"}],"totalCount":7}},"fileTreeProcessingTime":7.475858000000001,"foldersToFetch":[],"incompleteFileTree":false,"repo":{"id":117952236,"defaultBranch":"master","name":"color","ownerLogin":"slrem","currentUserCanPush":false,"isFork":true,"isEmpty":false,"createdAt":"2018-01-18T08:06:27.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/31646684?v=4","public":true,"private":false,"isOrgOwned":false},"codeLineWrapEnabled":false,"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"master","listCacheKey":"v0:1614238701.542551","canEdit":false,"refType":"branch","currentOid":"5df930a27be2502f99b292b7cc09ebad4d0891f4"},"path":"color_test.go","currentUser":null,"blob":{"rawLines":["package color","","import (","\t\"bytes\"","\t\"fmt\"","\t\"os\"","\t\"testing\"","","\t\"github.com/mattn/go-colorable\"",")","","// Testing colors is kinda different. First we test for given colors and their","// escaped formatted results. Next we create some visual tests to be tested.","// Each visual test includes the color name to be compared.","func TestColor(t *testing.T) {","\trb := new(bytes.Buffer)","\tOutput = rb","","\tNoColor = false","","\ttestColors := []struct {","\t\ttext string","\t\tcode Attribute","\t}{","\t\t{text: \"black\", code: FgBlack},","\t\t{text: \"red\", code: FgRed},","\t\t{text: \"green\", code: FgGreen},","\t\t{text: \"yellow\", code: FgYellow},","\t\t{text: \"blue\", code: FgBlue},","\t\t{text: \"magent\", code: FgMagenta},","\t\t{text: \"cyan\", code: FgCyan},","\t\t{text: \"white\", code: FgWhite},","\t\t{text: \"hblack\", code: FgHiBlack},","\t\t{text: \"hred\", code: FgHiRed},","\t\t{text: \"hgreen\", code: FgHiGreen},","\t\t{text: \"hyellow\", code: FgHiYellow},","\t\t{text: \"hblue\", code: FgHiBlue},","\t\t{text: \"hmagent\", code: FgHiMagenta},","\t\t{text: \"hcyan\", code: FgHiCyan},","\t\t{text: \"hwhite\", code: FgHiWhite},","\t}","","\tfor _, c := range testColors {","\t\tNew(c.code).Print(c.text)","","\t\tline, _ := rb.ReadString('\\n')","\t\tscannedLine := fmt.Sprintf(\"%q\", line)","\t\tcolored := fmt.Sprintf(\"\\x1b[%dm%s\\x1b[0m\", c.code, c.text)","\t\tescapedForm := fmt.Sprintf(\"%q\", colored)","","\t\tfmt.Printf(\"%s\\t: %s\\n\", c.text, line)","","\t\tif scannedLine != escapedForm {","\t\t\tt.Errorf(\"Expecting %s, got '%s'\\n\", escapedForm, scannedLine)","\t\t}","\t}","","\tfor _, c := range testColors {","\t\tline := New(c.code).Sprintf(\"%s\", c.text)","\t\tscannedLine := fmt.Sprintf(\"%q\", line)","\t\tcolored := fmt.Sprintf(\"\\x1b[%dm%s\\x1b[0m\", c.code, c.text)","\t\tescapedForm := fmt.Sprintf(\"%q\", colored)","","\t\tfmt.Printf(\"%s\\t: %s\\n\", c.text, line)","","\t\tif scannedLine != escapedForm {","\t\t\tt.Errorf(\"Expecting %s, got '%s'\\n\", escapedForm, scannedLine)","\t\t}","\t}","}","","func TestColorEquals(t *testing.T) {","\tfgblack1 := New(FgBlack)","\tfgblack2 := New(FgBlack)","\tbgblack := New(BgBlack)","\tfgbgblack := New(FgBlack, BgBlack)","\tfgblackbgred := New(FgBlack, BgRed)","\tfgred := New(FgRed)","\tbgred := New(BgRed)","","\tif !fgblack1.Equals(fgblack2) {","\t\tt.Error(\"Two black colors are not equal\")","\t}","","\tif fgblack1.Equals(bgblack) {","\t\tt.Error(\"Fg and bg black colors are equal\")","\t}","","\tif fgblack1.Equals(fgbgblack) {","\t\tt.Error(\"Fg black equals fg/bg black color\")","\t}","","\tif fgblack1.Equals(fgred) {","\t\tt.Error(\"Fg black equals Fg red\")","\t}","","\tif fgblack1.Equals(bgred) {","\t\tt.Error(\"Fg black equals Bg red\")","\t}","","\tif fgblack1.Equals(fgblackbgred) {","\t\tt.Error(\"Fg black equals fg black bg red\")","\t}","}","","func TestNoColor(t *testing.T) {","\trb := new(bytes.Buffer)","\tOutput = rb","","\ttestColors := []struct {","\t\ttext string","\t\tcode Attribute","\t}{","\t\t{text: \"black\", code: FgBlack},","\t\t{text: \"red\", code: FgRed},","\t\t{text: \"green\", code: FgGreen},","\t\t{text: \"yellow\", code: FgYellow},","\t\t{text: \"blue\", code: FgBlue},","\t\t{text: \"magent\", code: FgMagenta},","\t\t{text: \"cyan\", code: FgCyan},","\t\t{text: \"white\", code: FgWhite},","\t\t{text: \"hblack\", code: FgHiBlack},","\t\t{text: \"hred\", code: FgHiRed},","\t\t{text: \"hgreen\", code: FgHiGreen},","\t\t{text: \"hyellow\", code: FgHiYellow},","\t\t{text: \"hblue\", code: FgHiBlue},","\t\t{text: \"hmagent\", code: FgHiMagenta},","\t\t{text: \"hcyan\", code: FgHiCyan},","\t\t{text: \"hwhite\", code: FgHiWhite},","\t}","","\tfor _, c := range testColors {","\t\tp := New(c.code)","\t\tp.DisableColor()","\t\tp.Print(c.text)","","\t\tline, _ := rb.ReadString('\\n')","\t\tif line != c.text {","\t\t\tt.Errorf(\"Expecting %s, got '%s'\\n\", c.text, line)","\t\t}","\t}","","\t// global check","\tNoColor = true","\tdefer func() {","\t\tNoColor = false","\t}()","\tfor _, c := range testColors {","\t\tp := New(c.code)","\t\tp.Print(c.text)","","\t\tline, _ := rb.ReadString('\\n')","\t\tif line != c.text {","\t\t\tt.Errorf(\"Expecting %s, got '%s'\\n\", c.text, line)","\t\t}","\t}","","}","","func TestColorVisual(t *testing.T) {","\t// First Visual Test","\tOutput = colorable.NewColorableStdout()","","\tNew(FgRed).Printf(\"red\\t\")","\tNew(BgRed).Print(\" \")","\tNew(FgRed, Bold).Println(\" red\")","","\tNew(FgGreen).Printf(\"green\\t\")","\tNew(BgGreen).Print(\" \")","\tNew(FgGreen, Bold).Println(\" green\")","","\tNew(FgYellow).Printf(\"yellow\\t\")","\tNew(BgYellow).Print(\" \")","\tNew(FgYellow, Bold).Println(\" yellow\")","","\tNew(FgBlue).Printf(\"blue\\t\")","\tNew(BgBlue).Print(\" \")","\tNew(FgBlue, Bold).Println(\" blue\")","","\tNew(FgMagenta).Printf(\"magenta\\t\")","\tNew(BgMagenta).Print(\" \")","\tNew(FgMagenta, Bold).Println(\" magenta\")","","\tNew(FgCyan).Printf(\"cyan\\t\")","\tNew(BgCyan).Print(\" \")","\tNew(FgCyan, Bold).Println(\" cyan\")","","\tNew(FgWhite).Printf(\"white\\t\")","\tNew(BgWhite).Print(\" \")","\tNew(FgWhite, Bold).Println(\" white\")","\tfmt.Println(\"\")","","\t// Second Visual test","\tBlack(\"black\")","\tRed(\"red\")","\tGreen(\"green\")","\tYellow(\"yellow\")","\tBlue(\"blue\")","\tMagenta(\"magenta\")","\tCyan(\"cyan\")","\tWhite(\"white\")","\tHiBlack(\"hblack\")","\tHiRed(\"hred\")","\tHiGreen(\"hgreen\")","\tHiYellow(\"hyellow\")","\tHiBlue(\"hblue\")","\tHiMagenta(\"hmagenta\")","\tHiCyan(\"hcyan\")","\tHiWhite(\"hwhite\")","","\t// Third visual test","\tfmt.Println()","\tSet(FgBlue)","\tfmt.Println(\"is this blue?\")","\tUnset()","","\tSet(FgMagenta)","\tfmt.Println(\"and this magenta?\")","\tUnset()","","\t// Fourth Visual test","\tfmt.Println()","\tblue := New(FgBlue).PrintlnFunc()","\tblue(\"blue text with custom print func\")","","\tred := New(FgRed).PrintfFunc()","\tred(\"red text with a printf func: %d\\n\", 123)","","\tput := New(FgYellow).SprintFunc()","\twarn := New(FgRed).SprintFunc()","","\tfmt.Fprintf(Output, \"this is a %s and this is %s.\\n\", put(\"warning\"), warn(\"error\"))","","\tinfo := New(FgWhite, BgGreen).SprintFunc()","\tfmt.Fprintf(Output, \"this %s rocks!\\n\", info(\"package\"))","","\tnotice := New(FgBlue).FprintFunc()","\tnotice(os.Stderr, \"just a blue notice to stderr\")","","\t// Fifth Visual Test","\tfmt.Println()","","\tfmt.Fprintln(Output, BlackString(\"black\"))","\tfmt.Fprintln(Output, RedString(\"red\"))","\tfmt.Fprintln(Output, GreenString(\"green\"))","\tfmt.Fprintln(Output, YellowString(\"yellow\"))","\tfmt.Fprintln(Output, BlueString(\"blue\"))","\tfmt.Fprintln(Output, MagentaString(\"magenta\"))","\tfmt.Fprintln(Output, CyanString(\"cyan\"))","\tfmt.Fprintln(Output, WhiteString(\"white\"))","\tfmt.Fprintln(Output, HiBlackString(\"hblack\"))","\tfmt.Fprintln(Output, HiRedString(\"hred\"))","\tfmt.Fprintln(Output, HiGreenString(\"hgreen\"))","\tfmt.Fprintln(Output, HiYellowString(\"hyellow\"))","\tfmt.Fprintln(Output, HiBlueString(\"hblue\"))","\tfmt.Fprintln(Output, HiMagentaString(\"hmagenta\"))","\tfmt.Fprintln(Output, HiCyanString(\"hcyan\"))","\tfmt.Fprintln(Output, HiWhiteString(\"hwhite\"))","}","","func TestNoFormat(t *testing.T) {","\tfmt.Printf(\"%s %%s = \", BlackString(\"Black\"))","\tBlack(\"%s\")","","\tfmt.Printf(\"%s %%s = \", RedString(\"Red\"))","\tRed(\"%s\")","","\tfmt.Printf(\"%s %%s = \", GreenString(\"Green\"))","\tGreen(\"%s\")","","\tfmt.Printf(\"%s %%s = \", YellowString(\"Yellow\"))","\tYellow(\"%s\")","","\tfmt.Printf(\"%s %%s = \", BlueString(\"Blue\"))","\tBlue(\"%s\")","","\tfmt.Printf(\"%s %%s = \", MagentaString(\"Magenta\"))","\tMagenta(\"%s\")","","\tfmt.Printf(\"%s %%s = \", CyanString(\"Cyan\"))","\tCyan(\"%s\")","","\tfmt.Printf(\"%s %%s = \", WhiteString(\"White\"))","\tWhite(\"%s\")","","\tfmt.Printf(\"%s %%s = \", HiBlackString(\"HiBlack\"))","\tHiBlack(\"%s\")","","\tfmt.Printf(\"%s %%s = \", HiRedString(\"HiRed\"))","\tHiRed(\"%s\")","","\tfmt.Printf(\"%s %%s = \", HiGreenString(\"HiGreen\"))","\tHiGreen(\"%s\")","","\tfmt.Printf(\"%s %%s = \", HiYellowString(\"HiYellow\"))","\tHiYellow(\"%s\")","","\tfmt.Printf(\"%s %%s = \", HiBlueString(\"HiBlue\"))","\tHiBlue(\"%s\")","","\tfmt.Printf(\"%s %%s = \", HiMagentaString(\"HiMagenta\"))","\tHiMagenta(\"%s\")","","\tfmt.Printf(\"%s %%s = \", HiCyanString(\"HiCyan\"))","\tHiCyan(\"%s\")","","\tfmt.Printf(\"%s %%s = \", HiWhiteString(\"HiWhite\"))","\tHiWhite(\"%s\")","}","","func TestNoFormatString(t *testing.T) {","\ttests := []struct {","\t\tf func(string, ...interface{}) string","\t\tformat string","\t\targs []interface{}","\t\twant string","\t}{","\t\t{BlackString, \"%s\", nil, \"\\x1b[30m%s\\x1b[0m\"},","\t\t{RedString, \"%s\", nil, \"\\x1b[31m%s\\x1b[0m\"},","\t\t{GreenString, \"%s\", nil, \"\\x1b[32m%s\\x1b[0m\"},","\t\t{YellowString, \"%s\", nil, \"\\x1b[33m%s\\x1b[0m\"},","\t\t{BlueString, \"%s\", nil, \"\\x1b[34m%s\\x1b[0m\"},","\t\t{MagentaString, \"%s\", nil, \"\\x1b[35m%s\\x1b[0m\"},","\t\t{CyanString, \"%s\", nil, \"\\x1b[36m%s\\x1b[0m\"},","\t\t{WhiteString, \"%s\", nil, \"\\x1b[37m%s\\x1b[0m\"},","\t\t{HiBlackString, \"%s\", nil, \"\\x1b[90m%s\\x1b[0m\"},","\t\t{HiRedString, \"%s\", nil, \"\\x1b[91m%s\\x1b[0m\"},","\t\t{HiGreenString, \"%s\", nil, \"\\x1b[92m%s\\x1b[0m\"},","\t\t{HiYellowString, \"%s\", nil, \"\\x1b[93m%s\\x1b[0m\"},","\t\t{HiBlueString, \"%s\", nil, \"\\x1b[94m%s\\x1b[0m\"},","\t\t{HiMagentaString, \"%s\", nil, \"\\x1b[95m%s\\x1b[0m\"},","\t\t{HiCyanString, \"%s\", nil, \"\\x1b[96m%s\\x1b[0m\"},","\t\t{HiWhiteString, \"%s\", nil, \"\\x1b[97m%s\\x1b[0m\"},","\t}","","\tfor i, test := range tests {","\t\ts := fmt.Sprintf(\"%s\", test.f(test.format, test.args...))","\t\tif s != test.want {","\t\t\tt.Errorf(\"[%d] want: %q, got: %q\", i, test.want, s)","\t\t}","\t}","}"],"stylingDirectives":null,"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/slrem/color/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"color_test.go","displayUrl":"https://github.com/slrem/color/blob/master/color_test.go?raw=true","headerInfo":{"blobSize":"8.29 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":"https://desktop.github.com","isGitLfs":false,"onBranch":true,"shortPath":"a8ed14f","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Fslrem%2Fcolor%2Fblob%2Fmaster%2Fcolor_test.go","isCSV":false,"isRichtext":false,"toc":null,"lineInfo":{"truncatedLoc":"342","truncatedSloc":"279"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"Go","languageID":132,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/slrem/color/blob/master/color_test.go","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/slrem/color/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/slrem/color/raw/refs/heads/master/color_test.go","renderImageOrRaw":false,"richText":null,"renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":8,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":null,"showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":null},"copilotInfo":null,"copilotAccessAllowed":false,"modelsAccessAllowed":false,"modelsRepoIntegrationEnabled":false,"isMarketplaceEnabled":true,"csrf_tokens":{"/slrem/color/branches":{"post":"029sCUE0UlMNI5Ai6-LA60BM3aFEUp7NMMOceZqUHXfQXTVRWxuPV4T2d7D9hfxQFl6gYUh4eOVCsfALzQQFLw"},"/repos/preferences":{"post":"heu0QCbpgH5AEejO5Zd4MQJrj_k8VqBxaRNd5oWTAHN0iTAzPUbuWDQuHSYOs3WwU1jXI79dVR6RhpXTla2gww"}}},"title":"color/color_test.go at master · slrem/color","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-263cab1760dd.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-98e6e9db3609.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true}}}
0