diff options
author | Henri Sara <hesara@vaadin.com> | 2012-08-08 13:22:54 +0300 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2012-08-08 14:29:48 +0300 |
commit | f9d44e50e7c05723112a1a704583de3d2ee9e72c (patch) | |
tree | 453124cf5423bdb2e0e1eba408536af19fb91d66 /tests/sass/src | |
parent | 0a5ef5d891672ddb2b9b4aee1ef195870356520d (diff) | |
download | vaadin-framework-f9d44e50e7c05723112a1a704583de3d2ee9e72c.tar.gz vaadin-framework-f9d44e50e7c05723112a1a704583de3d2ee9e72c.zip |
Add SASS source code, unit tests and test resources to project (#9223)
Diffstat (limited to 'tests/sass/src')
27 files changed, 1351 insertions, 0 deletions
diff --git a/tests/sass/src/com/vaadin/sass/AllTests.java b/tests/sass/src/com/vaadin/sass/AllTests.java new file mode 100644 index 0000000000..574b1a4d93 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/AllTests.java @@ -0,0 +1,11 @@ +package com.vaadin.sass; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ CssTestSuite.class, ScssTestSuite.class, VisitorTestSuite.class }) +public class AllTests { + +} diff --git a/tests/sass/src/com/vaadin/sass/CssTestSuite.java b/tests/sass/src/com/vaadin/sass/CssTestSuite.java new file mode 100644 index 0000000000..e15da68e0c --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/CssTestSuite.java @@ -0,0 +1,17 @@ +package com.vaadin.sass; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +import com.vaadin.sass.testcases.css.Comments; +import com.vaadin.sass.testcases.css.Media; +import com.vaadin.sass.testcases.css.Properties; +import com.vaadin.sass.testcases.css.Reindeer; +import com.vaadin.sass.testcases.css.Selectors; + +@RunWith(Suite.class) +@SuiteClasses({ Selectors.class, Properties.class, Reindeer.class, Media.class, + Comments.class }) +public class CssTestSuite { +} diff --git a/tests/sass/src/com/vaadin/sass/ScssTestSuite.java b/tests/sass/src/com/vaadin/sass/ScssTestSuite.java new file mode 100644 index 0000000000..9ab0a76597 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/ScssTestSuite.java @@ -0,0 +1,26 @@ +package com.vaadin.sass; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +import com.vaadin.sass.testcases.scss.ControlDirectives; +import com.vaadin.sass.testcases.scss.Extends; +import com.vaadin.sass.testcases.scss.Functions; +import com.vaadin.sass.testcases.scss.Imports; +import com.vaadin.sass.testcases.scss.Mixins; +import com.vaadin.sass.testcases.scss.NestedProperties; +import com.vaadin.sass.testcases.scss.Nesting; +import com.vaadin.sass.testcases.scss.ParentImports; +import com.vaadin.sass.testcases.scss.ParentSelector; +import com.vaadin.sass.testcases.scss.Variables; +import com.vaadin.sass.tree.ImportNodeTest; + +@RunWith(Suite.class) +@SuiteClasses({ ControlDirectives.class, Extends.class, Functions.class, + ImportNodeTest.class, Imports.class, Mixins.class, + NestedProperties.class, Nesting.class, ParentImports.class, + Variables.class, ParentSelector.class }) +public class ScssTestSuite { + +} diff --git a/tests/sass/src/com/vaadin/sass/TestBase.java b/tests/sass/src/com/vaadin/sass/TestBase.java new file mode 100644 index 0000000000..6947d24961 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/TestBase.java @@ -0,0 +1,84 @@ +package com.vaadin.sass; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.net.URISyntaxException; + +import org.w3c.css.sac.CSSException; + +public class TestBase { + + protected ScssStylesheet stylesheet; + protected String originalScss; + protected String parsedScss; + protected String comparisonCss; + + public ScssStylesheet getStyleSheet(String filename) + throws URISyntaxException, CSSException, IOException { + File file = getFile(filename); + stylesheet = ScssStylesheet.get(file); + return stylesheet; + } + + public File getFile(String filename) throws URISyntaxException, + CSSException, IOException { + return new File(getClass().getResource(filename).toURI()); + } + + public String getFileContent(String filename) throws IOException, + CSSException, URISyntaxException { + File file = getFile(filename); + return getFileContent(file); + } + + /** + * Read in the full content of a file into a string. + * + * @param file + * the file to be read + * @return a String with the content of the + * @throws IOException + * when file reading fails + */ + public String getFileContent(File file) throws IOException { + StringBuilder content = new StringBuilder(); + + FileReader fileReader = new FileReader(file); + BufferedReader bufferedReader = new BufferedReader(fileReader); + String line = null; + // Handle the first line separately to get the right amount of line + // separators in the loop + if ((line = bufferedReader.readLine()) != null) { + content.append(line); + } + // Handle the rest of the lines + while ((line = bufferedReader.readLine()) != null) { + content.append(System.getProperty("line.separator")); + content.append(line); + } + bufferedReader.close(); + return content.toString(); + } + + public boolean testParser(String file) throws CSSException, IOException, + URISyntaxException { + originalScss = getFileContent(file); + ScssStylesheet sheet = getStyleSheet(file); + parsedScss = sheet.toString(); + return parsedScss.equals(originalScss); + } + + public boolean testCompiler(String scss, String css) { + try { + comparisonCss = getFileContent(css); + ScssStylesheet sheet = getStyleSheet(scss); + sheet.compile(); + parsedScss = sheet.toString(); + } catch (Exception e) { + return false; + } + return parsedScss.equals(comparisonCss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/VisitorTestSuite.java b/tests/sass/src/com/vaadin/sass/VisitorTestSuite.java new file mode 100644 index 0000000000..46dfce6fe1 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/VisitorTestSuite.java @@ -0,0 +1,14 @@ +package com.vaadin.sass; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +import com.vaadin.sass.testcases.visitor.MixinVisitorTest; +import com.vaadin.sass.testcases.visitor.NestedPropertiesVisitorTest; + +@RunWith(Suite.class) +@SuiteClasses({ NestedPropertiesVisitorTest.class, MixinVisitorTest.class }) +public class VisitorTestSuite { + +} diff --git a/tests/sass/src/com/vaadin/sass/parser/ParserTest.java b/tests/sass/src/com/vaadin/sass/parser/ParserTest.java new file mode 100644 index 0000000000..db7754406d --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/parser/ParserTest.java @@ -0,0 +1,49 @@ +package com.vaadin.sass.parser; + +import java.io.IOException; +import java.io.StringReader; + +import org.junit.Assert; +import org.junit.Test; +import org.w3c.css.sac.CSSException; +import org.w3c.css.sac.InputSource; +import org.w3c.css.sac.LexicalUnit; + +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; + +public class ParserTest { + + @Test + public void testParsePropertyValue() throws CSSException, IOException { + Parser parser = new Parser(); + + LexicalUnit value = parser.parsePropertyValue(new InputSource( + new StringReader("$margin/2;"))); + + Assert.assertEquals("margin", value.getStringValue()); + Assert.assertEquals(SCSSLexicalUnit.SCSS_VARIABLE, + value.getLexicalUnitType()); + value = value.getNextLexicalUnit(); + Assert.assertEquals(LexicalUnit.SAC_OPERATOR_SLASH, + value.getLexicalUnitType()); + value = value.getNextLexicalUnit(); + Assert.assertEquals(LexicalUnit.SAC_INTEGER, value.getLexicalUnitType()); + Assert.assertEquals(2, value.getIntegerValue()); + + } + + @Test + public void testCanIngoreSingleLineComment() { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + try { + parser.parseStyleSheet(new InputSource(new StringReader( + "//kjaljsföajsfalkj\n@12abcg;"))); + Assert.assertTrue(true); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } +}
\ No newline at end of file diff --git a/tests/sass/src/com/vaadin/sass/testcases/css/Comments.java b/tests/sass/src/com/vaadin/sass/testcases/css/Comments.java new file mode 100644 index 0000000000..c0690418e2 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/css/Comments.java @@ -0,0 +1,23 @@ +package com.vaadin.sass.testcases.css; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.TestBase; + +public class Comments extends TestBase { + String css = "/basic/comments.css"; + + @Test + public void testParser() throws CSSException, URISyntaxException, + IOException { + testParser(css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + originalScss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/css/EmptyBlock.java b/tests/sass/src/com/vaadin/sass/testcases/css/EmptyBlock.java new file mode 100644 index 0000000000..c80ebeac56 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/css/EmptyBlock.java @@ -0,0 +1,23 @@ +package com.vaadin.sass.testcases.css; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.TestBase; + +public class EmptyBlock extends TestBase { + String css = "/basic/empty_block.css"; + + @Test + public void testParser() throws CSSException, URISyntaxException, + IOException { + testParser(css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + originalScss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/css/Interpolation.java b/tests/sass/src/com/vaadin/sass/testcases/css/Interpolation.java new file mode 100644 index 0000000000..fd57f1c982 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/css/Interpolation.java @@ -0,0 +1,33 @@ +package com.vaadin.sass.testcases.css; + +import java.io.IOException; +import java.net.URISyntaxException; + +import org.junit.Assert; +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.TestBase; +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; +import com.vaadin.sass.parser.Parser; +import com.vaadin.sass.tree.BlockNode; + +public class Interpolation extends TestBase { + String scss = "/scss/interpolation.scss"; + + @Test + public void testParser() throws CSSException, URISyntaxException, + IOException { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + parser.parseStyleSheet(getClass().getResource(scss).getPath()); + ScssStylesheet root = handler.getStyleSheet(); + + Assert.assertEquals(3, root.getChildren().size()); + BlockNode blockNodeWithInterpolation = (BlockNode) root.getChildren() + .get(2); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/css/Media.java b/tests/sass/src/com/vaadin/sass/testcases/css/Media.java new file mode 100644 index 0000000000..21ab421ce4 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/css/Media.java @@ -0,0 +1,24 @@ +package com.vaadin.sass.testcases.css; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.TestBase; + +public class Media extends TestBase { + + String css = "/basic/media.css"; + + @Test + public void testParser() throws CSSException, URISyntaxException, + IOException { + testParser(css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + originalScss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/css/Properties.java b/tests/sass/src/com/vaadin/sass/testcases/css/Properties.java new file mode 100644 index 0000000000..e140a40a97 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/css/Properties.java @@ -0,0 +1,24 @@ +package com.vaadin.sass.testcases.css; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.TestBase; + +public class Properties extends TestBase { + + String css = "/basic/properties.css"; + + @Test + public void testParser() throws CSSException, URISyntaxException, + IOException { + testParser(css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + originalScss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/css/Reindeer.java b/tests/sass/src/com/vaadin/sass/testcases/css/Reindeer.java new file mode 100644 index 0000000000..9a82096026 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/css/Reindeer.java @@ -0,0 +1,24 @@ +package com.vaadin.sass.testcases.css; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.TestBase; + +public class Reindeer extends TestBase { + + String css = "/basic/reindeer.css"; + + @Test + public void testParser() throws CSSException, URISyntaxException, + IOException { + testParser(css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + originalScss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/css/Selectors.java b/tests/sass/src/com/vaadin/sass/testcases/css/Selectors.java new file mode 100644 index 0000000000..f8259e85c3 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/css/Selectors.java @@ -0,0 +1,24 @@ +package com.vaadin.sass.testcases.css; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.TestBase; + +public class Selectors extends TestBase { + + String css = "/basic/selectors.css"; + + @Test + public void testParser() throws CSSException, URISyntaxException, + IOException { + testParser(css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + originalScss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/ControlDirectives.java b/tests/sass/src/com/vaadin/sass/testcases/scss/ControlDirectives.java new file mode 100644 index 0000000000..d42199d1a6 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/scss/ControlDirectives.java @@ -0,0 +1,40 @@ +package com.vaadin.sass.testcases.scss; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.TestBase; +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; +import com.vaadin.sass.parser.Parser; + +public class ControlDirectives extends TestBase { + + String scss = "/scss/control-directives.scss"; + String css = "/css/control-directives.css"; + + @Test + public void testParser() throws CSSException, IOException { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + parser.parseStyleSheet(getClass().getResource(scss).getPath()); + ScssStylesheet root = handler.getStyleSheet(); + Assert.assertNotNull(root); + Assert.fail("Implement assert nodes"); + } + + @Test + public void testCompiler() throws CSSException, URISyntaxException, + IOException { + testCompiler(scss, css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + comparisonCss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/Extends.java b/tests/sass/src/com/vaadin/sass/testcases/scss/Extends.java new file mode 100644 index 0000000000..fa0d323528 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/scss/Extends.java @@ -0,0 +1,40 @@ +package com.vaadin.sass.testcases.scss; + +import java.io.IOException; +import java.net.URISyntaxException; + +import org.junit.Assert; +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.TestBase; +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; +import com.vaadin.sass.parser.Parser; +import com.vaadin.sass.tree.ExtendNode; + +public class Extends extends TestBase { + String scss = "/scss/extends.scss"; + String css = "/css/extends.css"; + + @Test + public void testParser() throws CSSException, URISyntaxException, + IOException { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + parser.parseStyleSheet(getClass().getResource(scss).getPath()); + ScssStylesheet root = handler.getStyleSheet(); + + Assert.assertTrue(root.getChildren().get(2).getChildren().get(0) instanceof ExtendNode); + } + + @Test + public void testCompiler() throws CSSException, URISyntaxException, + IOException { + testCompiler(scss, css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + comparisonCss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/Functions.java b/tests/sass/src/com/vaadin/sass/testcases/scss/Functions.java new file mode 100644 index 0000000000..d3085f675c --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/scss/Functions.java @@ -0,0 +1,42 @@ +package com.vaadin.sass.testcases.scss; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.TestBase; +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; +import com.vaadin.sass.parser.Parser; +import com.vaadin.sass.tree.BlockNode; + +public class Functions extends TestBase { + + String scss = "/scss/functions.scss"; + String css = "/css/functions.css"; + + @Test + public void testParser() throws CSSException, IOException { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + parser.parseStyleSheet(getClass().getResource(scss).getPath()); + ScssStylesheet root = handler.getStyleSheet(); + Assert.assertEquals(1, root.getChildren().size()); + BlockNode blockNode = (BlockNode) root.getChildren().get(0); + Assert.assertEquals(12, blockNode.getChildren().size()); + } + + @Test + public void testCompiler() throws CSSException, URISyntaxException, + IOException { + testCompiler(scss, css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + comparisonCss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/Imports.java b/tests/sass/src/com/vaadin/sass/testcases/scss/Imports.java new file mode 100644 index 0000000000..bcee04f46f --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/scss/Imports.java @@ -0,0 +1,42 @@ +package com.vaadin.sass.testcases.scss; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.TestBase; +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; +import com.vaadin.sass.parser.Parser; +import com.vaadin.sass.tree.ImportNode; + +public class Imports extends TestBase { + + String scss = "/scss/imports.scss"; + String css = "/css/imports.css"; + + @Test + public void testParser() throws CSSException, IOException { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + parser.parseStyleSheet(getClass().getResource(scss).getPath()); + ScssStylesheet root = handler.getStyleSheet(); + ImportNode importNode = (ImportNode) root.getChildren().get(0); + Assert.assertEquals("_partial-for-import", importNode.getUri()); + Assert.assertFalse(importNode.isPureCssImport()); + } + + @Test + public void testCompiler() throws CSSException, URISyntaxException, + IOException { + testCompiler(scss, css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + comparisonCss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/Mixins.java b/tests/sass/src/com/vaadin/sass/testcases/scss/Mixins.java new file mode 100644 index 0000000000..a4ecf75a35 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/scss/Mixins.java @@ -0,0 +1,103 @@ +package com.vaadin.sass.testcases.scss; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; +import org.w3c.css.sac.LexicalUnit; + +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.TestBase; +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; +import com.vaadin.sass.parser.Parser; +import com.vaadin.sass.tree.BlockNode; +import com.vaadin.sass.tree.MediaNode; +import com.vaadin.sass.tree.MixinDefNode; +import com.vaadin.sass.tree.MixinNode; + +public class Mixins extends TestBase { + + String scss = "/scss/mixins.scss"; + String css = "/css/mixins.css"; + + @Test + public void testParser() throws CSSException, URISyntaxException, + IOException { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + parser.parseStyleSheet(getClass().getResource(scss).getPath()); + ScssStylesheet root = handler.getStyleSheet(); + + MixinDefNode mixinDefNode0 = (MixinDefNode) root.getChildren().get(0); + Assert.assertEquals("font-settings", mixinDefNode0.getName()); + Assert.assertTrue(mixinDefNode0.getArglist().isEmpty()); + Assert.assertEquals(3, mixinDefNode0.getChildren().size()); + + MixinDefNode mixinDefNode1 = (MixinDefNode) root.getChildren().get(1); + Assert.assertEquals("rounded-borders", mixinDefNode1.getName()); + Assert.assertEquals(2, mixinDefNode1.getArglist().size()); + Assert.assertEquals("thickness", mixinDefNode1.getArglist().get(0) + .getName()); + Assert.assertEquals("radius", mixinDefNode1.getArglist().get(1) + .getName()); + Assert.assertEquals(LexicalUnit.SAC_PIXEL, mixinDefNode1.getArglist() + .get(1).getExpr().getLexicalUnitType()); + Assert.assertEquals(3f, mixinDefNode1.getArglist().get(1).getExpr() + .getFloatValue()); + + Assert.assertEquals(4, mixinDefNode1.getChildren().size()); + + BlockNode mainBlockNode = (BlockNode) root.getChildren().get(2); + Assert.assertEquals(2, mainBlockNode.getChildren().size()); + MixinNode mixinNode0MainBlock = (MixinNode) mainBlockNode.getChildren() + .get(0); + Assert.assertEquals("rounded-borders", mixinNode0MainBlock.getName()); + Assert.assertEquals(1f, mixinNode0MainBlock.getArglist().get(0) + .getFloatValue()); + Assert.assertEquals(LexicalUnit.SAC_PIXEL, mixinNode0MainBlock + .getArglist().get(0).getLexicalUnitType()); + MixinNode mixinNOde1MainBlock = (MixinNode) mainBlockNode.getChildren() + .get(1); + Assert.assertEquals("font-settings", mixinNOde1MainBlock.getName()); + Assert.assertTrue(mixinNOde1MainBlock.getArglist().isEmpty()); + + MixinNode mixinNode1MainBlock = (MixinNode) mainBlockNode.getChildren() + .get(1); + Assert.assertTrue(mixinNode1MainBlock.getArglist().isEmpty()); + + BlockNode footerBlockNode = (BlockNode) root.getChildren().get(3); + MixinNode mixinNodeFooterBlock = (MixinNode) footerBlockNode + .getChildren().get(0); + Assert.assertEquals(2f, mixinNodeFooterBlock.getArglist().get(0) + .getFloatValue()); + Assert.assertEquals("px", mixinNodeFooterBlock.getArglist().get(0) + .getDimensionUnitText()); + + Assert.assertEquals(10f, mixinNodeFooterBlock.getArglist().get(1) + .getFloatValue()); + Assert.assertEquals("px", mixinNodeFooterBlock.getArglist().get(1) + .getDimensionUnitText()); + + Assert.assertTrue(root.getChildren().get(4) instanceof MixinDefNode); + Assert.assertTrue(root.getChildren().get(4).getChildren().get(3) instanceof MediaNode); + Assert.assertTrue(root.getChildren().get(4).getChildren().get(4) instanceof MixinNode); + + MixinNode topLevelMixin = (MixinNode) root.getChildren().get(5); + Assert.assertEquals("layout", topLevelMixin.getName()); + + } + + @Test + public void testCompiler() throws CSSException, URISyntaxException, + IOException { + testCompiler(scss, css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + comparisonCss, parsedScss); + } + +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/NestedProperties.java b/tests/sass/src/com/vaadin/sass/testcases/scss/NestedProperties.java new file mode 100644 index 0000000000..a236eeac12 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/scss/NestedProperties.java @@ -0,0 +1,57 @@ +package com.vaadin.sass.testcases.scss; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.TestBase; +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; +import com.vaadin.sass.parser.Parser; +import com.vaadin.sass.tree.BlockNode; +import com.vaadin.sass.tree.NestPropertiesNode; +import com.vaadin.sass.tree.RuleNode; + +public class NestedProperties extends TestBase { + String scss = "/scss/nested-properties.scss"; + String css = "/css/nested-properties.css"; + + @Test + public void testParser() throws CSSException, IOException { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + parser.parseStyleSheet(getClass().getResource(scss).getPath()); + ScssStylesheet root = handler.getStyleSheet(); + Assert.assertEquals(1, root.getChildren().size()); + + BlockNode blockNode = (BlockNode) root.getChildren().get(0); + Assert.assertEquals(1, blockNode.getChildren().size()); + + NestPropertiesNode nestPropertiesNode = (NestPropertiesNode) blockNode + .getChildren().get(0); + Assert.assertEquals("font", nestPropertiesNode.getName()); + RuleNode nestedProperty0 = (RuleNode) nestPropertiesNode.getChildren() + .get(0); + RuleNode nestedProperty1 = (RuleNode) nestPropertiesNode.getChildren() + .get(1); + RuleNode nestedProperty2 = (RuleNode) nestPropertiesNode.getChildren() + .get(2); + Assert.assertEquals("family", nestedProperty0.getVariable()); + Assert.assertEquals("weight", nestedProperty1.getVariable()); + Assert.assertEquals("size", nestedProperty2.getVariable()); + } + + @Test + public void testCompiler() throws CSSException, URISyntaxException, + IOException { + testCompiler(scss, css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + comparisonCss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/Nesting.java b/tests/sass/src/com/vaadin/sass/testcases/scss/Nesting.java new file mode 100644 index 0000000000..1ca8bc762b --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/scss/Nesting.java @@ -0,0 +1,75 @@ +package com.vaadin.sass.testcases.scss; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.TestBase; +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; +import com.vaadin.sass.parser.Parser; +import com.vaadin.sass.tree.BlockNode; + +public class Nesting extends TestBase { + + String scss = "/scss/nesting.scss"; + String css = "/css/nesting.css"; + + @Test + public void testParser() throws CSSException, IOException { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + parser.parseStyleSheet(getClass().getResource(scss).getPath()); + ScssStylesheet root = handler.getStyleSheet(); + Assert.assertEquals(5, root.getChildren().size()); + + BlockNode blockNode0 = (BlockNode) root.getChildren().get(0); + Assert.assertEquals(2, blockNode0.getChildren().size()); + BlockNode nestedBlock0 = (BlockNode) blockNode0.getChildren().get(1); + org.junit.Assert.assertEquals(1, nestedBlock0.getChildren().size()); + + BlockNode blockNode1 = (BlockNode) root.getChildren().get(1); + Assert.assertEquals(2, blockNode1.getChildren().size()); + BlockNode nestedBlockInBlock1 = (BlockNode) blockNode1.getChildren() + .get(1); + Assert.assertEquals(1, nestedBlockInBlock1.getChildren().size()); + + BlockNode blockNode2 = (BlockNode) root.getChildren().get(2); + Assert.assertEquals(2, blockNode2.getChildren().size()); + BlockNode nestedBlockInBlock2 = (BlockNode) blockNode2.getChildren() + .get(1); + Assert.assertEquals(1, nestedBlockInBlock2.getChildren().size()); + + BlockNode blockNode3 = (BlockNode) root.getChildren().get(3); + Assert.assertEquals(2, blockNode3.getChildren().size()); + BlockNode nestedBlockInBlock3 = (BlockNode) blockNode3.getChildren() + .get(1); + Assert.assertEquals(2, nestedBlockInBlock3.getChildren().size()); + BlockNode nestednestedBlockInBlock3 = (BlockNode) nestedBlockInBlock3 + .getChildren().get(1); + Assert.assertEquals(1, nestednestedBlockInBlock3.getChildren().size()); + + BlockNode blockNode4 = (BlockNode) root.getChildren().get(4); + Assert.assertEquals(2, blockNode4.getChildren().size()); + BlockNode nestedBlockInBlock4 = (BlockNode) blockNode3.getChildren() + .get(1); + Assert.assertEquals(2, nestedBlockInBlock4.getChildren().size()); + BlockNode nestednestedBlockInBlock4 = (BlockNode) nestedBlockInBlock3 + .getChildren().get(1); + Assert.assertEquals(1, nestednestedBlockInBlock4.getChildren().size()); + } + + @Test + public void testCompiler() throws CSSException, URISyntaxException, + IOException { + testCompiler(scss, css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + comparisonCss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/ParentImports.java b/tests/sass/src/com/vaadin/sass/testcases/scss/ParentImports.java new file mode 100644 index 0000000000..b25c8417b8 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/scss/ParentImports.java @@ -0,0 +1,52 @@ +package com.vaadin.sass.testcases.scss; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.TestBase; +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; +import com.vaadin.sass.parser.Parser; +import com.vaadin.sass.tree.ImportNode; + +public class ParentImports extends TestBase { + + String scss = "/scss/folder-test/parent-import.scss"; + String css = "/css/parent-import.css"; + + @Test + public void testParser() throws CSSException, IOException { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + parser.parseStyleSheet(getClass().getResource(scss).getPath()); + ScssStylesheet root = handler.getStyleSheet(); + ImportNode importVariableNode = (ImportNode) root.getChildren().get(0); + Assert.assertEquals("../folder-test2/variables.scss", + importVariableNode.getUri()); + Assert.assertFalse(importVariableNode.isPureCssImport()); + + ImportNode importURLNode = (ImportNode) root.getChildren().get(1); + Assert.assertEquals("../folder-test2/url", importURLNode.getUri()); + Assert.assertFalse(importURLNode.isPureCssImport()); + + ImportNode importImportNode = (ImportNode) root.getChildren().get(2); + Assert.assertEquals("../folder-test2/base-imported.scss", + importImportNode.getUri()); + Assert.assertFalse(importImportNode.isPureCssImport()); + } + + @Test + public void testCompiler() throws CSSException, URISyntaxException, + IOException { + testCompiler(scss, css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + comparisonCss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/ParentSelector.java b/tests/sass/src/com/vaadin/sass/testcases/scss/ParentSelector.java new file mode 100644 index 0000000000..0df3fde8eb --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/scss/ParentSelector.java @@ -0,0 +1,47 @@ +package com.vaadin.sass.testcases.scss; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.TestBase; +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; +import com.vaadin.sass.parser.Parser; +import com.vaadin.sass.selector.SelectorUtil; +import com.vaadin.sass.tree.BlockNode; + +public class ParentSelector extends TestBase { + String scss = "/scss/parent-selector.scss"; + String css = "/css/parent-selector.css"; + + @Test + public void testParser() throws CSSException, IOException { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + parser.parseStyleSheet(getClass().getResource(scss).getPath()); + ScssStylesheet root = handler.getStyleSheet(); + BlockNode blockNode = (BlockNode) root.getChildren().get(0); + Assert.assertEquals(4, blockNode.getChildren().size()); + BlockNode nestedBlock1 = (BlockNode) blockNode.getChildren().get(2); + Assert.assertEquals("&:hover", + SelectorUtil.toString(nestedBlock1.getSelectorList())); + BlockNode nestedBlock2 = (BlockNode) blockNode.getChildren().get(3); + Assert.assertEquals("body.firefox &", + SelectorUtil.toString(nestedBlock2.getSelectorList())); + } + + @Test + public void testCompiler() throws CSSException, URISyntaxException, + IOException { + testCompiler(scss, css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + comparisonCss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/Variables.java b/tests/sass/src/com/vaadin/sass/testcases/scss/Variables.java new file mode 100644 index 0000000000..df6bd41fe1 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/scss/Variables.java @@ -0,0 +1,94 @@ +package com.vaadin.sass.testcases.scss; + +import java.io.IOException; +import java.net.URISyntaxException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.TestBase; +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; +import com.vaadin.sass.parser.Parser; +import com.vaadin.sass.parser.SCSSLexicalUnit; +import com.vaadin.sass.tree.BlockNode; +import com.vaadin.sass.tree.RuleNode; +import com.vaadin.sass.tree.VariableNode; + +public class Variables extends TestBase { + + String scss = "/scss/variables.scss"; + String css = "/css/variables.css"; + + @Test + public void testParser() throws CSSException, IOException { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + parser.parseStyleSheet(getClass().getResource(scss).getPath()); + ScssStylesheet root = handler.getStyleSheet(); + Assert.assertEquals(5, root.getChildren().size()); + + VariableNode varNode1 = (VariableNode) root.getChildren().get(0); + Assert.assertEquals("blue", varNode1.getName()); + // Assert.assertEquals("blue", varNode1.getExpr().); + + VariableNode varNode2 = (VariableNode) root.getChildren().get(1); + Assert.assertEquals("margin", varNode2.getName()); + Assert.assertEquals(8f, varNode2.getExpr().getFloatValue()); + Assert.assertEquals("px", varNode2.getExpr().getDimensionUnitText()); + + VariableNode varNode3 = (VariableNode) root.getChildren().get(2); + Assert.assertEquals("chameleon-font-family", varNode3.getName()); + + BlockNode blockNode1 = (BlockNode) root.getChildren().get(3); + Assert.assertEquals(4, blockNode1.getChildren().size()); + RuleNode ruleNode1Block1 = (RuleNode) blockNode1.getChildren().get(0); + Assert.assertEquals("border-color", ruleNode1Block1.getVariable()); + Assert.assertEquals(SCSSLexicalUnit.SCSS_VARIABLE, ruleNode1Block1 + .getValue().getLexicalUnitType()); + Assert.assertEquals("blue", ruleNode1Block1.getValue().getStringValue()); + + VariableNode varNode1Block1 = (VariableNode) blockNode1.getChildren() + .get(1); + Assert.assertEquals("blue", varNode1Block1.getName()); + + RuleNode ruleNode2Block1 = (RuleNode) blockNode1.getChildren().get(2); + Assert.assertEquals("color", ruleNode2Block1.getVariable()); + Assert.assertEquals(SCSSLexicalUnit.SCSS_VARIABLE, ruleNode2Block1 + .getValue().getLexicalUnitType()); + Assert.assertEquals("blue", ruleNode2Block1.getValue().getStringValue()); + + BlockNode blockNode2 = (BlockNode) root.getChildren().get(4); + RuleNode ruleNode1Block2 = (RuleNode) blockNode2.getChildren().get(0); + Assert.assertEquals("padding", ruleNode1Block2.getVariable()); + Assert.assertEquals(SCSSLexicalUnit.SCSS_VARIABLE, ruleNode1Block2 + .getValue().getLexicalUnitType()); + Assert.assertEquals("margin", ruleNode1Block2.getValue() + .getStringValue()); + + RuleNode ruleNode2Block2 = (RuleNode) blockNode2.getChildren().get(1); + Assert.assertEquals("margin", ruleNode2Block2.getVariable()); + Assert.assertEquals(SCSSLexicalUnit.SCSS_VARIABLE, ruleNode2Block2 + .getValue().getLexicalUnitType()); + Assert.assertEquals("margin", ruleNode2Block2.getValue() + .getStringValue()); + + RuleNode ruleNode3Block2 = (RuleNode) blockNode2.getChildren().get(2); + Assert.assertEquals("border-color", ruleNode3Block2.getVariable()); + Assert.assertEquals(SCSSLexicalUnit.SCSS_VARIABLE, ruleNode1Block2 + .getValue().getLexicalUnitType()); + Assert.assertEquals("blue", ruleNode3Block2.getValue().getStringValue()); + } + + @Test + public void testCompiler() throws CSSException, URISyntaxException, + IOException { + testCompiler(scss, css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + comparisonCss, parsedScss); + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/visitor/ImportVisitorTest.java b/tests/sass/src/com/vaadin/sass/testcases/visitor/ImportVisitorTest.java new file mode 100644 index 0000000000..0bc6cb8799 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/visitor/ImportVisitorTest.java @@ -0,0 +1,9 @@ +package com.vaadin.sass.testcases.visitor; + +import org.junit.Test; + +public class ImportVisitorTest { + @Test + public void canHandleNestedImports() { + } +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/visitor/MixinVisitorTest.java b/tests/sass/src/com/vaadin/sass/testcases/visitor/MixinVisitorTest.java new file mode 100644 index 0000000000..8030d4e0b1 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/visitor/MixinVisitorTest.java @@ -0,0 +1,263 @@ +package com.vaadin.sass.testcases.visitor; + +import java.util.ArrayList; + +import org.junit.Assert; +import org.junit.Test; +import org.w3c.css.sac.LexicalUnit; + +import com.steadystate.css.parser.LexicalUnitImpl; +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.parser.SCSSLexicalUnit; +import com.vaadin.sass.tree.BlockNode; +import com.vaadin.sass.tree.MixinDefNode; +import com.vaadin.sass.tree.MixinNode; +import com.vaadin.sass.tree.RuleNode; +import com.vaadin.sass.tree.VariableNode; +import com.vaadin.sass.visitor.MixinVisitor; + +public class MixinVisitorTest { + private MixinVisitor mixinVisitor = new MixinVisitor(); + + @Test + public void testTraversMixinWithoutArgs() { + ScssStylesheet root = new ScssStylesheet(); + MixinDefNode mixinDefNoArgs = new MixinDefNode("no-args", null); + BlockNode blockNode = new BlockNode(null); + mixinDefNoArgs.appendChild(blockNode); + root.appendChild(mixinDefNoArgs); + + BlockNode blockWithMixin = new BlockNode(null); + MixinNode mixin = new MixinNode("no-args", null); + blockWithMixin.appendChild(mixin); + root.appendChild(blockWithMixin); + + try { + mixinVisitor.traverse(root); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + + Assert.assertEquals(1, root.getChildren().size()); + BlockNode child = (BlockNode) root.getChildren().get(0); + BlockNode fromMixin = (BlockNode) child.getChildren().get(0); + Assert.assertFalse(fromMixin.hasChildren()); + } + + @Test + public void testTraverseMixinWithNonDefaultArgs() { + ScssStylesheet root = new ScssStylesheet(); + ArrayList<VariableNode> args = new ArrayList<VariableNode>(); + args.add(new VariableNode("arg", null, false)); + MixinDefNode mixinDefWithNonDefaultArg = new MixinDefNode( + "non-default-arg", args); + BlockNode blockNode = new BlockNode(null); + mixinDefWithNonDefaultArg.appendChild(blockNode); + root.appendChild(mixinDefWithNonDefaultArg); + + BlockNode blockWithMixin = new BlockNode(null); + ArrayList<LexicalUnit> includeArgs = new ArrayList<LexicalUnit>(); + LexicalUnit includeArg = LexicalUnitImpl.createPixel(null, 1f); + includeArgs.add(includeArg); + MixinNode mixin = new MixinNode("non-default-arg", includeArgs); + blockWithMixin.appendChild(mixin); + root.appendChild(blockWithMixin); + + try { + mixinVisitor.traverse(root); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + + Assert.assertEquals(1, root.getChildren().size()); + BlockNode child = (BlockNode) root.getChildren().get(0); + VariableNode varNode = (VariableNode) child.getChildren().get(0); + Assert.assertEquals("arg", varNode.getName()); + Assert.assertEquals(LexicalUnit.SAC_PIXEL, varNode.getExpr() + .getLexicalUnitType()); + Assert.assertEquals(1f, varNode.getExpr().getFloatValue(), 0); + BlockNode fromMixin = (BlockNode) child.getChildren().get(1); + Assert.assertFalse(fromMixin.hasChildren()); + + } + + @Test + public void testTraverseMixinWithDefaultArgs() { + ScssStylesheet root = new ScssStylesheet(); + ArrayList<VariableNode> args = new ArrayList<VariableNode>(); + args.add(new VariableNode("arg", LexicalUnitImpl.createPixel(null, 1f), + false)); + MixinDefNode mixinDefWithNonDefaultArg = new MixinDefNode( + "default-arg", args); + BlockNode blockNode = new BlockNode(null); + mixinDefWithNonDefaultArg.appendChild(blockNode); + root.appendChild(mixinDefWithNonDefaultArg); + + BlockNode blockWithMixin = new BlockNode(null); + MixinNode mixin = new MixinNode("default-arg", null); + blockWithMixin.appendChild(mixin); + root.appendChild(blockWithMixin); + + try { + mixinVisitor.traverse(root); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + + Assert.assertEquals(1, root.getChildren().size()); + BlockNode child = (BlockNode) root.getChildren().get(0); + VariableNode varNode = (VariableNode) child.getChildren().get(0); + Assert.assertEquals("arg", varNode.getName()); + Assert.assertEquals(LexicalUnit.SAC_PIXEL, varNode.getExpr() + .getLexicalUnitType()); + Assert.assertEquals(1f, varNode.getExpr().getFloatValue(), 0); + BlockNode fromMixin = (BlockNode) child.getChildren().get(1); + Assert.assertFalse(fromMixin.hasChildren()); + + } + + @Test + public void testMixinWithoutArgument() { + /* + * ArrayList<String> args = new ArrayList<String>(); args.add("arg"); + * MixinDefNode mixinDefWithArgs = new MixinDefNode("with-args", args); + * RuleNode ruleNode = new RuleNode("var", + * com.vaadin.sass.parser.LexicalUnitImpl.createVariable(0, 0, null, + * "arg"), false); mixinDefWithArgs.appendChild(ruleNode); + */ + ScssStylesheet root = new ScssStylesheet(); + MixinDefNode mixinDefNoArgs = new MixinDefNode("table-base", null); + BlockNode thBlockNode = new BlockNode(null); + RuleNode textAlignRuleNode = new RuleNode("text-align", + LexicalUnitImpl.createString(null, "center"), false, null); + thBlockNode.appendChild(textAlignRuleNode); + RuleNode fontWeightRuleNode = new RuleNode("font-weight", + LexicalUnitImpl.createString(null, "bold"), false, null); + thBlockNode.appendChild(fontWeightRuleNode); + mixinDefNoArgs.appendChild(thBlockNode); + + BlockNode tdthBlockNode = new BlockNode(null); + RuleNode paddingRuleNode = new RuleNode("padding", + LexicalUnitImpl.createPixel(null, 2f), false, null); + tdthBlockNode.appendChild(paddingRuleNode); + mixinDefNoArgs.appendChild(tdthBlockNode); + root.appendChild(mixinDefNoArgs); + + BlockNode dataBlock = new BlockNode(null); + MixinNode mixinNode = new MixinNode("table-base", null); + dataBlock.appendChild(mixinNode); + root.appendChild(dataBlock); + + try { + mixinVisitor.traverse(root); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + + Assert.assertEquals(1, root.getChildren().size()); + dataBlock = (BlockNode) root.getChildren().get(0); + BlockNode thBlock = (BlockNode) dataBlock.getChildren().get(0); + Assert.assertEquals(2, thBlock.getChildren().size()); + BlockNode thtdBlock = (BlockNode) dataBlock.getChildren().get(1); + Assert.assertEquals(1, thtdBlock.getChildren().size()); + + /* + * Assert.assertEquals(2, root.getChildren().size()); BlockNode + * datathBlockNode = (BlockNode) root.getChildren().get(0); + * Assert.assertEquals(LexicalUnit.SAC_IDENT, datathBlockNode + * .getSelectorList().item(0).getSelectorType()); + * Assert.assertEquals("text-align", ((RuleNode) datathBlockNode + * .getChildren().get(0)).getVariable()); Assert.assertEquals("center", + * ((RuleNode) datathBlockNode.getChildren() + * .get(0)).getValue().getStringValue()); + * Assert.assertEquals("font-weight", ((RuleNode) datathBlockNode + * .getChildren().get(1)).getVariable()); Assert.assertEquals("bold", + * ((RuleNode) datathBlockNode.getChildren() + * .get(1)).getValue().getStringValue()); + * + * BlockNode datathdatatdBlockNode = (BlockNode) + * root.getChildren().get(1); Assert.assertEquals(LexicalUnit.SAC_IDENT, + * datathdatatdBlockNode .getSelectorList().item(0).getSelectorType()); + * Assert.assertEquals(LexicalUnit.SAC_IDENT, datathdatatdBlockNode + * .getSelectorList().item(1).getSelectorType()); + * Assert.assertEquals("padding", ((RuleNode) datathdatatdBlockNode + * .getChildren().get(0)).getVariable()); Assert.assertEquals(2.0f, + * ((RuleNode) datathdatatdBlockNode + * .getChildren().get(0)).getValue().getFloatValue(), 0); + * Assert.assertEquals(LexicalUnit.SAC_PIXEL, ((RuleNode) + * datathdatatdBlockNode.getChildren().get(0)) + * .getValue().getLexicalUnitType()); + */ + + } + + @Test + public void testMixinWithArgument() { + ScssStylesheet root = new ScssStylesheet(); + ArrayList<VariableNode> argNameList = new ArrayList<VariableNode>(); + argNameList.add(new VariableNode("dist", null, false)); + MixinDefNode mixinDef = new MixinDefNode("left", argNameList); + + RuleNode floatRuleNode = new RuleNode("float", + LexicalUnitImpl.createString(null, "left"), false, null); + mixinDef.appendChild(floatRuleNode); + RuleNode marginLeftRuleNode = new RuleNode("margin-left", + com.vaadin.sass.parser.LexicalUnitImpl.createVariable(0, 0, + null, "dist"), false, null); + mixinDef.appendChild(marginLeftRuleNode); + root.appendChild(mixinDef); + + BlockNode dataBlock = new BlockNode(null); + ArrayList<LexicalUnit> argValueList = new ArrayList<LexicalUnit>(); + LexicalUnit arg = LexicalUnitImpl.createPixel(null, 10f); + argValueList.add(arg); + MixinNode mixinNode = new MixinNode("left", argValueList); + dataBlock.appendChild(mixinNode); + root.appendChild(dataBlock); + + try { + mixinVisitor.traverse(root); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + + Assert.assertEquals(1, root.getChildren().size()); + BlockNode dataBlockNode = (BlockNode) root.getChildren().get(0); + VariableNode variable = (VariableNode) dataBlockNode.getChildren().get( + 0); + Assert.assertEquals("dist", variable.getName()); + Assert.assertEquals("float", ((RuleNode) dataBlockNode.getChildren() + .get(1)).getVariable()); + Assert.assertEquals("left", ((RuleNode) dataBlockNode.getChildren() + .get(1)).getValue().getStringValue()); + Assert.assertEquals("margin-left", ((RuleNode) dataBlockNode + .getChildren().get(2)).getVariable()); + Assert.assertEquals(SCSSLexicalUnit.SCSS_VARIABLE, + ((RuleNode) dataBlockNode.getChildren().get(2)).getValue() + .getLexicalUnitType()); + } + + @Test + public void testTopLevelInclude() { + ScssStylesheet root = new ScssStylesheet(); + + MixinDefNode defNode = new MixinDefNode("mixin", null); + defNode.appendChild(new RuleNode("var", null, false, null)); + root.appendChild(defNode); + + MixinNode mixinNode = new MixinNode("mixin", null); + root.appendChild(mixinNode); + + try { + mixinVisitor.traverse(root); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + + Assert.assertEquals(1, root.getChildren().size()); + RuleNode varRule = (RuleNode) root.getChildren().get(0); + Assert.assertEquals("var", varRule.getVariable()); + + } + +} diff --git a/tests/sass/src/com/vaadin/sass/testcases/visitor/NestedPropertiesVisitorTest.java b/tests/sass/src/com/vaadin/sass/testcases/visitor/NestedPropertiesVisitorTest.java new file mode 100644 index 0000000000..48705c157e --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/visitor/NestedPropertiesVisitorTest.java @@ -0,0 +1,51 @@ +package com.vaadin.sass.testcases.visitor; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.tree.NestPropertiesNode; +import com.vaadin.sass.tree.RuleNode; +import com.vaadin.sass.tree.VariableNode; +import com.vaadin.sass.visitor.NestPropertiesVisitor; + +public class NestedPropertiesVisitorTest { + private NestPropertiesVisitor visitor = new NestPropertiesVisitor(); + + @Test + public void testEmptyTreeNoChange() { + ScssStylesheet root = new ScssStylesheet(); + Assert.assertFalse(root.hasChildren()); + visitor.traverse(root); + Assert.assertFalse(root.hasChildren()); + } + + @Test + public void testNoNestPropertiesNodeNoChange() { + ScssStylesheet root = new ScssStylesheet(); + root.appendChild(new VariableNode("", "")); + Assert.assertEquals(1, root.getChildren().size()); + visitor.traverse(root); + Assert.assertEquals(1, root.getChildren().size()); + } + + @Test + public void testNestedPropertiesCanBeUnnested() { + ScssStylesheet root = new ScssStylesheet(); + NestPropertiesNode nested = new NestPropertiesNode("nested"); + RuleNode child0 = new RuleNode("child0", null, false, null); + RuleNode child1 = new RuleNode("child1", null, true, null); + nested.appendChild(child0); + nested.appendChild(child1); + root.appendChild(nested); + + Assert.assertEquals(1, root.getChildren().size()); + visitor.traverse(root); + Assert.assertEquals(2, root.getChildren().size()); + + for (int i = 0; i < root.getChildren().size(); i++) { + RuleNode node = (RuleNode) root.getChildren().get(i); + Assert.assertEquals("nested-child" + i, node.getVariable()); + } + } +} diff --git a/tests/sass/src/com/vaadin/sass/tree/ImportNodeTest.java b/tests/sass/src/com/vaadin/sass/tree/ImportNodeTest.java new file mode 100644 index 0000000000..ff7e4d9034 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/tree/ImportNodeTest.java @@ -0,0 +1,60 @@ +package com.vaadin.sass.tree; + +import org.junit.Assert; +import org.junit.Test; + +import com.steadystate.css.parser.SACMediaListImpl; + +public class ImportNodeTest { + @Test + public void testIsPureCssImportShouldReturnTrueWhenIsURL() { + ImportNode node = new ImportNode("", null, true); + Assert.assertTrue(node.isPureCssImport()); + } + + @Test + public void testIsPureCssImportShouldReturnTrueWhenStartsWithHttp() { + ImportNode node = new ImportNode("http://abc", null, false); + Assert.assertTrue(node.isPureCssImport()); + } + + @Test + public void testIsPureCssImportShouldReturnTrueWhenEndsWithCss() { + ImportNode node = new ImportNode("abc.css", null, false); + Assert.assertTrue(node.isPureCssImport()); + } + + @Test + public void testIsPureCssImportShouldReturnTrueWhenHasMediaQueries() { + SACMediaListImpl ml = new SACMediaListImpl(); + ml.add("screen"); + ImportNode node = new ImportNode("", ml, false); + Assert.assertTrue(node.isPureCssImport()); + } + + @Test + public void testIsPureCssImportShouldReturnFalseInOtherCases() { + ImportNode node = new ImportNode("", null, false); + Assert.assertFalse(node.isPureCssImport()); + } + + @Test + public void testToStringWhenIsURL() { + ImportNode node = new ImportNode("test", null, true); + Assert.assertEquals("@import url(test);", node.toString()); + } + + @Test + public void testToStringWhenIsNotURL() { + ImportNode node = new ImportNode("test", null, false); + Assert.assertEquals("@import \"test\";", node.toString()); + } + + @Test + public void testToStringWithMediaQueries() { + SACMediaListImpl ml = new SACMediaListImpl(); + ml.add("screen"); + ImportNode node = new ImportNode("test", ml, true); + Assert.assertEquals("@import url(test) screen;", node.toString()); + } +} |