<commit_before>/*******************************************************************************
 * Copyright (c) 2012 - 2015 Signal Iduna Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 * Signal Iduna Corporation - initial API and implementation
 * akquinet AG
 * itemis AG
 *******************************************************************************/
package org.testeditor.tcl.dsl.validation

import org.eclipse.xtext.validation.Check
import org.eclipse.xtext.xtype.XImportSection
import org.testeditor.tcl.StepContentElement
import org.testeditor.tcl.TclPackage
import org.testeditor.tcl.TestStepContext
import javax.inject.Inject
import org.testeditor.tcl.util.TclModelUtil
import org.testeditor.tcl.TestCase
import org.testeditor.tsl.SpecificationStep
import org.testeditor.tcl.SpecificationStepImplementation
import java.util.List

class TclValidator extends AbstractTclValidator {

	public static val UNKNOWN_NAME = 'unknownName'
	public static val NO_VALID_IMPLEMENTATION = 'noValidImplementation'

	@Inject extension TclModelUtil

	@Check
	def void referencesComponentElement(StepContentElement contentElement) {
		val component = contentElement.componentElement
		if (component === null) {
			error('No ComponentElement found.', contentElement, null)
		}
	}

	override checkImports(XImportSection importSection) {
		// ignore for now
	}

	@Check
	def checkMaskPresent(TestStepContext tsContext) {
		if (tsContext.component.eIsProxy) {
			warning("mask is not defined in aml", TclPackage.Literals.TEST_STEP_CONTEXT__COMPONENT, UNKNOWN_NAME);
		}
	}

	@Check
	def checkSpec(TestCase testCase) {
		if (testCase.specification != null) {
			if (!testCase.specification.steps.matches(testCase.steps))
				error("Testcase doesn't implent the Specification", TclPackage.Literals.TEST_CASE__SPECIFICATION,
					NO_VALID_IMPLEMENTATION)
		}
	}

	def boolean matches(List<SpecificationStep> specSteps, List<SpecificationStepImplementation> specImplSteps) {
		if (specSteps.size != specImplSteps.size) {
			return false
		}
		return specImplSteps.map[contents.restoreString].containsAll(specSteps.map[contents.restoreString])
	}
}
<commit_msg>TE-291 Validate only that the spec hase more steps than the implemetation<commit_after>/*******************************************************************************
 * Copyright (c) 2012 - 2015 Signal Iduna Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 * Signal Iduna Corporation - initial API and implementation
 * akquinet AG
 * itemis AG
 *******************************************************************************/
package org.testeditor.tcl.dsl.validation

import org.eclipse.xtext.validation.Check
import org.eclipse.xtext.xtype.XImportSection
import org.testeditor.tcl.StepContentElement
import org.testeditor.tcl.TclPackage
import org.testeditor.tcl.TestStepContext
import javax.inject.Inject
import org.testeditor.tcl.util.TclModelUtil
import org.testeditor.tcl.TestCase
import org.testeditor.tsl.SpecificationStep
import org.testeditor.tcl.SpecificationStepImplementation
import java.util.List

class TclValidator extends AbstractTclValidator {

	public static val UNKNOWN_NAME = 'unknownName'
	public static val NO_VALID_IMPLEMENTATION = 'noValidImplementation'

	@Inject extension TclModelUtil

	@Check
	def void referencesComponentElement(StepContentElement contentElement) {
		val component = contentElement.componentElement
		if (component === null) {
			error('No ComponentElement found.', contentElement, null)
		}
	}

	override checkImports(XImportSection importSection) {
		// ignore for now
	}

	@Check
	def checkMaskPresent(TestStepContext tsContext) {
		if (tsContext.component.eIsProxy) {
			warning("mask is not defined in aml", TclPackage.Literals.TEST_STEP_CONTEXT__COMPONENT, UNKNOWN_NAME);
		}
	}

	@Check
	def checkSpec(TestCase testCase) {
		if (testCase.specification != null) {
			if (!testCase.specification.steps.matches(testCase.steps))
				error("Testcase doesn't implent the Specification", TclPackage.Literals.TEST_CASE__SPECIFICATION,
					NO_VALID_IMPLEMENTATION)
		}
	}

	def boolean matches(List<SpecificationStep> specSteps, List<SpecificationStepImplementation> specImplSteps) {
		if (specSteps.size > specImplSteps.size) {
			return false
		}
		return specImplSteps.map[contents.restoreString].containsAll(specSteps.map[contents.restoreString])
	}
}

{'fraction_non_alphanumeric': 0.14182344428364688, 'fraction_numerical': 0.0055819722968782305, 'mean_word_length': 5.728789986091794, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1377393', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1346, 'n_words': 327}