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.

Mixins.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.IOException;
  18. import java.net.URISyntaxException;
  19. import org.junit.Assert;
  20. import org.junit.Test;
  21. import org.w3c.css.sac.CSSException;
  22. import org.w3c.css.sac.LexicalUnit;
  23. import com.vaadin.sass.AbstractTestBase;
  24. import com.vaadin.sass.internal.ScssStylesheet;
  25. import com.vaadin.sass.internal.handler.SCSSDocumentHandler;
  26. import com.vaadin.sass.internal.handler.SCSSDocumentHandlerImpl;
  27. import com.vaadin.sass.internal.parser.LexicalUnitImpl;
  28. import com.vaadin.sass.internal.parser.Parser;
  29. import com.vaadin.sass.internal.tree.BlockNode;
  30. import com.vaadin.sass.internal.tree.MixinDefNode;
  31. import com.vaadin.sass.internal.tree.MixinNode;
  32. public class Mixins extends AbstractTestBase {
  33. String scss = "/scss/mixins.scss";
  34. String css = "/css/mixins.css";
  35. @Test
  36. public void testParser() throws CSSException, URISyntaxException,
  37. IOException {
  38. Parser parser = new Parser();
  39. SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl();
  40. parser.setDocumentHandler(handler);
  41. parser.parseStyleSheet(getClass().getResource(scss).getPath());
  42. ScssStylesheet root = handler.getStyleSheet();
  43. MixinDefNode mixinDefNode0 = (MixinDefNode) root.getChildren().get(0);
  44. Assert.assertEquals("font-settings", mixinDefNode0.getName());
  45. Assert.assertTrue(mixinDefNode0.getArglist().isEmpty());
  46. Assert.assertEquals(3, mixinDefNode0.getChildren().size());
  47. MixinDefNode mixinDefNode1 = (MixinDefNode) root.getChildren().get(1);
  48. Assert.assertEquals("rounded-borders", mixinDefNode1.getName());
  49. Assert.assertEquals(2, mixinDefNode1.getArglist().size());
  50. Assert.assertEquals("thickness", mixinDefNode1.getArglist().get(0)
  51. .getName());
  52. Assert.assertEquals("radius", mixinDefNode1.getArglist().get(1)
  53. .getName());
  54. Assert.assertEquals(LexicalUnit.SAC_PIXEL, mixinDefNode1.getArglist()
  55. .get(1).getExpr().getLexicalUnitType());
  56. Assert.assertEquals(3f, mixinDefNode1.getArglist().get(1).getExpr()
  57. .getFloatValue(), 0f);
  58. Assert.assertEquals(4, mixinDefNode1.getChildren().size());
  59. BlockNode mainBlockNode = (BlockNode) root.getChildren().get(3);
  60. Assert.assertEquals(3, mainBlockNode.getChildren().size());
  61. MixinNode mixinNode0MainBlock = (MixinNode) mainBlockNode.getChildren()
  62. .get(0);
  63. Assert.assertEquals("rounded-borders", mixinNode0MainBlock.getName());
  64. Assert.assertEquals("mixinVar", mixinNode0MainBlock.getArglist().get(0)
  65. .getStringValue());
  66. Assert.assertEquals(LexicalUnitImpl.SCSS_VARIABLE, mixinNode0MainBlock
  67. .getArglist().get(0).getLexicalUnitType());
  68. MixinNode mixinNOde1MainBlock = (MixinNode) mainBlockNode.getChildren()
  69. .get(1);
  70. Assert.assertEquals("font-settings", mixinNOde1MainBlock.getName());
  71. Assert.assertTrue(mixinNOde1MainBlock.getArglist().isEmpty());
  72. MixinNode mixinNOde2MainBlock = (MixinNode) mainBlockNode.getChildren()
  73. .get(2);
  74. Assert.assertEquals("main-details", mixinNOde2MainBlock.getName());
  75. Assert.assertTrue(mixinNOde1MainBlock.getArglist().isEmpty());
  76. MixinNode mixinNode1MainBlock = (MixinNode) mainBlockNode.getChildren()
  77. .get(1);
  78. Assert.assertTrue(mixinNode1MainBlock.getArglist().isEmpty());
  79. BlockNode footerBlockNode = (BlockNode) root.getChildren().get(3);
  80. MixinNode mixinNodeFooterBlock = (MixinNode) footerBlockNode
  81. .getChildren().get(0);
  82. Assert.assertEquals("mixinVar", mixinNodeFooterBlock.getArglist()
  83. .get(0).getStringValue());
  84. Assert.assertTrue(root.getChildren().get(0) instanceof MixinDefNode);
  85. Assert.assertTrue(root.getChildren().get(1) instanceof MixinDefNode);
  86. Assert.assertTrue(root.getChildren().get(5) instanceof MixinDefNode);
  87. Assert.assertTrue(root.getChildren().get(6) instanceof MixinDefNode);
  88. Assert.assertTrue(root.getChildren().get(8) instanceof MixinDefNode);
  89. Assert.assertTrue(root.getChildren().get(9) instanceof MixinNode);
  90. }
  91. @Test
  92. public void testCompiler() throws Exception {
  93. testCompiler(scss, css);
  94. }
  95. }