package com.marvinelsen.cedict.internal

import com.marvinelsen.cedict.api.CedictDefinition
import com.marvinelsen.chinese.transliteration.Syllable
import com.marvinelsen.chinese.transliteration.Tone
import io.kotest.core.spec.style.ShouldSpec
import io.kotest.matchers.shouldBe
import java.util.zip.GZIPInputStream

class CedictParserImplTest : ShouldSpec({
    should("parse lines correctly") {
        val cedictParser = RegexCedictParser()
        val cedictEntry =
            cedictParser.toCedictEntry("皮實 皮实 [pi2 shi5] /(of things) durable/(of people) sturdy; tough/")

        cedictEntry.traditional shouldBe "皮實"
        cedictEntry.simplified shouldBe "皮实"
        cedictEntry.pinyinSyllables shouldBe listOf(
            Syllable("pi", Tone.SECOND),
            Syllable("shi", Tone.FIFTH)
        )
        cedictEntry.definitions shouldBe listOf(
            CedictDefinition(listOf("(of things) durable")),
            CedictDefinition(listOf("(of people) sturdy", "tough"))
        )
    }

    should("parse all of cedict correctly") {
        val cedictFilePath = "/cedict_1_0_ts_utf-8_mdbg.txt.gz"
        val cedictFileStream = GZIPInputStream(javaClass.getResourceAsStream(cedictFilePath))

        val cedictParser = RegexCedictParser()
        val cedictEntries = cedictParser.parseCedict(cedictFileStream)

        cedictEntries.toList().size shouldBe 122_508
    }
})
