diff options
Diffstat (limited to 'cmake/elfinfo/src/main/test/io/trygvis/ld/InputSectionSpecTest.java')
-rw-r--r-- | cmake/elfinfo/src/main/test/io/trygvis/ld/InputSectionSpecTest.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/cmake/elfinfo/src/main/test/io/trygvis/ld/InputSectionSpecTest.java b/cmake/elfinfo/src/main/test/io/trygvis/ld/InputSectionSpecTest.java new file mode 100644 index 0000000..2950061 --- /dev/null +++ b/cmake/elfinfo/src/main/test/io/trygvis/ld/InputSectionSpecTest.java @@ -0,0 +1,38 @@ +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()); + } +} |