import java.util.List; import com.minamp.util.Lrc; /** LRC and plain-text lyrics parsing (com.minamp.util.Lrc). Run: * javac -d /tmp/lt src/com/minamp/util/Lrc.java test/LyricsTest.java && java -cp /tmp/lt LyricsTest */ public class LyricsTest { static int fails; static void check(boolean ok, String what) { System.out.println((ok ? "PASS " : "FAIL ") + what); if (!ok) fails++; } public static void main(String[] a) { boolean[] synced = new boolean[1]; List l = Lrc.parse("[ar:Pereza]\n[ti:Pompa]\n[00:12.50]First\r\n[00:05]Zero\n[01:02.123][00:20.00]Twice\n", synced); check(synced[0], "timed lyrics are synced"); check(l.size() == 4, "a line with two stamps counts twice, tags are dropped (" + l.size() + ")"); check(l.get(0).time == 5000 && l.get(0).text.equals("Zero"), "sorted by time"); check(l.get(1).time == 12500, "hundredths"); check(l.get(3).time == 62123 && l.get(3).text.equals("Twice"), "milliseconds"); check(Lrc.lineAt(l, 4000) == -1, "before the first line"); check(Lrc.lineAt(l, 13000) == 1, "line being sung"); check(Lrc.lineAt(l, 999999) == 3, "after the last line"); l = Lrc.parse("[offset:+500]\n[00:10.00]A <00:10.50>word <00:11.00>by word\n", synced); check(l.size() == 1 && l.get(0).time == 9500, "offset shows lines earlier"); check(l.get(0).text.equals("A word by word"), "word stamps removed: " + l.get(0).text); l = Lrc.parse("\n\nVerse one\nline two\n\nVerse two\n\n", synced); check(!synced[0], "plain text isn't synced"); check(l.size() == 4 && l.get(2).text.length() == 0, "blank lines between verses kept, at the ends dropped"); check(l.get(0).time == -1, "plain lines have no time"); check(Lrc.parse("", synced).isEmpty(), "empty text, no lines"); System.out.println(fails == 0 ? "all passed" : fails + " failed"); System.exit(fails == 0 ? 0 : 1); } }