<commit_before>package org.aim42.htmlsanitycheck.check

import org.aim42.htmlsanitycheck.collect.SingleCheckResults
import org.aim42.htmlsanitycheck.html.HtmlPage
import org.junit.Before
import org.junit.Test

class MissingLocalResourcesCheckerTest extends GroovyTestCase {

    private final static String HTMLHEAD = "<html><head></head><body>"

    Checker missingLocalResourcesChecker
    HtmlPage htmlPage
    SingleCheckResults collector

    @Before
    public void setUp() {
        collector = new SingleCheckResults()
    }

    @Test
    public void testExistingLocalResourceIsFound() {
        // 1.) create tmp directory D1 with subdir D2
        // 2.) create local resource file F1 in subdir D2
        // 3.) create tmp html file linking to F1 in directory D1
        // check that no issue is found
        assert false
    }


    @Test
    public void testCrossReferenceIsNotChecked() {
        String HTML = """$HTMLHEAD
            <h1>dummy-heading-1</h1>
            <a href="#aim42">aim42</a><commit_msg>intermediate success: created (still) failing regression test case<commit_after>package org.aim42.htmlsanitycheck.check

import org.aim42.htmlsanitycheck.collect.SingleCheckResults
import org.aim42.htmlsanitycheck.html.HtmlPage
import org.junit.Before
import org.junit.Test

class MissingLocalResourcesCheckerTest extends GroovyTestCase {

    private final static String HTMLHEAD = "<html><head></head><body>"

    Checker missingLocalResourcesChecker
    HtmlPage htmlPage
    SingleCheckResults collector

    @Before
    public void setUp() {
        collector = new SingleCheckResults()
    }

    @Test
    public void testExistingLocalResourceIsFound() {
        // 1.) create tmp directory d1 with subdir d2
        File d1 = File.createTempDir()
        File d2 = new File(d1 , "/d2")
        d2.mkdirs()

        // 2.) create local resource file f1 in subdir d2
        final String fname = "fname.html"
        File f1 = new File( d2, fname) << HTMLHEAD

        assertEquals( "created an artificial file","d2/fname.html",
                f1.canonicalPath - d1.canonicalPath - "/")

        // 3.) create tmp html file "index.html" linking to f1 in directory d1
        File index = new File( d1, "index.html") << HTMLHEAD
        index << """<a href="d2/$fname">link to local resource"</a></body></html>"""

        // 4.) check
        htmlPage = new HtmlPage( index )

        missingLocalResourcesChecker = new MissingLocalResourcesChecker(
                pageToCheck: htmlPage )
        collector = missingLocalResourcesChecker.performCheck()

        // assert that no issue is found (== the local resource d2/fname.html is found)
        assertEquals( "expected zero finding", 0, collector.nrOfProblems())
        assertEquals( "expected one check", 0, collector.nrOfItemsChecked)


    }


    @Test
    public void testCrossReferenceIsNotChecked() {
        String HTML = """$HTMLHEAD
            <h1>dummy-heading-1</h1>
            <a href="#aim42">aim42</a>
{'fraction_non_alphanumeric': 0.09438351611831174, 'fraction_numerical': 0.019940179461615155, 'mean_word_length': 2.810126582278481, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 23, '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': '3407410', 'n_tokens_mistral': 882, 'n_tokens_neox': 827, 'n_words': 242}