package yuku.alkitabconverter.util;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class DesktopVerseParserTest {
	@Test
	public void testVerseStringToAri() throws Exception {
		test("John 3:16", "0x2a0310 .");
		test("John 3.16", "0x2a0310 .");
		test("John 3:16-18", "0x2a0310 0x2a0312");
		test("John 3.16-18", "0x2a0310 0x2a0312");
		test("John 3:16-3:18", "0x2a0310 0x2a0312");
		test("John 3:16-4:18", "0x2a0310 0x2a0412");
		test("Kejadian 1:1", "0x000101 0x000101");
		test("Kej 1:1 dan 2", "0x000101 . 0x000102 .");
		test("Gen 1:1,3,5", "0x000101 . 0x000103 . 0x000105 .");

		// one chapter books
		test("jud 9", "0x400109 .");
		test("jud 9-12", "0x400109 0x40010c");
		test("jud 1:9", "0x400109 .");
		test("jud 1:9-12", "0x400109 0x40010c");

		// not one chapter books
		test("ps 9", "0x120900 .");
		test("ps 9-12", "0x120900 0x120c00");
		test("ps 1:9", "0x120109 .");
		test("ps 1:9-12", "0x120109 0x12010c");

		// multiple
		test("gn 2:2, 5, 8-32", "0x000202 . 0x000205 . 0x000208 0x000220");

		// new abbr
		test("wah 9:9", "0x410909 .");
		test("zak 9:9", "0x250909 .");
	}

	private void test(final String ref, final String s) {
		final IntArrayList parsed = DesktopVerseParser.verseStringToAri(ref);

		final String[] aris2 = s.split(" ");
		final IntArrayList expected = new IntArrayList();
		for (final String aris : aris2) {
			if (aris.equals(".")) { // repeat last
				expected.add(expected.get(expected.size() - 1));
			} else {
				expected.add(Integer.decode(aris));
			}
		}

		assertEquals(expected, parsed);
	}
}

@@ -1117,16 +1117,219 @@
 909 .%22);
+%0A%0A%09%09// single chapter book whole book%0A%09%09test(%22oba 0%22, %220x1E0100 .%22);%0A%09%09test(%22philemon 0%22, %220x380100 .%22);%0A%09%09test(%222 john 0%22, %220x3E0100 .%22);%0A%09%09test(%223 john 0%22, %220x3F0100 .%22);%0A%09%09test(%22jud 0%22, %220x400100 .%22);
 %0A%09%7D%0A%0A%09pr

add test cases.