<commit_before>package com.stats.completion

import com.intellij.testFramework.PlatformTestCase
import com.intellij.testFramework.UsefulTestCase
import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import java.io.File

class FileLoggerTest : PlatformTestCase() {
    
    fun `test data is appended`() {
        val path = createTempFile("x.txt").absolutePath
        val mockPathProvider = mock(FilePathProvider::class.java)
        `when`(mockPathProvider.statsFilePath).thenReturn(path)
        
        performLogging(mockPathProvider)

        var text = File(path).readText()
        val firstLength = text.length
        
        performLogging(mockPathProvider)
        
        text = File(path).readText()
        val secondLength = text.length
        
        UsefulTestCase.assertEquals(firstLength * 2, secondLength)
    }
    
    fun `test file is created if it doesn't exist`() {
        val path = "x.txt"
        val mockPathProvider = mock(FilePathProvider::class.java)
        `when`(mockPathProvider.statsFilePath).thenReturn(path)
        performLogging(mockPathProvider)
        var text = File(path).readText()
        UsefulTestCase.assertTrue(text.length > 0)
    }

    private fun performLogging(pathProvider: FilePathProvider): CompletionLogger {
        var loggerProvider = CompletionFileLoggerProvider(pathProvider)
        var logger = loggerProvider.newCompletionLogger()
        logger.completionStarted(emptyList())
        logger.charTyped('a', emptyList())
        logger.charTyped('b', emptyList())
        logger.charTyped('c', emptyList())
        logger.itemSelectedCompletionFinished(0, "")
        loggerProvider.dispose()
        return logger
    }


}<commit_msg>delete tmp file<commit_after>package com.stats.completion

import com.intellij.testFramework.PlatformTestCase
import com.intellij.testFramework.UsefulTestCase
import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import java.io.File

class FileLoggerTest : PlatformTestCase() {
    private val path = "x.txt"

    override fun tearDown() {
        val file = File(path)
        if (file.exists()) {
            file.delete()
        }
        super.tearDown()
    }

    fun `test data is appended`() {
        val path = createTempFile(path).absolutePath
        val mockPathProvider = mock(FilePathProvider::class.java)
        `when`(mockPathProvider.statsFilePath).thenReturn(path)
        
        performLogging(mockPathProvider)

        var text = File(path).readText()
        val firstLength = text.length
        
        performLogging(mockPathProvider)
        
        text = File(path).readText()
        val secondLength = text.length
        
        UsefulTestCase.assertEquals(firstLength * 2, secondLength)
    }
    
    fun `test file is created if it doesn't exist`() {
        val path = path
        val mockPathProvider = mock(FilePathProvider::class.java)
        `when`(mockPathProvider.statsFilePath).thenReturn(path)
        performLogging(mockPathProvider)
        var text = File(path).readText()
        UsefulTestCase.assertTrue(text.length > 0)
    }

    private fun performLogging(pathProvider: FilePathProvider): CompletionLogger {
        var loggerProvider = CompletionFileLoggerProvider(pathProvider)
        var logger = loggerProvider.newCompletionLogger()
        logger.completionStarted(emptyList())
        logger.completionCancelled()
        loggerProvider.dispose()
        return logger
    }


}
{'fraction_non_alphanumeric': 0.09331036462819409, 'fraction_numerical': 0.001435544071202986, 'mean_word_length': 2.897091722595078, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3096388', 'n_tokens_mistral': 951, 'n_tokens_neox': 933, 'n_words': 184}