Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2000-2013 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.sass.testcases.scss;
  17. import java.io.File;
  18. import java.io.IOException;
  19. import junit.framework.Assert;
  20. import org.junit.Test;
  21. import org.w3c.css.sac.CSSException;
  22. import com.vaadin.sass.AbstractTestBase;
  23. import com.vaadin.sass.internal.ScssStylesheet;
  24. import com.vaadin.sass.internal.handler.SCSSDocumentHandler;
  25. import com.vaadin.sass.internal.handler.SCSSDocumentHandlerImpl;
  26. import com.vaadin.sass.internal.parser.Parser;
  27. import com.vaadin.sass.internal.resolver.FilesystemResolver;
  28. import com.vaadin.sass.internal.tree.ImportNode;
  29. public class CompassImports extends AbstractTestBase {
  30. String scssOtherDirectory = "/scss/compass-test/compass-import.scss";
  31. String scssSameDirectory = "/scss/compass-test2/compass-import2.scss";
  32. String css = "/css/compass-import.css";
  33. String compassPath = "/scss/compass-test2";
  34. @Test
  35. public void testParser() throws CSSException, IOException {
  36. Parser parser = new Parser();
  37. SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl();
  38. parser.setDocumentHandler(handler);
  39. parser.parseStyleSheet(getClass().getResource(scssOtherDirectory)
  40. .getPath());
  41. ScssStylesheet root = handler.getStyleSheet();
  42. ImportNode importVariableNode = (ImportNode) root.getChildren().get(0);
  43. Assert.assertEquals("compass", importVariableNode.getUri());
  44. Assert.assertFalse(importVariableNode.isPureCssImport());
  45. }
  46. @Test
  47. public void testCompiler() throws Exception {
  48. testCompiler(scssSameDirectory, css, null);
  49. }
  50. @Test
  51. public void testCompilerWithCustomPath() throws Exception {
  52. File rootPath = new File(getClass().getResource(compassPath).toURI());
  53. testCompiler(scssOtherDirectory, css, rootPath.getPath());
  54. }
  55. public void testCompiler(String scss, String css, String additionalPath)
  56. throws Exception {
  57. comparisonCss = getFileContent(css);
  58. ScssStylesheet sheet = getStyleSheet(scss);
  59. Assert.assertNotNull(sheet);
  60. sheet.addResolver(new FilesystemResolver(additionalPath));
  61. sheet.compile();
  62. parsedScss = sheet.toString();
  63. Assert.assertEquals("Original CSS and parsed CSS do not match",
  64. comparisonCss, parsedScss);
  65. }
  66. }