Просмотр исходного кода

test(date): check the trimmed lower-case date in its own test

gocritic's mapKey check flags the leading space and trailing newline in a map key, so the case with surrounding whitespace moves out of the table into its own test.
ybai08 1 день назад
Родитель
Сommit
12eb4d801a
1 измененных файлов с 13 добавлено и 1 удалено
  1. 13 1
      internal/reader/date/parser_test.go

+ 13 - 1
internal/reader/date/parser_test.go

@@ -53,7 +53,6 @@ func TestParseAtomDateWithLowerCaseSeparators(t *testing.T) {
 		"2003-12-13t18:30:02Z":      1071340202,
 		"1985-04-12t23:20:50.52z":   482196050,
 		"1996-12-19t16:39:57-08:00": 851042397,
-		" 2003-12-13t18:30:02z\n":   1071340202,
 	}
 
 	for input, expectedTS := range testCases {
@@ -69,6 +68,19 @@ func TestParseAtomDateWithLowerCaseSeparators(t *testing.T) {
 	}
 }
 
+func TestParseAtomDateWithLowerCaseSeparatorsAndSurroundingWhitespace(t *testing.T) {
+	// The separators are looked for at fixed positions, after the input is trimmed.
+	date, err := Parse(" 2003-12-13t18:30:02z\n")
+	if err != nil {
+		t.Fatalf(`Unable to parse date: %v`, err)
+	}
+
+	expectedTS := int64(1071340202)
+	if date.Unix() != expectedTS {
+		t.Errorf(`The Unix timestamp should be %v instead of %v`, expectedTS, date.Unix())
+	}
+}
+
 func TestParseRSSDateTimezone(t *testing.T) {
 	date, err := Parse("Fri, 31 Mar 2023 20:19:00 America/Los_Angeles")
 	if err != nil {