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 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests;
  17. import static org.junit.Assert.assertTrue;
  18. import static org.junit.Assert.fail;
  19. import java.util.regex.Matcher;
  20. import java.util.regex.Pattern;
  21. import org.junit.Test;
  22. import com.vaadin.sass.internal.ScssStylesheet;
  23. /*
  24. * This test checks that the transition mixin in valo/bourbon is usable (#15484).
  25. */
  26. public class CompileTransitionPropertyTest {
  27. @Test
  28. public void testCompilation() throws Exception {
  29. String file = getClass().getResource("styles.scss").getFile();
  30. if (file.contains("%20")) {
  31. fail("path contains spaces, please move the project");
  32. }
  33. ScssStylesheet ss = ScssStylesheet
  34. .get(file);
  35. ss.compile();
  36. // extract the style rules for .my-label
  37. String compiled = ss.printState();
  38. Pattern pattern = Pattern.compile("(.my-label)(\\s)+(\\{)[^\\}]*");
  39. Matcher matcher = pattern.matcher(compiled);
  40. assertTrue("Could not find style rules for .my-label.", matcher.find());
  41. String elementStyle = matcher.group();
  42. elementStyle = elementStyle.replaceFirst("(.my-label)(\\s)+(\\{)(\\s)*",
  43. "");
  44. // Check that the correct rules are present
  45. Pattern p1 = Pattern
  46. .compile("transition-property(\\s*):(\\s*)transform(\\s*);");
  47. Pattern p2 = Pattern.compile(
  48. "-moz-transition-property(\\s*):(\\s*)-moz-transform(\\s*);");
  49. Pattern p3 = Pattern.compile(
  50. "-webkit-transition-property(\\s*):(\\s*)-webkit-transform(\\s*);");
  51. assertTrue("The style 'transition-property: transform' is missing.",
  52. p1.matcher(elementStyle).find());
  53. assertTrue(
  54. "The style '-moz-transition-property: -moz-transform' is missing.",
  55. p2.matcher(elementStyle).find());
  56. assertTrue(
  57. "The style '-webkit-transition-property: -webkit-transform' is missing.",
  58. p3.matcher(elementStyle).find());
  59. // Check that there are no other styles for .my-label
  60. String modifiedStyle = p1.matcher(elementStyle).replaceFirst("");
  61. modifiedStyle = p2.matcher(modifiedStyle).replaceFirst("");
  62. modifiedStyle = p3.matcher(modifiedStyle).replaceFirst("");
  63. // Only whitespace should remain after removing the style rules
  64. modifiedStyle = modifiedStyle.replaceAll("(\\s)", "");
  65. assertTrue("Unexpected style rules for .my-label: " + modifiedStyle,
  66. modifiedStyle.length() == 0);
  67. }
  68. }