New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(templatehelper): no styles in Ascii mode #14
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package termenv | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"testing" | ||
"text/template" | ||
) | ||
|
||
func TestTemplateFuncs(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
profile Profile | ||
}{ | ||
{"ascii", Ascii}, | ||
{"ansi", ANSI}, | ||
{"ansi256", ANSI256}, | ||
{"truecolor", TrueColor}, | ||
} | ||
const templateFile = "./testdata/templatehelper.tpl" | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
tpl, err := template.New("templatehelper.tpl").Funcs(TemplateFuncs(test.profile)).ParseFiles(templateFile) | ||
if err != nil { | ||
t.Fatalf("unexpected error parsing template: %v", err) | ||
} | ||
var buf bytes.Buffer | ||
if err = tpl.Execute(&buf, nil); err != nil { | ||
t.Fatalf("unexpected error executing template: %v", err) | ||
} | ||
actual := buf.Bytes() | ||
filename := fmt.Sprintf("./testdata/templatehelper_%s.txt", test.name) | ||
expected, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
t.Fatalf("unexpected error reading golden file %q: %v", filename, err) | ||
} | ||
if !bytes.Equal(buf.Bytes(), expected) { | ||
t.Fatalf("template output does not match golden file.\n--- Expected ---\n%s\n--- Actual ---\n%s\n", string(expected), string(actual)) | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Plain | ||
{{ Color "#ff0000" "Red" }} | ||
{{ Color "#ff0000" "#00ff00" "Red on Blue" }} | ||
{{ Foreground "#00ffff" "Cyan" }} | ||
{{ Background "#ff00ff" "Magenta Bg" }} | ||
{{ Foreground "#00ffff" (Background "#ff00ff" "Cyan on Magenta Bg") }} | ||
{{ Bold "Bold" }} | ||
{{ Faint "Faint" }} | ||
{{ Italic "Italic" }} | ||
{{ Underline "Underline" }} | ||
{{ Overline "Overline" }} | ||
{{ Blink "Blink" }} | ||
{{ Reverse "Reverse" }} | ||
{{ CrossOut "CrossOut" }} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Plain | ||
[91mRed[0m | ||
[91;102mRed on Blue[0m | ||
[96mCyan[0m | ||
[105mMagenta Bg[0m | ||
[96m[105mCyan on Magenta Bg[0m[0m | ||
[1mBold[0m | ||
[2mFaint[0m | ||
[3mItalic[0m | ||
[4mUnderline[0m | ||
[53mOverline[0m | ||
[5mBlink[0m | ||
[7mReverse[0m | ||
[9mCrossOut[0m |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Plain | ||
[38;5;196mRed[0m | ||
[38;5;196;48;5;46mRed on Blue[0m | ||
[38;5;51mCyan[0m | ||
[48;5;201mMagenta Bg[0m | ||
[38;5;51m[48;5;201mCyan on Magenta Bg[0m[0m | ||
[1mBold[0m | ||
[2mFaint[0m | ||
[3mItalic[0m | ||
[4mUnderline[0m | ||
[53mOverline[0m | ||
[5mBlink[0m | ||
[7mReverse[0m | ||
[9mCrossOut[0m |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Plain | ||
Red | ||
Red on Blue | ||
Cyan | ||
Magenta Bg | ||
Cyan on Magenta Bg | ||
Bold | ||
Faint | ||
Italic | ||
Underline | ||
Overline | ||
Blink | ||
Reverse | ||
CrossOut |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Plain | ||
[38;2;255;0;0mRed[0m | ||
[38;2;255;0;0;48;2;0;255;0mRed on Blue[0m | ||
[38;2;0;255;255mCyan[0m | ||
[48;2;255;0;255mMagenta Bg[0m | ||
[38;2;0;255;255m[48;2;255;0;255mCyan on Magenta Bg[0m[0m | ||
[1mBold[0m | ||
[2mFaint[0m | ||
[3mItalic[0m | ||
[4mUnderline[0m | ||
[53mOverline[0m | ||
[5mBlink[0m | ||
[7mReverse[0m | ||
[9mCrossOut[0m |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not the biggest fan of doing this kind of comparison and output in tests, but I didn't want to introduce a test-only dependency unless you're ok with it.
A couple I had in mind to make these sorts of tests more readable/maintainable:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, that's probably a sensible suggestion. I haven't looked into
goldie
yet, but I've usedtestify
before.