<commit_before>package htmlcheck;

import java.util.Collection;
import java.util.List;

import org.hamcrest.Matcher;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;

public class HtmlCheckerTests {

	@Test
	public void shouldAllowAbsoluteUrlsInHrefAttributes() {
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><a href=\"http://adestination/to/somewhere\"></a></body></html>"), isEmpty());
	}

	@Test
	public void shouldAllowAbsoluteUrlsInSrcAttributes() {
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><script type=\"text/javscrtipt\" src=\"http://foo.com/bar.js\"></script></body></html>"), isEmpty());
	}

	@Test
	@Ignore("not implemented - app doesn't currently resolve its own URLs")
	public void shouldNotAllowRelativeUrlsInSrcAttributes() {
		assertThat(errorsOn("<html><body id=\"foo\"><script src=\"/bar.js\"></script></body></html>"), hasItem(new HtmlCheckError(
				"html > body > script links to 'adestination/to/somewhere', which is not absolute")));
	}

	@Test
	@Ignore("not implemented - app doesn't currently resolve its own URLs")
	public void shouldNotAllowRelativeUrlsInHrefAttributes() {
		assertThat(errorsOn("<html><body id=\"foo\"><a href=\"adestination/to/somewhere\"></a></body></html>"), hasItem(new HtmlCheckError(
				"html > body > a links to 'adestination/to/somewhere', which is not absolute")));
	}

	@Test
	public void shouldNotAllowInlineStyleAttributes() {
		assertThat(errorsOn("<html><body id=\"foo\"><a style=\"color: black\">Bad inline style</a></body></html>"), 
				hasItem(new HtmlCheckError("BANNED ATTRIBUTE: html > body#foo > a uses disallowed inline style: color")));
	}

	@Test
	public void shouldLimitElementsUsedInsideStyleAttributes() {
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"display: none\">Hidden</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"width: 0\">Width</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"height: 0\">Height</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"background-image: none\">Background Image</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"visibility: none\">Visibility</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"top: 0\">Top</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"left: 0\">Left</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"bottom: 0\">Bottom</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"right: 0\">Right</div></body></html>"), isEmpty());

		assertThat(errorsOn("<html><body id=\"foo\"><div style=\"foo: bar\">FAIL</div></body></html>"), 
				hasItem(new HtmlCheckError("BANNED ATTRIBUTE: html > body#foo > div uses disallowed inline style: foo")));

		assertThat(errorsOn("<html><body id=\"foo\"><div id=\"bar\" style=\"foo: bar\">FAIL</div></body></html>"), 
				hasItem(new HtmlCheckError("BANNED ATTRIBUTE: html > body#foo > div#bar uses disallowed inline style: foo")));
	}

	@Test<commit_msg>wondering what to do with these ignored rules and rules that may not generally apply to any project<commit_after>package htmlcheck;

import java.util.Collection;
import java.util.List;

import org.hamcrest.Matcher;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;

public class HtmlCheckerTests {

	@Test
	public void shouldAllowAbsoluteUrlsInHrefAttributes() {
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><a href=\"http://adestination/to/somewhere\"></a></body></html>"), isEmpty());
	}

	@Test
	public void shouldAllowAbsoluteUrlsInSrcAttributes() {
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><script type=\"text/javscrtipt\" src=\"http://foo.com/bar.js\"></script></body></html>"), isEmpty());
	}

	@Test
	@Ignore("not implemented")
	public void shouldNotAllowRelativeUrlsInSrcAttributes() {
		assertThat(errorsOn("<html><body id=\"foo\"><script src=\"/bar.js\"></script></body></html>"), hasItem(new HtmlCheckError(
				"html > body > script links to 'adestination/to/somewhere', which is not absolute")));
	}

	@Test
	@Ignore("not implemented")
	public void shouldNotAllowRelativeUrlsInHrefAttributes() {
		assertThat(errorsOn("<html><body id=\"foo\"><a href=\"adestination/to/somewhere\"></a></body></html>"), hasItem(new HtmlCheckError(
				"html > body > a links to 'adestination/to/somewhere', which is not absolute")));
	}

	@Test
	public void shouldNotAllowInlineStyleAttributes() {
		assertThat(errorsOn("<html><body id=\"foo\"><a style=\"color: black\">Bad inline style</a></body></html>"), 
				hasItem(new HtmlCheckError("BANNED ATTRIBUTE: html > body#foo > a uses disallowed inline style: color")));
	}

	@Test
	public void shouldLimitElementsUsedInsideStyleAttributes() {
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"display: none\">Hidden</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"width: 0\">Width</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"height: 0\">Height</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"background-image: none\">Background Image</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"visibility: none\">Visibility</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"top: 0\">Top</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"left: 0\">Left</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"bottom: 0\">Bottom</div></body></html>"), isEmpty());
		assertThat(errorsOn("<html><head><title></title></head><body id=\"foo\"><div style=\"right: 0\">Right</div></body></html>"), isEmpty());

		assertThat(errorsOn("<html><body id=\"foo\"><div style=\"foo: bar\">FAIL</div></body></html>"), 
				hasItem(new HtmlCheckError("BANNED ATTRIBUTE: html > body#foo > div uses disallowed inline style: foo")));

		assertThat(errorsOn("<html><body id=\"foo\"><div id=\"bar\" style=\"foo: bar\">FAIL</div></body></html>"), 
				hasItem(new HtmlCheckError("BANNED ATTRIBUTE: html > body#foo > div#bar uses disallowed inline style: foo")));
	}

	@Test
{'fraction_non_alphanumeric': 0.23006896551724138, 'fraction_numerical': 0.0016551724137931034, 'mean_word_length': 6.383910386965376, 'pattern_counts': {'":': 0, '<': 283, '<?xml version=': 0, '>': 303, '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': '6943486', 'n_tokens_mistral': 2336, 'n_tokens_neox': 2267, 'n_words': 402}