<commit_before>package javamm.tests

import com.google.inject.Inject
import javamm.JavammInjectorProvider
import javamm.javamm.JavammXVariableDeclaration
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.xbase.XExpression
import org.eclipse.xtext.xbase.typesystem.IBatchTypeResolver
import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference
import org.junit.Test
import org.junit.runner.RunWith

import static org.junit.Assert.*
import javamm.javamm.JavammSemicolonStatement

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(JavammInjectorProvider))
class JavammTypeComputerTest extends JavammAbstractTest {

	@Inject
	IBatchTypeResolver typeResolver;

	@Test
	def testStringLiteral() {
		'''"a"'''.assertActualType("java.lang.String")
	}

	@Test
	def testCharLiteral() {
		"'a'".assertActualType("char")
	}

	@Test
	def testCharLiteralWithCharExpectation() {
		"char c = 'a'".assertVarExpressionActualType("char")
	}

	@Test
	def testCharLiteralWithIntExpectation() {
		"int c = 'a'".assertVarExpressionActualType("int")
	}

	@Test
	def testCharLiteralWithStringExpectation() {
		"String c = 'a'".assertVarExpressionActualType("char")
	}

	@Test
	def testCharLiteralWithVoidExpectation() {
		"void c = 'a'".assertVarExpressionActualType("char")
	}

	@Test
	def testCharLiteralWithBooleanExpectation() {
		"boolean c = 'a'".assertVarExpressionActualType("char")
	}

	@Test
	def testNumberLiteral() {
		"0".assertActualType("int")
	}

	@Test
	def testNumberLiteralWithByteExpectation() {
		"byte b = 0".assertVarExpressionActualType("byte")
	}

	@Test
	def testNumberLiteralWithShortExpectation() {
		"short b = 0".assertVarExpressionActualType("short")
	}

	@Test
	def testNumberLiteralWithShortExpectationGreaterThanMaxShort() {
		"short b = 32768".assertVarExpressionActualType("int")
	}

	@Test
	def testNumberLiteralWithCharExpectation() {
		"char b = 0".assertVarExpressionActualType("char")
	}

	@Test
	def testNumberLiteralWithCharExpectationGreaterThanMaxChar() {
		"char b = 65536".assertVarExpressionActualType("int")
	}

	@Test
	def testNumberLiteralWithLongExpectation() {
		"long b = 65536".assertVarExpressionActualType("int")
	}

	@Test
	def testNumberLiteralWithString() {
		"String b = 65536".assertVarExpressionActualType("int")
	}

	@Test
	def void testAdditionalVars() {
		"int i, j, k;".assertLastExpression[
			val varDecl = variableDeclaration
			varDecl.additionalVariables.forEach[
				assertActualType("void")
			]
		]
	}

	@Test
	def void testAdditionalVarsAddedToScope() {<commit_msg>47: other tests for type of variable declarations<commit_after>package javamm.tests

import com.google.inject.Inject
import javamm.JavammInjectorProvider
import javamm.javamm.JavammXVariableDeclaration
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.xbase.XExpression
import org.eclipse.xtext.xbase.typesystem.IBatchTypeResolver
import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference
import org.junit.Test
import org.junit.runner.RunWith

import static org.junit.Assert.*
import javamm.javamm.JavammSemicolonStatement

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(JavammInjectorProvider))
class JavammTypeComputerTest extends JavammAbstractTest {

	@Inject
	IBatchTypeResolver typeResolver;

	@Test
	def testStringLiteral() {
		'''"a"'''.assertActualType("java.lang.String")
	}

	@Test
	def testCharLiteral() {
		"'a'".assertActualType("char")
	}

	@Test
	def testCharLiteralWithCharExpectation() {
		"char c = 'a'".assertVarExpressionActualType("char")
	}

	@Test
	def testCharLiteralWithIntExpectation() {
		"int c = 'a'".assertVarExpressionActualType("int")
	}

	@Test
	def testCharLiteralWithStringExpectation() {
		"String c = 'a'".assertVarExpressionActualType("char")
	}

	@Test
	def testCharLiteralWithVoidExpectation() {
		"void c = 'a'".assertVarExpressionActualType("char")
	}

	@Test
	def testCharLiteralWithBooleanExpectation() {
		"boolean c = 'a'".assertVarExpressionActualType("char")
	}

	@Test
	def testNumberLiteral() {
		"0".assertActualType("int")
	}

	@Test
	def testNumberLiteralWithByteExpectation() {
		"byte b = 0".assertVarExpressionActualType("byte")
	}

	@Test
	def testNumberLiteralWithShortExpectation() {
		"short b = 0".assertVarExpressionActualType("short")
	}

	@Test
	def testNumberLiteralWithShortExpectationGreaterThanMaxShort() {
		"short b = 32768".assertVarExpressionActualType("int")
	}

	@Test
	def testNumberLiteralWithCharExpectation() {
		"char b = 0".assertVarExpressionActualType("char")
	}

	@Test
	def testNumberLiteralWithCharExpectationGreaterThanMaxChar() {
		"char b = 65536".assertVarExpressionActualType("int")
	}

	@Test
	def testNumberLiteralWithLongExpectation() {
		"long b = 65536".assertVarExpressionActualType("int")
	}

	@Test
	def testNumberLiteralWithString() {
		"String b = 65536".assertVarExpressionActualType("int")
	}

	@Test
	def void testVariableDeclaration() {
		"int i;".assertLastExpression[
			variableDeclaration.assertActualType("void")
		]
	}

	@Test
	def void testVariableDeclarationAddedToScope() {
		'''
		int i;
		i;
		'''.assertActualType("int")
	}

	@Test
	def void testAdditionalVars() {
		"int i, j, k;".assertLastExpression[
			val varDecl = variableDeclaration
			varDecl.additionalVariables.forEach[
				assertActualType("void")
			]
		]
	}

	@Test
	def void testAdditionalVarsAddedToScope() {
{'fraction_non_alphanumeric': 0.11428049003474126, 'fraction_numerical': 0.009873834339001646, 'mean_word_length': 5.968152866242038, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4227542', 'n_tokens_mistral': 1951, 'n_tokens_neox': 1814, 'n_words': 296}