mirror of
https://github.com/go-task/task.git
synced 2025-06-23 00:38:19 +02:00
feat: better functional options for reader (#2148)
This commit is contained in:
@ -31,8 +31,8 @@ func TestNewSnippet(t *testing.T) {
|
||||
name: "first line, first column",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(1),
|
||||
SnippetWithColumn(1),
|
||||
WithLine(1),
|
||||
WithColumn(1),
|
||||
},
|
||||
want: &Snippet{
|
||||
linesRaw: []string{
|
||||
@ -52,9 +52,9 @@ func TestNewSnippet(t *testing.T) {
|
||||
name: "first line, first column, padding=2",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(1),
|
||||
SnippetWithColumn(1),
|
||||
SnippetWithPadding(2),
|
||||
WithLine(1),
|
||||
WithColumn(1),
|
||||
WithPadding(2),
|
||||
},
|
||||
want: &Snippet{
|
||||
linesRaw: []string{
|
||||
@ -96,8 +96,8 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "empty",
|
||||
b: []byte{},
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(1),
|
||||
SnippetWithColumn(1),
|
||||
WithLine(1),
|
||||
WithColumn(1),
|
||||
},
|
||||
want: "",
|
||||
},
|
||||
@ -110,7 +110,7 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "1st line, 0th column (line indicator only)",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(1),
|
||||
WithLine(1),
|
||||
},
|
||||
want: "> 1 | \x1b[33mversion\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36m3\x1b[0m\x1b[1m\x1b[30m\x1b[0m",
|
||||
},
|
||||
@ -118,7 +118,7 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "0th line, 1st column (column indicator only)",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithColumn(1),
|
||||
WithColumn(1),
|
||||
},
|
||||
want: "",
|
||||
},
|
||||
@ -126,8 +126,8 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "0th line, 1st column, padding=2 (column indicator only)",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithColumn(1),
|
||||
SnippetWithPadding(2),
|
||||
WithColumn(1),
|
||||
WithPadding(2),
|
||||
},
|
||||
want: " 1 | \x1b[33mversion\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36m3\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 2 | \x1b[1m\x1b[30m\x1b[0m\n | ^",
|
||||
},
|
||||
@ -135,8 +135,8 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "1st line, 1st column",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(1),
|
||||
SnippetWithColumn(1),
|
||||
WithLine(1),
|
||||
WithColumn(1),
|
||||
},
|
||||
want: "> 1 | \x1b[33mversion\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36m3\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n | ^",
|
||||
},
|
||||
@ -144,8 +144,8 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "1st line, 10th column",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(1),
|
||||
SnippetWithColumn(10),
|
||||
WithLine(1),
|
||||
WithColumn(10),
|
||||
},
|
||||
want: "> 1 | \x1b[33mversion\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36m3\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n | ^",
|
||||
},
|
||||
@ -153,9 +153,9 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "1st line, 1st column, padding=2",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(1),
|
||||
SnippetWithColumn(1),
|
||||
SnippetWithPadding(2),
|
||||
WithLine(1),
|
||||
WithColumn(1),
|
||||
WithPadding(2),
|
||||
},
|
||||
want: "> 1 | \x1b[33mversion\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36m3\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n | ^\n 2 | \x1b[1m\x1b[30m\x1b[0m\n 3 | \x1b[33mtasks\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m",
|
||||
},
|
||||
@ -163,9 +163,9 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "1st line, 10th column, padding=2",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(1),
|
||||
SnippetWithColumn(10),
|
||||
SnippetWithPadding(2),
|
||||
WithLine(1),
|
||||
WithColumn(10),
|
||||
WithPadding(2),
|
||||
},
|
||||
want: "> 1 | \x1b[33mversion\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36m3\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n | ^\n 2 | \x1b[1m\x1b[30m\x1b[0m\n 3 | \x1b[33mtasks\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m",
|
||||
},
|
||||
@ -173,8 +173,8 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "5th line, 1st column",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(5),
|
||||
SnippetWithColumn(1),
|
||||
WithLine(5),
|
||||
WithColumn(1),
|
||||
},
|
||||
want: "> 5 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mvars\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n | ^",
|
||||
},
|
||||
@ -182,8 +182,8 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "5th line, 5th column",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(5),
|
||||
SnippetWithColumn(5),
|
||||
WithLine(5),
|
||||
WithColumn(5),
|
||||
},
|
||||
want: "> 5 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mvars\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n | ^",
|
||||
},
|
||||
@ -191,9 +191,9 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "5th line, 5th column, padding=2",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(5),
|
||||
SnippetWithColumn(5),
|
||||
SnippetWithPadding(2),
|
||||
WithLine(5),
|
||||
WithColumn(5),
|
||||
WithPadding(2),
|
||||
},
|
||||
want: " 3 | \x1b[33mtasks\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 4 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mdefault\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n> 5 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mvars\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n | ^\n 6 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mFOO\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36mfoo\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 7 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mBAR\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36mbar\x1b[0m\x1b[1m\x1b[30m\x1b[0m",
|
||||
},
|
||||
@ -201,10 +201,10 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "5th line, 5th column, padding=2, no indicators",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(5),
|
||||
SnippetWithColumn(5),
|
||||
SnippetWithPadding(2),
|
||||
SnippetWithNoIndicators(),
|
||||
WithLine(5),
|
||||
WithColumn(5),
|
||||
WithPadding(2),
|
||||
WithNoIndicators(),
|
||||
},
|
||||
want: " 3 | \x1b[33mtasks\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 4 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mdefault\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 5 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mvars\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 6 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mFOO\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36mfoo\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 7 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mBAR\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36mbar\x1b[0m\x1b[1m\x1b[30m\x1b[0m",
|
||||
},
|
||||
@ -212,8 +212,8 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "10th line, 1st column",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(10),
|
||||
SnippetWithColumn(1),
|
||||
WithLine(10),
|
||||
WithColumn(1),
|
||||
},
|
||||
want: "> 10 | \x1b[1m\x1b[30m \x1b[0m\x1b[1m\x1b[30m- \x1b[0m\x1b[36mecho \"{{.BAR}}\"\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n | ^",
|
||||
},
|
||||
@ -221,8 +221,8 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "10th line, 23rd column",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(10),
|
||||
SnippetWithColumn(23),
|
||||
WithLine(10),
|
||||
WithColumn(23),
|
||||
},
|
||||
want: "> 10 | \x1b[1m\x1b[30m \x1b[0m\x1b[1m\x1b[30m- \x1b[0m\x1b[36mecho \"{{.BAR}}\"\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n | ^",
|
||||
},
|
||||
@ -230,8 +230,8 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "10th line, 24th column (out of bounds)",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(10),
|
||||
SnippetWithColumn(24),
|
||||
WithLine(10),
|
||||
WithColumn(24),
|
||||
},
|
||||
want: "> 10 | \x1b[1m\x1b[30m \x1b[0m\x1b[1m\x1b[30m- \x1b[0m\x1b[36mecho \"{{.BAR}}\"\x1b[0m\x1b[1m\x1b[30m\x1b[0m",
|
||||
},
|
||||
@ -239,9 +239,9 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "10th line, 23rd column, padding=2",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(10),
|
||||
SnippetWithColumn(23),
|
||||
SnippetWithPadding(2),
|
||||
WithLine(10),
|
||||
WithColumn(23),
|
||||
WithPadding(2),
|
||||
},
|
||||
want: " 8 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mcmds\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 9 | \x1b[1m\x1b[30m \x1b[0m\x1b[1m\x1b[30m- \x1b[0m\x1b[36mecho \"{{.FOO}}\"\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n> 10 | \x1b[1m\x1b[30m \x1b[0m\x1b[1m\x1b[30m- \x1b[0m\x1b[36mecho \"{{.BAR}}\"\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n | ^",
|
||||
},
|
||||
@ -249,9 +249,9 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "5th line, 5th column, padding=100",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(5),
|
||||
SnippetWithColumn(5),
|
||||
SnippetWithPadding(100),
|
||||
WithLine(5),
|
||||
WithColumn(5),
|
||||
WithPadding(100),
|
||||
},
|
||||
want: " 1 | \x1b[33mversion\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36m3\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 2 | \x1b[1m\x1b[30m\x1b[0m\n 3 | \x1b[33mtasks\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 4 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mdefault\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n> 5 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mvars\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n | ^\n 6 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mFOO\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36mfoo\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 7 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mBAR\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m \x1b[0m\x1b[36mbar\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 8 | \x1b[1m\x1b[30m \x1b[0m\x1b[33mcmds\x1b[0m\x1b[1m\x1b[30m:\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 9 | \x1b[1m\x1b[30m \x1b[0m\x1b[1m\x1b[30m- \x1b[0m\x1b[36mecho \"{{.FOO}}\"\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 10 | \x1b[1m\x1b[30m \x1b[0m\x1b[1m\x1b[30m- \x1b[0m\x1b[36mecho \"{{.BAR}}\"\x1b[0m\x1b[1m\x1b[30m\x1b[0m",
|
||||
},
|
||||
@ -259,8 +259,8 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "11th line (out of bounds), 1st column",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(11),
|
||||
SnippetWithColumn(1),
|
||||
WithLine(11),
|
||||
WithColumn(1),
|
||||
},
|
||||
want: "",
|
||||
},
|
||||
@ -268,9 +268,9 @@ func TestSnippetString(t *testing.T) {
|
||||
name: "11th line (out of bounds), 1st column, padding=2",
|
||||
b: []byte(sample),
|
||||
opts: []SnippetOption{
|
||||
SnippetWithLine(11),
|
||||
SnippetWithColumn(1),
|
||||
SnippetWithPadding(2),
|
||||
WithLine(11),
|
||||
WithColumn(1),
|
||||
WithPadding(2),
|
||||
},
|
||||
want: " 9 | \x1b[1m\x1b[30m \x1b[0m\x1b[1m\x1b[30m- \x1b[0m\x1b[36mecho \"{{.FOO}}\"\x1b[0m\x1b[1m\x1b[30m\x1b[0m\n 10 | \x1b[1m\x1b[30m \x1b[0m\x1b[1m\x1b[30m- \x1b[0m\x1b[36mecho \"{{.BAR}}\"\x1b[0m\x1b[1m\x1b[30m\x1b[0m",
|
||||
},
|
||||
|
Reference in New Issue
Block a user