<commit_before>package org.aim42.htmlsanitycheck

import org.aim42.htmlsanitycheck.collect.SinglePageResults
import org.junit.Before
import org.junit.Test

class AllChecksRunnerTest extends GroovyTestCase {

    final static String HTML_HEAD = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <head></head><html>'

    private File tmpFile

    private AllChecksRunner allChecksRunner

    @Before
    void setup() {

    }


    @Test
    public void testSingleCorrectHTMLFile() {
        String HTML = """$HTML_HEAD<body><title>hsc</title></body></html>"""

        // create file with proper html content
        tmpFile = File.createTempFile("testfile", ".html") <<HTML

        // wrap tmpFile in Collection to comply to AllChecksRunner API
        allChecksRunner = new AllChecksRunner( new HashSet<File>( [tmpFile] ) )

        SinglePageResults pageResults = allChecksRunner.performAllChecksForOneFile(tmpFile)

        // expectation:
        // 4 checks run
        // 0 items checked
        // 0 findings
        // title = "hsc"
        int expected = 5
        assertEquals("expected $expected kinds of checks", expected, pageResults.singleCheckResults.size())

        assertEquals("expected 0 items checked", 0, pageResults.nrOfItemsCheckedOnPage())

        assertEquals("expected 0 findings", 0, pageResults.nrOfFindingsOnPage())

        assertEquals("expected hsc title", "hsc", pageResults.pageTitle)

        String tmpFileName = tmpFile.name
        assertEquals("expected $tmpFileName as fileName", tmpFileName, pageResults.pageFileName )
    }


    @Test
    public void testSingleBrokenHtmlFile() {
        String HTML = """$HTML_HEAD<body><title>Faulty Dragon</title></body>
                   <h1 id="aim42">dummy-heading-1</h1>
                   <h2 id="aim42">duplicate id</h2>
                   <a href="#nonexisting">broken cross reference</a>
                </html>"""

        // create file
        tmpFile = File.createTempFile("testfile", ".html") << HTML

        allChecksRunner = new AllChecksRunner(
                new HashSet<File>( [tmpFile] ),
                File.createTempDir( "testdir", ""),
                false)

        SinglePageResults pageResults = allChecksRunner.performAllChecksForOneFile( tmpFile )

        // expectation:
        // 4 checks run
        // 3 items checked
        // X findings
        // title = "Faulty Dragon"
        int expected = 5
        assertEquals("expected $expected kinds of checks", expected, pageResults.singleCheckResults.size())

        assertEquals("expected 2 items checked", 2, pageResults.nrOfItemsCheckedOnPage())

        assertEquals("expected 2 findings", 2, pageResults.nrOfFindingsOnPage())

    }

}
<commit_msg>clarified and corrected assert in test<commit_after>package org.aim42.htmlsanitycheck

import org.aim42.htmlsanitycheck.collect.SinglePageResults
import org.junit.Before
import org.junit.Test

class AllChecksRunnerTest extends GroovyTestCase {

    final static String HTML_HEAD = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <head></head><html>'

    private File tmpFile

    private AllChecksRunner allChecksRunner

    @Before
    void setup() {

    }


    @Test
    public void testSingleCorrectHTMLFile() {
        String HTML = """$HTML_HEAD<body><title>hsc</title></body></html>"""

        // create file with proper html content
        tmpFile = File.createTempFile("testfile", ".html") <<HTML

        // wrap tmpFile in Collection to comply to AllChecksRunner API
        allChecksRunner = new AllChecksRunner( new HashSet<File>( [tmpFile] ) )

        SinglePageResults pageResults = allChecksRunner.performAllChecksForOneFile(tmpFile)

        // expectation:
        // 4 checks run
        // 0 items checked
        // 0 findings
        // title = "hsc"
        int expected = 5
        assertEquals("expected $expected kinds of checks", expected, pageResults.singleCheckResults.size())

        assertEquals("expected 0 items checked", 0, pageResults.nrOfItemsCheckedOnPage())

        assertEquals("expected 0 findings", 0, pageResults.nrOfFindingsOnPage())

        assertEquals("expected hsc title", "hsc", pageResults.pageTitle)

        String tmpFileName = tmpFile.name
        assertEquals("expected $tmpFileName as fileName", tmpFileName, pageResults.pageFileName )
    }


    @Test
    public void testSingleBrokenHtmlFile() {
        String HTML = """$HTML_HEAD<body><title>Faulty Dragon</title></body>
                   <h1 id="aim42">dummy-heading-1</h1>
                   <h2 id="aim42">duplicate id</h2>
                   <a href="#nonexisting">broken cross reference</a>
                </html>"""

        // create file
        tmpFile = File.createTempFile("testfile", ".html") << HTML

        allChecksRunner = new AllChecksRunner(
                new HashSet<File>( [tmpFile] ),
                File.createTempDir( "testdir", ""),
                false)

        SinglePageResults pageResults = allChecksRunner.performAllChecksForOneFile( tmpFile )

        int expected = 5
        assertEquals("expected $expected kinds of checks", expected, pageResults.singleCheckResults.size())

        assertEquals("expected 2 findings", 2, pageResults.nrOfFindingsOnPage())

    }

}

{'fraction_non_alphanumeric': 0.10787671232876712, 'fraction_numerical': 0.01141552511415525, 'mean_word_length': 2.6917134831460676, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 47, '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': '5712562', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1379, 'n_words': 353}