You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompileTransitionPropertyTest.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package com.vaadin.tests;
  2. import static org.junit.Assert.assertTrue;
  3. import static org.junit.Assert.fail;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6. import org.junit.Test;
  7. import com.vaadin.sass.internal.ScssStylesheet;
  8. /*
  9. * This test checks that the transition mixin in valo/bourbon is usable (#15484).
  10. */
  11. public class CompileTransitionPropertyTest {
  12. @Test
  13. public void testCompilation() throws Exception {
  14. String file = getClass().getResource("styles.scss").getFile();
  15. if (file.contains("%20")) {
  16. fail("path contains spaces, please move the project");
  17. }
  18. ScssStylesheet ss = ScssStylesheet.get(file);
  19. ss.compile();
  20. // extract the style rules for .my-label
  21. String compiled = ss.printState();
  22. Pattern pattern = Pattern.compile("(.my-label)(\\s)+(\\{)[^\\}]*");
  23. Matcher matcher = pattern.matcher(compiled);
  24. assertTrue("Could not find style rules for .my-label.", matcher.find());
  25. String elementStyle = matcher.group();
  26. elementStyle = elementStyle.replaceFirst("(.my-label)(\\s)+(\\{)(\\s)*",
  27. "");
  28. // Check that the correct rules are present
  29. Pattern p1 = Pattern
  30. .compile("transition-property(\\s*):(\\s*)transform(\\s*);");
  31. Pattern p2 = Pattern.compile(
  32. "-moz-transition-property(\\s*):(\\s*)-moz-transform(\\s*);");
  33. Pattern p3 = Pattern.compile(
  34. "-webkit-transition-property(\\s*):(\\s*)-webkit-transform(\\s*);");
  35. assertTrue("The style 'transition-property: transform' is missing.",
  36. p1.matcher(elementStyle).find());
  37. assertTrue(
  38. "The style '-moz-transition-property: -moz-transform' is missing.",
  39. p2.matcher(elementStyle).find());
  40. assertTrue(
  41. "The style '-webkit-transition-property: -webkit-transform' is missing.",
  42. p3.matcher(elementStyle).find());
  43. // Check that there are no other styles for .my-label
  44. String modifiedStyle = p1.matcher(elementStyle).replaceFirst("");
  45. modifiedStyle = p2.matcher(modifiedStyle).replaceFirst("");
  46. modifiedStyle = p3.matcher(modifiedStyle).replaceFirst("");
  47. // Only whitespace should remain after removing the style rules
  48. modifiedStyle = modifiedStyle.replaceAll("(\\s)", "");
  49. assertTrue("Unexpected style rules for .my-label: " + modifiedStyle,
  50. modifiedStyle.isEmpty());
  51. }
  52. }