<commit_before>﻿using System.Diagnostics.CodeAnalysis;
using Gibberish.AST;
using Gibberish.AST._1_Bare;
using Gibberish.Execution;
using Gibberish.Parsing;
using Gibberish.Tests.ZzTestHelpers;
using JetBrains.Annotations;
using NUnit.Framework;

namespace Gibberish.Tests.CompileFasm.BeAbleToDefineAThunk
{
	[TestFixture]
	public class CompileThunks
	{
		[Test]
		public void ShouldAssembleBlocksfromValidNesting()
		{
			var testSubject = new AssembleBlocks();
			var result = testSubject.Transform(
				BasicAst.RawBlock("outer block")
					.WithBody(
						b =>
						{
							b.AddStatement("outer 1");
							b.AddBlock("nested 1")
								.WithBody(inner => inner.AddStatement("nested 1.1"));
							b.AddStatement("outer 2");
							b.AddBlock("nested 2")
								.WithBody(
									inner =>
									{
										inner.AddStatement("nested 2.1");
										inner.AddBlankLine();
										inner.AddStatement("nested 2.2");
									});
							b.AddBlock("nested 3")
								.WithBody(inner => inner.AddStatement("nested 3.1"));
						})
					.Build());
			result.Should()
				.BeRecognizedAs(
					BasicAst.Block("outer block")
						.WithBody(
							b =>
							{
								b.AddStatement("outer 1");
								b.AddBlock("nested 1")
									.WithBody(inner => inner.AddStatement("nested 1.1"));
								b.AddStatement("outer 2");
								b.AddBlock("nested 2")
									.WithBody(
										inner =>
										{
											inner.AddStatement("nested 2.1");
											inner.AddBlankLine();
											inner.AddStatement("nested 2.2");
										});
								b.AddBlock("nested 3")
									.WithBody(inner => inner.AddStatement("nested 3.1"));
							}));
		}

		[Test]
		public void CompilingATrivialDefineThunkNodeShouldCreateThunkInNameTable()
		{
			var testSubject = Tools.Fasm_Old.Compiler_OldApi;
			var parse = FasmAstOld.Thunk(ArbitraryName, FasmAstOld.PassRaw);
			testSubject.CompileFragment(parse, _arbitraryDistrict);
			_arbitraryDistrict.Name(ArbitraryName)
				.ShouldHave(
					new
					{
						name = ArbitraryName
					});
		}

		private const string ArbitraryName = "the.name";

		[NotNull, SuppressMessage("ReSharper", "NotNullMemberIsNotInitialized")] private City _city;
		[NotNull, SuppressMessage("ReSharper", "NotNullMemberIsNotInitialized")] private District _arbitraryDistrict;

		[SetUp]
		public void Setup()
		{
			_city = new City();
			_arbitraryDistrict = _city.District("CompileTest");
		}
	}
}
<commit_msg>Split out a few existing test cases into their own tests.<commit_after>﻿using System.Diagnostics.CodeAnalysis;
using Gibberish.AST;
using Gibberish.AST._1_Bare;
using Gibberish.Execution;
using Gibberish.Parsing;
using Gibberish.Tests.ZzTestHelpers;
using JetBrains.Annotations;
using NUnit.Framework;

namespace Gibberish.Tests.CompileFasm.BeAbleToDefineAThunk
{
	[TestFixture]
	public class CompileThunks
	{
		[Test]
		public void ShouldFindBlockwithSimpleStatements()
		{
			var testSubject = new AssembleBlocks();
			var result = testSubject.Transform(
				BasicAst.RawBlock("outer block")
					.WithBody(
						b =>
						{
							b.AddStatement("outer 1");
							b.AddStatement("outer 2");
						})
					.Build());
			result.Should()
				.BeRecognizedAs(
					BasicAst.Block("outer block")
						.WithBody(
							b =>
							{
								b.AddStatement("outer 1");
								b.AddStatement("outer 2");
							}));
		}

		[Test]
		public void BlocksShouldBeNestable()
		{
			var testSubject = new AssembleBlocks();
			var result = testSubject.Transform(
				BasicAst.RawBlock("outer block")
					.WithBody(
						b =>
						{
							b.AddBlock("nested 1")
								.WithBody(inner => inner.AddStatement("nested 1.1"));
						})
					.Build());
			result.Should()
				.BeRecognizedAs(
					BasicAst.Block("outer block")
						.WithBody(
							b =>
							{
								b.AddBlock("nested 1")
									.WithBody(inner => inner.AddStatement("nested 1.1"));
							}));
		}

