package com.pixelized.desktop.lwa.parser.word

import com.pixelized.shared.lwa.parser.word.Word
import com.pixelized.shared.lwa.parser.word.WordParser
import org.junit.Test

class WordParserTest {

    @Test
    fun testInvalidExpression() {
        val parser = WordParser()
        parser.test(expression = "", expected = null)
        parser.test(expression = " ", expected = null)
        parser.test(expression = "1", expected = null)
        parser.test(expression = "1d6", expected = null)
        parser.test(expression = "pouet", expected = null)
    }

    @Test
    fun testValidExpression() {
        val parser = WordParser()
        Word.Type.entries.forEach { type ->
            parser.test(expression = type.name, expected = Word(type))
        }
    }

    private fun WordParser.test(
        expression: String,
        expected: Word?,
    ) {
        val result = parse(value = expression)
        assert(result == expected) {
            "WordParser.parse(value=$expression) is expected to return:$expected, but was:$result"
        }
    }
}