CheckFigurePaths extends Rule { @Override public List<Advice> evaluate(AnnotatedString s, AnnotatedString original) { List<Advice> out_list = new ArrayList<Advice>(); List<String> lines = s.getLines(); for (int line_cnt = 0; line_cnt < lines.size(); line_cnt++) { String line = lines.get(line_cnt); Matcher mat = m_figurePattern.matcher(line); if (mat.find()) { String path = mat.group(2).trim(); if (isAbsolute(path)) { Position start_pos = s.getSourcePosition(new Position(line_cnt, mat.start(2))); Position end_pos = s.getSourcePosition(new Position(line_cnt, mat.start(2) + mat.group(2).length())); Range r = new Range(start_pos, end_pos); out_list.add(new Advice(this, r, "Do not use an absolute path for a figure", original.getResourceName(), original.getLine(start_pos.getLine()), original.getOffset(start_pos))); } } } return out_list; } CheckFigurePaths(); @Override List<Advice> evaluate(AnnotatedString s, AnnotatedString original); @Override String getDescription();  }
@Test public void test1() { AnnotatedString in_string = AnnotatedString.read(new Scanner("\\begin{figure}\n" + "\\includegraphics{path/to/file.pdf}\n" + "\\end{figure}")); Rule r = new CheckFigurePaths(); List<Advice> ad_list = r.evaluate(in_string, in_string); assertTrue(ad_list.isEmpty()); }
@Test public void test2() { AnnotatedString in_string = AnnotatedString.read(new Scanner("\\begin{figure}\n" + "\\includegraphics{D:\\Sylvain\\file.pdf}\n" + "\\end{figure}")); Rule r = new CheckFigurePaths(); List<Advice> ad_list = r.evaluate(in_string, in_string); assertEquals(1, ad_list.size()); }
@Test public void test3() { AnnotatedString in_string = AnnotatedString.read(new Scanner("\\begin{figure}\n" + "\\includegraphics{/home/Sylvain/file.pdf}\n" + "\\end{figure}")); Rule r = new CheckFigurePaths(); List<Advice> ad_list = r.evaluate(in_string, in_string); assertEquals(1, ad_list.size()); }