/*
 * generated by Xtext 2.14.0
 */
package com.minres.rdl.tests

import com.google.inject.Inject
import com.minres.rdl.rdl.Root
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(XtextRunner)
@InjectWith(RDLInjectorProvider)
class RDLParsingTest {
	@Inject
	ParseHelper<Root> parseHelper
	
	@Test
	def void loadModel() {
		val result = parseHelper.parse('''
			regfile uart_regs {
				reg {
					name="txdata";
					desc="Transmit data register";
					field {} data[7:0];
					field {} full[31:31];
				} txdata @0x00;
				reg {
					name="rxdata";
					desc="Receive data register";
					field {} data[7:0];
					field {} empty[31:31];
				}rxdata @0x04;
				reg {
					name="txctrl";
					desc="Transmit control register";
					field {} txen[1];
					field {} nstop[1];
					field {} txcnt[18:16];
				}txctrl @0x08;
				reg {
					name="rxctrl";
					desc="Receive control register";
					field {} rxen[1];
					field {} rxcnt[18:16];
				}rxctrl @0x0C;
				reg {
					name="ie";
					desc="UART interrupt enable";
					field{} txwm[1];
					field{} rxwm[1];
				}ie @0x10;
				reg {
					name="ip";
					desc="UART Interrupt pending";
					field{} txwm[1];
					field{} rxwm[1];
				} ip @0x14;
				reg {
					name="div";
					desc="Baud rate divisor";
					field{} div[16];
				} div @0x18;
			};
		''')
		Assert.assertNotNull(result)
		val errors = result.eResource.errors
		Assert.assertTrue('''Unexpected errors: «errors.join(", ")»''', errors.isEmpty)
	}
}
