<commit_before>namespace Boojay.Compilation.Tests

import System.IO
import NUnit.Framework

import Boo.Lang.Compiler.Ast

import Boojay.Compilation
import Boojay.Compilation.TypeSystem

[TestFixture]
class UtilsTest(TestWithCompilerContext):
	
	[Test] def SimpleCompile():
		simpleCompileTest = [|
			import java.lang
			
			class Foo:
				pass
		|]
		
		for type in simpleCompileTest.Members:
			className = "${type.FullName.Replace('.', '/')}.class"
			File.Delete(className) if File.Exists(className)

		boojayCompile(CompileUnit(simpleCompileTest))
		
		Assert.AreEqual(1, len(simpleCompileTest.Members))
		
		for type in simpleCompileTest.Members:
			className = "${type.FullName.Replace('.', '/')}.class"
			Assert.IsTrue(File.Exists(className), "File does not exists: ${className}")

	[Test] def CompileWithJars():
		compileWithJarsTest = [|
			import java.lang
			
			class Foo:
				def getBarName():
					Bar().getName()
		|]
		
		library = [|
			import java.lang
			
			class Bar:
				def getName():
					return "Bar"
		|]
		
		generatedJar = generateTempJarWith(library)
		jarCompileUnit = JarTypeSystemProvider().ForJar(generatedJar)

		for type in compileWithJarsTest.Members:
			className = "${type.FullName.Replace('.', '/')}.class"
			File.Delete(className) if File.Exists(className)

		boojayCompile(CompileUnit(compileWithJarsTest), jarCompileUnit)
		
		Assert.AreEqual(1, len(compileWithJarsTest.Members))
		
		for type in compileWithJarsTest.Members:
			className = "${type.FullName.Replace('.', '/')}.class"
			Assert.IsTrue(File.Exists(className), "File does not exists: ${className}")
		
			<commit_msg>little refactoring to remove code duplication<commit_after>namespace Boojay.Compilation.Tests

import System.IO
import NUnit.Framework

import Boo.Lang.Compiler.Ast

import Boojay.Compilation
import Boojay.Compilation.TypeSystem

[TestFixture]
class UtilsTest(TestWithCompilerContext):
	
	[Test] def SimpleCompile():
		simpleCompileTest = [|
			import java.lang
			
			class Foo:
				pass
		|]
		
		RemoveClasses(simpleCompileTest)

		boojayCompile(CompileUnit(simpleCompileTest))
		
		Assert.AreEqual(1, len(simpleCompileTest.Members))
		
		AssertClassesGeneration(simpleCompileTest)
		
	[Test] def CompileWithJars():
		compileWithJarsTest = [|
			import java.lang
			
			class Foo:
				def getBarName():
					Bar().getName()
		|]
		
		library = [|
			import java.lang
			
			class Bar:
				def getName():
					return "Bar"
		|]
		
		generatedJar = generateTempJarWith(library)
		jarCompileUnit = JarTypeSystemProvider().ForJar(generatedJar)

		RemoveClasses(compileWithJarsTest)

		boojayCompile(CompileUnit(compileWithJarsTest), jarCompileUnit)
		
		Assert.AreEqual(1, len(compileWithJarsTest.Members))

		AssertClassesGeneration(compileWithJarsTest)
		
	private def RemoveClasses(unit as Module):
		for type in unit.Members:
			className = "${type.FullName.Replace('.', '/')}.class"
			File.Delete(className) if File.Exists(className)
		
	private def AssertClassesGeneration(unit as Module):
		for type in unit.Members:
			className = "${type.FullName.Replace('.', '/')}.class"
			Assert.IsTrue(File.Exists(className), "File does not exists: ${className}")
		
			
{'fraction_non_alphanumeric': 0.11869715001565925, 'fraction_numerical': 0.001252740369558409, 'mean_word_length': 4.2619439868204285, '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': '2883984', 'n_tokens_mistral': 1202, 'n_tokens_neox': 978, 'n_words': 198}