/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * 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 com.android.tools.idea.lang

import com.google.common.truth.Truth.assertThat
import com.intellij.lang.ParserDefinition
import com.intellij.lexer.FlexAdapter
import com.intellij.psi.PsiErrorElement
import com.intellij.psi.PsiFile
import com.intellij.psi.TokenType
import com.intellij.psi.tree.IElementType
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.testFramework.ParsingTestCase
import junit.framework.TestCase

abstract class AndroidParsingTestCase(
  fileExtension: String,
  parserDefinition: ParserDefinition
) : ParsingTestCase("no_data_path_needed", fileExtension, parserDefinition) {

  override fun getTestDataPath() = com.android.tools.idea.lang.getTestDataPath()

  protected fun toParseTreeText(input: String): String {
    val psiFile = createPsiFile("in-memory", input)
    return toParseTreeText(psiFile, true, false).trim()
  }

  protected fun getErrorMessage(input: String): String? {
    val psiFile = createPsiFile("in-memory", input)
    return getErrorMessage(psiFile)
  }

  private fun getErrorMessage(psiFile: PsiFile?) = PsiTreeUtil.findChildOfType(psiFile, PsiErrorElement::class.java)?.errorDescription
}

abstract class AndroidLexerTestCase(private val lexer: FlexAdapter): TestCase() {

  protected val SPACE = " " to TokenType.WHITE_SPACE
  protected val NEWLINE = "\n" to TokenType.WHITE_SPACE

  protected fun assertTokenTypes(input: String, vararg expectedTokenTypes: Pair<String, IElementType>) {
    val actualTokenTypes = mutableListOf<Pair<String, IElementType>>()
    lexer.start(input)
    while (lexer.tokenType != null) {
      actualTokenTypes.add(lexer.tokenText to lexer.tokenType!!)
      lexer.advance()
    }

    assertThat(actualTokenTypes).containsExactlyElementsIn(expectedTokenTypes.asIterable())
  }
}
