package net.time4j.calendar.hindu;

import net.time4j.calendar.IndianMonth;
import net.time4j.format.expert.ChronoFormatter;
import net.time4j.format.expert.PatternType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.text.ParseException;
import java.util.Locale;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;


@RunWith(JUnit4.class)
public class HinduFormatTest {

    @Test
    public void printMY() {
        ChronoFormatter<HinduCalendar> f =
            ChronoFormatter.ofPattern("G, MMMM yyyy", PatternType.CLDR, Locale.ENGLISH, HinduCalendar.family());
        HinduCalendar cal = HinduCalendar.ofOldSolar(3101, HinduMonth.of(IndianMonth.MAGHA).getRasi(), 19);
        assertThat(
            f.print(cal),
            is("K.Y, Magha 3101"));
    }

    @Test
    public void parseMY() throws ParseException {
        ChronoFormatter<HinduCalendar> f =
            ChronoFormatter.ofPattern("G, MMMM yyyy", PatternType.CLDR, Locale.ENGLISH, HinduCalendar.family())
                .withCalendarVariant(AryaSiddhanta.SOLAR.variant())
                .withDefault(HinduCalendar.DAY_OF_MONTH, HinduDay.valueOf(1));
        HinduCalendar cal = HinduCalendar.ofOldSolar(3101, HinduMonth.of(IndianMonth.MAGHA).getRasi(), 1);
        assertThat(
            f.parse("K.Y, Magha 3101"),
            is(cal));
    }

    @Test
    public void printDMY() {
        ChronoFormatter<HinduCalendar> f =
            ChronoFormatter.ofPattern("G, d. MMMM yyyy", PatternType.CLDR, Locale.ENGLISH, HinduCalendar.family());
        HinduCalendar cal = HinduCalendar.ofOldSolar(3101, HinduMonth.of(IndianMonth.MAGHA).getRasi(), 19);
        assertThat(
            f.print(cal),
            is("K.Y, 19. Magha 3101"));
    }

    @Test
    public void parseDMY() throws ParseException {
        ChronoFormatter<HinduCalendar> f =
            ChronoFormatter.ofPattern("G, d. MMMM yyyy", PatternType.CLDR, Locale.ENGLISH, HinduCalendar.family())
                .withCalendarVariant(AryaSiddhanta.SOLAR.variant());
        HinduCalendar cal = HinduCalendar.ofOldSolar(3101, HinduMonth.of(IndianMonth.MAGHA).getRasi(), 19);
        assertThat(
            f.parse("K.Y, 19. Magha 3101"),
            is(cal));
    }

    @Test
    public void printOrdinalDate() {
        ChronoFormatter<HinduCalendar> f =
            ChronoFormatter.ofPattern("D yyyy", PatternType.CLDR, Locale.ENGLISH, HinduCalendar.family());
        HinduCalendar cal = HinduCalendar.ofOldSolar(3101, HinduMonth.of(IndianMonth.MAGHA).getRasi(), 19);
        assertThat(
            f.print(cal),
            is("293 3101"));
    }

    @Test
    public void parseOrdinalDate() throws ParseException {
        ChronoFormatter<HinduCalendar> f =
            ChronoFormatter.ofPattern("D yyyy", PatternType.CLDR, Locale.ENGLISH, HinduCalendar.family())
                .withCalendarVariant(AryaSiddhanta.SOLAR.variant());
        HinduCalendar cal = HinduCalendar.ofOldSolar(3101, HinduMonth.of(IndianMonth.MAGHA).getRasi(), 19);
        assertThat(f.parse("293 3101"), is(cal));
        assertThat(cal.getDayOfYear(), is(293));
    }

}

@@ -1409,407 +1409,8 @@
  %7D%0A%0A
-    @Test%0A    public void printDMY() %7B%0A        ChronoFormatter%3CHinduCalendar%3E f =%0A            ChronoFormatter.ofPattern(%22G, d. MMMM yyyy%22, PatternType.CLDR, Locale.ENGLISH, HinduCalendar.family());%0A        HinduCalendar cal = HinduCalendar.ofOldSolar(3101, HinduMonth.of(IndianMonth.MAGHA).getRasi(), 19);%0A        assertThat(%0A            f.print(cal),%0A            is(%22K.Y, 19. Magha 3101%22));%0A    %7D%0A%0A
     

Revert "added format test"