Package com.google.gwt.thirdparty.common.css.compiler.ast

Examples of com.google.gwt.thirdparty.common.css.compiler.ast.CssTree


*/
public class RuntimeConditionalBlockCollectorTest extends BaseGssTest {

  public void testCollectRuntimeConditionalBlock() {
    // given
    CssTree cssTree = parseAndBuildTree(lines(
        "@if (eval('com.foo.BAR')) {",
        "  .foo {",
        "    padding: 5px;",
        "  }",
        "  @if (is('ie9')) {",
        "    .foo {",
        "      padding: 55px;",
        "    }",
        "  }",
        "}",
        "@elseif (eval('com.foo.bar()')) {",
        "  @if (eval('com.foo.FOO')) {",
        "    .foo {",
        "      padding: 15px;",
        "    }",
        "  }",
        "  @else{",
        "    .foo {",
        "      padding: 15px;",
        "    }",
        "  }",
        "}",
        "@if (is('ie6')) {",
        "  .foo {",
        "    padding: 25px;",
        "  }",
        "}",
        "@elseif (eval('com.foo.BAR')) {",
        "  .foo {",
        "    padding: 35px;",
        "  }",
        "}"));

    RuntimeConditionalBlockCollector visitor =
        new RuntimeConditionalBlockCollector(cssTree.getMutatingVisitController());

    // when
    visitor.runPass();

    // then
View Full Code Here


            "}"
        ));
  }

  private void assertPrintedResult(String expectedCss, String source) {
    CssTree cssTree = parseAndBuildTree(source);

    CssPrinter pass = new CssPrinter(cssTree);
    pass.runPass();

    assertEquals(expectedCss, pass.getCompactPrintedString());
View Full Code Here

   */
  private static class GssWrapper {
    private static Set<String> getCssClassNames(String fileName, String cssSource,
        Set<JClassType> imports, TreeLogger logger) throws UnableToCompleteException {
      SourceCode sourceCode = new SourceCode(fileName, cssSource);
      CssTree tree;
      try {
        tree = new GssParser(sourceCode).parse();
      } catch (GssParserException e) {
        logger.log(TreeLogger.ERROR, "Unable to parse CSS", e);
        throw new UnableToCompleteException();
View Full Code Here

    imageMethod = mock(JMethod.class);
  }

  public void testInvalidSpriteWithSeveralValue() {
    // given
    CssTree cssTree = parseAndBuildTree(lines(
        ".someClassWithSprite { ",
        "  gwt-sprite: imageResource otherImageResource;",
        "}"));

    ImageSpriteCreator visitor = new ImageSpriteCreator(cssTree.getMutatingVisitController(),
        resourceContext, errorManager, methodByPathHelper);

    // when
    visitor.runPass();
View Full Code Here

    verify(errorManager).report(any(GssError.class));
  }

  public void testInvalidSpriteImageMethodNotFound() throws NotFoundException {
    // given
    CssTree cssTree = parseAndBuildTree(lines(
        ".someClassWithSprite { ",
        "  gwt-sprite: imageResource;",
        "}"));
    when(resourceContext.getClientBundleType()).thenReturn(mock(JClassType.class));
    when(methodByPathHelper.getMethodByPath(any(ResourceContext.class), anyList(),
        any(JClassType.class))).thenThrow(new NotFoundException(""));

    ImageSpriteCreator visitor = new ImageSpriteCreator(cssTree.getMutatingVisitController(),
        resourceContext, errorManager, methodByPathHelper);

    // when
    visitor.runPass();
View Full Code Here

    testSpriteCreation("no-repeat", RepeatStyle.None);
  }

  private void testSpriteCreation(String repeat, RepeatStyle repeatStyle) throws NotFoundException {
    // given
    CssTree cssTree = parseAndBuildTree(lines(
        ".someClassWithSprite { ",
        "  color: white;",
        "  gwt-sprite: 'imageResource';",
        "  background-color: black;",
        "}"));

    when(methodByPathHelper.getMethodByPath(any(ResourceContext.class), anyList(),
        any(JClassType.class))).thenReturn(imageMethod);

    if (repeatStyle != null) {
      // simulate a @ImageOptions(repeatStyle)
      ImageOptions imageOptions = mock(ImageOptions.class);
      when(imageOptions.repeatStyle()).thenReturn(repeatStyle);
      when(imageMethod.getAnnotation(ImageOptions.class)).thenReturn(imageOptions);
    }

    ImageSpriteCreator visitor = new ImageSpriteCreator(cssTree.getMutatingVisitController(),
        resourceContext, errorManager, methodByPathHelper);

    // when
    visitor.runPass();

    // then
    verify(errorManager, never()).report(any(GssError.class));

    String widthRule = "[/* @alternate */]width:[ImageSpriteCreatorTest.this.imageResource()" +
        ".getWidth() + \"px\"], ";
    String heightRule = "[/* @alternate */]height:[ImageSpriteCreatorTest.this.imageResource()" +
        ".getHeight() + \"px\"], ";

    if (repeatStyle == RepeatStyle.Horizontal || repeatStyle == RepeatStyle.Both) {
      widthRule = "";
    }

    if (repeatStyle == RepeatStyle.Vertical || repeatStyle == RepeatStyle.Both) {
      heightRule = "";
    }

    String cssTreeStringExpected = "[" +
        "[.someClassWithSprite]{" +
        "[color:[white], " +
        heightRule +
        widthRule +
        "[/* @alternate */]overflow:[hidden], " +
        "[/* @alternate */]background:" +
        "[url(ImageSpriteCreatorTest.this.imageResource().getSafeUri().asString()), " +
        "\"-\" + ImageSpriteCreatorTest.this.imageResource().getLeft() + \"px\", " +
        "\"-\" + ImageSpriteCreatorTest.this.imageResource().getTop() + \"px\",  " +
        "" + repeat + "], " +
        "background-color:[black]]" +
        "}]";
    assertEquals(cssTreeStringExpected, cssTree.getRoot().getBody().toString());
  }
View Full Code Here

*/
public class PermutationsCollectorTest extends BaseGssTest {

  public void testPermutationCollector() {
    // given
    CssTree cssTree = parseAndBuildTree(lines(
        "@if (is('custom.one', 'foo') && is('custom.one', 'bar')) {",
        "  .foo {",
        "    padding: 5px;",
        " }",
        "}",
        "",
        "@elseif (!is('custom.two', 'foo') && is('custom.three', 'foo') " +
            "|| is('custom.four', 'foo')) {",
        "  .foo {",
        "    padding: 15px;",
        " }",
        "}"));

    ErrorManager errorManager = mock(ErrorManager.class);
    PermutationsCollector visitor = new PermutationsCollector(cssTree.getMutatingVisitController(),
        errorManager);

    // when
    visitor.runPass();

View Full Code Here

    assertTrue(permutationAxis.contains("custom.three"));
    assertTrue(permutationAxis.contains("custom.four"));
  }

  public void testUserAgentShortcut() {
    CssTree cssTree = parseAndBuildTree(lines(
        "@if (is('custom.one', 'foo') && is('ie6')) {",
        "  .foo {",
        "    padding: 5px;",
        " }",
        "}"));

    ErrorManager errorManager = mock(ErrorManager.class);
    PermutationsCollector visitor = new PermutationsCollector(cssTree.getMutatingVisitController(),
        errorManager);

    // when
    visitor.runPass();
View Full Code Here

    assertTrue(permutationAxis.contains("custom.one"));
    assertTrue(permutationAxis.contains("user.agent"));
  }

  public void testRuntimeConditionAreIgnored() {
    CssTree cssTree = parseAndBuildTree(lines(
        "@if (eval('com.foo.BAR')) {",
        "  .foo {",
        "    padding: 5px;",
        "  }",
        "}",
        "@elseif (eval('com.foo.bar()')) {",
        "  @if (is('custom.one', 'foo')) {",
        "    .foo {",
        "      padding: 15px;",
        "    }",
        "  }",
        "  @else{",
        "    .foo {",
        "      padding: 15px;",
        "    }",
        "  }",
        "}"));

    ErrorManager errorManager = mock(ErrorManager.class);
    PermutationsCollector visitor = new PermutationsCollector(cssTree.getMutatingVisitController(),
        errorManager);

    // when
    visitor.runPass();
View Full Code Here

    assertEquals(1, permutationAxis.size());
    assertTrue(permutationAxis.contains("custom.one"));
  }

  public void testInvalidConditionThrowsAnError() {
    CssTree cssTree = parseAndBuildTree(lines(
        "@if (evaluate('com.foo.BAR')) {",
        "  .foo {",
        "    padding: 5px;",
        "  }",
        "}"
    ));

    ErrorManager errorManager = mock(ErrorManager.class);
    PermutationsCollector visitor = new PermutationsCollector(cssTree.getMutatingVisitController(),
        errorManager);

    // when
    visitor.runPass();
View Full Code Here

TOP

Related Classes of com.google.gwt.thirdparty.common.css.compiler.ast.CssTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.