StringTemplateCSSHelperTest.java 文件源码

java
阅读 16 收藏 0 点赞 0 评论 0

项目:JavaCSS 作者:
@Test
public void finds_the_matching_css() {
    String javaInput = "package com.foo.bar;";

    String cssInput =
          ".packageDeclaration \";\"::before {\n"
        + "   content: \" \";\n"
        + "}\n";

    StringTemplateCSSHelper helper = new StringTemplateCSSHelper(cssInput);

    Java8Lexer lexer = new Java8Lexer(new ANTLRInputStream(javaInput));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    Java8Parser parser = new Java8Parser(tokens);
    ParseTree ast = parser.compilationUnit();

    Collection<ParseTree> matches = XPath.findAll(ast, "//';'", parser);

    Assert.assertNotNull(matches);
    Assert.assertEquals(1, matches.size());

    ParseTree semiColon = matches.toArray(new ParseTree[1])[0];
    Assert.assertNotNull(semiColon);

    List<Css> matchedCss = helper.retrieveMatchingCss(semiColon, ast);

    Assert.assertNotNull(matchedCss);
    Assert.assertEquals(1, matchedCss.size());
    Css css = matchedCss.get(0);
    Assert.assertNotNull(css);
    List<String> matchedSelectors = css.getSelectors();
    Assert.assertNotNull(matchedSelectors);
    Assert.assertEquals(2, matchedSelectors.size());
    Assert.assertEquals(".packageDeclaration", matchedSelectors.get(0));
    Assert.assertEquals("\";\"::before", matchedSelectors.get(1));

    List<Property<?>> properties = css.getProperties();
    Assert.assertNotNull(properties);
    Assert.assertEquals(1, properties.size());
    @SuppressWarnings("unchecked")
    Property<String> content = (Property<String>) properties.get(0);
    Assert.assertNotNull(content);
    Assert.assertEquals("content", content.getKey());
    Assert.assertEquals(" ", content.getValue());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号