package io.wealthwizards.appsynctesting.utils;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

@DisplayName("$util.str")
public class StrTest {
    @Test
    @DisplayName(".toUpper")
    public void shouldImplementToUpper() {
        var str = new Str();

        assertEquals("HELLO", str.toUpper("hello"));
        // this is expected behaviour from AppSync
        assertThrows(NullPointerException.class, () -> str.toUpper(null));
    }

    @Test
    @DisplayName(".toLower")
    public void shouldImplementToLower() {
        var str = new Str();

        assertEquals("hello", str.toLower("HELLO"));
        // this is expected behaviour from AppSync
        assertThrows(NullPointerException.class, () -> str.toLower(null));
    }

    @Test
    @DisplayName(".toReplace")
    public void shouldImplementToReplace() {
        var str = new Str();

        assertEquals("bye bye bye", str.toReplace("hi hi hi", "hi", "bye"));
        // this is expected behaviour from AppSync
        assertThrows(NullPointerException.class, () -> str.toReplace("hi hi hi", null, "bye"));
    }

    @Test
    @DisplayName(".toNormalize")
    public void shouldImplementToNormalize() {
        var str = new Str();

        var original = "schön";

        assertEquals("schön", str.toNormalise(original, "nfc"));
        assertEquals("scho\u0308n", str.toNormalise(original, "nfd"));
        assertEquals("schön", str.toNormalise(original, "nfkc"));
        assertEquals("scho\u0308n", str.toNormalise(original, "nfkd"));
    }
}
