From f0b984cbe9508eac9c8bb9f6d0cd728ada08ad0e Mon Sep 17 00:00:00 2001 From: David Sansome Date: Fri, 25 Jun 2010 15:15:02 +0000 Subject: [PATCH] Prepend a 0 to single-digit track numbers in the organiser. Fixes issue #438 --- src/core/organiseformat.cpp | 5 +++++ tests/organiseformat_test.cpp | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/core/organiseformat.cpp b/src/core/organiseformat.cpp index 7ee4f1cfa..f04d4c7a3 100644 --- a/src/core/organiseformat.cpp +++ b/src/core/organiseformat.cpp @@ -139,6 +139,11 @@ QString OrganiseFormat::TagValue(const QString &tag, const Song &song) const { if (value == "0" || value == "-1") value = ""; + + // Prepend a 0 to single-digit track numbers + if (tag == "track" && value.length() == 1) + value.prepend('0'); + return value; } diff --git a/tests/organiseformat_test.cpp b/tests/organiseformat_test.cpp index 6f7f6cc30..69ddf66d5 100644 --- a/tests/organiseformat_test.cpp +++ b/tests/organiseformat_test.cpp @@ -123,3 +123,19 @@ TEST_F(OrganiseFormatTest, ReplaceNonAscii) { song_.set_artist(QString::fromUtf8("Владимир Высоцкий")); EXPECT_EQ("________ ________", format_.GetFilenameForSong(song_)); } + +TEST_F(OrganiseFormatTest, TrackNumberPadding) { + format_.set_format("%track"); + + song_.set_track(9); + EXPECT_EQ("09", format_.GetFilenameForSong(song_)); + + song_.set_track(99); + EXPECT_EQ("99", format_.GetFilenameForSong(song_)); + + song_.set_track(999); + EXPECT_EQ("999", format_.GetFilenameForSong(song_)); + + song_.set_track(0); + EXPECT_EQ("", format_.GetFilenameForSong(song_)); +}