<commit_before>package org.whaka.asserts.matcher

import org.whaka.TestData
import org.whaka.asserts.ComparisonAssertResult
import org.whaka.util.reflection.comparison.ComparisonFail
import org.whaka.util.reflection.comparison.ComparisonPerformer
import org.whaka.util.reflection.comparison.ComparisonResult

import spock.lang.Specification

class ComparisonMatcherTest extends Specification {

	def "construction"() {
		given:
			ComparisonPerformer performer = Mock()
		when:
			def m = new ComparisonMatcher(value, performer)
		then:
			0 * performer.compare(_, _)
		and:
			m.getValue().is(value)
			m.getComparisonPerformer().is(performer)
		where:
			value << TestData.variousObjects()
	}

	def "matches: success"() {
		given:
			ComparisonPerformer performer = Mock()
			ComparisonResult comparisonResult = new ComparisonResult(null, null, null, true)
			def m = new ComparisonMatcher("value", performer)
		when:
			ComparisonAssertResult res = m.matches("item", "msg " + cause, cause).orElse(null)
		then:
			1 * performer.compare("item", "value") >> comparisonResult
		and:
			res == null
		where:
			cause << TestData.variousCauses()
	}

	def "matches: fail"() {
		given:
			ComparisonPerformer performer = Mock()
			ComparisonResult comparisonResult = new ComparisonResult("item", "value", performer, false)
			def m = new ComparisonMatcher("value", performer)
		when:
			ComparisonAssertResult res = m.matches("item", "msg " + cause, cause).get()
		then:
			1 * performer.compare("item", "value") >> comparisonResult
		and:
			res.getComparisonResult().is(comparisonResult)
			res.getActual() == "item"
			res.getExpected() == "value"
			res.getMessage() == "msg $cause"
			res.getCause() == cause
		where:
			cause << TestData.variousCauses()
	}

	def "matches: if comparison fail happened - specified cause is ignored"() {
		given:
			ComparisonPerformer performer = Mock()
			def comparisonCause = new IOException("stahp!")
			ComparisonResult comparisonResult = new ComparisonFail(null, null, null, comparisonCause)
			def m = new ComparisonMatcher("value", performer)
		when:
			ComparisonAssertResult res = m.matches("item", "msg " + cause, cause).get()
		then:
			1 * performer.compare("item", "value") >> comparisonResult<commit_msg>#70 [ASAP] Tests are failing<commit_after>package org.whaka.asserts.matcher

import org.whaka.TestData
import org.whaka.asserts.ComparisonAssertResult
import org.whaka.util.reflection.comparison.ComparisonFail
import org.whaka.util.reflection.comparison.ComparisonPerformer
import org.whaka.util.reflection.comparison.ComparisonResult

import spock.lang.Specification

class ComparisonMatcherTest extends Specification {

	def "construction"() {
		given:
			ComparisonPerformer performer = Mock()
		when:
			def m = new ComparisonMatcher(value, performer)
		then:
			0 * performer.apply(_, _)
		and:
			m.getValue().is(value)
			m.getComparisonPerformer().is(performer)
		where:
			value << TestData.variousObjects()
	}

	def "matches: success"() {
		given:
			ComparisonPerformer performer = Mock()
			ComparisonResult comparisonResult = new ComparisonResult(null, null, null, true)
			def m = new ComparisonMatcher("value", performer)
		when:
			ComparisonAssertResult res = m.matches("item", "msg " + cause, cause).orElse(null)
		then:
			1 * performer.apply("item", "value") >> comparisonResult
		and:
			res == null
		where:
			cause << TestData.variousCauses()
	}

	def "matches: fail"() {
		given:
			ComparisonPerformer performer = Mock()
			ComparisonResult comparisonResult = new ComparisonResult("item", "value", performer, false)
			def m = new ComparisonMatcher("value", performer)
		when:
			ComparisonAssertResult res = m.matches("item", "msg " + cause, cause).get()
		then:
			1 * performer.apply("item", "value") >> comparisonResult
		and:
			res.getComparisonResult().is(comparisonResult)
			res.getActual() == "item"
			res.getExpected() == "value"
			res.getMessage() == "msg $cause"
			res.getCause() == cause
		where:
			cause << TestData.variousCauses()
	}

	def "matches: if comparison fail happened - specified cause is ignored"() {
		given:
			ComparisonPerformer performer = Mock()
			def comparisonCause = new IOException("stahp!")
			ComparisonResult comparisonResult = new ComparisonFail(null, null, null, comparisonCause)
			def m = new ComparisonMatcher("value", performer)
		when:
			ComparisonAssertResult res = m.matches("item", "msg " + cause, cause).get()
		then:
			1 * performer.apply("item", "value") >> comparisonResult
{'fraction_non_alphanumeric': 0.12386439175714602, 'fraction_numerical': 0.0022158209616662972, 'mean_word_length': 4.649561952440551, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2498394', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1312, 'n_words': 329}