<commit_before>/*
 * Copyright (C) 2018 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.co.reecedunn.intellij.plugin.xqdoc.tests.parser

import com.intellij.util.Range
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.nullValue
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import uk.co.reecedunn.intellij.plugin.core.tests.assertion.assertThat
import uk.co.reecedunn.intellij.plugin.xqdoc.parser.XQDocElementType
import uk.co.reecedunn.intellij.plugin.xqdoc.parser.XQDocParser

@DisplayName("xqDoc - Parser")
class XQDocParserTest {
    @Nested
    @DisplayName("xquery comment")
    internal inner class XQueryComment {
        @Test
        @DisplayName("empty")
        fun empty() {
            val parser = XQDocParser("")
            assertThat(parser.isXQDoc, `is`(false))
            assertThat(parser.elementType, `is`(nullValue()))
            assertThat(parser.text, `is`(nullValue()))
            assertThat(parser.textRange, `is`(nullValue()))

            assertThat(parser.next(), `is`(false))
            assertThat(parser.elementType, `is`(nullValue()))
            assertThat(parser.text, `is`(nullValue()))
            assertThat(parser.textRange, `is`(nullValue()))
        }

        @Test
        @DisplayName("xquery comment")
        fun xqueryComment() {
            val parser = XQDocParser("Lorem ipsum dolor")
            assertThat(parser.isXQDoc, `is`(false))
            assertThat(parser.elementType, `is`(nullValue()))
            assertThat(parser.text, `is`(nullValue()))
            assertThat(parser.textRange, `is`(nullValue()))

            assertThat(parser.next(), `is`(false))
            assertThat(parser.elementType, `is`(nullValue()))
            assertThat(parser.text, `is`(nullValue()))
            assertThat(parser.textRange, `is`(nullValue()))
        }
    }

    @Nested
    @DisplayName("description")
    internal inner class Description {
        @Test
        @DisplayName("empty")
        fun empty() {
            val parser = XQDocParser("~")
            assertThat(parser.isXQDoc, `is`(true))
            assertThat(parser.elementType, `is`(nullValue()))
            assertThat(parser.text, `is`(nullValue()))
            assertThat(parser.textRange, `is`(nullValue()))

            assertThat(parser.next(), `is`(false))
            assertThat(parser.elementType, `is`(nullValue()))
            assertThat(parser.text, `is`(nullValue()))
            assertThat(parser.textRange, `is`(nullValue()))
        }

        @Test
        @DisplayName("single line")
        fun singleLine() {
            val parser = XQDocParser("~Lorem ipsum dolor")
            assertThat(parser.isXQDoc, `is`(true))
            assertThat(parser.elementType, `is`(nullValue()))
            assertThat(parser.text, `is`(nullValue()))
            assertThat(parser.textRange, `is`(nullValue()))

            assertThat(parser.next(), `is`(true))
            assertThat(parser.elementType, `is`(XQDocElementType.DESCRIPTION_LINE))
            assertThat(parser.text, `is`("Lorem ipsum dolor"))
            assertThat(parser.textRange, `is`(Range(1, 18)))

            assertThat(parser.next(), `is`(false))
            assertThat(parser.elementType, `is`(nullValue()))
            assertThat(parser.text, `is`(nullValue()))
            assertThat(parser.textRange, `is`(nullValue()))
        }
    }
}<commit_msg>[xqdoc] Add match helper functions to the tests.<commit_after>/*
 * Copyright (C) 2018 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.co.reecedunn.intellij.plugin.xqdoc.tests.parser

import com.intellij.psi.tree.IElementType
import com.intellij.util.Range
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.nullValue
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import uk.co.reecedunn.intellij.plugin.core.tests.assertion.assertThat
import uk.co.reecedunn.intellij.plugin.xqdoc.parser.XQDocElementType
import uk.co.reecedunn.intellij.plugin.xqdoc.parser.XQDocParser

@DisplayName("xqDoc - Parser")
class XQDocParserTest {
    private fun matchStart(parser: XQDocParser, isXQDoc: Boolean) {
        assertThat(parser.isXQDoc, `is`(isXQDoc))
        assertThat(parser.elementType, `is`(nullValue()))
        assertThat(parser.text, `is`(nullValue()))
        assertThat(parser.textRange, `is`(nullValue()))
    }

    private fun match(parser: XQDocParser, elementType: IElementType, text: String, textRange: Range<Int>) {
        assertThat(parser.next(), `is`(true))
        assertThat(parser.elementType, `is`(elementType))
        assertThat(parser.text, `is`(text))
        assertThat(parser.textRange, `is`(textRange))
    }

    private fun matchEof(parser: XQDocParser) {
        assertThat(parser.next(), `is`(false))
        assertThat(parser.elementType, `is`(nullValue()))
        assertThat(parser.text, `is`(nullValue()))
        assertThat(parser.textRange, `is`(nullValue()))
    }

    @Nested
    @DisplayName("xquery comment")
    internal inner class XQueryComment {
        @Test
        @DisplayName("empty")
        fun empty() {
            val parser = XQDocParser("")
            matchStart(parser, false)
            matchEof(parser)
        }

        @Test
        @DisplayName("xquery comment")
        fun xqueryComment() {
            val parser = XQDocParser("Lorem ipsum dolor")
            matchStart(parser, false)
            matchEof(parser)
        }
    }

    @Nested
    @DisplayName("description")
    internal inner class Description {
        @Test
        @DisplayName("empty")
        fun empty() {
            val parser = XQDocParser("~")
            matchStart(parser, true)
            matchEof(parser)
        }

        @Test
        @DisplayName("single line")
        fun singleLine() {
            val parser = XQDocParser("~Lorem ipsum dolor")
            matchStart(parser, true)
            match(parser, XQDocElementType.DESCRIPTION_LINE, "Lorem ipsum dolor", Range(1, 18))
            matchEof(parser)
        }
    }
}
{'fraction_non_alphanumeric': 0.12554112554112554, 'fraction_numerical': 0.0030721966205837174, 'mean_word_length': 2.907255864702673, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2147757', 'n_tokens_mistral': 2101, 'n_tokens_neox': 2118, 'n_words': 455}