<commit_before>package com.github.mibac138.argparser.parser

import com.github.mibac138.argparser.named.name
import com.github.mibac138.argparser.reader.asReader
import com.github.mibac138.argparser.syntax.dsl.element
import com.github.mibac138.argparser.syntax.dsl.syntaxContainer
import com.github.mibac138.argparser.syntax.dsl.syntaxElement
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

/**
 * Created by mibac138 on 07-05-2017.
 */
class MixedParserRegistryImplTest {
    val parser = MixedParserRegistryImpl()

    @Test fun basicTest() {
        parser.registerParser(SequenceParser(), 0)
        parser.registerParser(SequenceParser(), 1)
        val output = parser.parse("Hello! :)".asReader(), syntaxContainer {
            element(String::class.java)
            element(String::class.java)
        })

        assertEquals(listOf("Hello!", ":)"), output[null])
    }

    @Test fun mediumTest() {
        parser.registerParser(IntParser(), 0)
        parser.registerParser(SequenceParser(), "name")
        val syntax = syntaxContainer {
            element(Int::class.java)
            element(String::class.java, { name = "name" })
        }
        val output = parser.parse("15 --name:Mike".asReader(), syntax)

        assertEquals(mapOf<String?, Any>(null to listOf(15), "name" to "Mike"), output)
    }

    @Test fun complexTest() {
        parser.registerParser(BooleanParser(), 0)
        parser.registerParser(IntParser(), 1)
        parser.registerParser(BooleanParser(), 2)
        parser.registerParser(SequenceParser(), "seq1")
        parser.registerParser(SequenceParser(), "seq2")
        parser.registerParser(SequenceParser(), "seq3")
        val syntax = syntaxContainer {
            element(Boolean::class.java)
            element(Int::class.java)
            element(Boolean::class.java)
            element(String::class.java, { name = "seq1" })
            element(String::class.java, { name = "seq2" })
            element(String::class.java, { name = "seq3" })
        }
        val output = parser.parse("true --seq1='Hiya!' --seq2: 'Lorem ipsum' 100 false --seq3=Hi".asReader(), syntax)

        assertContentEquals(mapOf(
                null to listOf(true, 100, false),
                "seq1" to "'Hiya!'",
                "seq2" to "'Lorem ipsum'",
                "seq3" to "Hi"
        ), output)
    }

    /*@Test*/ fun missionImpossible() {
        parser.registerParser(SequenceParser(), 0)
        parser.registerParser(SequenceParser(), 1)
        parser.registerParser(SequenceParser(), "seq")
        val syntax = syntaxContainer {
            element(String::class.java) { name = "seq" }
            element(String::class.java)
            element(String::class.java) { required = false; defaultValue = "default" }
        }
        val output = parser.parse("yes --seq:sequence".asReader(), syntax)

        println(output)
        assertContentEquals(mapOf(
                null to listOf("yes", "default"),
                "seq" to "sequence"
        ), output)
    }

    @Test fun issue9() {
        parser.registerParser(SequenceParser(), 0)

        val syntax = syntaxElement(String::class.java) {
            required = false
            defaultValue = "default"
        }

        //
        val output = parser.parse(" ".asReader(), syntax)
        println(output)
        assertContentEquals(mapOf(
                null to listOf("default")
        ), output)
    }

    private fun assertContentEquals(a: Map<String?, Any>, b: Map<String?, *>) {
        a.forEach { (key, value) -><commit_msg>Remove unnecessary print from test<commit_after>package com.github.mibac138.argparser.parser

import com.github.mibac138.argparser.named.name
import com.github.mibac138.argparser.reader.asReader
import com.github.mibac138.argparser.syntax.dsl.element
import com.github.mibac138.argparser.syntax.dsl.syntaxContainer
import com.github.mibac138.argparser.syntax.dsl.syntaxElement
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

/**
 * Created by mibac138 on 07-05-2017.
 */
class MixedParserRegistryImplTest {
    val parser = MixedParserRegistryImpl()

    @Test fun basicTest() {
        parser.registerParser(SequenceParser(), 0)
        parser.registerParser(SequenceParser(), 1)
        val output = parser.parse("Hello! :)".asReader(), syntaxContainer {
            element(String::class.java)
            element(String::class.java)
        })

        assertEquals(listOf("Hello!", ":)"), output[null])
    }

    @Test fun mediumTest() {
        parser.registerParser(IntParser(), 0)
        parser.registerParser(SequenceParser(), "name")
        val syntax = syntaxContainer {
            element(Int::class.java)
            element(String::class.java, { name = "name" })
        }
        val output = parser.parse("15 --name:Mike".asReader(), syntax)

        assertEquals(mapOf<String?, Any>(null to listOf(15), "name" to "Mike"), output)
    }

    @Test fun complexTest() {
        parser.registerParser(BooleanParser(), 0)
        parser.registerParser(IntParser(), 1)
        parser.registerParser(BooleanParser(), 2)
        parser.registerParser(SequenceParser(), "seq1")
        parser.registerParser(SequenceParser(), "seq2")
        parser.registerParser(SequenceParser(), "seq3")
        val syntax = syntaxContainer {
            element(Boolean::class.java)
            element(Int::class.java)
            element(Boolean::class.java)
            element(String::class.java, { name = "seq1" })
            element(String::class.java, { name = "seq2" })
            element(String::class.java, { name = "seq3" })
        }
        val output = parser.parse("true --seq1='Hiya!' --seq2: 'Lorem ipsum' 100 false --seq3=Hi".asReader(), syntax)

        assertContentEquals(mapOf(
                null to listOf(true, 100, false),
                "seq1" to "'Hiya!'",
                "seq2" to "'Lorem ipsum'",
                "seq3" to "Hi"
        ), output)
    }

    /*@Test*/ fun missionImpossible() {
        parser.registerParser(SequenceParser(), 0)
        parser.registerParser(SequenceParser(), 1)
        parser.registerParser(SequenceParser(), "seq")
        val syntax = syntaxContainer {
            element(String::class.java) { name = "seq" }
            element(String::class.java)
            element(String::class.java) { required = false; defaultValue = "default" }
        }
        val output = parser.parse("yes --seq:sequence".asReader(), syntax)

        println(output)
        assertContentEquals(mapOf(
                null to listOf("yes", "default"),
                "seq" to "sequence"
        ), output)
    }

    @Test fun issue9() {
        parser.registerParser(SequenceParser(), 0)

        val syntax = syntaxElement(String::class.java) {
            required = false
            defaultValue = "default"
        }

        val output = parser.parse(" ".asReader(), syntax)
        assertContentEquals(mapOf(
                null to listOf("default")
        ), output)
    }

    private fun assertContentEquals(a: Map<String?, Any>, b: Map<String?, *>) {
        a.forEach { (key, value) ->
{'fraction_non_alphanumeric': 0.13515016685205783, 'fraction_numerical': 0.01696329254727475, 'mean_word_length': 2.5036531904529955, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2774348', 'n_tokens_mistral': 2127, 'n_tokens_neox': 1997, 'n_words': 399}