package io.trygvis.ld; import io.trygvis.ld.antlr.GnuLdLexer; import io.trygvis.ld.antlr.GnuLdParser; import org.antlr.v4.runtime.ANTLRInputStream; import org.antlr.v4.runtime.CommonTokenStream; import org.junit.Test; import static org.junit.Assert.assertEquals; public class InputSectionSpecTest { @Test public void testName1() throws Exception { a("*(.text)", "(input_section_spec (input_section_spec_no_keep (wildcard_spec (wildcard_name *)) ( (file_name_list (wildcard_spec (wildcard_name .text))) )))"); } // This doesn't feel right @Test public void testName2() throws Exception { a("*(.text.*)", "(input_section_spec (input_section_spec_no_keep (wildcard_spec (wildcard_name *)) ( (file_name_list (file_name_list (wildcard_spec (wildcard_name .text.))) opt_comma (wildcard_spec (wildcard_name *))) )))"); } @Test public void testName3() throws Exception { a("KEEP(*/init_high.cpp.obj(.isr_vectors))", "(input_section_spec KEEP ( (input_section_spec_no_keep (wildcard_spec (wildcard_name *)) / init_high.cpp.obj ( .isr_vectors) ))"); } private void a(String input, String expected) { GnuLdParser parser = new GnuLdParser(new CommonTokenStream(new GnuLdLexer(new ANTLRInputStream(input)))); parser.setBuildParseTree(true); parser.removeErrorListeners(); parser.addErrorListener(new SystemOutReportingErrorListener(input)); GnuLdParser.Input_section_specContext input_section_spec = parser.input_section_spec(); assertEquals(input, expected, input_section_spec.toStringTree(parser)); assertEquals(0, parser.getNumberOfSyntaxErrors()); } }