package io.proleap.cobol.asg.environment.configuration;

import static org.junit.Assert.assertNotNull;

import java.io.File;

import org.junit.Test;

import io.proleap.cobol.CobolTestBase;
import io.proleap.cobol.asg.metamodel.CompilationUnit;
import io.proleap.cobol.asg.metamodel.Program;
import io.proleap.cobol.asg.metamodel.ProgramUnit;
import io.proleap.cobol.asg.metamodel.environment.EnvironmentDivision;
import io.proleap.cobol.asg.metamodel.environment.configuration.ConfigurationSection;
import io.proleap.cobol.asg.metamodel.environment.configuration.object.ObjectComputerParagraph;
import io.proleap.cobol.asg.metamodel.environment.configuration.source.SourceComputerParagraph;
import io.proleap.cobol.asg.metamodel.environment.inputoutput.InputOutputSection;
import io.proleap.cobol.asg.metamodel.environment.inputoutput.filecontrol.FileControlParagraph;
import io.proleap.cobol.asg.runner.impl.CobolParserRunnerImpl;
import io.proleap.cobol.preprocessor.CobolPreprocessor.CobolSourceFormatEnum;

public class ConfigurationSectionWrongOrderTest extends CobolTestBase {

	@Test
	public void test() throws Exception {
		final File inputFile = new File(
				"src/test/resources/io/proleap/cobol/asg/environment/configuration/ConfigurationSectionWrongOrder.cbl");
		final Program program = new CobolParserRunnerImpl().analyzeFile(inputFile, CobolSourceFormatEnum.FIXED);

		final CompilationUnit compilationUnit = program.getCompilationUnit("ConfigurationSectionWrongOrder");
		final ProgramUnit programUnit = compilationUnit.getProgramUnit();
		final EnvironmentDivision environmentDivision = programUnit.getEnvironmentDivision();

		{
			final ConfigurationSection configurationSection = environmentDivision.getConfigurationSection();
			final SourceComputerParagraph sourceComputerParagraph = configurationSection.getSourceComputerParagraph();
			assertNotNull(sourceComputerParagraph);

			final ObjectComputerParagraph objectComputerParagraph = configurationSection.getObjectComputerParagraph();
			assertNotNull(objectComputerParagraph);
		}

		{
			final InputOutputSection inputOutputSection = environmentDivision.getInputOutputSection();
			final FileControlParagraph fileControlParagraph = inputOutputSection.getFileControlParagraph();
			assertNotNull(fileControlParagraph);
		}
	}
}

@@ -854,32 +854,118 @@
 ntrolParagraph;%0A
+import io.proleap.cobol.asg.metamodel.environment.specialnames.SpecialNamesParagraph;%0A
 import io.prolea
@@ -2138,16 +2138,169 @@
 );%0A%09%09%7D%0A%0A
+%09%09%7B%0A%09%09%09final SpecialNamesParagraph specialNamesParagraph = environmentDivision.getSpecialNamesParagraph();%0A%09%09%09assertNotNull(specialNamesParagraph);%0A%09%09%7D%0A%0A
 %09%09%7B%0A%09%09%09f

test fix