use of org.opensolaris.opengrok.analysis.Scopes.Scope in project OpenGrok by OpenGrok.
the class CAnalyzerFactoryTest method testScopeAnalyzer.
/**
* Test of writeXref method, of class CAnalyzerFactory.
*
* @throws java.lang.Exception
*/
@Test
public void testScopeAnalyzer() throws Exception {
String path = repository.getSourceRoot() + "/c/sample.c";
File f = new File(path);
if (!(f.canRead() && f.isFile())) {
fail("c testfile " + f + " not found");
}
Document doc = new Document();
doc.add(new Field(QueryBuilder.FULLPATH, path, string_ft_nstored_nanalyzed_norms));
StringWriter xrefOut = new StringWriter();
analyzer.setCtags(ctags);
analyzer.setScopesEnabled(true);
analyzer.analyze(doc, getStreamSource(path), xrefOut);
IndexableField scopesField = doc.getField(QueryBuilder.SCOPES);
assertNotNull(scopesField);
Scopes scopes = Scopes.deserialize(scopesField.binaryValue().bytes);
Scope globalScope = scopes.getScope(-1);
// foo, bar, main
assertEquals(3, scopes.size());
for (int i = 0; i < 50; ++i) {
if (i >= 8 && i <= 22) {
assertEquals("foo", scopes.getScope(i).getName());
assertNull(scopes.getScope(i).getNamespace());
} else if (i >= 24 && i <= 38) {
assertEquals("bar", scopes.getScope(i).getName());
assertNull(scopes.getScope(i).getNamespace());
} else if (i >= 41 && i <= 48) {
assertEquals("main", scopes.getScope(i).getName());
assertNull(scopes.getScope(i).getNamespace());
} else {
assertEquals(scopes.getScope(i), globalScope);
assertNull(scopes.getScope(i).getNamespace());
}
}
}
use of org.opensolaris.opengrok.analysis.Scopes.Scope in project OpenGrok by OpenGrok.
the class ScopesTest method testGetScope.
/**
* Test of getScope method, of class Scopes.
*/
@Test
public void testGetScope() {
Scopes instance = new Scopes();
Scope globalScope = instance.getScope(0);
instance.addScope(new Scope(10, 20, "scope1", "ns"));
instance.addScope(new Scope(25, 30, "scope2", "ns"));
instance.addScope(new Scope(40, 40, "scope3", "ns"));
instance.addScope(new Scope(60, 70, "scope4", "ns"));
instance.addScope(new Scope(80, 90, "scope5", "ns"));
instance.addScope(new Scope(91, 100, "scope6", "ns"));
assertEquals(instance.size(), 6);
assertEquals(instance.getScope(1), globalScope);
assertEquals(instance.getScope(10).getName(), "scope1");
assertEquals(instance.getScope(15).getName(), "scope1");
assertEquals(instance.getScope(20).getName(), "scope1");
assertEquals(instance.getScope(21), globalScope);
assertEquals(instance.getScope(24), globalScope);
assertEquals(instance.getScope(39), globalScope);
assertEquals(instance.getScope(40).getName(), "scope3");
assertEquals(instance.getScope(41), globalScope);
assertEquals(instance.getScope(90).getName(), "scope5");
assertEquals(instance.getScope(100).getName(), "scope6");
assertEquals(instance.getScope(101), globalScope);
assertEquals(instance.getScope(500), globalScope);
}
Aggregations