-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use COLUMNS env var or dynamic terminal width (up to UIWidth max) - Refresh each time, in case the user’s terminal is resized - Fix #53 (regression since e4e6d44)
- Loading branch information
Showing
6 changed files
with
170 additions
and
3 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
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,25 @@ | ||
-- expected -- | ||
🕛 UTC 00:01, Sun Nov 05, 2017 | ||
🕛 UTC 00:01, Sun Nov 05, 2017 | ||
🕛 UTC 00:01, Sun Nov 05, 2017 | ||
-- observed: narrow -- | ||
|
||
What time is it? | ||
|
||
🕛 UTC 00:01, Sun Nov 05, 2017 | ||
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ||
📆 Sun 05 | ||
-- observed: medium -- | ||
|
||
What time is it? | ||
|
||
🕛 UTC 00:01, Sun Nov 05, 2017 | ||
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ||
📆 Sun 05 | ||
-- observed: wide -- | ||
|
||
What time is it? | ||
|
||
🕛 UTC 00:01, Sun Nov 05, 2017 | ||
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ||
📆 Sun 05 |
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,83 @@ | ||
/** | ||
* This file is part of tz. | ||
* | ||
* tz is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your | ||
* option) any later version. | ||
* | ||
* tz is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with tz. If not, see <https://www.gnu.org/licenses/>. | ||
**/ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
"golang.org/x/tools/txtar" | ||
) | ||
|
||
func TestRightAlignment(t *testing.T) { | ||
testDataFile := "testdata/view/test-right-alignment.txt" | ||
testData, err := txtar.ParseFile(testDataFile) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
expected := stripAnsiControlSequencesAndNewline(testData.Files[0].Data) | ||
|
||
tests := []struct { | ||
columns int | ||
}{ | ||
{columns: 1}, | ||
{columns: 80}, | ||
{columns: 999}, | ||
} | ||
|
||
originalColumns := os.Getenv("COLUMNS") | ||
var observations []string | ||
for _, test := range tests { | ||
os.Setenv("COLUMNS", strconv.Itoa(test.columns)) | ||
observed := stripAnsiControlSequences(utcMinuteAfterMidnightModel.View()) | ||
observations = append(observations, observed) | ||
} | ||
os.Setenv("COLUMNS", originalColumns) | ||
|
||
archive := txtar.Archive{ | ||
Comment: testData.Comment, | ||
Files: []txtar.File{ | ||
{ | ||
Name: "expected", | ||
Data: []byte(expected), | ||
}, | ||
{ | ||
Name: "observed: narrow", | ||
Data: []byte(observations[0]), | ||
}, | ||
{ | ||
Name: "observed: medium", | ||
Data: []byte(observations[1]), | ||
}, | ||
{ | ||
Name: "observed: wide", | ||
Data: []byte(observations[2]), | ||
}, | ||
}, | ||
} | ||
os.WriteFile(testDataFile, txtar.Format(&archive), 0666) | ||
|
||
expectations := strings.Split(expected, "\n") | ||
for i, test := range tests { | ||
if !strings.Contains(observations[i], expectations[i]) { | ||
t.Errorf("Expected %d-column alignment “%s”, but got: “%s”", test.columns, expectations[i], observations[i]) | ||
} | ||
} | ||
} |