-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
223 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,78 @@ | ||
package common | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
c "github.com/gookit/color" | ||
) | ||
|
||
func TestEnableColorize(t *testing.T) { | ||
os.Setenv(RrhConfigPath, "../testdata/config.json") | ||
var config = OpenConfig() | ||
config.Update(RrhEnableColorized, "true") | ||
var cs = InitializeColor(config) | ||
|
||
var boolTrue1 = cs.ColorizedBool("true") | ||
var boolTrueWont = c.FgGreen.Render("true") | ||
if boolTrue1 != boolTrueWont { | ||
t.Errorf("bool true did not match: wont: %s, got: %s", boolTrue1, boolTrueWont) | ||
} | ||
|
||
cs.SetColorize(false) | ||
var boolTrue2 = cs.ColorizedBool("true") | ||
if boolTrue2 != "true" { | ||
t.Errorf("bool true did not match: wont: %s, got: %s", boolTrue2, "true") | ||
} | ||
|
||
cs.SetColorize(true) | ||
var boolTrue3 = cs.ColorizedBool("true") | ||
if boolTrue3 != boolTrueWont { | ||
t.Errorf("bool true did not match: wont: %s, got: %s", boolTrue3, boolTrueWont) | ||
} | ||
cs.ClearColorize() | ||
} | ||
|
||
func TestParse(t *testing.T) { | ||
var testcases = []struct { | ||
givenString string | ||
repoColor string | ||
groupColor string | ||
labelColor string | ||
wontRepo string | ||
wontGroup string | ||
wontLabel string | ||
givenString string | ||
repoColor string | ||
groupColor string | ||
labelColor string | ||
boolTrueColor string | ||
boolFalseColor string | ||
wontRepo string | ||
wontGroup string | ||
wontLabel string | ||
wontBoolTrue string | ||
wontBoolFalse string | ||
}{ | ||
{"repository:fg=white;op=bold,underscore", "37;1;4", "", "", c.Style{c.FgWhite, c.Bold, c.OpUnderscore}.Render("repository"), "groupName", "label"}, | ||
{"group: fg=red+repository:fg=white;op=bold,underscore", "37;1;4", "31", "", c.Style{c.FgWhite, c.Bold, c.OpUnderscore}.Render("repository"), c.FgRed.Render("groupName"), "label"}, | ||
{"group: fg=red+group: fg=blue+label:op=bold", "", "34", "1", "repository", c.FgBlue.Render("groupName"), c.Bold.Render("label")}, | ||
{"repository:fg=white;op=bold,underscore", "37;1;4", "", "", "", "", c.Style{c.FgWhite, c.Bold, c.OpUnderscore}.Render("repository"), "groupName", "label", "true", "false"}, | ||
{"group: fg=red+repository:fg=white;op=bold,underscore", "37;1;4", "31", "", "", "", c.Style{c.FgWhite, c.Bold, c.OpUnderscore}.Render("repository"), c.FgRed.Render("groupName"), "label", "true", "false"}, | ||
{"group: fg=red+group: fg=blue+label:op=bold", "", "34", "1", "", "", "repository", c.FgBlue.Render("groupName"), c.Bold.Render("label"), "true", "false"}, | ||
{"boolTrue: fg=green+boolFalse: fg=blue", "", "", "", "32", "34", "repository", "groupName", "label", c.FgGreen.Render("true"), c.FgBlue.Render("false")}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
parse(tc.givenString) | ||
if repoColor != tc.repoColor { | ||
t.Errorf("%v: repo color did not match, wont: %s, got: %s", tc.givenString, tc.repoColor, repoColor) | ||
} | ||
if groupColor != tc.groupColor { | ||
t.Errorf("%v: group color did not match, wont: %s, got: %s", tc.givenString, tc.groupColor, groupColor) | ||
var cs = Color{settings: colorSettings{}, funcs: colorFuncs{}} | ||
cs.parse(tc.givenString) | ||
if v, ok := cs.settings["repository"]; !ok || v != tc.repoColor { | ||
t.Errorf("%v: repo color did not match, wont: %s, got: %s", tc.givenString, tc.repoColor, v) | ||
} | ||
if groupColor != tc.groupColor { | ||
t.Errorf("%v: group color did not match, wont: %s, got: %s", tc.givenString, tc.groupColor, groupColor) | ||
if v, ok := cs.settings["group"]; !ok || v != tc.groupColor { | ||
t.Errorf("%v: group color did not match, wont: %s, got: %s", tc.givenString, tc.groupColor, v) | ||
} | ||
if labelColor != tc.labelColor { | ||
t.Errorf("%v: label color did not match, wont: %s, got: %s", tc.givenString, tc.labelColor, labelColor) | ||
if v, ok := cs.settings["label"]; !ok || v != tc.labelColor { | ||
t.Errorf("%v: label color did not match, wont: %s, got: %s", tc.givenString, tc.labelColor, v) | ||
} | ||
if name := ColorizedRepositoryID("repository"); name != tc.wontRepo { | ||
if name := cs.ColorizedRepositoryID("repository"); name != tc.wontRepo { | ||
t.Errorf("repository id did not match: wont: %s, got: %s", tc.wontRepo, name) | ||
} | ||
if name := ColorizedGroupName("groupName"); name != tc.wontGroup { | ||
if name := cs.ColorizedGroupName("groupName"); name != tc.wontGroup { | ||
t.Errorf("group name did not match: wont: %s, got: %s", tc.wontGroup, name) | ||
} | ||
if name := ColorizedLabel("label"); name != tc.wontLabel { | ||
if name := cs.ColorizedLabel("label"); name != tc.wontLabel { | ||
t.Errorf("label did not match: wont: %s, got: %s", tc.wontLabel, name) | ||
} | ||
ClearColorize() | ||
} | ||
} |
Oops, something went wrong.