// TODO(oana): Added a task in tracker for fixing these dependencies and // making the mocking of objects easier. public void testEnterArgumentNode() { CssDefinitionNode def = new CssDefinitionNode(new CssLiteralNode("COLOR")); MutatingVisitController visitController = createMock(MutatingVisitController.class); CssTree tree = createMock(CssTree.class); expect(tree.getMutatingVisitController()).andReturn(visitController).anyTimes(); ConstantDefinitions definitions = EasyMock.createMock(ConstantDefinitions.class); expect(definitions.getConstantDefinition("COLOR")).andReturn(def).anyTimes(); replay(definitions); replay(tree); ReplaceConstantReferences pass = new ReplaceConstantReferences( tree, definitions, true /* removeDefs */, new DummyErrorManager(), true /* allowUndefinedConstants */); Capture<List<CssNode>> tempList = new Capture<List<CssNode>>(); visitController.replaceCurrentBlockChildWith(capture(tempList), eq(true)); replay(visitController); CssConstantReferenceNode node = new CssConstantReferenceNode("COLOR", null); pass.enterArgumentNode(node); verify(visitController); assertEquals(1, tempList.getValue().size()); assertEquals(CssCompositeValueNode.class, tempList.getValue().get(0).getClass()); }
public void testEnterValueNode() { CssDefinitionNode def = new CssDefinitionNode(new CssLiteralNode("COLOR")); def.getParameters().add(new CssLiteralNode("red")); CssPropertyNode prop1 = new CssPropertyNode("padding", null); CssPropertyValueNode value1 = new CssPropertyValueNode(); BackDoorNodeMutation.addChildToBack(value1, new CssNumericNode("5", "px")); CssPropertyNode prop2 = new CssPropertyNode("color", null); CssPropertyValueNode value2 = new CssPropertyValueNode(); CssConstantReferenceNode ref = new CssConstantReferenceNode("COLOR", null); BackDoorNodeMutation.addChildToBack(value2, ref); CssDeclarationNode decl1 = new CssDeclarationNode(prop1); decl1.setPropertyValue(value1); CssDeclarationNode decl2 = new CssDeclarationNode(prop2); decl2.setPropertyValue(value2); CssRulesetNode ruleset = new CssRulesetNode(); CssSelectorNode sel = new CssSelectorNode("foo", null); ruleset.addSelector(sel); ruleset.addDeclaration(decl1); ruleset.addDeclaration(decl2); CssBlockNode body = new CssBlockNode(false); BackDoorNodeMutation.addChildToBack(body, ruleset); CssRootNode root = new CssRootNode(body); CssTree tree = new CssTree(null, root); ConstantDefinitions constantDefinitions = new ConstantDefinitions(); constantDefinitions.addConstantDefinition(def); ReplaceConstantReferences pass = new ReplaceConstantReferences( tree, constantDefinitions, true /* removeDefs */, new DummyErrorManager(), true /* allowUndefinedConstants */); pass.runPass(); assertEquals(tree.getRoot().getBody().toString(), "[[foo]{[padding:[5px], color:[red]]}]"); }
public void testRunPass() { MutatingVisitController visitController = createMock(MutatingVisitController.class); CssTree tree = createMock(CssTree.class); expect(tree.getMutatingVisitController()).andReturn(visitController).anyTimes(); // We need to have this replayed because in the constructor of // ReplaceConstantReferences pass we need tree.getMutatingVisitController(). replay(tree); ReplaceConstantReferences pass = new ReplaceConstantReferences( tree, new ConstantDefinitions(), true /* removeDefs */, new DummyErrorManager(), true /* allowUndefinedConstants */); visitController.startVisit(pass); replay(visitController); pass.runPass(); verify(visitController); }
public void testEnterValueNode2() { CssPropertyNode prop = new CssPropertyNode("color", null); CssPropertyValueNode value = new CssPropertyValueNode(); BackDoorNodeMutation.addChildToBack(value, new CssHexColorNode("#123344", null)); CssDeclarationNode decl = new CssDeclarationNode(prop); decl.setPropertyValue(value); CssRulesetNode ruleset = new CssRulesetNode(); CssSelectorNode sel = new CssSelectorNode("foo", null); ruleset.addSelector(sel); ruleset.addDeclaration(decl); CssBlockNode body = new CssBlockNode(false); BackDoorNodeMutation.addChildToBack(body, ruleset); CssRootNode root = new CssRootNode(body); CssTree tree = new CssTree(null, root); ColorValueOptimizer pass = new ColorValueOptimizer(tree.getMutatingVisitController()); pass.runPass(); assertEquals(tree.getRoot().getBody().toString(), "[[foo]{[color:[#123344]]}]"); }