		[Test]
		public void FollowingABlockWithALessNestedStatementEndsTheInnerBlock()
		{
			var testSubject = new AssembleBlocks();
			var result = testSubject.Transform(
				BasicAst.RawBlock("outer block")
					.WithBody(
						b =>
						{
							b.AddBlock("nested 1")
								.WithBody(inner => inner.AddStatement("nested 1.1"));
							b.AddStatement("outer 1");
						})
					.Build());
			result.Should()
				.BeRecognizedAs(
					BasicAst.Block("outer block")
						.WithBody(
							b =>
							{
								b.AddBlock("nested 1")
									.WithBody(inner => inner.AddStatement("nested 1.1"));
								b.AddStatement("outer 1");
							}));
		}

		[Test]
		public void FollowingABlockWithALessNestedBlockEndsTheInnerBlockAndStartsANewOne()
		{
			var testSubject = new AssembleBlocks();
			var result = testSubject.Transform(
				BasicAst.RawBlock("outer block")
					.WithBody(
						b =>
						{
							b.AddBlock("nested 1")
								.WithBody(inner => inner.AddStatement("nested 1.1"));
							b.AddBlock("nested 2")
								.WithBody(inner => inner.AddStatement("nested 2.1"));
						})
					.Build());
			result.Should()
				.BeRecognizedAs(
					BasicAst.Block("outer block")
						.WithBody(
							b =>
							{
								b.AddBlock("nested 1")
									.WithBody(inner => inner.AddStatement("nested 1.1"));
								b.AddBlock("nested 2")
									.WithBody(inner => inner.AddStatement("nested 2.1"));
							}));
		}

		[Test]
		public void BlankLinesInBlocksShouldBeSkipped()
		{
			var testSubject = new AssembleBlocks();
			var result = testSubject.Transform(
				BasicAst.RawBlock("outer block")
					.WithBody(
						b =>
						{
							b.AddStatement("outer 1");
							b.AddBlankLine();
							b.AddStatement("outer 2");
						})
					.Build());
			result.Should()
				.BeRecognizedAs(
					BasicAst.Block("outer block")
						.WithBody(
							b =>
							{
								b.AddStatement("outer 1");
								b.AddBlankLine();
								b.AddStatement("outer 2");
							}));
		}

		[Test]
		public void FilesEndingInNestedBlockShouldParseCleanly()
		{
			var testSubject = new AssembleBlocks();
			var result = testSubject.Transform(
				BasicAst.RawBlock("outer block")
					.WithBody(
						b =>
						{
							b.AddBlock("nested 1")
								.WithBody(inner => inner.AddStatement("nested 1.1"));
						})
					.Build());
			result.Should()
				.BeRecognizedAs(
					BasicAst.Block("outer block")
						.WithBody(
							b =>
							{
								b.AddBlock("nested 1")
									.WithBody(inner => inner.AddStatement("nested 1.1"));
							}));
		}

		[Test]
		public void CompilingATrivialDefineThunkNodeShouldCreateThunkInNameTable()
		{
			var testSubject = Tools.Fasm_Old.Compiler_OldApi;
			var parse = FasmAstOld.Thunk(ArbitraryName, FasmAstOld.PassRaw);
			testSubject.CompileFragment(parse, _arbitraryDistrict);
			_arbitraryDistrict.Name(ArbitraryName)
				.ShouldHave(
					new
					{
						name = ArbitraryName
					});
		}

		private const string ArbitraryName = "the.name";

		[NotNull, SuppressMessage("ReSharper", "NotNullMemberIsNotInitialized")] private City _city;
		[NotNull, SuppressMessage("ReSharper", "NotNullMemberIsNotInitialized")] private District _arbitraryDistrict;

		[SetUp]
		public void Setup()
		{
			_city = new City();
			_arbitraryDistrict = _city.District("CompileTest");
		}
	}
}

{'fraction_non_alphanumeric': 0.13140096618357489, 'fraction_numerical': 0.009385783298826778, 'mean_word_length': 2.678172588832487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '3230440', 'n_tokens_mistral': 3362, 'n_tokens_neox': 2267, 'n_words': 414}