/** Test for {@link ExtractUtils#covers(SourceRange, DartNode)}. */ public void test_covers_SourceRange_DartNode() throws Exception { setTestUnitContent( "// filler filler filler filler filler filler filler filler filler filler", "class A {", "}", ""); DartUnit unitNode = DartCompilerUtilities.resolveUnit(testUnit); assertFalse(ExtractUtils.covers(new SourceRange(0, 1), unitNode)); assertTrue(ExtractUtils.covers(new SourceRange(0, 1000), unitNode)); }
/** * Asserts that {@link ExtractUtils#getNodePrefix(DartNode)} in {@link #testUnit} has expected * prefix. */ private void assert_getNodePrefix(String nodePattern, String expectedPrefix) throws Exception { // prepare AST ExtractUtils utils = new ExtractUtils(testUnit); // find node int nodeOffset = findOffset(nodePattern); DartVariableStatement node = findNode(utils.getUnitNode(), nodeOffset, DartVariableStatement.class); assertNotNull(node); // assert prefix assertEquals(expectedPrefix, utils.getNodePrefix(node)); }
/** Asserts that value of the top-level field "x" in given source has the given type name. */ private String assertType(String expectedTypeName, String[] lines) throws Exception { DartExpression expression = getMarkerVariableExpression(lines); String type = ExtractUtils.getTypeSource(expression); if (expectedTypeName != null) { assertNotNull(type); assertEquals(expectedTypeName, type); } else { assertNull(type); } return type; }
/** * Asserts that each top-level variable has associative (or not) {@link DartBinaryExpression} * value. */ private void assert_isAssociative(boolean expected) throws DartModelException { DartUnit unit = DartCompilerUtilities.resolveUnit(testUnit); for (DartNode topLevelNode : unit.getTopLevelNodes()) { if (topLevelNode instanceof DartFieldDefinition) { DartFieldDefinition fieldDefinition = (DartFieldDefinition) topLevelNode; List<DartField> fields = fieldDefinition.getFields(); if (fields.size() == 1) { DartBinaryExpression expression = (DartBinaryExpression) fields.get(0).getValue(); assertEquals(expected, ExtractUtils.isAssociative(expression)); } } } }
/** Test for {@link ExtractUtils#getLinePrefix(int)}. */ public void test_getLinePrefix() throws Exception { setTestUnitContent("000\n 111\n \n "); ExtractUtils utils = new ExtractUtils(testUnit); // 0 assertEquals("", utils.getLinePrefix(0)); assertEquals("", utils.getLinePrefix(1)); assertEquals("", utils.getLinePrefix(2)); // 1 assertEquals(" ", utils.getLinePrefix(4)); assertEquals(" ", utils.getLinePrefix(5)); assertEquals(" ", utils.getLinePrefix(6)); assertEquals(" ", utils.getLinePrefix(7)); assertEquals(" ", utils.getLinePrefix(8)); // 2 assertEquals(" ", utils.getLinePrefix(10)); assertEquals(" ", utils.getLinePrefix(11)); assertEquals(" ", utils.getLinePrefix(12)); // 3 assertEquals(" ", utils.getLinePrefix(15)); }
/** Test for {@link ExtractUtils#getLineThis(int)}. */ public void test_getLineThis() throws Exception { setTestUnitContent("aaa\r\nbbbb\r\nccccc"); ExtractUtils utils = new ExtractUtils(testUnit); // 0 assertEquals(0, utils.getLineThis(0)); assertEquals(0, utils.getLineThis(1)); assertEquals(0, utils.getLineThis(2)); // 5 assertEquals(5, utils.getLineThis(5)); assertEquals(5, utils.getLineThis(6)); assertEquals(5, utils.getLineThis(7)); assertEquals(5, utils.getLineThis(8)); // 11 assertEquals(11, utils.getLineThis(11)); assertEquals(11, utils.getLineThis(12)); assertEquals(11, utils.getLineThis(13)); assertEquals(11, utils.getLineThis(14)); assertEquals(11, utils.getLineThis(15)); }
/** Test for {@link ExtractUtils#getEndOfLine()}. */ public void test_getEndOfLine_windows() throws Exception { setTestUnitContent("aaa\r\nbbb\r\nccc"); ExtractUtils utils = new ExtractUtils(testUnit); assertEquals("\r\n", utils.getEndOfLine()); }
/** Test for {@link ExtractUtils#getEndOfLine()}. */ public void test_getEndOfLine_default() throws Exception { setTestUnitContent(""); ExtractUtils utils = new ExtractUtils(testUnit); assertEquals(ExtractUtils.DEFAULT_END_OF_LINE, utils.getEndOfLine()); }
public void test_getType_null() throws Exception { assertSame(null, ExtractUtils.getTypeSource((DartExpression) null)); }
/** Test for {@link ExtractUtils#getText(int, int)}. */ public void test_getText() throws Exception { setTestUnitContent("// 0123456789"); ExtractUtils utils = new ExtractUtils(testUnit); assertEquals("0123", utils.getText(3, 4)); }